Skip to content

Conversation

@mjf
Copy link
Contributor

@mjf mjf commented Oct 10, 2025

This patchset aligns Space Lua arithmetic model with standard Lua. It also extends arithmetic test suite for Space Lua.

Copy link
Collaborator

@zefhemel zefhemel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, this is looking simpler than before. As I understand it you do end up using a boxed value (new Number) in the end and do all the conversions around that. Is Number somehow preserving whether a value was an integer or a float? I don't really understand this part.

@mjf
Copy link
Contributor Author

mjf commented Oct 13, 2025

We only add distinction for zero and only when needed in order to align with Lua. Number itself does not preserve int vs float but we do, via a Symbol tag, on boxed +0 and by recomputing "integerness" for non-zero values.

@mjf mjf requested a review from zefhemel October 13, 2025 08:40
mjf added 2 commits October 13, 2025 12:35
Signed-off-by: Matouš Jan Fialka <[email protected]>
@mjf
Copy link
Contributor Author

mjf commented Oct 13, 2025

The code seems to be working as expected (as I hope). There is some code left that may be deduplicated into helper wrappers but I am uncertain about this step for I do not know what the impact of extra function calls to these wrappers would be in terms of performance. It won't be hard to make this step later...

It does not break anything for me and also passes all checks and tests. I also do not see any performance impact personally. Both does not mean there is not some issue left, or some performance regression will occure.

This branch also adds missing __unm and __bnot metamethods. The implementation is still missing the __len and correct #. As I realized the # operator is misbehaving now (as well as the accompanied unimplemented __len metamethod) which should be fixed. But not here. I'd rather create separate FR for it (and perhaps take over it) for it is not strictly speaking an arithmetical operation and it will definitely need some extra work to make it aligned with Lua.

__len: the length (#) operation. If the object is not a string, Lua will try its metamethod. If there is a metamethod, Lua calls it with the object as argument, and the result of the call (always adjusted to one value) is the result of the operation. If there is no metamethod but the object is a table, then Lua uses the table length operation (see §3.4.7). Otherwise, Lua raises an error. -- docs

mjf added 3 commits October 13, 2025 14:41
- add new basic tests
- add helper for negative tests
- add more negative tests
- fix few typos

Signed-off-by: Matouš Jan Fialka <[email protected]>
@mjf mjf changed the title Align Space Lua arithmetic model with standard Lua Space Lua: Align arithmetic model with standard Lua Oct 15, 2025
@zefhemel zefhemel merged commit 27339c9 into silverbulletmd:main Oct 16, 2025
2 checks passed
@zefhemel
Copy link
Collaborator

Alright, this works for me. I mostly understand what's happening here. Thanks for the effort!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants