# Compile a statment node
meth compile_stmt(n: PExpr)
do
+ if n == null then return
add_instr("/* Compile stmt {n.locate} */")
n.prepare_compile_stmt(self)
var i = cfc._variable_index
var i = cfc._variable_index
var s = n.compile_expr(self)
cfc._variable_index = i
- if s[0] == ' ' then
+ if s[0] == ' ' or cfc.is_valid_variable(s) then
return s
end
var v = cfc.get_var("Result for expr {n.locate}")
# Ensure that a c expression is a var
meth ensure_var(s: String, comment: String): String
do
- if s.substring(0,3) == "variable" then
+ if cfc.is_valid_variable(s) then
+ add_instr("/* Ensure var {s}: {comment}*/")
return s
end
var v = cfc.get_var(null)
end
end
+ # Is s a valid variable
+ protected meth is_valid_variable(s: String): Bool
+ do
+ for i in [0.._variable_index[ do
+ if s == variable(i) then return true
+ end
+ return false
+ end
+
# Mark the variable available
meth free_var(v: String)
do
if self isa AConcreteInitPropdef then
v.invoke_super_init_calls_after(null)
end
- if n_block != null then
- v.compile_stmt(n_block)
- end
+ v.compile_stmt(n_block)
v.add_instr("{v.nmc.return_label}: while(false);")
if self isa AConcreteInitPropdef then
v.add_instr("init_table[{itpos}] = 1;")
redef class ADoExpr
redef meth compile_stmt(v)
do
- if n_block != null then
- v.compile_stmt(n_block)
- end
+ v.compile_stmt(n_block)
end
end
var e = v.compile_expr(n_expr)
v.add_instr("if (!UNTAG_Bool({e})) break; /* while*/")
v.cfc.free_var(e)
- if n_block != null then
- v.compile_stmt(n_block)
- end
+ v.compile_stmt(n_block)
v.add_instr("{v.nmc.continue_label}: while(0);")
v.unindent
v.add_instr("}")
e = v.ensure_var(e, "For item")
var cname = v.cfc.register_variable(variable)
v.add_assignment(cname, e)
- var n_block = n_block
- if n_block != null then
- v.compile_stmt(n_block)
- end
+ v.compile_stmt(n_block)
v.add_instr("{v.nmc.continue_label}: while(0);")
e = meth_next.compile_call(v, [iter])
assert e == null
for ne in n_exprs do
var e = v.ensure_var(v.compile_expr(ne), "super-string element")
if ne.stype != stype then
- v.add_assignment(e, meth_to_s.compile_call(v, [e]))
+ v.cfc.free_var(e)
+ e = meth_to_s.compile_call(v, [e])
end
+ v.cfc.free_var(e)
meth_add.compile_call(v, [array, e])
end
v.nmc.continue_label = "continue_label{v.new_number}"
v.nmc.break_label = v.nmc.return_label
- if n_expr != null then v.compile_stmt(n_expr)
+ v.compile_stmt(n_expr)
v.add_instr("{v.nmc.continue_label}: while(false);")
v.nmc.continue_label = "continue_label{v.new_number}"
v.nmc.break_label = v.nmc.return_label
- if n_expr != null then v.compile_stmt(n_expr)
+ v.compile_stmt(n_expr)
v.add_instr("{v.nmc.continue_label}: while(false);")