.
This commit is contained in:
105
src/vm/vm.cc
105
src/vm/vm.cc
@@ -52,82 +52,49 @@ void VM::run_until_return()
|
||||
|
||||
void VM::step()
|
||||
{
|
||||
|
||||
Operation op = code_.operation(loc_.top());
|
||||
Value a, b;
|
||||
switch (op.instruction) {
|
||||
|
||||
//
|
||||
// stack management
|
||||
//
|
||||
|
||||
case Instruction::PushInt8:
|
||||
case Instruction::PushInt16:
|
||||
case Instruction::PushInt32:
|
||||
push_integer(op.operator_);
|
||||
break;
|
||||
case Instruction::Sum:
|
||||
a = stack_.pop(); b = stack_.pop();
|
||||
stack_.push(binary_operation(a, b, BinaryOperationType::Sum));
|
||||
break;
|
||||
case Instruction::Subtract:
|
||||
a = stack_.pop(); b = stack_.pop();
|
||||
stack_.push(binary_operation(a, b, BinaryOperationType::Subtraction));
|
||||
break;
|
||||
case Instruction::Multiply:
|
||||
a = stack_.pop(); b = stack_.pop();
|
||||
stack_.push(binary_operation(a, b, BinaryOperationType::Multiplication));
|
||||
break;
|
||||
case Instruction::Divide:
|
||||
a = stack_.pop(); b = stack_.pop();
|
||||
stack_.push(binary_operation(a, b, BinaryOperationType::Division));
|
||||
break;
|
||||
case Instruction::DivideInt:
|
||||
a = stack_.pop(); b = stack_.pop();
|
||||
stack_.push(binary_operation(a, b, BinaryOperationType::IntegerDivision));
|
||||
break;
|
||||
case Instruction::Equals:
|
||||
a = stack_.pop(); b = stack_.pop();
|
||||
stack_.push(binary_operation(a, b, BinaryOperationType::Equality));
|
||||
break;
|
||||
case Instruction::NotEquals:
|
||||
a = stack_.pop(); b = stack_.pop();
|
||||
stack_.push(binary_operation(a, b, BinaryOperationType::Inequality));
|
||||
break;
|
||||
case Instruction::LessThan:
|
||||
a = stack_.pop(); b = stack_.pop();
|
||||
stack_.push(binary_operation(a, b, BinaryOperationType::LessThan));
|
||||
break;
|
||||
case Instruction::LessThanEq:
|
||||
a = stack_.pop(); b = stack_.pop();
|
||||
stack_.push(binary_operation(a, b, BinaryOperationType::LessThanOrEquals));
|
||||
break;
|
||||
case Instruction::GreaterThan:
|
||||
a = stack_.pop(); b = stack_.pop();
|
||||
stack_.push(binary_operation(a, b, BinaryOperationType::GreaterThan));
|
||||
break;
|
||||
case Instruction::GreaterThanEq:
|
||||
a = stack_.pop(); b = stack_.pop();
|
||||
stack_.push(binary_operation(a, b, BinaryOperationType::GreaterThanOrEquals));
|
||||
break;
|
||||
case Instruction::And:
|
||||
a = stack_.pop(); b = stack_.pop();
|
||||
stack_.push(binary_operation(a, b, BinaryOperationType::BitwiseAnd));
|
||||
break;
|
||||
case Instruction::Or:
|
||||
a = stack_.pop(); b = stack_.pop();
|
||||
stack_.push(binary_operation(a, b, BinaryOperationType::BitwiseOr));
|
||||
break;
|
||||
case Instruction::Xor:
|
||||
a = stack_.pop(); b = stack_.pop();
|
||||
stack_.push(binary_operation(a, b, BinaryOperationType::BitwiseXor));
|
||||
break;
|
||||
case Instruction::Power:
|
||||
a = stack_.pop(); b = stack_.pop();
|
||||
stack_.push(binary_operation(a, b, BinaryOperationType::Power));
|
||||
break;
|
||||
case Instruction::ShiftLeft:
|
||||
a = stack_.pop(); b = stack_.pop();
|
||||
stack_.push(binary_operation(a, b, BinaryOperationType::ShiftLeft));
|
||||
break;
|
||||
case Instruction::ShiftRight:
|
||||
a = stack_.pop(); b = stack_.pop();
|
||||
stack_.push(binary_operation(a, b, BinaryOperationType::ShiftRight));
|
||||
break;
|
||||
|
||||
//
|
||||
// logical/arithmetic
|
||||
//
|
||||
|
||||
#define BIN_OP(op) { Value a = stack_.pop(); Value b = stack_.pop(); stack_.push(binary_operation(a, b, BinaryOperationType::op)); }
|
||||
case Instruction::Sum: BIN_OP(Sum) break;
|
||||
case Instruction::Subtract: BIN_OP(Subtraction) break;
|
||||
case Instruction::Multiply: BIN_OP(Multiplication) break;
|
||||
case Instruction::Divide: BIN_OP(Division) break;
|
||||
case Instruction::DivideInt: BIN_OP(IntegerDivision) break;
|
||||
case Instruction::Equals: BIN_OP(Equality) break;
|
||||
case Instruction::NotEquals: BIN_OP(Inequality) break;
|
||||
case Instruction::LessThan: BIN_OP(LessThan) break;
|
||||
case Instruction::LessThanEq: BIN_OP(LessThanOrEquals) break;
|
||||
case Instruction::GreaterThan: BIN_OP(GreaterThan) break;
|
||||
case Instruction::GreaterThanEq: BIN_OP(GreaterThanOrEquals) break;
|
||||
case Instruction::And: BIN_OP(BitwiseAnd) break;
|
||||
case Instruction::Or: BIN_OP(BitwiseOr) break;
|
||||
case Instruction::Xor: BIN_OP(BitwiseXor) break;
|
||||
case Instruction::Power: BIN_OP(Power) break;
|
||||
case Instruction::ShiftLeft: BIN_OP(ShiftLeft) break;
|
||||
case Instruction::ShiftRight: BIN_OP(ShiftRight) break;
|
||||
case Instruction::Modulo: BIN_OP(Modulo) break;
|
||||
#undef BIN_OP
|
||||
|
||||
//
|
||||
// function operations
|
||||
//
|
||||
|
||||
case Instruction::Return: {
|
||||
Value v = stack_.pop();
|
||||
stack_.pop_fp();
|
||||
|
||||
Reference in New Issue
Block a user