From: NeilBrown Date: Sun, 5 Dec 2021 00:09:57 +0000 (+1100) Subject: oceani: remove the HACK concerning type names starting with space X-Git-Url: https://ocean-lang.org/code/?p=ocean;a=commitdiff_plain;h=ef3bbba20f9e426125498f78fe3b1f4ea75de68a oceani: remove the HACK concerning type names starting with space 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 --- diff --git a/csrc/oceani.mdc b/csrc/oceani.mdc index e09fe07..e7976cf 100644 --- a/csrc/oceani.mdc +++ b/csrc/oceani.mdc @@ -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;