The module map

Thirty-one files: teko.tk and the thirty teko_*.tk modules it #includes. The order of those includes is not cosmetic — a module may forward-declare a function a later module defines, but a global has to already exist where it is read, so a file that touches another's tables is included after it. teko_type.tk opens the list because its words have to be reserved before anything else registers, and teko_switch.tk closes it because it consumes what teko_loop.tk and teko_ternary.tk built.

teko_init() in teko.tk is the only place a registration happens; the modules define the handlers and the tables. What each one registers is listed below in the include order.

moduleteachesregisterskeeps
teko_type.tkbool char byte isize usize ptr str, true/false/nullseven type_alias over core ids, one type_new for params—
teko_prefix.tk!b[1], -a.x, ~g[2] read as C# reads themnothing: it is a helper tk_dot/tk_bracket call—
teko_float.tkf32/f64calls float_init() and the two float machines of mc's <float>—
teko_struct.tkthe type table itself, and structsyntax("struct"), on_stmt for a local of struct type, one type_new per declared typetypes, fields, locals in scope, the node table, array-field addresses, counted stores
teko_array.tkT a[N] local and global, a[i], a.Lengthon_stmt for the N_VAR/N_GLOBAL the core buildslocal arrays per scope, global arrays, deferred writes
teko_const.tkconst i64 N = 10 at top level and as a membersyntax("const")folded constants, global and per type
teko_ns.tknamespace A.B, file-scoped namespace A.B;, using, import, qualified namessyntax for the three words, plus syntax_stmt/syntax_expr per namespace segment and per short type namenamespaces, segments, short names, using directives, functions read inside a block namespace
teko_fwd.tkfree order of declaration for a type namesource_claim and on_source — the two lexer callbacks, both registered before any word is reservedthe names the pre-scan found
teko_ref.tkref T / out T parameters and argumentstwo type_new, on_stmt, syntax_expr("ref")/("out")the pointee of every ref/out parameter and argument
teko_iface.tkinterface, its default bodies, its static signaturessyntax("interface")interface methods, (class, interface) pairs, one conformance list per class
teko_trait.tktrait and use A, B; — PHP's flatteningsyntax("trait")traits, queued use entries, flattening depth
teko_generic.tkclass Box<T, const N: i64> by record and replaysyntax_stmt per generic namegenerics, their parameters, the recorded parts, the instances made
teko_class.tkclass, the vtable, virtual/override, constructors, destructors, abstract, partialsyntax("class"), and the honest stop for typemethods, virtual slots, constructors, default arguments
teko_di.tkthe three lifetime markers, inject, scope { }syntax_expr("inject"), syntax_stmt("scope")services, inject sites, open scopes, the cycle stack, per-scope locals
teko_prop.tkT Name { get; set; }, arrow accessors, value, per-accessor visibilitynothing of its own: read by teko_class.tk's member readerproperties, summed over all types
teko_this.tkthe receiver a method does not declare, this, base.m()syntax_expr("this")which type's body is open, and whether it is static
teko_access.tkpublic private protected internal static abstract partial, and Type.membersyntax for the four leading words, and syntax_expr/syntax_stmt per type namethe project root internal is measured from, deferred static accesses
teko_typeof.tknothing of the surface: it is the static-type oracleone pass()the names of one function, and the accesses waiting for the pass
teko_deleg.tkdelegate, contextual and explicit values, lambdas, use (...)syntax("delegate"), on_stmt for the capture taint(delegate, function) thunk pairs, capture lists, by-reference lambdas
teko_heaparr.tkT[] on the heap, new T[n], its guarded indexsyntax_type — the one in this compilerone type row per element type, global T[] declarations
teko_ternary.tkc ? a : bsyntax_infix("?")the placeholder calls the pass rewrites
teko_stmt.tkevery { block, and the honest stops for var, match, when, a local constsyntax_stmt("{") and one per stopped word—
teko_expr.tknew, . as field/method/property accesssyntax_expr("new"), syntax_infix(".")forward-deferred new sites
teko_params.tkparams T[], the array built at the call sitesyntax_infix("[")the parameters the modifier marked, and the declarations carrying one, each shared or not
teko_default.tki64 add(i64 a, i64 b = 10)syntax_param — the one in this compilerone row per free declaration with a parameter list
teko_over.tkoverload of a top-level function by signaturenothing: one pass()every declaration of the unit, and the names declared more than once
teko_ops.tkoperator+ and its siblings as static members, and the unary +syntax_expr("+")the operators each type declares
teko_rc.tknothing of the surface: reference counting injected over every bodyone pass()the loops open at one point of one function
teko_loop.tkwhile, do, for, foreach, and ++/--/+=/-=four syntax_stmt, and word_add for the lexemes the rewrite compares against—
teko_switch.tkboth switch spellings, case, when guards, defaultsyntax_stmt("switch"), syntax_infix("switch")the jump levels a guard has to check after the parse

teko.tk itself teaches nothing. It holds the includes, teko_init(), and the two subcommand handlers core_teko.mc registers: tk_build, which prefers DIR/teko.toml over mc's own DIR/mc.toml default before delegating to the driver unchanged, and tk_limits, which recognises a .tk single file the core's own check would not.

Reading a module #

Every module carries a header comment that states the surface it teaches, what the generated code looks like, and the reason for the shape it has. Those headers are the account of record; the pages here summarise them and do not replace them.

Three shapes recur:

The tables #

Each module owns fixed-size global arrays with a TK_MAX* cap and a one-line comment saying what the cap counts. They are sized against a measured count over this tree, not by guess: the self-hosted unit is around eight and a half thousand lines of core plus the modules, which is what raised six of them past their original fixture-sized values (pitfalls.md). Overflowing one is an error with its own message, never silent corruption.

Edit this page