Skip to content

Commit

Permalink
Add dedicated instruction for static method calls
Browse files Browse the repository at this point in the history
Instead of using two instructions for static method calls (one to get
the receiver and one to perform a virtual method call), we now have a
dedicated CallStatic instruction. This instruction takes a class ID
directly and calls a method on the provided class.

As part of this we also remove the GetModule and GetClass instructions,
as these are no longer necessary.

Changelog: added
  • Loading branch information
yorickpeterse committed Oct 26, 2022
1 parent e88c404 commit 452c07f
Show file tree
Hide file tree
Showing 15 changed files with 478 additions and 529 deletions.
287 changes: 141 additions & 146 deletions bytecode/src/lib.rs
Expand Up @@ -64,6 +64,7 @@ pub enum Opcode {
ByteArrayRemove,
ByteArraySet,
CallDynamic,
CallStatic,
CallVirtual,
CheckRefs,
Decrement,
Expand Down Expand Up @@ -91,18 +92,18 @@ pub enum Opcode {
FutureDrop,
FutureGet,
FutureGetFor,
GetClass,
FuturePoll,
GetConstant,
GetFalse,
GetField,
GetModule,
GetNil,
GetTrue,
GetUndefined,
Goto,
Increment,
IntAdd,
IntBitAnd,
IntBitNot,
IntBitOr,
IntBitXor,
IntClone,
Expand All @@ -115,16 +116,24 @@ pub enum Opcode {
IntMod,
IntMul,
IntPow,
IntRotateLeft,
IntRotateRight,
IntShl,
IntShr,
IntSub,
IntToFloat,
IntToString,
IntUnsignedShr,
IntWrappingAdd,
IntWrappingMul,
IntWrappingSub,
IsUndefined,
JumpTable,
MoveRegister,
MoveResult,
ObjectEq,
Panic,
Pop,
ProcessAllocate,
ProcessFinishTask,
ProcessGetField,
Expand All @@ -133,6 +142,7 @@ pub enum Opcode {
ProcessSetField,
ProcessSuspend,
ProcessWriteResult,
Push,
Reduce,
RefKind,
Return,
Expand All @@ -142,18 +152,7 @@ pub enum Opcode {
StringDrop,
StringEq,
StringSize,
JumpTable,
Throw,
Push,
Pop,
FuturePoll,
IntBitNot,
IntRotateLeft,
IntRotateRight,
IntWrappingAdd,
IntWrappingSub,
IntWrappingMul,
IntUnsignedShr,
}

impl Opcode {
Expand Down Expand Up @@ -211,69 +210,68 @@ impl Opcode {
49 => Opcode::GetConstant,
50 => Opcode::GetFalse,
51 => Opcode::GetField,
52 => Opcode::GetClass,
53 => Opcode::GetModule,
54 => Opcode::GetNil,
55 => Opcode::GetTrue,
56 => Opcode::GetUndefined,
57 => Opcode::Goto,
58 => Opcode::Branch,
59 => Opcode::BranchResult,
60 => Opcode::Increment,
61 => Opcode::IntAdd,
62 => Opcode::IntBitAnd,
63 => Opcode::IntBitOr,
64 => Opcode::IntBitXor,
65 => Opcode::IntClone,
66 => Opcode::IntDiv,
67 => Opcode::IntEq,
68 => Opcode::IntGe,
69 => Opcode::IntGt,
70 => Opcode::IntLe,
71 => Opcode::IntLt,
72 => Opcode::IntMod,
73 => Opcode::IntMul,
74 => Opcode::IntPow,
75 => Opcode::IntShl,
76 => Opcode::IntShr,
77 => Opcode::IntSub,
78 => Opcode::IntToFloat,
79 => Opcode::IntToString,
80 => Opcode::IsUndefined,
81 => Opcode::RefKind,
82 => Opcode::MoveResult,
83 => Opcode::ObjectEq,
84 => Opcode::Panic,
85 => Opcode::ProcessAllocate,
86 => Opcode::ProcessGetField,
87 => Opcode::ProcessSendAsync,
88 => Opcode::ProcessSend,
89 => Opcode::ProcessSetField,
90 => Opcode::ProcessSuspend,
91 => Opcode::ProcessWriteResult,
92 => Opcode::Free,
93 => Opcode::Reduce,
94 => Opcode::Return,
95 => Opcode::SetField,
96 => Opcode::StringByte,
97 => Opcode::StringConcat,
98 => Opcode::StringDrop,
99 => Opcode::StringEq,
100 => Opcode::StringSize,
101 => Opcode::Throw,
102 => Opcode::DecrementAtomic,
103 => Opcode::ProcessFinishTask,
104 => Opcode::JumpTable,
105 => Opcode::Push,
106 => Opcode::Pop,
107 => Opcode::FuturePoll,
108 => Opcode::IntBitNot,
109 => Opcode::IntRotateLeft,
110 => Opcode::IntRotateRight,
111 => Opcode::IntWrappingAdd,
112 => Opcode::IntWrappingSub,
113 => Opcode::IntWrappingMul,
114 => Opcode::IntUnsignedShr,
52 => Opcode::CallStatic,
53 => Opcode::GetNil,
54 => Opcode::GetTrue,
55 => Opcode::GetUndefined,
56 => Opcode::Goto,
57 => Opcode::Branch,
58 => Opcode::BranchResult,
59 => Opcode::Increment,
60 => Opcode::IntAdd,
61 => Opcode::IntBitAnd,
62 => Opcode::IntBitOr,
63 => Opcode::IntBitXor,
64 => Opcode::IntClone,
65 => Opcode::IntDiv,
66 => Opcode::IntEq,
67 => Opcode::IntGe,
68 => Opcode::IntGt,
69 => Opcode::IntLe,
70 => Opcode::IntLt,
71 => Opcode::IntMod,
72 => Opcode::IntMul,
73 => Opcode::IntPow,
74 => Opcode::IntShl,
75 => Opcode::IntShr,
76 => Opcode::IntSub,
77 => Opcode::IntToFloat,
78 => Opcode::IntToString,
79 => Opcode::IsUndefined,
80 => Opcode::RefKind,
81 => Opcode::MoveResult,
82 => Opcode::ObjectEq,
83 => Opcode::Panic,
84 => Opcode::ProcessAllocate,
85 => Opcode::ProcessGetField,
86 => Opcode::ProcessSendAsync,
87 => Opcode::ProcessSend,
88 => Opcode::ProcessSetField,
89 => Opcode::ProcessSuspend,
90 => Opcode::ProcessWriteResult,
91 => Opcode::Free,
92 => Opcode::Reduce,
93 => Opcode::Return,
94 => Opcode::SetField,
95 => Opcode::StringByte,
96 => Opcode::StringConcat,
97 => Opcode::StringDrop,
98 => Opcode::StringEq,
99 => Opcode::StringSize,
100 => Opcode::Throw,
101 => Opcode::DecrementAtomic,
102 => Opcode::ProcessFinishTask,
103 => Opcode::JumpTable,
104 => Opcode::Push,
105 => Opcode::Pop,
106 => Opcode::FuturePoll,
107 => Opcode::IntBitNot,
108 => Opcode::IntRotateLeft,
109 => Opcode::IntRotateRight,
110 => Opcode::IntWrappingAdd,
111 => Opcode::IntWrappingSub,
112 => Opcode::IntWrappingMul,
113 => Opcode::IntUnsignedShr,
_ => return Err(format!("The opcode {} is invalid", byte)),
};

Expand Down Expand Up @@ -335,69 +333,68 @@ impl Opcode {
Opcode::GetConstant => 49,
Opcode::GetFalse => 50,
Opcode::GetField => 51,
Opcode::GetClass => 52,
Opcode::GetModule => 53,
Opcode::GetNil => 54,
Opcode::GetTrue => 55,
Opcode::GetUndefined => 56,
Opcode::Goto => 57,
Opcode::Branch => 58,
Opcode::BranchResult => 59,
Opcode::Increment => 60,
Opcode::IntAdd => 61,
Opcode::IntBitAnd => 62,
Opcode::IntBitOr => 63,
Opcode::IntBitXor => 64,
Opcode::IntClone => 65,
Opcode::IntDiv => 66,
Opcode::IntEq => 67,
Opcode::IntGe => 68,
Opcode::IntGt => 69,
Opcode::IntLe => 70,
Opcode::IntLt => 71,
Opcode::IntMod => 72,
Opcode::IntMul => 73,
Opcode::IntPow => 74,
Opcode::IntShl => 75,
Opcode::IntShr => 76,
Opcode::IntSub => 77,
Opcode::IntToFloat => 78,
Opcode::IntToString => 79,
Opcode::IsUndefined => 80,
Opcode::RefKind => 81,
Opcode::MoveResult => 82,
Opcode::ObjectEq => 83,
Opcode::Panic => 84,
Opcode::ProcessAllocate => 85,
Opcode::ProcessGetField => 86,
Opcode::ProcessSendAsync => 87,
Opcode::ProcessSend => 88,
Opcode::ProcessSetField => 89,
Opcode::ProcessSuspend => 90,
Opcode::ProcessWriteResult => 91,
Opcode::Free => 92,
Opcode::Reduce => 93,
Opcode::Return => 94,
Opcode::SetField => 95,
Opcode::StringByte => 96,
Opcode::StringConcat => 97,
Opcode::StringDrop => 98,
Opcode::StringEq => 99,
Opcode::StringSize => 100,
Opcode::Throw => 101,
Opcode::DecrementAtomic => 102,
Opcode::ProcessFinishTask => 103,
Opcode::JumpTable => 104,
Opcode::Push => 105,
Opcode::Pop => 106,
Opcode::FuturePoll => 107,
Opcode::IntBitNot => 108,
Opcode::IntRotateLeft => 109,
Opcode::IntRotateRight => 110,
Opcode::IntWrappingAdd => 111,
Opcode::IntWrappingSub => 112,
Opcode::IntWrappingMul => 113,
Opcode::IntUnsignedShr => 114,
Opcode::CallStatic => 52,
Opcode::GetNil => 53,
Opcode::GetTrue => 54,
Opcode::GetUndefined => 55,
Opcode::Goto => 56,
Opcode::Branch => 57,
Opcode::BranchResult => 58,
Opcode::Increment => 59,
Opcode::IntAdd => 60,
Opcode::IntBitAnd => 61,
Opcode::IntBitOr => 62,
Opcode::IntBitXor => 63,
Opcode::IntClone => 64,
Opcode::IntDiv => 65,
Opcode::IntEq => 66,
Opcode::IntGe => 67,
Opcode::IntGt => 68,
Opcode::IntLe => 69,
Opcode::IntLt => 70,
Opcode::IntMod => 71,
Opcode::IntMul => 72,
Opcode::IntPow => 73,
Opcode::IntShl => 74,
Opcode::IntShr => 75,
Opcode::IntSub => 76,
Opcode::IntToFloat => 77,
Opcode::IntToString => 78,
Opcode::IsUndefined => 79,
Opcode::RefKind => 80,
Opcode::MoveResult => 81,
Opcode::ObjectEq => 82,
Opcode::Panic => 83,
Opcode::ProcessAllocate => 84,
Opcode::ProcessGetField => 85,
Opcode::ProcessSendAsync => 86,
Opcode::ProcessSend => 87,
Opcode::ProcessSetField => 88,
Opcode::ProcessSuspend => 89,
Opcode::ProcessWriteResult => 90,
Opcode::Free => 91,
Opcode::Reduce => 92,
Opcode::Return => 93,
Opcode::SetField => 94,
Opcode::StringByte => 95,
Opcode::StringConcat => 96,
Opcode::StringDrop => 97,
Opcode::StringEq => 98,
Opcode::StringSize => 99,
Opcode::Throw => 100,
Opcode::DecrementAtomic => 101,
Opcode::ProcessFinishTask => 102,
Opcode::JumpTable => 103,
Opcode::Push => 104,
Opcode::Pop => 105,
Opcode::FuturePoll => 106,
Opcode::IntBitNot => 107,
Opcode::IntRotateLeft => 108,
Opcode::IntRotateRight => 109,
Opcode::IntWrappingAdd => 110,
Opcode::IntWrappingSub => 111,
Opcode::IntWrappingMul => 112,
Opcode::IntUnsignedShr => 113,
}
}

Expand Down Expand Up @@ -455,8 +452,7 @@ impl Opcode {
Opcode::GetConstant => "get_constant",
Opcode::GetFalse => "get_false",
Opcode::GetField => "get_field",
Opcode::GetClass => "get_class",
Opcode::GetModule => "get_module",
Opcode::CallStatic => "call_static",
Opcode::GetNil => "get_nil",
Opcode::GetTrue => "get_true",
Opcode::GetUndefined => "get_undefined",
Expand Down Expand Up @@ -565,8 +561,8 @@ impl Opcode {
Opcode::ByteArrayPush => 2,
Opcode::ByteArrayRemove => 3,
Opcode::ByteArraySet => 4,
Opcode::CallDynamic => 5,
Opcode::CallVirtual => 4,
Opcode::CallDynamic => 3,
Opcode::CallVirtual => 2,
Opcode::CheckRefs => 1,
Opcode::Decrement => 1,
Opcode::DecrementAtomic => 2,
Expand All @@ -593,11 +589,10 @@ impl Opcode {
Opcode::FutureDrop => 2,
Opcode::FutureGet => 1,
Opcode::FutureGetFor => 2,
Opcode::GetClass => 3,
Opcode::CallStatic => 3,
Opcode::GetConstant => 3,
Opcode::GetFalse => 1,
Opcode::GetField => 3,
Opcode::GetModule => 3,
Opcode::GetNil => 1,
Opcode::GetTrue => 1,
Opcode::GetUndefined => 1,
Expand Down Expand Up @@ -1280,7 +1275,7 @@ mod tests {

#[test]
fn test_opcode_from_byte() {
assert_eq!(Opcode::from_byte(94), Ok(Opcode::Return));
assert_eq!(Opcode::from_byte(93), Ok(Opcode::Return));
assert_eq!(
Opcode::from_byte(255),
Err("The opcode 255 is invalid".to_string())
Expand Down

0 comments on commit 452c07f

Please sign in to comment.