Go Backend
Third target. Status: v2 — verified; go vet is clean and the full conformance suite
passes in go test.
Representation
| LT | Go |
|---|---|
Int (i64) | int64 — overflow wrapping is built into Go |
Float | float64; division goes through lt.FDiv so 1.0/0.0 is not rejected by the compiler as a constant |
Str | string; code point operations use lt.StrLen/StrSlice/StrChars/... |
Bool | bool |
List<T> | lt.List[T] |
Map<K,V> | lt.Map[K,V] (ordered entries, lookup via binary search) |
Dict<V> | lt.Dict[V] (Str keys, insertion order, map[string]V index) |
fn(A) -> R | func(A) R; a lambda becomes a func literal |
Value | prelude enum value as lt.Variant; lt.JSONParse/JSONStringify + lt.ValueFactory |
Set<T> | lt.Set[T] |
Option<T> / Result<T,E> | lt.Variant (Tag, Order, Type, Values) |
enum | lt.Variant with Type = enum name + constructor EnumVariant(...); structural display from Type/Tag/Values, with no per-enum display function |
struct | struct with exported fields + NewUser(...); embed fields remain regular fields, widening becomes a field access (users.TableInfo) |
| package-level functions | func Name(...) for export, func name(...) (camelCase) for private |
| package bindings | var Name T = … / var name T = … |
package | one package directory: gen/<package>/<package>.go |
| receiver functions | remain package-level functions; p.len() becomes len(p) when lowering |
Display/Eq/Ord | lt.Disp, lt.Eq, lt.Cmp via the LtDisplay/LtEq/LtCmp methods on structs; lt.Variant renders its own display from Type/Tag/Values |
? | if __try.Tag == "err"/"none" { return __try } |
to_string() | lt.Disp(value) |
| tagged template | call to a package-level function with lt.List[string] + lt.List[T] |
match | switch __m.Tag { case "Some": ... } |
| JSX | call to New<Struct>(...) |
expect.eq etc. | lt.ExpectEqual / ExpectNotEqual / ExpectTrue / ExpectFalse |
test "title" | func TestTitle(t *testing.T) in <package>_test.go, in the same package |
Tests are emitted as package <name> (not <name>_test) so that private helpers in that package
remain callable — Go does not export lowercase identifiers to other packages.
Package structure
out/go/
go.mod module linguatungga, go 1.22
lt/runtime.go
gen/<package>/<package>.go one directory per LT package
gen/<package>/<package>_test.go only from `lt test`
Cross-package imports use the module path: import m1 "linguatungga/gen/user".
Test
lt test -t go tests/conformance/*.lt --out out/conformance --run
--run runs go test ./.... The scripts/conformance-go.sh script also runs
go vet ./... and uses the local toolchain at /mnt/A29EE2F79EE2C341/tools/go when go is not
on PATH.
Limitations
- Enum/
Option/Resultpayloads are stored asany; the emitter inserts type assertions it knows from the IR, so type errors still cannot come from an LT program that passed typecheck. - Struct fields are exported to be idiomatic; immutability is enforced by the LT compiler, not Go.
- Generic parameters are erased from enum types (because enums use
lt.Variant). Orderingis not exposed on the language surface yet.- Builtins are only available as receivers (
xs.Map(…)), notlist.map(xs, …).
Formatting
gofmt is context-sensitive (it removes spaces around + in call arguments but
keeps them in return), so the emitter does not mimic it byte for byte. Go output is formatted by
running gofmt -w during packaging; shipped packages must still produce empty gofmt -l output.