Implement cat as stack frame

This commit is contained in:
Andrew Morris
2023-05-30 12:28:08 +10:00
parent 4164f44ece
commit c12a27a1ff
6 changed files with 98 additions and 34 deletions

View File

@@ -102,17 +102,7 @@ impl BytecodeDecoder {
BytecodeType::SignedByte => (self.decode_signed_byte() as f64).to_val(),
BytecodeType::Number => self.decode_number().to_val(),
BytecodeType::String => self.decode_string().to_val(),
BytecodeType::Array => {
let mut vals: Vec<Val> = Vec::new();
while self.peek_type() != BytecodeType::End {
vals.push(self.decode_val(registers));
}
self.decode_type(); // End (TODO: assert)
vals.to_val()
}
BytecodeType::Array => self.decode_vec_val(registers).to_val(),
BytecodeType::Object => {
let mut string_map: BTreeMap<String, Val> = BTreeMap::new();
let mut symbol_map: BTreeMap<VsSymbol, Val> = BTreeMap::new();
@@ -154,6 +144,18 @@ impl BytecodeDecoder {
};
}
pub fn decode_vec_val(&mut self, registers: &Vec<Val>) -> Vec<Val> {
let mut vals: Vec<Val> = Vec::new();
while self.peek_type() != BytecodeType::End {
vals.push(self.decode_val(registers));
}
self.decode_type(); // End (TODO: assert)
vals
}
pub fn decode_signed_byte(&mut self) -> i8 {
let res = self.bytecode[self.pos] as i8;
self.pos += 1;