Skip to main content

Module convert

Module convert 

Source
Expand description

Translate a parsed lux program into a target language’s source.

Each backend — rust, swift, go — walks the same ast the interpreter runs and emits idiomatic source for its target: func becomes fn / func, lux’s enums become Rust variants, Swift cases, or a Go interface, and the top-level statements are wrapped in a main. The point is for a learner to watch their own program turn into the language they’re growing toward, so the output is meant to be read.

lux has no separate type checker yet, so to decide the handful of places where the same lux syntax must emit different code — string + versus numeric +, length on a string versus an array, how a value prints — the shared Types below carries a small type_of that infers an expression’s type on demand from the declared signatures. It assumes a well-formed program; the target compiler is the backstop for anything it can’t see.

Functions§

to_go
Translate a whole program to Go source text.
to_rust
Translate a whole program to Rust source text.
to_swift
Translate a whole program to Swift source text.