This commit is contained in:
Andre Wagner
2026-05-05 21:11:41 -05:00
parent 6428c6cf7f
commit 516ee9f406
4 changed files with 48 additions and 14 deletions

View File

@@ -2,7 +2,7 @@ Progress of the Lua port:
- [x] Assembler - [x] Assembler
- [x] Basic VM execution - [x] Basic VM execution
- [ ] Logic/arithmetic expressions - [x] Logic/arithmetic expressions
- [ ] Functions - [ ] Functions
- [ ] Local variables - [ ] Local variables
- [ ] Calling functions - [ ] Calling functions
@@ -19,6 +19,7 @@ Progress of the Lua port:
- [ ] Tables - [ ] Tables
- [ ] Garbage collection - [ ] Garbage collection
- [ ] Metatables - [ ] Metatables
- [ ] Real
- [ ] Error handling - [ ] Error handling
- [ ] Closures/upvalues - [ ] Closures/upvalues

View File

@@ -57,19 +57,19 @@ Logical/arithmetic:
22 mul Multiply top 2 values in stack 22 mul Multiply top 2 values in stack
23 div Float division 23 div Float division
24 idiv Integer division 24 idiv Integer division
25 eq Equality 25 mod Modulo
26 neq Inequality 26 eq Equality
27 lt Less than 27 neq Inequality
28 lte Less than or equals 28 lt Less than
29 gt Greater than 29 lte Less than or equals
2a gte Greater than or equals 2a gt Greater than
2b and Bitwise AND 2b gte Greater than or equals
2c or Bitwise OR 2c and Bitwise AND
2d xor Bitwise XOR 2d or Bitwise OR
2e pow Power 2e xor Bitwise XOR
2f shl Shift left 2f pow Power
30 shr Shift right 30 shl Shift left
31 mod Modulo 31 shr Shift right
Other value operations: Other value operations:
40 len Get table, array or string size 40 len Get table, array or string size

View File

@@ -158,6 +158,23 @@ end
do do
assert_eq(arith(2, 5, 'sum'):to_integer(-1), 7) assert_eq(arith(2, 5, 'sum'):to_integer(-1), 7)
assert_eq(arith(2, 5, 'sub'):to_integer(-1), -3) assert_eq(arith(2, 5, 'sub'):to_integer(-1), -3)
assert_eq(arith(2, 5, 'mul'):to_integer(-1), 10)
assert_eq(arith(20, 3, 'idiv'):to_integer(-1), 6)
assert_eq(arith(5, 5, 'eq'):to_integer(-1), 1)
assert_eq(arith(5, 5, 'neq'):to_integer(-1), 0)
assert_eq(arith(4, 5, 'lt'):to_integer(-1), 1)
assert_eq(arith(5, 5, 'lt'):to_integer(-1), 0)
assert_eq(arith(4, 5, 'lte'):to_integer(-1), 1)
assert_eq(arith(5, 5, 'lte'):to_integer(-1), 1)
assert_eq(arith(5, 5, 'gt'):to_integer(-1), 0)
assert_eq(arith(5, 5, 'gte'):to_integer(-1), 1)
assert_eq(arith(20, 5, 'and'):to_integer(-1), 4)
assert_eq(arith(20, 5, 'or'):to_integer(-1), 21)
assert_eq(arith(20, 5, 'xor'):to_integer(-1), 17)
assert_eq(arith(2, 5, 'pow'):to_integer(-1), 32)
assert_eq(arith(2, 5, 'shl'):to_integer(-1), 64)
assert_eq(arith(20, 3, 'shr'):to_integer(-1), 2)
assert_eq(arith(20, 3, 'mod'):to_integer(-1), 2)
end end
print('End.') print('End.')

View File

@@ -173,6 +173,22 @@ end
EXPR.sum.integer.integer = function(vm, b, a) vm:push_integer(a + b) end EXPR.sum.integer.integer = function(vm, b, a) vm:push_integer(a + b) end
EXPR.sub.integer.integer = function(vm, b, a) vm:push_integer(a - b) end EXPR.sub.integer.integer = function(vm, b, a) vm:push_integer(a - b) end
EXPR.mul.integer.integer = function(vm, b, a) vm:push_integer(a * b) end
-- TODO - div
EXPR.idiv.integer.integer = function(vm, b, a) vm:push_integer(math.floor(a / b)) end
EXPR.mod.integer.integer = function(vm, b, a) vm:push_integer(a % b) end
EXPR.eq.integer.integer = function(vm, b, a) vm:push_integer((a == b) and 1 or 0) end
EXPR.neq.integer.integer = function(vm, b, a) vm:push_integer((a ~= b) and 1 or 0) end
EXPR.lt.integer.integer = function(vm, b, a) vm:push_integer((a < b) and 1 or 0) end
EXPR.lte.integer.integer = function(vm, b, a) vm:push_integer((a <= b) and 1 or 0) end
EXPR.gt.integer.integer = function(vm, b, a) vm:push_integer((a > b) and 1 or 0) end
EXPR.gte.integer.integer = function(vm, b, a) vm:push_integer((a >= b) and 1 or 0) end
EXPR['and'].integer.integer = function(vm, b, a) vm:push_integer(a & b) end
EXPR['or'].integer.integer = function(vm, b, a) vm:push_integer(a | b) end
EXPR.xor.integer.integer = function(vm, b, a) vm:push_integer(a ~ b) end
EXPR.pow.integer.integer = function(vm, b, a) vm:push_integer(a ^ b) end
EXPR.shl.integer.integer = function(vm, b, a) vm:push_integer(a << b) end
EXPR.shr.integer.integer = function(vm, b, a) vm:push_integer(a >> b) end
---------------------- ----------------------
-- -- -- --