]> ocean-lang.org Git - ocean/blobdiff - csrc/oceani.mdc
oceani: fix a couple of issues
[ocean] / csrc / oceani.mdc
index e3dc493d7fb1b787ba46cca80fb0724d43ef1560..2804224da5759f95e08ef7cb4f0ce17618607551 100644 (file)
@@ -1437,8 +1437,10 @@ in `rval`.
        {
                struct lrval ret = _interp_exec(e);
 
-               if (typeret)
+               if (ret.lval)
                        *typeret = ret.type;
+               else
+                       free_value(ret.type, &ret.rval);
                return ret.lval;
        }
 
@@ -1485,10 +1487,6 @@ different phases of parse, analyse, print, interpret.
 
 Thus far we have arrays and structs.
 
-Some complex types need do not exist in a name table, so they are kept
-on a linked list in the context (`anon_typelist`).  This allows them to
-be freed when parsing is complete.
-
 #### Arrays
 
 Arrays can be declared by giving a size and a type, as `[size]type' so
@@ -1511,9 +1509,6 @@ make a copy of an array with controllable recursive depth.
                struct type *member;
        } array;
 
-###### value union fields
-       void *array;
-
 ###### value functions
 
        static void array_init(struct type *type, struct value *val)
@@ -1582,16 +1577,19 @@ make a copy of an array with controllable recursive depth.
                .free = array_free,
        };
 
+###### declare terminals
+       $TERM [ ]
+
 ###### type grammar
 
-       | [ NUMBER ] Type ${
-               $0 = calloc(1, sizeof(struct type));
-               *($0) = array_prototype;
-               $0->array.member = $<4;
-               $0->array.vsize = NULL;
-               {
+       | [ NUMBER ] Type ${ {
                char tail[3];
                mpq_t num;
+               struct text noname = { "", 0 };
+
+               $0 = add_type(c, noname, &array_prototype);
+               $0->array.member = $<4;
+               $0->array.vsize = NULL;
                if (number_parse(num, tail, $2.txt) == 0)
                        tok_err(c, "error: unrecognised number", &$2);
                else if (tail[0])
@@ -1606,41 +1604,23 @@ make a copy of an array with controllable recursive depth.
                                        &$2);
                        mpq_clear(num);
                }
-               $0->next = c->anon_typelist;
-               c->anon_typelist = $0;
-               }
-       }$
+       } }$
 
        | [ IDENTIFIER ] Type ${ {
                struct variable *v = var_ref(c, $2.txt);
+               struct text noname = { "", 0 };
 
                if (!v)
                        tok_err(c, "error: name undeclared", &$2);
                else if (!v->constant)
                        tok_err(c, "error: array size must be a constant", &$2);
 
-               $0 = calloc(1, sizeof(struct type));
-               *($0) = array_prototype;
+               $0 = add_type(c, noname, &array_prototype);
                $0->array.member = $<4;
                $0->array.size = 0;
                $0->array.vsize = v;
-               $0->next = c->anon_typelist;
-               c->anon_typelist = $0;
        } }$
 
-###### parse context
-
-       struct type *anon_typelist;
-
-###### free context types
-
-       while (context.anon_typelist) {
-               struct type *t = context.anon_typelist;
-
-               context.anon_typelist = t->next;
-               free(t);
-       }
-
 ###### Binode types
        Index,
 
@@ -1818,6 +1798,9 @@ function will be needed.
                free(e);
                break;
 
+###### declare terminals
+       $TERM struct .
+
 ###### variable grammar
 
        | Variable . IDENTIFIER ${ {
@@ -2064,6 +2047,8 @@ an executable.
 
 ###### Grammar
 
+       $TERM True False
+
        $*val
        Value ->  True ${
                        $0 = new_val(Tbool, $1);
@@ -2185,6 +2170,8 @@ link to find the primary instance.
 
 ###### Grammar
 
+       $TERM : ::
+
        $*var
        VariableDecl -> IDENTIFIER : ${ {
                struct variable *v = var_decl(c, $1.txt);
@@ -3002,11 +2989,10 @@ is in-place.
 ###### Binode types
        Block,
 
-###### expr precedence
-       $TERM pass
-
 ###### Grammar
 
+       $TERM { } ;
+
        $*binode
        Block -> { IN OptNL Statementlist OUT OptNL } ${ $0 = $<Sl; }$
                | { SimpleStatements } ${ $0 = reorder_bilist($<SS); }$
@@ -3076,6 +3062,7 @@ is in-place.
                        $0->right = $<1;
                        }$
 
+       $TERM pass
        SimpleStatement -> pass ${ $0 = NULL; }$
                | ERROR ${ tok_err(c, "Syntax error in statement", &$1); }$
                ## SimpleStatement Grammar
@@ -3251,6 +3238,9 @@ it is declared, and error will be raised as the name is created as
        Assign,
        Declare,
 
+###### declare terminals
+       $TERM =
+
 ###### SimpleStatement Grammar
        | Variable = Expression ${
                        $0 = new(binode);
@@ -3374,6 +3364,7 @@ it is declared, and error will be raised as the name is created as
                        rtype = Tnone;
                } else {
                        free_value(v->type, v->val);
+                       free(v->val);
                        v->val = val_alloc(v->type, NULL);
                }
                break;
@@ -3921,6 +3912,8 @@ various declarations in the parse context.
        $void
        Ocean -> OptNL DeclarationList
 
+       ## declare terminals
+
        OptNL ->
                | OptNL NEWLINE
        Newlines -> NEWLINE
@@ -3964,6 +3957,8 @@ searching through for the Nth constant for decreasing N.
 
 ###### top level grammar
 
+       $TERM const
+
        DeclareConstant -> const { IN OptNL ConstList OUT OptNL } Newlines
                | const { SimpleConstList } Newlines
                | const IN OptNL ConstList OUT Newlines
@@ -4070,6 +4065,8 @@ analysis is a bit more interesting at this level.
                        c->prog = $<1;
        } }$
 
+       $TERM program
+
        $*binode
        Program -> program OpenScope Varlist ColonBlock Newlines ${
                $0 = new(binode);