Add unimplemented new instruction

This commit is contained in:
Andrew Morris
2022-05-27 12:46:48 +10:00
parent d978dd8004
commit cf4e95456e
6 changed files with 20 additions and 0 deletions

View File

@@ -217,6 +217,7 @@ impl<'a> Assembler<'a> {
("jmpif", Instruction::JmpIf),
("unary+", Instruction::UnaryPlus),
("unary-", Instruction::UnaryMinus),
("new", Instruction::New),
]);
for (word, instruction) in instruction_word_map {
@@ -800,6 +801,7 @@ enum Instruction {
JmpIf = 0x28,
UnaryPlus = 0x29,
UnaryMinus = 0x2a,
New = 0x2b,
}
enum InstructionArg {
@@ -856,6 +858,7 @@ fn get_instruction_layout(instruction: Instruction) -> Vec<InstructionArg> {
JmpIf => Vec::from([Value, Label]),
UnaryPlus => Vec::from([Value, Register]),
UnaryMinus => Vec::from([Value, Register]),
New => Vec::from([Value, Value, Register]),
};
}

View File

@@ -46,6 +46,7 @@ pub enum Instruction {
JmpIf = 0x28,
UnaryPlus = 0x29,
UnaryMinus = 0x2a,
New = 0x2b,
}
impl Instruction {

View File

@@ -10,5 +10,6 @@ mod vs_array;
mod native_function;
mod builtins;
mod math;
mod vs_class;
pub use virtual_machine::VirtualMachine;

View File

@@ -371,6 +371,8 @@ impl VirtualMachine {
UnaryPlus => frame.apply_unary_op(operations::op_unary_plus),
UnaryMinus => frame.apply_unary_op(operations::op_unary_minus),
New => std::panic!("Not implemented"),
};
}

View File

@@ -0,0 +1,11 @@
use std::rc::Rc;
use super::vs_value::Val;
use super::vs_function::VsFunction;
pub struct VsClass {
pub constructor: Rc<VsFunction>,
pub instance_prototype: Val,
}
impl VsClass {}

View File

@@ -5,6 +5,7 @@ use super::vs_function::VsFunction;
use super::virtual_machine::StackFrame;
use super::vs_object::VsObject;
use super::vs_array::VsArray;
// use super::vs_class::VsClass;
use super::operations::{op_sub, op_submov};
#[derive(Clone)]
@@ -18,6 +19,7 @@ pub enum Val {
Array(Rc<VsArray>),
Object(Rc<VsObject>),
Function(Rc<VsFunction>),
// Class(Rc<VsClass>),
Static(&'static dyn ValTrait),
Custom(Rc<dyn ValTrait>),
}