dillon1000/react
Commit
Browse files Add HIR "tree" visitor and use it for codegen, alternate printer
Refactors Codegen to extract the core "visit IR as a tree" logic separately from the code to emit JS: * `HIRTreeVisitor` is a new helper that visits the HIR as a tree. You call `visitTree(ir, yourVisitor)` and it drives visiting of the IR, tracking blocks and scopes and calling methods as appropriate. * `Codegen` is now implemented as a Visitor implementation. For example `enterBlock()` creates an empty `Array<t.Statement>`, `leaveBlock()` wraps that in a `t.BlockStatement`, etc. * `printHIRTree()` is a new IR printer (implemented as a visitor) that prints the HIR in tree form, so it retains the original shape of the code but with each block replaced with its IR equivalent.
Changed paths7 files
First-parent comparisoncompiler/forget/src/HIR/Codegen.ts ModifiedA compiler/forget/src/HIR/HIRTreeVisitor.ts AddedA compiler/forget/src/HIR/PrintHIRTree.ts AddedM compiler/forget/src/__tests__/fixtures/hir/mutable-lifetime-loops.expect.md ModifiedM compiler/forget/src/__tests__/fixtures/hir/mutable-lifetime-with-aliasing.expect.md ModifiedM compiler/forget/src/__tests__/fixtures/hir/mutable-liverange-loop.expect.md ModifiedM compiler/forget/src/__tests__/hir-test.ts ModifiedPatch
Files changed
Rendering syntax-highlighted changes…