Merge: Fix --no-union-attributes
authorJean Privat <jean@pryen.org>
Tue, 24 Mar 2015 00:24:12 +0000 (07:24 +0700)
committerJean Privat <jean@pryen.org>
Tue, 24 Mar 2015 00:24:12 +0000 (07:24 +0700)
--no-union-attributes was broken since the tagging of primitive. This PR fix it.

Pull-Request: #1218
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>

lib/string_experimentations/utf8_noindex.nit
src/compiler/separate_compiler.nit

index 0fa637a..2875a8b 100644 (file)
@@ -231,7 +231,7 @@ class FlatStringIter
 
        private var it: UnicodeChar
 
-       private var is_created: Bool
+       private var is_created = false
 
        init(s: FlatString) do from(s, 0)
 
index 8cb75e7..00125ea 100644 (file)
@@ -1580,7 +1580,7 @@ class SeparateCompilerVisitor
                        self.add("{res} = {recv}->attrs[{a.const_color}] != NULL; /* {a} on {recv.inspect}*/")
                else
 
-                       if not mtype.is_c_primitive then
+                       if not mtype.is_c_primitive and not mtype.is_tagged then
                                self.add("{res} = {recv}->attrs[{a.const_color}].val != NULL; /* {a} on {recv.inspect} */")
                        else
                                self.add("{res} = 1; /* NOT YET IMPLEMENTED: isset of primitives: {a} on {recv.inspect} */")
@@ -1661,7 +1661,11 @@ class SeparateCompilerVisitor
                self.require_declaration(a.const_color)
                if self.compiler.modelbuilder.toolcontext.opt_no_union_attribute.value then
                        var attr = "{recv}->attrs[{a.const_color}]"
-                       if mtype.is_c_primitive then
+                       if mtype.is_tagged then
+                               # The attribute is not primitive, thus store it as tagged
+                               var tv = autobox(value, compiler.mainmodule.object_type)
+                               self.add("{attr} = {tv}; /* {a} on {recv.inspect} */")
+                       else if mtype.is_c_primitive then
                                assert mtype isa MClassType
                                # The attribute is primitive, thus we store it in a box
                                # The trick is to create the box the first time then resuse the box
@@ -2304,3 +2308,14 @@ redef class AMethPropdef
                return super
        end
 end
+
+redef class AAttrPropdef
+       redef fun init_expr(v, recv)
+       do
+               super
+               if is_lazy and v.compiler.modelbuilder.toolcontext.opt_no_union_attribute.value then
+                       var guard = self.mlazypropdef.mproperty
+                       v.write_attribute(guard, recv, v.bool_instance(false))
+               end
+       end
+end