MIR: lexical scoping + builder vars modules

This commit is contained in:
nyash-codex
2025-12-13 01:30:04 +09:00
parent 5c75506dcc
commit 1fae4f1648
16 changed files with 388 additions and 29 deletions

View File

@ -21,7 +21,7 @@ Assignment to an identifier resolves as follows:
1) If a `local` declaration with the same name exists in the current block, update that binding.
2) Otherwise, search outward through enclosing blocks and update the first found binding.
3) If no binding exists in any enclosing scope, create a new binding in the current scope.
3) If no binding exists in any enclosing scope, it is an error (undeclared variable). Declare it with `local`.
This matches intuitive blockscoped semantics (Lualike), and differs from Python where inner blocks do not create a new scope (function scope), and assignment would create a local unless `nonlocal`/`global` is used.
@ -63,4 +63,3 @@ The above semantics are enforced consistently across:
- LLVM harness/EXE: parity tests validate identical exit codes/behavior.
See also: quick/integration smokes `scope_assign_vm.sh`, `vm_llvm_scope_assign.sh`.