This commit is contained in:
Andre Wagner
2026-04-30 09:38:43 -05:00
parent 5843a19b2f
commit 50b55eaeef
4 changed files with 58 additions and 1 deletions

View File

@@ -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