Enable voids in bytecode

This commit is contained in:
Andrew Morris
2022-05-16 10:11:19 +10:00
parent 4e712a28b1
commit b940f22040
3 changed files with 10 additions and 1 deletions

View File

@@ -17,6 +17,7 @@ pub struct BytecodeDecoder {
#[derive(PartialEq)]
pub enum BytecodeType {
End = 0x00,
Void = 0x01,
Undefined = 0x02,
Null = 0x03,
False = 0x04,
@@ -37,6 +38,7 @@ impl BytecodeType {
return match byte {
0x00 => End,
0x01 => Void,
0x02 => Undefined,
0x03 => Null,
0x04 => False,
@@ -77,6 +79,7 @@ impl BytecodeDecoder {
pub fn decode_val(&mut self, registers: &Vec<Val>) -> Val {
return match self.decode_type() {
BytecodeType::End => std::panic!("Cannot decode end"),
BytecodeType::Void => Val::Void,
BytecodeType::Undefined => Val::Undefined,
BytecodeType::Null => Val::Null,
BytecodeType::False => Val::Bool(false),

View File

@@ -260,7 +260,12 @@ pub fn op_sub(left: Val, right: Val) -> Val {
return Val::Undefined;
}
return array_data[right_index].clone();
let res = array_data[right_index].clone();
return match res {
Val::Void => Val::Undefined,
_ => res,
};
},
Val::Object(object_data) => {
return object_data

View File

@@ -34,6 +34,7 @@ impl ValTrait for VsPointer {
return match bd.decode_type() {
BytecodeType::End => std::panic!("Invalid: pointer to end"),
BytecodeType::Void => std::panic!("Invalid: pointer to void"),
BytecodeType::Undefined => VsType::Undefined,
BytecodeType::Null => VsType::Null,
BytecodeType::False => VsType::Bool,