mirror of
https://github.com/imjasonh/nescript
synced 2026-07-08 08:55:38 +00:00
Function bodies can declare local variables with \`var NAME: u8 = …\`. Previously the lowering created a VarId for them but didn't track it on the \`IrFunction.locals\` list, so the IR codegen had no address to map it to and \`LoadVar\` / \`StoreVar\` silently did nothing. The generated function body read and wrote random temp slots. Fixes: - Lowering: replaced the per-function \`locals\` local with a long-lived \`current_locals\` field; \`lower_function\` resets it on entry and moves it into the \`IrFunction\` at exit. Each \`Statement::VarDecl\` inside a function body appends to \`current_locals\`. - IR codegen: iterate every function's \`locals\` list. Params 0..4 still map to \$04-\$07, and the remaining locals get addresses in main RAM starting at \$0300. Each function's locals are disjoint, so nested calls don't corrupt each other's state. - Integration test \`program_with_function_local_variables\` exercises nested calls with function-local state to guard against regression. https://claude.ai/code/session_01W6eQFStA66EuMKHUFo2rx3 |
||
|---|---|---|
| .. | ||
| integration | ||
| integration_test.rs | ||