summaryrefslogtreecommitdiff
path: root/zjit/src/codegen.rs
diff options
context:
space:
mode:
authorAaron Patterson <[email protected]>2025-06-09 21:12:53 -0700
committerAaron Patterson <[email protected]>2025-06-10 10:42:01 -0700
commit0f922edca018c20c8b9b8c7711b371e26a724104 (patch)
tree69d1ddeba04188b807297db492b7de1b4220be12 /zjit/src/codegen.rs
parentc54e96d651b53d4105447c3bb4fb94903bd67cc5 (diff)
ZJIT: Support get/set on global variables
Adds support for code like: ```ruby $foo $foo = x ```
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/13569
Diffstat (limited to 'zjit/src/codegen.rs')
-rw-r--r--zjit/src/codegen.rs20
1 files changed, 20 insertions, 0 deletions
diff --git a/zjit/src/codegen.rs b/zjit/src/codegen.rs
index 0dbe815c71..e32534b283 100644
--- a/zjit/src/codegen.rs
+++ b/zjit/src/codegen.rs
@@ -275,6 +275,8 @@ fn gen_insn(cb: &mut CodeBlock, jit: &mut JITState, asm: &mut Assembler, functio
Insn::PatchPoint(_) => return Some(()), // For now, rb_zjit_bop_redefined() panics. TODO: leave a patch point and fix rb_zjit_bop_redefined()
Insn::CCall { cfun, args, name: _, return_type: _, elidable: _ } => gen_ccall(jit, asm, *cfun, args)?,
Insn::GetIvar { self_val, id, state: _ } => gen_getivar(asm, opnd!(self_val), *id),
+ Insn::SetGlobal { id, val, state: _ } => gen_setglobal(asm, *id, opnd!(val)),
+ Insn::GetGlobal { id, state: _ } => gen_getglobal(asm, *id),
Insn::SetIvar { self_val, id, val, state: _ } => gen_setivar(asm, opnd!(self_val), *id, opnd!(val)),
_ => {
debug!("ZJIT: gen_function: unexpected insn {:?}", insn);
@@ -317,6 +319,24 @@ fn gen_setivar(asm: &mut Assembler, recv: Opnd, id: ID, val: Opnd) -> Opnd {
)
}
+/// Look up global variables
+fn gen_getglobal(asm: &mut Assembler, id: ID) -> Opnd {
+ asm_comment!(asm, "call rb_gvar_get");
+ asm.ccall(
+ rb_gvar_get as *const u8,
+ vec![Opnd::UImm(id.0)],
+ )
+}
+
+/// Set global variables
+fn gen_setglobal(asm: &mut Assembler, id: ID, val: Opnd) -> Opnd {
+ asm_comment!(asm, "call rb_gvar_set");
+ asm.ccall(
+ rb_gvar_set as *const u8,
+ vec![Opnd::UImm(id.0), val],
+ )
+}
+
/// Compile an interpreter entry block to be inserted into an ISEQ
fn gen_entry_prologue(asm: &mut Assembler, iseq: IseqPtr) {
asm_comment!(asm, "ZJIT entry point: {}", iseq_get_location(iseq, 0));