This commit is contained in:
2026-05-01 22:04:21 -05:00
parent 9e6d9c6212
commit 5299ae9d63
2 changed files with 35 additions and 18 deletions

View File

@@ -53,6 +53,7 @@ void VM::run_until_return()
void VM::step()
{
Operation op = code_.operation(loc_.top());
Value a, b;
switch (op.instruction) {
case Instruction::PushInt8:
case Instruction::PushInt16:
@@ -60,55 +61,72 @@ void VM::step()
push_integer(op.operator_);
break;
case Instruction::Sum:
stack_.push(binary_operation(stack_.pop(), stack_.pop(), BinaryOperationType::Sum));
a = stack_.pop(); b = stack_.pop();
stack_.push(binary_operation(a, b, BinaryOperationType::Sum));
break;
case Instruction::Subtract:
stack_.push(binary_operation(stack_.pop(), stack_.pop(), BinaryOperationType::Subtraction));
a = stack_.pop(); b = stack_.pop();
stack_.push(binary_operation(a, b, BinaryOperationType::Subtraction));
break;
case Instruction::Multiply:
stack_.push(binary_operation(stack_.pop(), stack_.pop(), BinaryOperationType::Multiplication));
a = stack_.pop(); b = stack_.pop();
stack_.push(binary_operation(a, b, BinaryOperationType::Multiplication));
break;
case Instruction::Divide:
stack_.push(binary_operation(stack_.pop(), stack_.pop(), BinaryOperationType::Division));
a = stack_.pop(); b = stack_.pop();
stack_.push(binary_operation(a, b, BinaryOperationType::Division));
break;
case Instruction::DivideInt:
stack_.push(binary_operation(stack_.pop(), stack_.pop(), BinaryOperationType::IntegerDivision));
a = stack_.pop(); b = stack_.pop();
stack_.push(binary_operation(a, b, BinaryOperationType::IntegerDivision));
break;
case Instruction::Equals:
stack_.push(binary_operation(stack_.pop(), stack_.pop(), BinaryOperationType::Equality));
a = stack_.pop(); b = stack_.pop();
stack_.push(binary_operation(a, b, BinaryOperationType::Equality));
break;
case Instruction::NotEquals:
stack_.push(binary_operation(stack_.pop(), stack_.pop(), BinaryOperationType::Inequality));
a = stack_.pop(); b = stack_.pop();
stack_.push(binary_operation(a, b, BinaryOperationType::Inequality));
break;
case Instruction::LessThan:
stack_.push(binary_operation(stack_.pop(), stack_.pop(), BinaryOperationType::LessThan));
a = stack_.pop(); b = stack_.pop();
stack_.push(binary_operation(a, b, BinaryOperationType::LessThan));
break;
case Instruction::LessThanEq:
stack_.push(binary_operation(stack_.pop(), stack_.pop(), BinaryOperationType::LessThanOrEquals));
a = stack_.pop(); b = stack_.pop();
stack_.push(binary_operation(a, b, BinaryOperationType::LessThanOrEquals));
break;
case Instruction::GreaterThan:
stack_.push(binary_operation(stack_.pop(), stack_.pop(), BinaryOperationType::GreaterThan));
a = stack_.pop(); b = stack_.pop();
stack_.push(binary_operation(a, b, BinaryOperationType::GreaterThan));
break;
case Instruction::GreaterThanEq:
stack_.push(binary_operation(stack_.pop(), stack_.pop(), BinaryOperationType::GreaterThanOrEquals));
a = stack_.pop(); b = stack_.pop();
stack_.push(binary_operation(a, b, BinaryOperationType::GreaterThanOrEquals));
break;
case Instruction::And:
stack_.push(binary_operation(stack_.pop(), stack_.pop(), BinaryOperationType::BitwiseAnd));
a = stack_.pop(); b = stack_.pop();
stack_.push(binary_operation(a, b, BinaryOperationType::BitwiseAnd));
break;
case Instruction::Or:
stack_.push(binary_operation(stack_.pop(), stack_.pop(), BinaryOperationType::BitwiseOr));
a = stack_.pop(); b = stack_.pop();
stack_.push(binary_operation(a, b, BinaryOperationType::BitwiseOr));
break;
case Instruction::Xor:
stack_.push(binary_operation(stack_.pop(), stack_.pop(), BinaryOperationType::BitwiseXor));
a = stack_.pop(); b = stack_.pop();
stack_.push(binary_operation(a, b, BinaryOperationType::BitwiseXor));
break;
case Instruction::Power:
stack_.push(binary_operation(stack_.pop(), stack_.pop(), BinaryOperationType::Power));
a = stack_.pop(); b = stack_.pop();
stack_.push(binary_operation(a, b, BinaryOperationType::Power));
break;
case Instruction::ShiftLeft:
stack_.push(binary_operation(stack_.pop(), stack_.pop(), BinaryOperationType::ShiftLeft));
a = stack_.pop(); b = stack_.pop();
stack_.push(binary_operation(a, b, BinaryOperationType::ShiftLeft));
break;
case Instruction::ShiftRight:
stack_.push(binary_operation(stack_.pop(), stack_.pop(), BinaryOperationType::ShiftRight));
a = stack_.pop(); b = stack_.pop();
stack_.push(binary_operation(a, b, BinaryOperationType::ShiftRight));
break;
case Instruction::Return: {
Value v = stack_.pop();