# Register where a functionnal nit return must store its value
readable writable var _return_value: nullable IRegister
+ # The method associated to the iroutine (if any)
+ readable var _method: nullable MMMethod
+
init(visitor: AbsSyntaxVisitor, r: IRoutine, m: nullable MMMethod)
do
- super(visitor.module, r, m)
+ super(visitor.module, r)
_visitor = visitor
_return_seq = r.body
_return_value = r.result
+ _method = m
end
# Insert implicit super init calls
end
var l = n.super_init_calls.length
while i < l do
- var p = n.super_init_calls[i]
- if p == stop_prop then break
+ var sp = n.super_init_calls[i]
+ if sp == stop_prop then break
var cargs = new Array[IRegister]
- if p.signature.arity == 0 then
+ if sp.signature.arity == 0 then
cargs.add(iroutine.params.first)
else
for va in iroutine.params do
cargs.add(va)
end
end
- stmt(new ICall(p, cargs))
+ stmt(new ICall(sp, cargs))
i += 1
end
end
redef fun accept_icode_generation(vv)
do
var v = vv.icode_ctx
- var iclos = variable.closure.signature.generate_empty_iclosuredef
+ var iclos = variable.closure.signature.generate_empty_iclosuredef(v)
var old_seq = v.seq
v.seq = iclos.body
escapable.continue_seq = iclos.body
end
else if c == once "NativeArray".to_symbol then
if n == once "object_id".to_symbol then
- s = "TAG_Int(UNBOX_NativeArray(@@@))"
+ s = "TAG_Int(((Nit_NativeArray)@@@)->object_id)"
else if n == once "[]".to_symbol then
- s = "UNBOX_NativeArray(@@@)[UNTAG_Int(@@@)]"
+ s = "((Nit_NativeArray)@@@)->val[UNTAG_Int(@@@)]"
else if n == once "[]=".to_symbol then
- s = "UNBOX_NativeArray(@@@)[UNTAG_Int(@@@)]=@@@;"
+ s = "((Nit_NativeArray)@@@)->val[UNTAG_Int(@@@)]=@@@"
else if n == once "copy_to".to_symbol then
var t = p[0]
p[0] = p[1]
p[1] = t
- s = "(void)memcpy(UNBOX_NativeArray(@@@), UNBOX_NativeArray(@@@), UNTAG_Int(@@@)*sizeof(val_t));"
+ s = "(void)memcpy(((Nit_NativeArray )@@@)->val, ((Nit_NativeArray)@@@)->val, UNTAG_Int(@@@)*sizeof(val_t))"
end
else if c == once "NativeString".to_symbol then
if n == once "object_id".to_symbol then
s = "(void)memcpy(UNBOX_NativeString(@@@)+UNTAG_Int(@@@), UNBOX_NativeString(@@@)+UNTAG_Int(@@@), UNTAG_Int(@@@));"
end
else if n == once "object_id".to_symbol then
- s = "TAG_Int((bigint)@@@)"
+ s = "TAG_Int((bigint)((obj_t)@@@)[1].object_id)"
else if n == once "sys".to_symbol then
s = "(G_sys)"
else if n == once "is_same_type".to_symbol then
s = "exit(UNTAG_Int(@@@));"
else if n == once "calloc_array".to_symbol then
p[0] = p[1]
- s = "BOX_NativeArray((val_t*)malloc((UNTAG_Int(@@@) * sizeof(val_t))))"
+ s = "NEW_NativeArray(UNTAG_Int(@@@), sizeof(val_t))"
else if n == once "calloc_string".to_symbol then
p[0] = p[1]
s = "BOX_NativeString((char*)malloc((UNTAG_Int(@@@) * sizeof(char))))"
end
end
+redef class ALoopExpr
+ redef fun generate_icode(v)
+ do
+ var seq_old = v.seq
+ var iloop = new ILoop
+ v.stmt(iloop)
+ escapable.break_seq = iloop
+ v.seq = iloop
+
+ # Process inside
+ if n_block != null then
+ var seq = new ISeq
+ v.stmt(seq)
+ v.seq = seq
+ escapable.continue_seq = seq
+ v.generate_stmt(n_block)
+ end
+
+ v.seq = seq_old
+ return null
+ end
+end
+
redef class AForExpr
redef fun generate_icode(v)
do
return null
end
else
- var p = prop
+ p = prop
var rtype = p.signature.return_type
if rtype == null then
v.stmt(new ISuper(p, args))
v.add_assignment(r, r2)
end
v.seq = iif.else_seq
- var r3 = closdecl_default.inline_in_seq(iif.else_seq, args)
+ var r3 = v.inline_routine(closdecl_default, args, null)
if r != null then
assert r3 != null
v.add_assignment(r, r3)