Commit 598b60c8

598b60c82c48Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 8 files · +6 added · ~2 modified

Description

Add M1: scalars, locals, operators, control flow, interpolation

Build the real type system and analyzer/codegen architecture on top of the M0 scaffold.

  • src/types.{c,h}: the type lattice as a C enum (scalars + poly top), with unify/numeric helpers. Ports the legacy string-tag vocabulary.
  • src/compiler.{c,h}: the shared Compiler state (per-node type cache + top-level local variable table) -- the in-memory stand-in for the legacy .ir.
  • src/analyze.{c,h}: whole-program inference. Registers locals, reaches a fixpoint on their types, and fills the node type cache. infer_type is the shared type query.
  • src/codegen.c: rewritten for the M1 subset against the exact legacy runtime ABI -- mrb_int/mrb_float/tag-byte strings, hoisted + GC-rooted local decls, sp_int_*/sp_idiv/sp_imod/sp_int_pow/sp_str_concat/sp_str_eq, float arithmetic, string interpolation via sp_sprintf, type-dispatched puts/print/p, and if/unless/while/until.

A mixed scalar program (locals, interpolation, float math, if/else, while, p, print) compiles and matches CRuby output exactly. make test: 1 pass / 1 fail / 842 error (up from 0). The dominant remaining blockers are arrays/hashes, user-method return types (DefNode), and symbols.

Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]

Details

Commit
598b60c82c48
Parent
93530674539e

MakefilemodifiedView file

@@ -298,8 +298,9 @@
298298 # harness invokes cc to link against libspinel_rt.a.
299299
300300 SPINELC = build/spinelc$(EXE)
301-SPINELC_HDRS = src/node_table.h src/codegen.h
302-SPINELC_OBJ = build/csrc/node_table.o build/csrc/codegen.o build/csrc/main.o
301+SPINELC_HDRS = src/node_table.h src/codegen.h src/types.h src/compiler.h src/analyze.h
302+SPINELC_OBJ = build/csrc/node_table.o build/csrc/types.o build/csrc/compiler.o \
303+ build/csrc/analyze.o build/csrc/codegen.o build/csrc/main.o
303304
304305 build/csrc:
305306 @mkdir -p build/csrc