.
This commit is contained in:
26
src/vm/vm.cc
26
src/vm/vm.cc
@@ -25,6 +25,18 @@ void VM::call(size_t n_params)
|
||||
loc_.pop();
|
||||
}
|
||||
|
||||
int32_t VM::to_integer(int index) const
|
||||
{
|
||||
Value i = stack_.at(index);
|
||||
assert_type(i, Type::Integer);
|
||||
return i.as_integer();
|
||||
}
|
||||
|
||||
void VM::push_integer(int32_t value)
|
||||
{
|
||||
stack_.push(Value::CreateInteger(value));
|
||||
}
|
||||
|
||||
void VM::run_until_return()
|
||||
{
|
||||
size_t level = stack_.fp_level();
|
||||
@@ -37,9 +49,21 @@ void VM::step()
|
||||
{
|
||||
Operation op = code_.operation(loc_.top());
|
||||
switch (op.instruction) {
|
||||
// TODO
|
||||
case Instruction::PushInt8:
|
||||
case Instruction::PushInt16:
|
||||
case Instruction::PushInt32:
|
||||
push_integer(op.operator_);
|
||||
break;
|
||||
default:
|
||||
throw VMInvalidOpcode((uint8_t) op.instruction);
|
||||
}
|
||||
loc_.top() = op.next_location;
|
||||
}
|
||||
|
||||
void VM::assert_type(Value const& val, Type type)
|
||||
{
|
||||
if (val.type() != type)
|
||||
throw VMTypeError(type, val.type());
|
||||
}
|
||||
|
||||
} // tyche
|
||||
|
||||
Reference in New Issue
Block a user