Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Go Backend

Third target. Status: v2 — verified; go vet is clean and the full conformance suite passes in go test.

Representation

LTGo
Int (i64)int64 — overflow wrapping is built into Go
Floatfloat64; division goes through lt.FDiv so 1.0/0.0 is not rejected by the compiler as a constant
Strstring; code point operations use lt.StrLen/StrSlice/StrChars/...
Boolbool
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) -> Rfunc(A) R; a lambda becomes a func literal
Valueprelude 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)
enumlt.Variant with Type = enum name + constructor EnumVariant(...); structural display from Type/Tag/Values, with no per-enum display function
structstruct with exported fields + NewUser(...); embed fields remain regular fields, widening becomes a field access (users.TableInfo)
package-level functionsfunc Name(...) for export, func name(...) (camelCase) for private
package bindingsvar Name T = … / var name T = …
packageone package directory: gen/<package>/<package>.go
receiver functionsremain package-level functions; p.len() becomes len(p) when lowering
Display/Eq/Ordlt.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 templatecall to a package-level function with lt.List[string] + lt.List[T]
matchswitch __m.Tag { case "Some": ... }
JSXcall 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/Result payloads are stored as any; 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).
  • Ordering is not exposed on the language surface yet.
  • Builtins are only available as receivers (xs.Map(…)), not list.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.