Commit 538a8eee
538a8eeedd5cMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 4 files · +2 added · ~2 modified
Description
Merge pull request #271 from ryanseys/rs-node-global-var-op-write
feat(parse,codegen): support GlobalVariableOperatorWriteNode ($x += val)
Details
- Commit
- 538a8eeedd5c
- Parent
- 91406e8e7e3c
- Merge parent
- b1dc9f14e3f5
spinel_codegen.rbmodifiedView file
@@ -24598,6 +24598,44 @@
2459824598
return2459924599
end2460024600
end24601+
if t == "GlobalVariableOperatorWriteNode"24602+
# `$x += val`, `$x -= val`, etc. Mirrors LocalVariableOperatorWriteNode24603+
# for the storage path (sanitize_gvar instead of fiber_var_ref).24604+
op = @nd_binop[nid]24605+
val = compile_expr(@nd_expression[nid])24606+
cname = sanitize_gvar(@nd_name[nid])24607+
if op == "+"24608+
emit(" " + cname + " += " + val + ";")24609+
end24610+
if op == "-"24611+
emit(" " + cname + " -= " + val + ";")24612+
end24613+
if op == "*"24614+
emit(" " + cname + " *= " + val + ";")24615+
end24616+
if op == "/"24617+
emit(" " + cname + " /= " + val + ";")24618+
end24619+
if op == "%"24620+
emit(" " + cname + " = sp_imod(" + cname + ", " + val + ");")24621+
end24622+
if op == "<<"24623+
emit(" " + cname + " <<= " + val + ";")24624+
end24625+
if op == ">>"24626+
emit(" " + cname + " >>= " + val + ";")24627+
end24628+
if op == "&"24629+
emit(" " + cname + " &= " + val + ";")24630+
end24631+
if op == "|"24632+
emit(" " + cname + " |= " + val + ";")24633+
end24634+
if op == "^"24635+
emit(" " + cname + " ^= " + val + ";")24636+
end24637+
return24638+
end2460124639
if t == "LocalVariableWriteNode"2460224640
lname = @nd_name[nid]2460324641
# 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…