]> ocean-lang.org Git - ocean/commitdiff
oceani: remove the HACK concerning type names starting with space
authorNeilBrown <neil@brown.name>
Sun, 5 Dec 2021 00:09:57 +0000 (11:09 +1100)
committerNeilBrown <neil@brown.name>
Sun, 5 Dec 2021 00:09:57 +0000 (11:09 +1100)
structures returned inline from a function call can be copied.
Other structures - in general - cannot.

This patch introduces a (slightly) better way to tell the difference
than the 'space' hack that was previously used.

Signed-off-by: NeilBrown <neil@brown.name>
csrc/oceani.mdc

index e09fe07a1c22fee614fd2356d9a5bf0e05991553..e7976cf086ef03b338527549a4d3d069af7afd45 100644 (file)
@@ -589,13 +589,15 @@ which can be `NULL` signifying "unknown".  A `prop_err` flag set is
 passed by reference.  It has `Efail` set when an error is found, and
 `Eretry` when the type for some element is set via propagation.  If
 any expression cannot be evaluated immediately, `Enoconst` is set.
+If the expression can be copied, `Emaycopy` is set.
 
 If it remains unchanged at `0`, then no more propagation is needed.
 
 ###### ast
 
        enum val_rules {Rnolabel = 1<<0, Rboolok = 1<<1, Rnoconstant = 1<<2};
-       enum prop_err {Efail = 1<<0, Eretry = 1<<1, Enoconst = 1<<2};
+       enum prop_err {Efail = 1<<0, Eretry = 1<<1, Enoconst = 1<<2,
+                      Emaycopy = 1<<3};
 
 ###### format cases
        case 'r':
@@ -3209,6 +3211,8 @@ it in the "SimpleStatement Grammar" which will be described later.
                }
                *perr |= Enoconst;
                v->var->type->check_args(c, perr, v->var->type, args);
+               if (v->var->type->function.inline_result)
+                       *perr |= Emaycopy;
                return v->var->type->function.return_type;
        }
 
@@ -4290,7 +4294,7 @@ it is declared, and error will be raised as the name is created as
                                propagate_types(b->left, c, perr, t,
                                                (b->op == Assign ? Rnoconstant : 0));
                }
-               if (t && t->dup == NULL && t->name.txt[0] != ' ') // HACK
+               if (t && t->dup == NULL && !(*perr & Emaycopy))
                        type_err(c, "error: cannot assign value of type %1", b, t, 0, NULL);
                return Tnone;
 
@@ -5099,7 +5103,7 @@ is a bit more interesting at this level.
                 * is a list for 'struct var'
                 */
                struct type *t = add_anon_type(c, &structure_prototype,
-                                              " function result");
+                                              "function result");
                int cnt = 0;
                struct binode *b;