GSET
Core Concepts

How GSET Works

The pipeline — tree-sitter frontend, typed IR, semantic pass, backend emitter.

GSET is a compiler in the classic sense: it reads source, builds an IR, and writes target source. There is no virtual machine and no interpreter loop.

The pipeline

fib.py
   │   [tree-sitter grammar]
   ▼
 concrete syntax tree ──► [lowering] ──► typed IR (spans, types, diagnostics)
                                          │
                                          ▼
                              [semantic pass]  scope + type inference
                                          │
                                          ▼
                              [backend emitter] ──► target source (complete runnable file)
                                          │
                                          ├── gset transpile  →  stdout or -o file
                                          └── gset run        →  temp dir  →  go run
  1. Frontend — a tree-sitter grammar parses the source; a query-driven lowering pass walks the concrete syntax tree and produces the IR through a validating builder.
  2. IR — every node carries a source span, a type (possibly Unknown), and its language. Imports are first-class IR items that backends are required to consume.
  3. Semantic pass — resolves lexical scopes (a function-local binding shadows a module-level one rather than widening it) and fills types from literals, annotations, arithmetic, calls, and collection elements. Genuinely dynamic code stays Type::Unknown and propagates.
  4. Backend — a Backend trait with a capability matrix, emitting through a CodeWriter that owns indentation.

Capability matrix instead of silent drops

Backends declare support before emission:

enum Support { Native, Desugared, Unsupported }

trait Backend {
    fn id(&self) -> TargetId;
    fn capability(&self, c: Capability) -> Support;
    fn emit_module(&self, m: &Module, w: &mut CodeWriter) -> Result<(), Diagnostic>;
}

The driver queries capability() per construct before emitting. Unsupported becomes a typed error or an explicit // gset(unsupported): marker — never a silent return nil.

Startup design

Invocation latency is the dominant cost in a per-invocation transpiler. The binary does not initialise any grammar, and does not populate any language registry, until transpile or run has established which language is actually needed. Grammars are Cargo features, so a grammar is only linked into binaries that use it.

The gate that mechanises correctness

Every corpus program must transpile into output that passes the target language's own syntax checker — today gofmt and go vet; from M2 the full set (gofmt/go vet, python -m py_compile, node --check, javac, ruby -c). && into Ruby, ?? into Go, []interface{}{} into Java: none of it can survive this gate.

Next: Configuration.

On this page