if not strs.has_key(i) then strs[i] = "closctx->variable[{i}]"
else
strs = once new HashMap[Int, String]
- if not strs.has_key(i) then strs[i] = "REG[{i}]"
+ if not strs.has_key(i) then strs[i] = "fra.me.REG[{i}]"
end
s = strs[i]
ids[e] = s
# Compile the body of the routine, return the result value is any
fun compile_inside_to_c(v: I2CCompilerVisitor, args: Array[String]): nullable String
do
- # Add the trace
+ # Create and push the stack frame
var ll = 0
if location != null then
ll = location.line_start
end
- v.add_decl("struct trace_t trace = \{NULL, NULL, {ll}, LOCATE_{v.basecname}\};")
- v.add_instr("trace.prev = tracehead; tracehead = &trace;")
- v.add_instr("trace.file = LOCATE_{v.visitor.module.name};")
-
- # Add local variables
- if std_slots_nb == 0 then
- v.add_decl("val_t *REG = NULL;")
+ # Encapsulate the frame ('me') in a larger structure ('fra') that has enough space to store the local variables (REG)
+ if std_slots_nb > 1 then
+ v.add_decl("struct \{struct stack_frame_t me; val_t MORE_REG[{std_slots_nb-1}];\} fra;")
else
- var init_vals = new Buffer
- init_vals.append "val_t REG[{std_slots_nb}] = \{ NIT_NULL"
- for i in [1..std_slots_nb[ do init_vals.append(", NIT_NULL")
- init_vals.append " \};"
- v.add_decl(init_vals.to_s)
+ v.add_decl("struct \{struct stack_frame_t me;\} fra;")
+ end
+ v.add_instr("fra.me.prev = stack_frame_head; stack_frame_head = &fra.me;")
+ v.add_instr("fra.me.file = LOCATE_{v.visitor.module.name};")
+ v.add_instr("fra.me.line = {ll};")
+ v.add_instr("fra.me.meth = LOCATE_{v.basecname};")
+ v.add_instr("fra.me.REG_size = {std_slots_nb};")
+
+ # Declare/initialize local variables
+ for i in [0..std_slots_nb[ do
+ v.add_instr("fra.me.REG[{i}] = NIT_NULL;")
end
for i in [0..tag_slots_nb[ do
v.add_decl("val_t REGB{i};")
# Compile body
body.compile_to_c(v)
- v.add_instr("tracehead = trace.prev;")
+ v.add_instr("stack_frame_head = fra.me.prev;")
v.return_label = old_rl
var r = result
if r != null then
body.compile_to_c(v)
var e = v.register(result.as(not null))
v.add_instr("once_value_{i} = {e};")
+ v.add_instr("register_static_object(&once_value_{i});")
if res.stype.is_nullable then v.add_instr("once_bool_{i} = true;")
v.unindent
v.add_instr("} else {e} = once_value_{i};")
v.add_instr("{closcnv}.variable = closctx->variable;")
v.add_instr("{closcnv}.closurevariable = closctx->closurevariable;")
else
- v.add_instr("{closcnv}.variable = REG;")
+ v.add_instr("{closcnv}.variable = fra.me.REG;")
v.add_instr("{closcnv}.closurevariable = CREG;")
end