* Space Lua: Refactor control flow signals
Removes "return throws an exception" failure mode. @zef :)
Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
* Remove unused function
Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
* Remove another unused function
Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
* Remove unused `LuaBreak`/`LuaReturn` exception control flow
Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
---------
Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
* Space Lua: `<close>` attribute, `__close` metamethod and extensive tests
Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
* Space Lua: Align arithmetical error messages with Lua 5.4
**Fixes:**
- Tighten `tonumber` semantics to accept hex floats like `0x1.2` while
keeping plain hex as integers.
- Improve Lua compatibility by fixing relational `>`/`>=` operand
ordering to preserve correct error type direction.
**Changes:**
- Update concatenation errors to include the operand type.
- Add `LuaStringCoercionError` from numeric coercion and handle it
in `luaOp()` to emit correct messages (or fallback).
- Raise
> `bad argument #2 to 'tonumber' (base out of range)`
for invalid bases.
- Update test suite
**Notes:**
- The `arithmetic_test.lua` test suite now passes if run with Lua 5.4.
Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
* Run `make fmt`
Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
* Rename `assert_throws` to `assertThrows` in Lua test suite
Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
* Replace `LuaStringCoercionError` class with sentinel constant
Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
---------
Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
* Space Lua: Add AST block type label/goto and duplicated label bools
* Space Lua: Add label/goto resolution and evaluation
Add per block map of labels metadata, per function block metadata cache
and `processBlock` to track AST blocks (`If`, `While`, `Repeat`, `For`
and `ForIn`, and `Do`) while recording labels and their positions.
Align with Lua scoping rules (_e.g._, a `goto` can not jump into the
scope of a local). Also allow the super-special "safe" end of block
cases (except inside `Repeat`). Duplicated labels are detected (error
`label 'foo' is already defined` etc.). The AST context for error
reporting is preserved. The `WeakMap` caches map any block to its
function's metadata.
Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
* Space Lua: The `goto` parse flags and eval path
At parser mark each block with `hasLabel`/`hasGoto` and record the first
duplicated label. Flags then propagate through blocks and control flow.
If no `goto`, run the block in a simple loop and raise duplicate label
error if any is present. If `goto` exists, jump via a label map.
Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
* Space Lua: Add labels and `goto` statement test suite
Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
* Space Lua: Minor `goto`/labels improvement and test hotfix
- The `getBlockGotoMeta` now called only when a block has either
`hasGoto` or `hasLabel`.
- Add `BlocksFlags` type to get rid of some `(... as any)`s by view.
- Add `blockMetaOrThrow` helper.
- Fix test to reflect standard Lua semantics.
Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
* Space Lua: Goto: Add missing Lua semantics checks
Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
* Space Lua: Goto: Add Lua semantics checks also covered in Lua tests
Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
* Space Lua: Goto: Fix semantic divergence revealed by fixing unfinished test
Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
* Fix typo
Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
* Space Lua: Optimize block env creation and cache goto metadata
Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
* Avoid using the venomous snake case
Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
* Add comment for WeakMap use
Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
* Space Lua: Block Label Fast-path Optimization
Add block flag `hasLabelHere` during parsing and use it in eval to skip
expensive metadata generation for blocks and entire functions without
label or goto.
Refactor eval logic:
- early fast path when a function is known to have no label/goto,
- later fast path for blocks in functions with goto.
Fetch metadata only when needed.
Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
* Space Lua: Remove `BlockFlags` indirection from eval
- Add `hasLabelHere` flag to `LuaBlock`.
- Remove `BlockFlags` indirection from eval.
- Set `hasLabelHere` directly.
- Add some "guards".
- Improve consistency of child filtering.
Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
* Remove redundant return statement
Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
---------
Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
* Add result-or-promise (RP) exec model to interpreter (async-first).
* Add centralized table property access with fast misses.
* Update table string keys to be object map.
* Update error contexts to be more consistent and precise.
* Update evaluator to return either values or _Promises_.
* Update func calls, unary and bin operations, and expression lists.
* Update _stdlib_ to the changes and improve errors.
* Add tests to validate async control flow and error contexts.
* Add dedicated benches that isolate the _runtime_ from parsing.
* Align Space Lua arithmetic model with standard Lua
* Add missing __unm and __bnot metamethods
- add new basic tests
- add helper for negative tests
* Add comments for ASCII numeric constants
Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>