syntax: allow untyped variable declaration
[nit.git] / src / syntax / icode_generation.nit
index cdceefc..fb4a801 100644 (file)
@@ -58,7 +58,9 @@ special ICodeBuilder
                if _variables.has_key(v) then
                        return _variables[v]
                else
-                       var reg = new_register(v.stype.as(not null))
+                       var t = v.stype
+                       if t == null then t = visitor.type_object.as_nullable
+                       var reg = new_register(t)
                        _variables[v] = reg
                        return reg
                end
@@ -340,7 +342,7 @@ redef class AClosureDecl
        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
@@ -544,16 +546,16 @@ redef class AInternMethPropdef
                        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
@@ -573,7 +575,7 @@ redef class AInternMethPropdef
                                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
@@ -583,10 +585,10 @@ redef class AInternMethPropdef
                        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))))"
+                       s = "BOX_NativeString((char*)raw_alloc((UNTAG_Int(@@@) * sizeof(char))))"
                end
                if s == null then
                        v.visitor.error(self, "Fatal error: unknown intern method {method.full_name}.")
@@ -825,6 +827,7 @@ redef class AAssertExpr
                v.stmt(iif)
                var seq_old = v.seq
                v.seq = iif.else_seq
+               v.generate_stmt(n_else)
                var id = n_id
                if id == null then
                        v.add_abort("Assert failed")
@@ -1450,7 +1453,7 @@ redef class AClosureCallExpr
                                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)