Fix unm-instruction

This commit is contained in:
Sofia 2026-03-16 16:44:03 +02:00
parent d04ddd95d0
commit f3870e2e1a
3 changed files with 4 additions and 5 deletions

View File

@ -21,4 +21,4 @@ print(add(10)(15))
print(add(10)(15)) print(add(10)(15))
print(b) print(b)
print(min(11, 9)) print(min(11, 9))
print(10 > 5 or 11 < 10) print(10 - 15)

View File

@ -351,9 +351,8 @@ impl Expression {
)); ));
} }
BinaryOperator::Sub => { BinaryOperator::Sub => {
let temp = scope.register_counter.next(); instructions.push(Instruction::Unm(reg, *rhs.get(0).unwrap()));
instructions.push(Instruction::Unm(temp, *rhs.get(0).unwrap())); instructions.push(Instruction::Add(reg, *lhs.get(0).unwrap(), reg));
instructions.push(Instruction::Add(reg, *lhs.get(0).unwrap(), temp));
} }
BinaryOperator::And => { BinaryOperator::And => {
instructions.push(Instruction::And( instructions.push(Instruction::And(

View File

@ -154,7 +154,7 @@ impl Value {
match self { match self {
Value::Number(lhs) => { Value::Number(lhs) => {
let res = -LuaNumber::from_bits(*lhs); let res = -LuaNumber::from_bits(*lhs);
Value::Number((res as u64 as f64).to_bits()) Value::Number(res.to_bits())
} }
_ => Value::Nil, _ => Value::Nil,
} }