codetranspiler

package module
v1.2.9 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

Local development additions (not yet released)

Native Go analysis is available through NativeAnalysisJSON("go", "input.go", source) and the CLI command native-analysis -source go input.go -o analysis.json. It uses Go's parser and type checker, preserving literal spelling, structured types, source spans, and lexical symbol relations. Imports are currently rejected. The output is an analysis artifact, not an executable SemanticProgram.

The separate NativeSemanticJSON("go", "input.go", source) API and semantic-export -native -source go input.go -o program.json CLI path now produce an executable SemanticProgram for a bounded Go scalar/control subset. They preserve block shadowing and source mapping, and reject unsupported input without falling back to the old parser. Its Go target and embedded runtime are verified alongside Python, Rust, C and C++ for the bounded subset; other targets are gated by the native.go.scalar capability. Native helper functions support bool/string/fixed-width integer parameters, zero or one return value, direct calls and conditional returns. Their sparse caller-to-callee matrix orders declarations and rejects recursion. The additional native.go.functions capability enables the embedded runtime and Go/Python/Rust/C/C++ emission. Argument order, argument side effects and boolean short-circuit behavior are checked against original Go execution after a deterministic JSON roundtrip. Void fallthrough becomes an explicit semantic return. Empty functions, loop returns and ordered effectful operands are included in the executable fixture internal/backend/testdata/native_functions.go. C is also tested with -O2. Architecture-sized integers, floating-point native operations, general imports, recursive functions and Unicode are not yet part of this strict executable subset. Existing default translation remains legacy.

CapabilityMatrixJSON(features) and capability-matrix [feature ...] expose feature-by-target status matrices. Required capabilities now gate emission; unknown dialect operations gate execution and emission.

ImplementationMatrixJSON() and implementation-matrix expose 19 typed integer operations across JSON, runtime, all 13 source adapters and all 13 target adapters (19 x 28). This matrix gates emission directly from the actual operation nodes; removing a document's optional requirement strings cannot bypass it. Its route matrix describes declared availability, not execution-test evidence.

The new tagged_exact_scalars_v1 value contract preserves int8/16/32/64 and uint8/16/32/64 without binary64 conversion. Typed core nodes encode literals, loads, addition/subtraction/multiplication, bit operations, comparisons, formatting, and explicit integer conversions with modular wrap semantics. Division, remainder and shifts are not implemented in this subset. Integer parameter types and value-passing semantics survive the executable JSON codec. The 1,472-case integer matrix uses boundaries and seeded values across all eight domains, with an independent big.Int oracle and optional external runs.

Implemented native input is currently Go. Exact integer target adapters are Go, Python, Rust, C, C++, Java and C#. Other native frontends and exact target adapters remain explicit unsupported matrix entries, not claimed implementations.

See frontend migration status and the complete development instructions for implemented boundaries, the 1,024-case arithmetic differential test, and remaining compiler work.

Go Reference

Code-Transpiler is a matrix-driven many-to-many compiler for 13 programming languages. It is available as a Windows application, a command-line program and an importable Go package.

Go module:   github.com/tarekwasfy01/Code-Transpiler
Go package:  codetranspiler
Executable:  CodeTranspiler.exe

Go package names cannot contain -, so the module and repository are named Code-Transpiler, while the identifier used in Go source is codetranspiler.

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.

See Universal AST migration status for measured direct coverage, target capability matrices and the remaining compatibility adapters.

Route availability means that the supported common subset can be parsed and emitted. It does not claim complete equivalence for every feature of every source and target language.

Supported languages

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

Aliases include py, rs, c++ and c#. The registry therefore exposes 156 directed source-to-target routes (13 × 12).

Install the Go package

go get github.com/tarekwasfy01/Code-Transpiler

Import it:

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

Go automatically binds that import to the declared package name codetranspiler. An explicit alias is also possible:

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

Complete Go API

Translate source code
func Transpile(source, target, code string) (string, error)
package main

import (
	"fmt"
	"log"

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

func main() {
	source := "x = 2\nprint(x + 3)\n"
	generated, err := codetranspiler.Transpile("python", "go", source)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Print(generated)
}

If source and target are identical, the input is returned unchanged. Unsupported input produces an error instead of a silent semantic fallback.

Export SemanticProgram JSON
func SemanticJSON(source, code string) ([]byte, error)
document, err := codetranspiler.SemanticJSON("c", cSource)
if err != nil {
	log.Fatal(err)
}
err = os.WriteFile("program.semantic.json", document, 0o644)

The JSON document stores the executable program and its verified semantic relations. Original source code is not required for later emission.

Translate SemanticProgram JSON
func TranspileSemanticJSON(target string, data []byte) (string, error)
document, err := os.ReadFile("program.semantic.json")
if err != nil {
	log.Fatal(err)
}

rustCode, err := codetranspiler.TranspileSemanticJSON("rust", document)
if err != nil {
	log.Fatal(err)
}

The importer validates the schema version, AST structure, semantic contracts and relation matrices.

List languages
func Languages() []Language
type Language struct {
	ID         string
	Aliases    []string
	Extensions []string
}
for _, language := range codetranspiler.Languages() {
	fmt.Printf("%s %v\n", language.ID, language.Extensions)
}
Language registry as JSON
func LanguagesJSON() ([]byte, error)

This is intended for editors, GUIs and integrations that should consume the compiler registry instead of maintaining their own language list.

Query backend capabilities
func BackendCapability(feature, target string) Capability
type Capability struct {
	Feature string
	Backend string
	Status  string
	Reason  string
}
capability := codetranspiler.BackendCapability("core", "go")
fmt.Println(capability.Status, capability.Reason)

Possible status values:

Status Meaning
native Direct backend representation
lowering Converted to an equivalent lower-level construction
emulated Implemented through generated runtime support
unsupported Must be rejected by the backend

CLI command reference

GUI
CodeTranspiler.exe
CodeTranspiler.exe gui
Help and version
CodeTranspiler.exe help
CodeTranspiler.exe --help
CodeTranspiler.exe -h
CodeTranspiler.exe version
CodeTranspiler.exe --version
Languages and targets
CodeTranspiler.exe languages
CodeTranspiler.exe targets

Both commands list all 13 registered language IDs.

All routes
CodeTranspiler.exe routes

Prints all 156 directed source target pairs as tab-separated rows.

Embedded runtime sources
CodeTranspiler.exe runtimes

Lists generated target-runtime source bundles. Native compilers and interpreters are not bundled.

Translate one file
CodeTranspiler.exe transpile `
  -source <source-id> `
  -target <target-id> `
  input-file `
  -o output-file

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

Defaults are -source auto (file extension) and -target go. If -o is omitted, the output is written beside the input using the target extension. Value flags may appear before or after the input filename.

Batch translation

For one input and all registered targets, use:

go run ./cmd/r2many transpile input.py -target all -o translated
go run ./cmd/r2many transpile -from c -to rust input.c -o output.rs

-from/-to alias -source/-target. The all-target mode parses once and emits 13 outputs including a copy for the identity route. It writes translation-report.json with per-target paths or errors and returns nonzero if any target fails. Source overwrites are refused; implicit identity output uses .transpiled in the filename. Unknown extensions require -source. -native opts into the strict native frontend; unsupported languages/features are rejected without fallback. Default mode retains the existing common-subset frontends for all 13 languages, not complete native-language equivalence.

CodeTranspiler.exe transpile-batch

The command reads a JSON request array from standard input and writes a JSON response array to standard output. No code is executed.

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

Each response contains the same id and either code or error.

Get-Content requests.json |
  .\CodeTranspiler.exe transpile-batch |
  Set-Content responses.json
Export SemanticProgram
CodeTranspiler.exe semantic-export `
  -source python `
  input.py `
  -o program.semantic.json
Translate SemanticProgram
CodeTranspiler.exe semantic-transpile `
  -target rust `
  program.semantic.json `
  -o output.rs

If -o is omitted, generated source is written to standard output.

Query a capability
CodeTranspiler.exe capability <target> <feature>
CodeTranspiler.exe capability go core

Example response:

{
  "feature": "core",
  "backend": "go",
  "status": "lowering",
  "reason": "shared semantic core lowering"
}
Execute R or a generated target
CodeTranspiler.exe run input.R
CodeTranspiler.exe run -target go input.R
CodeTranspiler.exe run -target rust input.R
CodeTranspiler.exe run -target python input.R

run currently accepts R source. Without -target, it uses the embedded compatibility runtime. With -target, it transpiles R and invokes an installed target toolchain.

Target Required external command
Go go
Rust rustc
C++ g++ or clang++
C gcc or clang
Python python, python3 or py
Zig zig
Julia julia
Nim nim
C# csc or dotnet
Java javac and java
Kotlin kotlinc and java
Swift swift or swiftc

SemanticProgram contents

The versioned document includes:

  • executable statements and expressions
  • stable node, scope and binding IDs
  • structured recursive types and exact textual literals
  • operation, dispatch, evaluation and indexing semantics
  • named, default and missing arguments
  • effects and conservative purity information
  • syntax, control, data, binding, scope and evaluation-order matrices
  • contracts, metadata, extensions and capability-gated dialects

Sparse relations use COO encoding:

{
  "rows": 20,
  "cols": 6,
  "storage": "coo",
  "entries": [[0,1,1], [4,3,1]]
}

See SEMANTIC_PROGRAM.md for the complete current format and its semantic boundaries.

Build from source

Requirements:

  • Windows x64
  • Go 1.26 or newer
  • PowerShell
powershell -ExecutionPolicy Bypass -File .\build-onefile.ps1

Output:

dist\CodeTranspiler.exe

The build script runs all source-package tests, generates the Windows icon resource, builds a trimmed x64 executable and validates its PE header, architecture and GUI subsystem.

Run tests without building:

go test ./...

Validation status

The current v1 release has been checked for:

  • 156/156 directed routes producing target output for small common-subset smoke programs
  • SemanticProgram JSON export/import and target generation
  • direct SemanticProgram execution and observation comparison
  • import from a separate Go consumer module
  • tests from the minimal GitHub folder
  • GitHub Actions go test ./...

Routing coverage and full semantic equivalence are reported separately. Complex language-specific constructs may require dialect lowering, runtime emulation or an explicit unsupported result.

License

Code-Transpiler is licensed under the MIT License. See LICENSE. Third-party information is recorded in THIRD_PARTY_NOTICES.md and THIRD_PARTY_NOTICES.txt.

CrossTL source is not bundled. Its possible future role as an external GPU adapter is described in CROSSTL_DESIGN.md.

Repository

Local development: run ./run-matrix-workbench.ps1 in PowerShell to calculate current implementation gaps, analyze type probes and run project tests. Each run writes a fresh report under outputs/matrix-workbench/. See Matrix workbench for calculations, options and the distinction between declared support and execution evidence.

For the combined Go/Python/R/Rust/C++/Kotlin/Java/C# matrix handoffs, use ./run-all-handoffs.ps1; see Joint handoff workflow.

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

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 MarshalSemanticSE added in v1.2.9

func MarshalSemanticSE(program *SemanticProgram) ([]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 SemanticSE added in v1.2.9

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

SemanticSE is the .se-named alias of the lossless SemanticProgram format.

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 TranspileSemanticSE added in v1.2.9

func TranspileSemanticSE(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 ParseSemanticSE added in v1.2.9

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

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
matrix-audit command

Jump to

Keyboard shortcuts

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