From 41786d355a464d990865084c7a8d5689fd233e9a Mon Sep 17 00:00:00 2001 From: Max Bernstein Date: Thu, 6 Feb 2025 10:58:38 -0500 Subject: Bring back Opnd --- zjit/src/lib.rs | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/zjit/src/lib.rs b/zjit/src/lib.rs index 8429d2aa05..e40009f89d 100644 --- a/zjit/src/lib.rs +++ b/zjit/src/lib.rs @@ -19,11 +19,16 @@ pub struct InsnId(usize); #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub struct BlockId(usize); +#[derive(Debug, PartialEq)] +enum Opnd { + Const(VALUE), + Insn(InsnId), +} + #[derive(Debug, PartialEq)] enum Insn { Param { idx: usize }, - Const { val: VALUE }, - Return { val: InsnId }, + Return { val: Opnd }, } #[derive(Debug, PartialEq)] @@ -65,7 +70,7 @@ enum RubyOpcode { } struct FrameState { - stack: Vec, + stack: Vec, } impl FrameState { @@ -73,11 +78,11 @@ impl FrameState { FrameState { stack: vec![] } } - fn push(&mut self, val: InsnId) { - self.stack.push(val); + fn push(&mut self, opnd: Opnd) { + self.stack.push(opnd); } - fn pop(&mut self) -> InsnId { + fn pop(&mut self) -> Opnd { self.stack.pop().expect("Bytecode stack mismatch") } } @@ -89,7 +94,7 @@ fn to_ssa(opcodes: &Vec) -> Function { for opcode in opcodes { match opcode { RubyOpcode::Putnil => { - state.push(result.push_insn(block, Insn::Const { val: Qnil })); + state.push(Opnd::Const(Qnil)); }, RubyOpcode::Leave => { result.push_insn(block, Insn::Return { val: state.pop() }); @@ -113,10 +118,10 @@ mod tests { assert_eq!(function, Function { entry_block: BlockId(0), insns: vec![ - Insn::Const { val: RubyValue::Nil }, - Insn::Return { val: InsnId(0) }], + Insn::Return { val: Opnd::Const(Qnil) } + ], blocks: vec![ - Block { params: vec![], insns: vec![InsnId(0), InsnId(1)] } + Block { params: vec![], insns: vec![InsnId(0)] } ], }); } -- cgit v1.2.3