]> ocean-lang.org Git - ocean/blobdiff - csrc/oceani.mdc
oceani: implement struct field initialisation properly.
[ocean] / csrc / oceani.mdc
index 7ff26c5f7aac1871ac03b9e1fa2fd79aa9c37bd2..416084e26512c613ec287d70feaa85a8ad65e0e6 100644 (file)
@@ -537,6 +537,9 @@ Named type are stored in a simple linked list.  Objects of each type are
        {
                struct value *ret;
 
+               if (t->prepare_type)
+                       t->prepare_type(t);
+
                ret = calloc(1, t->size);
                if (init)
                        memcpy(ret, init, t->size);
@@ -1755,7 +1758,12 @@ function will be needed.
                for (i = 0; i < type->structure.nfields; i++) {
                        struct value *v;
                        v = (void*) val->ptr + type->structure.fields[i].offset;
-                       val_init(type->structure.fields[i].type, v);
+                       if (type->structure.fields[i].init)
+                               dup_value(type->structure.fields[i].type, 
+                                         type->structure.fields[i].init,
+                                         v);
+                       else
+                               val_init(type->structure.fields[i].type, v);
                }
        }
 
@@ -3366,9 +3374,6 @@ it is declared, and error will be raised as the name is created as
                        v = v->merged;
                free_value(v->type, v->val);
                free(v->val);
-               if (v->type->prepare_type)
-                       // FIXME is this the first usage of the type?
-                       v->type->prepare_type(v->type);
                if (b->right) {
                        right = interp_exec(b->right, &rtype);
                        v->val = val_alloc(v->type, &right);