Commit Graph
7 Commits
Author SHA1 Message Date
Matouš Jan FialkaandGitHub 9419cdcd9b Space Lua: <close> attribute, __close metamethod and extensive tests (#1791)
Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
2026-01-28 09:05:23 +01:00
Matouš Jan FialkaandGitHub 5b03ed872c Space Lua: Add <const> attribute (#1715)
* Space Lua: Implement <const> attribute

Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>

* Space Lua: Implement <const> attribute

- Add Lua attributes with parse time validation
- Add `<const>` attribute semantic tests

Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>

---------

Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
2025-12-03 15:44:15 +01:00
Matouš Jan FialkaandGitHub 7912f05949 Space Lua: Add goto and labels support (#1686)
* 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>
2025-11-18 16:35:08 +01:00
Zef HemelandGitHub 272f293ddb Optional client encryption (#1640)
Implements #1268
2025-10-22 15:35:37 +02:00
onespacemanandGitHub c797273028 Expose codemirror's toggleComment command (#1635) 2025-10-16 08:18:46 +02:00
Matouš Jan FialkaandGitHub e91bec71c0 Fix Lua arithmetic model (#1587)
This patch fixes the Lua arithmetic model at parser level only. Runtime
level fixtures are left for future work.

MOTIVATION

Space Lua treats all numbers as IEEE-754 doubles (JS semantics), so it
preserves negative zero. Lua uses integers and floats. The literal "-0"
in Lua is parsed as unary minus applied to the integer literal "0",
which yields the integer "0" (no sign). This difference flips the sign
of the divisor in "1/-0" and "-1/-0". Although it could be fixed without
touching the parser by changing only unary minus evaluation, this commit
goes a little further and provides integer vs float differenciating at
the parser level as well uses it to fix the unary minus evaluation.

Extensive tests are added to test this exact change works and the Space
Lua arithmetic model is aligned with Lua. Note that things like `-(expr)`
in general may still produce results inconsistent with Lua. This cannot
be fixed at parser level and must be fixed at runtime level which will
need far more complex change to the Space Lua interpreter code. Therefor
these cases we omitted from the tests.

Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
2025-10-03 16:31:00 +02:00
Zef Hemel f4336bf09f Code restructuring: eliminated the top-level lib/ directory 2025-09-23 17:00:34 +02:00