Execution — fw-06-compilers
Steps extracted from CONCEPTS.md. Read the concepts first; this file is the doing.
Record results in observation.md; tick checkpoints in verification.md.
3. Build order
- Lexer for a small template language: text, interpolation
{{ }}, elements, attributes, directives. - Parser → AST, with source locations on every node.
- Transforms: interpolation, attribute binding, event binding, conditionals, loops.
- Codegen → a render function returning your
fw-05VNodes. - Static hoisting: detect fully-static subtrees; emit them once.
- Patch flags: annotate dynamic bindings; make your renderer honour them.
- Error reporting with source locations — a caret-and-line message, not a stack trace.
- Then: a JSX-to-
createElementtransform over real JS, using an existing JS parser.
4. Failure Lab
- Drop source locations. Produce a compile error and try to act on it. This is why step 2 says every node.
- Hoist a subtree that is not actually static (it reads a variable). Show the stale render.
- Emit a wrong patch flag — mark a dynamic node static. Show the missed update. This is the central risk of compiler optimisation: a wrong annotation is a silent correctness bug, not a slow one.
- Codegen that breaks on a legal input (nested quotes, unicode, an expression containing
}}).