Support decoding all instructions

This commit is contained in:
Andrew Morris
2022-05-03 16:54:14 +10:00
parent fa64b907e2
commit f387bdd396
2 changed files with 53 additions and 18 deletions

View File

@@ -193,23 +193,6 @@ impl BytecodeDecoder {
}
pub fn decode_instruction(&mut self) -> Instruction {
use Instruction::*;
return match self.decode_byte() {
0x00 => End,
0x01 => Mov,
0x02 => OpInc,
0x04 => OpPlus,
0x05 => OpMinus,
0x06 => OpMul,
0x08 => OpMod,
0x0d => OpTripleNe,
0x11 => OpLess,
0x21 => Call,
0x27 => Jmp,
0x28 => JmpIf,
_ => std::panic!("Not implemented"),
}
return Instruction::from_byte(self.decode_byte());
}
}

View File

@@ -45,3 +45,55 @@ pub enum Instruction {
Jmp = 0x27,
JmpIf = 0x28,
}
impl Instruction {
pub fn from_byte(byte: u8) -> Instruction {
use Instruction::*;
return match byte {
0x00 => End,
0x01 => Mov,
0x02 => OpInc,
0x03 => OpDec,
0x04 => OpPlus,
0x05 => OpMinus,
0x06 => OpMul,
0x07 => OpDiv,
0x08 => OpMod,
0x09 => OpExp,
0x0a => OpEq,
0x0b => OpNe,
0x0c => OpTripleEq,
0x0d => OpTripleNe,
0x0e => OpAnd,
0x0f => OpOr,
0x10 => OpNot,
0x11 => OpLess,
0x12 => OpLessEq,
0x13 => OpGreater,
0x14 => OpGreaterEq,
0x15 => OpNullishCoalesce,
0x16 => OpOptionalChain,
0x17 => OpBitAnd,
0x18 => OpBitOr,
0x19 => OpBitNot,
0x1a => OpBitXor,
0x1b => OpLeftShift,
0x1c => OpRightShift,
0x1d => OpRightShiftUnsigned,
0x1e => TypeOf,
0x1f => InstanceOf,
0x20 => In,
0x21 => Call,
0x22 => Apply,
0x23 => Bind,
0x24 => Sub,
0x25 => SubMov,
0x26 => SubCall,
0x27 => Jmp,
0x28 => JmpIf,
_ => std::panic!("Unrecognized instruction: {}", byte),
};
}
}