Add unimplemented yield instruction

This commit is contained in:
Andrew Morris
2023-05-31 14:20:45 +10:00
parent 0eda3716ae
commit 12bfe5bf7f
7 changed files with 21 additions and 2 deletions

View File

@@ -293,6 +293,7 @@ pub enum Instruction {
Next(Register, Register),
UnpackIterRes(Register, Register, Register),
Cat(Value, Register),
Yield(Value, Register),
}
impl std::fmt::Display for Instruction {
@@ -461,6 +462,9 @@ impl std::fmt::Display for Instruction {
Instruction::Cat(iterables, register) => {
write!(f, "cat {} {}", iterables, register)
}
Instruction::Yield(value, register) => {
write!(f, "yield {} {}", value, register)
}
}
}
}
@@ -526,6 +530,7 @@ impl Instruction {
Next(..) => InstructionByte::Next,
UnpackIterRes(..) => InstructionByte::UnpackIterRes,
Cat(..) => InstructionByte::Cat,
Yield(..) => InstructionByte::Yield,
}
}
}

View File

@@ -244,6 +244,10 @@ impl Assembler {
self.value(iterables);
self.register(dst);
}
Yield(value, dst) => {
self.value(value);
self.register(dst);
}
}
}

View File

@@ -230,6 +230,7 @@ impl<'a> AssemblyParser<'a> {
("next", InstructionByte::Next),
("unpack_iter_res", InstructionByte::UnpackIterRes),
("cat", InstructionByte::Cat),
("yield", InstructionByte::Yield),
]);
for (word, instruction) in instruction_word_map {
@@ -695,6 +696,7 @@ impl<'a> AssemblyParser<'a> {
self.assemble_register(),
),
Cat => Instruction::Cat(self.assemble_value(), self.assemble_register()),
Yield => Instruction::Yield(self.assemble_value(), self.assemble_register()),
}
}

View File

@@ -49,7 +49,8 @@ pub fn instruction_mutates_this(instruction: &Instruction) -> bool {
| SetCatch(_, reg)
| ConstSubCall(_, _, _, reg)
| ThisSubCall(_, _, _, reg)
| Cat(_, reg) => reg == &Register::This,
| Cat(_, reg)
| Yield(_, reg) => reg == &Register::This,
Next(iter, res) => iter == &Register::This || res == &Register::This,
UnpackIterRes(_, value_reg, done_reg) => {

View File

@@ -245,7 +245,8 @@ where
| Import(arg, _)
| ImportStar(arg, _)
| Throw(arg)
| Cat(arg, _) => {
| Cat(arg, _)
| Yield(arg, _) => {
self.value(Some(owner), arg);
}
OpPlus(arg1, arg2, _)