Commit b1dc9f14
b1dc9f14e3f5Merged
Ryan Seys <[email protected]> · 6 months ago · 4 files · +2 added · ~2 modified
Description
feat(parse,codegen): support GlobalVariableOperatorWriteNode ($x += val)
Mirror of LocalVariableOperatorWriteNode (spinel_codegen.rb:21659) but the storage path uses sanitize_gvar(name) -> g_ C symbol instead of fiber_var_ref. Supports +, -, *, /, %, <<, >>, &, |, ^ operators on int-typed globals.
No bigint operator path: globals don't carry the same per-variable type tracking locals do. If a future test needs $bigvar += big_val that path can be added by mirroring lines 21664-21680.
Test: test/global_var_op_write.rb. Bootstrap: gen2.c == gen3.c.
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- b1dc9f14e3f5
- Parent
- fea5369dddb0
spinel_codegen.rbmodifiedView file
@@ -24440,6 +24440,44 @@
2444024440
return2444124441
end2444224442
end24443+
if t == "GlobalVariableOperatorWriteNode"24444+
# `$x += val`, `$x -= val`, etc. Mirrors LocalVariableOperatorWriteNode24445+
# for the storage path (sanitize_gvar instead of fiber_var_ref).24446+
op = @nd_binop[nid]24447+
val = compile_expr(@nd_expression[nid])24448+
cname = sanitize_gvar(@nd_name[nid])24449+
if op == "+"24450+
emit(" " + cname + " += " + val + ";")24451+
end24452+
if op == "-"24453+
emit(" " + cname + " -= " + val + ";")24454+
end24455+
if op == "*"24456+
emit(" " + cname + " *= " + val + ";")24457+
end24458+
if op == "/"24459+
emit(" " + cname + " /= " + val + ";")24460+
end24461+
if op == "%"24462+
emit(" " + cname + " = sp_imod(" + cname + ", " + val + ");")24463+
end24464+
if op == "<<"24465+
emit(" " + cname + " <<= " + val + ";")24466+
end24467+
if op == ">>"24468+
emit(" " + cname + " >>= " + val + ";")24469+
end24470+
if op == "&"24471+
emit(" " + cname + " &= " + val + ";")24472+
end24473+
if op == "|"24474+
emit(" " + cname + " |= " + val + ";")24475+
end24476+
if op == "^"24477+
emit(" " + cname + " ^= " + val + ";")24478+
end24479+
return24480+
end2444324481
if t == "LocalVariableWriteNode"2444424482
lname = @nd_name[nid]2444524483
# Check for method(:name) assignmentspinel_parse.cmodifiedView file
Loading diff…
test/global_var_op_write.rbaddedView file
Loading diff…
test/global_var_op_write.rb.expectedaddedView file
Loading diff…