Commit 1af0d84d
1af0d84d0da3Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 1 file · ~1 modified
Description
docs(codegen): banner the Pre-emission analysis section
Refactor item 2: the pre-emission analysis (the detect_, resolve_,
rewrite_, scan_, infer_, collect_ helpers that turn the parsed
AST into the per-class / per-method / per-ivar tables the emit phase
consumes) spans roughly 3500 lines between collect_all and emit_header
with no top-level marker. Adding two banner comments makes the phase
boundary visible and indexes the Pass-numbering convention used inside
collect_all so a reader landing on a Pass 2.7 call site can find
both the driver and the convention.
Pure documentation — no behavior change. Bootstrap (gen2 == gen3) clean; 199 tests + 56 benches pass.
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- 1af0d84d0da3
- Parent
- ea8f4043d8f0
spinel_codegen.rbmodifiedView file
end end # ============================================================ # Pre-emission analysis # ============================================================ # # Two top-level drivers turn the parsed AST into the per-class / # per-method / per-ivar tables that the emit phase consumes: # # collect_all — populates @cls_*, @meth_*, @const_*, @module_* # tables; runs structural passes (Pass 0-3). # infer_all_returns — refines the tables: param types from call # sites, ivar types from writers, return types # from method bodies. # # Pass-numbering convention used inside collect_all (mirrored in the # `Pass N` comments on each call site): # # Pass 0 collect_module modules first (used by # include lookup later) # Pass 1 collect_class class table + parents # Pass 1.5 detect_circular_inheritance reject cycles before any # parent walker recurses # into them (issue #106) # Pass 2 collect_toplevel_method, top-level defs, constants, # collect_constant, and define_method # collect_define_method # Pass 2.5 infer_lambda_param_types lambda call-site types # flow back into stored # lambda value's params # Pass 2.6 rewrite_instance_eval_calls hoist `recv.instance_eval` # blocks into file-scope # functions with typed # self # Pass 2.7 resolve_module_singleton_ constant-fold module- # accessors level singleton accessors # (issue #126 stage 1) # Pass 3 infer_all_returns return-type inference # with param/ivar refines # # Anything between this banner and `def emit_header` (the start of the # emission phase) is part of pre-emission analysis: the various # detect_*, resolve_*, rewrite_*, scan_*, infer_*, and collect_* # helpers that the two drivers above call into. def collect_all root = @root_id if @nd_type[root] != "ProgramNode" 0 end # ============================================================ # Emission # ============================================================ # # End of pre-emission analysis. From here down, the codegen # consumes the tables built above and writes C: header, runtime # blocks, struct/forward decls, class methods, top-level methods, # main(). emit_header is the entry point; generate_code (above) # orchestrates the order. def emit_header emit_raw("/* Generated by Spinel v2 AOT compiler */") emit_raw("#include <stdio.h>")