Add Putstring

This commit is contained in:
Max Bernstein 2025-02-06 11:21:40 -05:00 committed by Takashi Kokubun
parent cabfa3bfe1
commit f0954d1b2b
Notes: git 2025-04-18 13:49:52 +00:00

View File

@ -17,6 +17,9 @@ enum Opnd {
enum Insn { enum Insn {
// SSA block parameter. Also used for function parameters in the function's entry block. // SSA block parameter. Also used for function parameters in the function's entry block.
Param { idx: usize }, Param { idx: usize },
StringCopy { val: Opnd },
// Control flow instructions
Return { val: Opnd }, Return { val: Opnd },
} }
@ -53,6 +56,7 @@ impl Function {
enum RubyOpcode { enum RubyOpcode {
Putnil, Putnil,
Putobject(VALUE), Putobject(VALUE),
Putstring(VALUE),
Setlocal(usize), Setlocal(usize),
Getlocal(usize), Getlocal(usize),
Leave, Leave,
@ -103,6 +107,10 @@ fn to_ssa(opcodes: &Vec<RubyOpcode>) -> Function {
match opcode { match opcode {
RubyOpcode::Putnil => { state.push(Opnd::Const(Qnil)); }, RubyOpcode::Putnil => { state.push(Opnd::Const(Qnil)); },
RubyOpcode::Putobject(val) => { state.push(Opnd::Const(*val)); }, RubyOpcode::Putobject(val) => { state.push(Opnd::Const(*val)); },
RubyOpcode::Putstring(val) => {
let insn_id = Opnd::Insn(result.push_insn(block, Insn::StringCopy { val: Opnd::Const(*val) }));
state.push(insn_id);
}
RubyOpcode::Setlocal(idx) => { RubyOpcode::Setlocal(idx) => {
let val = state.pop(); let val = state.pop();
state.setlocal(*idx, val); state.setlocal(*idx, val);