codetranspiler

package module
v1.2.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 8, 2026 License: MIT Imports: 5 Imported by: 0

README

Code Transpiler

code-transpiler-logo

Go Reference   Get it from Microsoft

Semantic Programming Language

The Semantic Programming Language (.sp) originated from Code Transpiler and its language-independent SemanticProgram / Universal AST.

Code Transpiler remains the associated Go package, reference implementation and bootstrap compiler.

Semantic Programming Language:

https://github.com/tarekwasfy01/Semantic-Programming-Language


About

Code Transpiler is a matrix-driven many-to-many compiler and transpiler for 13 programming languages.

It provides:

  • Go package
  • Windows application
  • command-line interface
  • SemanticProgram / UAST
  • source-to-source transpilation
  • native x86-64 compilation
  • assembly, machine-code, object and executable processing
  • binary-to-Semantic lifting
Go module:  github.com/tarekwasfy01/Code-Transpiler
Go package: codetranspiler
Executable: CodeTranspiler.exe

Run the API example directly

The list-languages example is its own ready-to-run Go module. No manual go mod init or go get step is required:

cd examples/list-languages
go run .

On Windows, examples\list-languages\run.cmd performs dependency tidying and runs the example automatically. The importable library supports pure-Go builds with CGO_ENABLED=0; the optional external grammar scanner reports a capability error only when a grammar that actually requires it is used.

The compiler lowers supported constructs into SemanticProgram, whose canonical state is the matrix-derived Universal AST. The old recursive statement/expression tree is retained only as a generated compatibility view. The semantic runtime, R writer, signature checks, call resolution, typed operation checks, generic emitters and function-flow analysis now consume universal nodes directly. No legacy function or call tree is reconstructed. Canonical JSON contains universal nodes, semantic facets, typed fields, language projection, source positions and graph relations. A backend rejects UAST semantics that its direct or compatibility lowering cannot preserve.

ID Language Extensions
r R .R, .r
go Go .go
rust Rust .rs
cpp C++ .cpp, .cc, .cxx, .hpp
c C .c, .h
python Python .py
zig Zig .zig
julia Julia .jl
nim Nim .nim
csharp C# .cs
java Java .java
kotlin Kotlin .kt
swift Swift .swift

The registry exposes 156 directed source-to-target routes.


Install the Go Package

go get github.com/tarekwasfy01/Code-Transpiler

Import:

import codetranspiler "github.com/tarekwasfy01/Code-Transpiler"

Example:

package main

import (
    "fmt"
    "log"

    codetranspiler "github.com/tarekwasfy01/Code-Transpiler"
)

func main() {
    code, err := codetranspiler.Transpile(
        "python",
        "go",
        "print(2 + 3)",
    )
    if err != nil {
        log.Fatal(err)
    }

    fmt.Print(code)
}

Main Go API

Transpile source
func Transpile(source, target, code string) (string, error)
Export SemanticProgram JSON
func SemanticJSON(source, code string) ([]byte, error)
Export Semantic .sp
func SemanticSP(source, code string) ([]byte, error)
Load .sp
func ParseSemanticSP(data []byte) (*SemanticProgram, error)
Write .sp
func MarshalSemanticSP(program *SemanticProgram) ([]byte, error)
Transpile Semantic JSON
func TranspileSemanticJSON(target string, data []byte) (string, error)
Transpile Semantic .sp
func TranspileSemanticSP(target string, data []byte) (string, error)
Compile
func Compile(source string, options CompileOptions) (CompileResult, error)
Languages
func Languages() []Language
func LanguagesJSON() ([]byte, error)
Capabilities
func BackendCapability(feature, target string) Capability
func CapabilityMatrixJSON(features []string) ([]byte, error)
func ImplementationMatrixJSON() ([]byte, error)
Native Go analysis
func NativeAnalysisJSON(source, filename, code string) ([]byte, error)
func NativeSemanticJSON(source, filename, code string) ([]byte, error)
Binary / executable lifting
func BinarySemanticJSON(data []byte, options CompileOptions) ([]byte, error)
func DecompileSemanticJSON(data []byte, options CompileOptions) ([]byte, error)

Command-Line Interface

All commands use:

CodeTranspiler.exe <command>

The compact alias is also available:

CodeTranspiler.exe sp <command>

GUI

Start the graphical application:

CodeTranspiler.exe

or:

CodeTranspiler.exe gui

Help

CodeTranspiler.exe help
CodeTranspiler.exe --help
CodeTranspiler.exe -h

Version

CodeTranspiler.exe version
CodeTranspiler.exe --version

Displays version, commit, build date and compiler engine information.


Licenses

CodeTranspiler.exe licenses

Also accepted:

CodeTranspiler.exe licences
CodeTranspiler.exe --licenses
CodeTranspiler.exe --licences

Displays bundled third-party license information.


Languages

CodeTranspiler.exe languages

or:

CodeTranspiler.exe targets

Lists registered language IDs, names and extensions.


Routes

CodeTranspiler.exe routes

Lists all directed source-to-target language routes.


Runtime Bundles

CodeTranspiler.exe runtimes

Lists embedded target-runtime source bundles.


Transpile Source Code

CodeTranspiler.exe transpile `
  -source python `
  -target go `
  input.py `
  -o output.go

Aliases:

-source = -from
-target = -to

Examples:

CodeTranspiler.exe transpile -source c -target go input.c -o output.go
CodeTranspiler.exe transpile -source go -target rust input.go -o output.rs
CodeTranspiler.exe transpile -source python -target cpp input.py -o output.cpp
CodeTranspiler.exe transpile -source r -target julia input.R -o output.jl

Automatic source detection:

CodeTranspiler.exe transpile input.py -target rust -o output.rs

Generate all registered targets:

CodeTranspiler.exe transpile input.py -target all -o translated

Strict native frontend where supported:

CodeTranspiler.exe transpile -native -source go -target rust input.go -o output.rs

Batch Transpilation

CodeTranspiler.exe transpile-batch

Reads a JSON array from standard input:

[
  {
    "id": "python-go",
    "source": "python",
    "target": "go",
    "code": "print(2 + 3)"
  },
  {
    "id": "c-rust",
    "source": "c",
    "target": "rust",
    "code": "int main(void) { return 0; }"
  }
]

Example PowerShell pipeline:

Get-Content requests.json |
  .\CodeTranspiler.exe transpile-batch |
  Set-Content responses.json

Run Source Code

Embedded execution:

CodeTranspiler.exe run -source python -target embedded input.py

Run through a target:

CodeTranspiler.exe run -source c -target go input.c

Aliases:

CodeTranspiler.exe run -from python -to embedded input.py

SemanticProgram Export

Export JSON:

CodeTranspiler.exe semantic-export `
  -source go `
  input.go `
  -o program.semantic.json

Export Semantic .sp:

CodeTranspiler.exe semantic-export `
  -source go `
  -format sp `
  input.go `
  -o program.sp

Export compressed .spz:

CodeTranspiler.exe semantic-export `
  -source go `
  -format spz `
  input.go `
  -o program.spz

Strict native Go frontend:

CodeTranspiler.exe semantic-export `
  -native `
  -source go `
  input.go `
  -o program.semantic.json

Semantic Transpilation

From JSON:

CodeTranspiler.exe semantic-transpile `
  -target rust `
  program.semantic.json `
  -o output.rs

From .sp:

CodeTranspiler.exe semantic-transpile `
  -target rust `
  program.sp `
  -o output.rs

From .spz:

CodeTranspiler.exe semantic-transpile `
  -target rust `
  program.spz `
  -o output.rs

Semantic Format Conversion

JSON to .sp:

CodeTranspiler.exe semantic-convert `
  program.semantic.json `
  -o program.sp

.sp to JSON:

CodeTranspiler.exe semantic-convert `
  program.sp `
  -o program.semantic.json

.sp to .spz:

CodeTranspiler.exe semantic-convert `
  program.sp `
  -o program.spz

.spz to .sp:

CodeTranspiler.exe semantic-convert `
  program.spz `
  -o program.sp

Format Semantic .sp

CodeTranspiler.exe semantic-format program.sp

Write formatted output:

CodeTranspiler.exe semantic-format `
  program.sp `
  -o formatted.sp

Validate SemanticProgram

Validate .sp:

CodeTranspiler.exe semantic-validate program.sp

Validate .spz:

CodeTranspiler.exe semantic-validate program.spz

Validate JSON:

CodeTranspiler.exe semantic-validate program.semantic.json

Successful validation prints:

VALID

Semantic Information

CodeTranspiler.exe semantic-info program.sp

Also accepts JSON and .spz.

Returns information such as:

  • schema version
  • source language
  • evaluation model
  • UAST presence
  • semantic node count

Native Compilation

Compile Go directly to a Windows x86-64 executable:

CodeTranspiler.exe compile `
  -source go `
  -target native-x86_64-windows `
  input.go `
  -o program.exe

Compile Semantic:

CodeTranspiler.exe compile `
  -source sp `
  input.sp `
  -o program.exe

Available native output targets:

native-x86_64-windows
object-x86_64-windows
machine-x86_64
asm-x86_64

Machine Code

CodeTranspiler.exe compile `
  -source go `
  -target machine-x86_64 `
  input.go `
  -o program.bin

Hexadecimal output:

CodeTranspiler.exe compile `
  -source go `
  -target machine-x86_64 `
  --hex `
  input.go

Assembly

CodeTranspiler.exe compile `
  -source go `
  -target asm-x86_64 `
  input.go `
  -o program.asm

Object File

CodeTranspiler.exe compile `
  -source go `
  -target object-x86_64-windows `
  input.go `
  -o program.obj

Compile Options

Common options:

-source <language>
-target <target>
-input <kind>
-output <kind>
-arch <architecture>
-os <operating-system>
-abi <ABI>
-entry <function>
-o <file>
--hex
--via-assembly

Input kinds:

source
assembly
machine
object
executable

Output kinds:

source
assembly
machine
object
executable

Default native platform:

Architecture: x86_64
OS:           windows
ABI:          win64

--via-assembly explicitly uses an assembly route. Direct native compilation normally uses the internal encoder.


Machine IR

Decode supported low-level input into Machine IR:

CodeTranspiler.exe machine-ir `
  -input machine `
  program.bin `
  -o machine-ir.json

Supported input kinds:

assembly
machine
object
executable

Examples:

CodeTranspiler.exe machine-ir -input assembly program.asm -o machine-ir.json
CodeTranspiler.exe machine-ir -input object program.obj -o machine-ir.json
CodeTranspiler.exe machine-ir -input executable program.exe -o machine-ir.json

Decompile / Semantic Lift

Assembly to SemanticProgram:

CodeTranspiler.exe decompile `
  -input assembly `
  program.asm `
  -o program.semantic.json

Machine code:

CodeTranspiler.exe decompile `
  -input machine `
  program.bin `
  -o program.semantic.json

Object file:

CodeTranspiler.exe decompile `
  -input object `
  program.obj `
  -o program.semantic.json

Executable:

CodeTranspiler.exe decompile `
  -input executable `
  program.exe `
  -o program.semantic.json

Native Go Analysis

CodeTranspiler.exe native-analysis `
  -source go `
  input.go `
  -o analysis.json

Extracts native type, symbol and source information without producing the regular source-language translation output.


Capability Query

CodeTranspiler.exe capability go core

General form:

CodeTranspiler.exe capability <target> <feature>

Returns JSON describing the backend capability.


Capability Matrix

CodeTranspiler.exe capability-matrix

Additional features may be supplied:

CodeTranspiler.exe capability-matrix feature1 feature2

Returns the feature-by-target capability matrix.


Implementation Matrix

CodeTranspiler.exe implementation-matrix

Displays typed operation implementation information across the compiler.


Add Code Transpiler to PATH

Windows:

CodeTranspiler.exe setpath

Adds the installation directory to the machine PATH using an elevated PowerShell process.


Build from Source

Requirements:

  • Go
  • Windows x64
  • PowerShell

Build:

powershell -ExecutionPolicy Bypass -File .\build\build-onefile.ps1

Output:

dist\CodeTranspiler.exe

Run tests:

go test ./...

Build directly with Go:

go build ./...

License

Code Transpiler is licensed under the MIT License.

See:

LICENSE
THIRD_PARTY_NOTICES.md
THIRD_PARTY_NOTICES.txt

Repositories

Code Transpiler

https://github.com/tarekwasfy01/Code-Transpiler

Semantic Programming Language

https://github.com/tarekwasfy01/Semantic-Programming-Language

Documentation

Overview

Copyright (c) 2026 Tarek Wasfy Package codetranspiler exposes the stable many-to-many Code Transpiler API.

Import path: github.com/tarekwasfy01/Code-Transpiler

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BinarySemanticJSON added in v1.2.8

func BinarySemanticJSON(data []byte, options CompileOptions) ([]byte, error)

BinarySemanticJSON lifts an x86-64 assembly, machine-code, COFF, or PE32+ input through the structured machine frontend and returns the same SemanticProgram JSON used by source-language inputs. Unsupported or ambiguous instructions fail closed instead of being guessed as source.

func CapabilityMatrixJSON added in v1.0.5

func CapabilityMatrixJSON(features []string) ([]byte, error)

CapabilityMatrixJSON returns status matrices for semantic requirements across all registered targets. Unknown requested features are unsupported.

func DecompileSemanticJSON added in v1.2.8

func DecompileSemanticJSON(data []byte, options CompileOptions) ([]byte, error)

DecompileSemanticJSON is the public decompilation entry point for binary and assembly inputs. It returns the canonical SemanticProgram JSON emitted by the structured machine frontend, without routing through a source parser.

func ImplementationMatrixJSON added in v1.0.5

func ImplementationMatrixJSON() ([]byte, error)

ImplementationMatrixJSON returns typed operations by frontend, JSON, runtime and target implementation stages. Declarations are not execution test results.

func LanguagesJSON

func LanguagesJSON() ([]byte, error)

func MarshalSemanticSP added in v1.2.8

func MarshalSemanticSP(program *SemanticProgram) ([]byte, error)

MarshalSemanticSP serializes a canonical program as readable SP.

func MarshalSemanticSPZ added in v1.2.8

func MarshalSemanticSPZ(program *SemanticProgram) ([]byte, error)

MarshalSemanticSPZ returns the optional compressed SP transport.

func NativeAnalysisJSON added in v1.0.5

func NativeAnalysisJSON(source, filename, code string) ([]byte, error)

NativeAnalysisJSON extracts native types, source spans and symbol relations. Currently supports import-free Go files. This is an analysis artifact, not an executable SemanticProgram; TranspileSemanticJSON intentionally rejects it.

func NativeSemanticJSON added in v1.0.5

func NativeSemanticJSON(source, filename, code string) ([]byte, error)

NativeSemanticJSON converts a supported native source subset directly to an executable SemanticProgram. It never retries the legacy textual frontend. Accepts a bounded Go scalar/function subset, including fixed-width integers.

func SemanticJSON

func SemanticJSON(source, code string) ([]byte, error)

func SemanticSP added in v1.2.8

func SemanticSP(source, code string) ([]byte, error)

SemanticSP exports a source program as the readable, lossless Semantic Programming transport format.

func Transpile

func Transpile(source, target, code string) (string, error)

func TranspileSemanticJSON

func TranspileSemanticJSON(target string, data []byte) (string, error)

func TranspileSemanticSP added in v1.2.8

func TranspileSemanticSP(target string, data []byte) (string, error)

TranspileSemanticSP imports the canonical SP transport and emits a target through the same UAST backend used by JSON and source APIs.

Types

type Capability

type Capability struct {
	Feature string `json:"feature"`
	Backend string `json:"backend"`
	Status  string `json:"status"`
	Reason  string `json:"reason,omitempty"`
}

func BackendCapability

func BackendCapability(feature, target string) Capability

type CompileOptions added in v1.2.1

type CompileOptions = backend.CompileOptions

type CompileResult added in v1.2.1

type CompileResult = backend.CompileResult

func Compile added in v1.2.1

func Compile(source string, options CompileOptions) (CompileResult, error)

Compile uses the same ModernFrontend and canonical UAST as Transpile. Native outputs are encoded in-process; Assembly is an optional rendering.

type Language

type Language struct {
	ID         string   `json:"id"`
	Aliases    []string `json:"aliases"`
	Extensions []string `json:"extensions"`
}

func Languages

func Languages() []Language

type SemanticProgram added in v1.2.8

type SemanticProgram = backend.SemanticProgram

func ParseSemanticSP added in v1.2.8

func ParseSemanticSP(data []byte) (*SemanticProgram, error)

ParseSemanticSP imports a readable SP document into the canonical program.

func ParseSemanticSPZ added in v1.2.8

func ParseSemanticSPZ(data []byte) (*SemanticProgram, error)

ParseSemanticSPZ imports the optional compressed SP transport.

type TranspileRequest added in v1.0.6

type TranspileRequest = manytomany.TranspileRequest

TranspileRequest and TranspileTrace expose the same immutable diagnostic boundary used by the bundled GUI and CLI.

type TranspileTrace added in v1.0.6

type TranspileTrace = manytomany.TranspileTrace

func TranspileWithTrace added in v1.0.6

func TranspileWithTrace(request TranspileRequest) (string, TranspileTrace, error)

TranspileWithTrace is useful for differential diagnostics: it returns the exact hashes and native/runtime decision made by the common TranspileCore.

Directories

Path Synopsis
cmd
r2many command
repair-frozen command
signature-bind command
sp-closure command
internal
ui
matrices
matrix-audit command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL