this_subcall

This commit is contained in:
Andrew Morris
2023-04-05 10:31:05 +10:00
parent dc685f5892
commit 0ee1f473ce
7 changed files with 30 additions and 9 deletions

View File

@@ -289,6 +289,7 @@ pub enum Instruction {
UnsetCatch,
ConstSubCall(Value, Value, Value, Register),
RequireMutableThis,
ThisSubCall(Value, Value, Value, Register),
}
impl std::fmt::Display for Instruction {
@@ -437,6 +438,13 @@ impl std::fmt::Display for Instruction {
)
}
Instruction::RequireMutableThis => write!(f, "require_mutable_this"),
Instruction::ThisSubCall(obj, subscript, args, register) => {
write!(
f,
"this_subcall {} {} {} {}",
obj, subscript, args, register
)
}
}
}
}
@@ -498,6 +506,7 @@ impl Instruction {
UnsetCatch => InstructionByte::UnsetCatch,
ConstSubCall(..) => InstructionByte::ConstSubCall,
RequireMutableThis => InstructionByte::RequireMutableThis,
ThisSubCall(..) => InstructionByte::ThisSubCall,
}
}
}

View File

@@ -212,7 +212,8 @@ impl Assembler {
}
Apply(arg1, arg2, arg3, dst)
| SubCall(arg1, arg2, arg3, dst)
| ConstSubCall(arg1, arg2, arg3, dst) => {
| ConstSubCall(arg1, arg2, arg3, dst)
| ThisSubCall(arg1, arg2, arg3, dst) => {
self.value(arg1);
self.value(arg2);
self.value(arg3);

View File

@@ -226,6 +226,7 @@ impl<'a> AssemblyParser<'a> {
("unset_catch", InstructionByte::UnsetCatch),
("const_subcall", InstructionByte::ConstSubCall),
("require_mutable_this", InstructionByte::RequireMutableThis),
("this_subcall", InstructionByte::ThisSubCall),
]);
for (word, instruction) in instruction_word_map {
@@ -678,6 +679,12 @@ impl<'a> AssemblyParser<'a> {
self.assemble_register(),
),
RequireMutableThis => Instruction::RequireMutableThis,
ThisSubCall => Instruction::ThisSubCall(
self.assemble_value(),
self.assemble_value(),
self.assemble_value(),
self.assemble_register(),
),
}
}

View File

@@ -47,7 +47,8 @@ pub fn instruction_mutates_this(instruction: &Instruction) -> bool {
| Import(_, reg)
| ImportStar(_, reg)
| SetCatch(_, reg)
| ConstSubCall(_, _, _, reg) => reg == &Register::This,
| ConstSubCall(_, _, _, reg)
| ThisSubCall(_, _, _, reg) => reg == &Register::This,
Apply(_, ctx, _, reg) | SubCall(ctx, _, _, reg) => {
reg == &Register::This

View File

@@ -282,7 +282,8 @@ where
}
Apply(arg1, arg2, arg3, _)
| SubCall(arg1, arg2, arg3, _)
| ConstSubCall(arg1, arg2, arg3, _) => {
| ConstSubCall(arg1, arg2, arg3, _)
| ThisSubCall(arg1, arg2, arg3, _) => {
self.value(Some(owner), arg1);
self.value(Some(owner), arg2);
self.value(Some(owner), arg3);