A C#-like language, taught to a compiler that already exists.
teko has no compiler of its own. Thirty-one hook modules and a
runtime teach mc — a small
compiler that compiles itself — the constructs its base grammar leaves out:
class, interface, trait, generics, delegates,
properties, namespaces, dependency injection resolved while compiling and reference
counting scoped to the block. mc enters by release, pinned in one file,
and nothing in its core changes.
-
Taught, never forked
Not one line of
mcchanges for teko's sake. The whole language is hook modules in this repository, registered from ordinary source; whenmcgenuinely cannot express something, the answer is a minimal reproducer sent to that project, never a workaround here.31 modules · 0 lines of mc changed
-
It compiles itself
The taught compiler is one unit, and the proof is a ladder: stock
mcbuilds it, it builds itself, and the third generation comes out byte for byte identical to the second — on five native pairs, each on a machine of that operating system and architecture.cmp teko2.o teko3.o → identical
-
Every construct has an oracle
Forty-five fixtures, each carrying the exit code it must produce, are compiled by the taught compiler and run. What is not taught is refused where it is written, with a short cause; the refusals are a documented surface, not a surprise at run time.
45 fixtures · no silently wrong result
The whole idea, in one file #
teko is not a compiler. It is a set of hook modules that teach one — mc, whose base
grammar already has expressions, statements, functions and loops. What this repository
adds is the delta a C#-shaped surface needs: types with a vtable, conformance through an
interface table, traits flattened at compile time, generics, delegates and lambdas,
properties, namespaces, dependency injection resolved while compiling, and reference
counting that reclaims at the end of a scope. mc enters by release, pinned in
MC_VERSION; a version other than the pin is not expected to build this
tree, and raising the pin is a change of its own.
// expect-exit: 42
#include "rt.tk"
interface Shape {
i64 area();
}
class Square : Shape {
public i64 side;
public Square(i64 s) {
side = s; // `side` is `this.side`: no receiver is written
}
public i64 area() {
return side * side;
}
}
i64 main() {
Shape s = new Square(6); // dispatch through the interface table
return s.area() + 6;
}
That program is compiled and run by the documentation gate, like every other teko sample
on this site: the exit code in its first line is the oracle, and a page whose sample stops
producing it does not merge. The same rule governs the language itself — forty-five
fixtures under tests/, each carrying the exit code it must produce, built by the taught
compiler and executed on five native pairs.
Start with the guide, which reads in order from a first program to packaging; look things up in the reference, which describes only what runs today; read what v0.4.0 refuses before assuming a construct is missing by accident. What is designed and not yet built is kept apart, in the specs, and how the port itself is put together — the modules, the passes, the bootstrap ladder — is the internals.