Commit f5fc7284
f5fc728473baMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 4 files · +2 added · ~2 modified
Description
Merge pull request #297 from ryanseys/rs-node-global-var-and-write
feat(parse,codegen): support GlobalVariableAndWriteNode ($x &&= val)
Details
- Commit
- f5fc728473ba
- Parent
- a37df6cc446c
- Merge parent
- ad55a8c08b81
spinel_codegen.rbmodifiedView file
@@ -25360,6 +25360,18 @@
2536025360
emit(" }")2536125361
return2536225362
end25363+
if t == "GlobalVariableAndWriteNode"25364+
# `$x &&= val`. Short-circuit: only evaluate RHS when LHS is25365+
# truthy. compile_expr can emit prerequisite statements; running25366+
# it inside the C `if` block keeps those side effects on the25367+
# assign branch only. Mirror of OrWrite, condition inverted.25368+
cname = sanitize_gvar(@nd_name[nid])25369+
emit(" if (" + cname + ") {")25370+
val = compile_expr(@nd_expression[nid])25371+
emit(" " + cname + " = " + val + ";")25372+
emit(" }")25373+
return25374+
end2536325375
if t == "ClassVariableWriteNode"2536425376
# `@@x = val` inside class body or method. Storage is the2536525377
# per-(class,name) C global cvar_<ClassName>_<var> registeredspinel_parse.cmodifiedView file
Loading diff…
test/global_var_and_write.rbaddedView file
Loading diff…
test/global_var_and_write.rb.expectedaddedView file
Loading diff…