]> ocean-lang.org Git - ocean/commitdiff
oceani: use new slice syntax for argv argument.
authorNeilBrown <neil@brown.name>
Sat, 18 Dec 2021 03:34:16 +0000 (14:34 +1100)
committerNeilBrown <neil@brown.name>
Sat, 18 Dec 2021 07:36:58 +0000 (18:36 +1100)
Rather than "argv:[argc::]string", the argv parameter is now
  "argv:[]string"
This will be the syntax for general array references.

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

index 03aa85083bd25f866f0cf65ccb78402880f90d7f..9db8e9363a469d66beb43cdceae215136542a862 100644 (file)
@@ -113,7 +113,7 @@ calculations on them.
 
 ###### test: valvar
 
 
 ###### test: valvar
 
-       func main(argv:[argc::]string)
+       func main(argv:[]string)
                a := 23; b:=12 ; b1 := -b
                print a, b, a+b, a-b, a*b, a/b, a%b
                print a<b, a<=b, a>b, a>=b, a<a, a==b, a==a
                a := 23; b:=12 ; b1 := -b
                print a, b, a+b, a-b, a*b, a/b, a%b
                print a<b, a<=b, a>b, a>=b, a<a, a==b, a==a
@@ -319,7 +319,7 @@ Here I break it into two parts, keeping the array code separate.
 
 ###### test: sayhello
 
 
 ###### test: sayhello
 
-       func main(av:[ac::number]string)
+       func main(av:[]string)
                A := $av[1]; B := $av[2]
                astr := av[3]
                l := av[]
                A := $av[1]; B := $av[2]
                astr := av[3]
                l := av[]
@@ -750,7 +750,7 @@ A simple linked list example
                        freelist(lp)
                        @free = list.next
 
                        freelist(lp)
                        @free = list.next
 
-       func main(argv:[ac::]string)
+       func main(argv:[]string)
                list : linkage
 
                insert(list, "@start");
                list : linkage
 
                insert(list, "@start");
index fb154be366f3c5759231c29fd7a0309daa001581..a3574ea24e91167880aa12d2cff4bcefc1a1e412 100644 (file)
@@ -2468,15 +2468,11 @@ with a const size by whether they are prepared at parse time or not.
                /* Both are arrays, so we can look at details */
                if (!type_compat(require->array.member, have->array.member, 0))
                        return 0;
                /* Both are arrays, so we can look at details */
                if (!type_compat(require->array.member, have->array.member, 0))
                        return 0;
-               if (have->array.unspec && require->array.unspec) {
-                       if (have->array.vsize && require->array.vsize &&
-                           have->array.vsize != require->array.vsize)  // UNTESTED
-                               /* sizes might not be the same */
-                               return 0;       // UNTESTED
-                       return 1;
-               }
+               if (have->array.unspec && require->array.unspec &&
+                   have->array.size != require->array.size)
+                       return 0;       // UNTESTED
                if (have->array.unspec || require->array.unspec)
                if (have->array.unspec || require->array.unspec)
-                       return 1;       // UNTESTED
+                       return 1;
                if (require->array.vsize == NULL && have->array.vsize == NULL)
                        return require->array.size == have->array.size;
 
                if (require->array.vsize == NULL && have->array.vsize == NULL)
                        return require->array.size == have->array.size;
 
@@ -2554,25 +2550,14 @@ with a const size by whether they are prepared at parse time or not.
                $0->array.vsize = v;
        } }$
 
                $0->array.vsize = v;
        } }$
 
-###### Grammar
-       $*type
-       OptType -> Type ${ $0 = $<1; }$
-               | ${ $0 = NULL; }$
-
 ###### formal type grammar
 
 ###### formal type grammar
 
-       | [ IDENTIFIER :: OptType ] Type ${ {
-               struct variable *v = var_decl(c, $ID.txt);
-
-               v->type = $<OT;
-               v->constant = 1;
-               if (!v->type)
-                       v->type = Tnum;
-               $0 = add_anon_type(c, &array_prototype, "array[var]");
-               $0->array.member = $<6;
+       | [ ] Type ${ {
+               $0 = add_anon_type(c, &array_prototype, "array[]");
+               $0->array.member = $<Type;
                $0->array.size = 0;
                $0->array.unspec = 1;
                $0->array.size = 0;
                $0->array.unspec = 1;
-               $0->array.vsize = v;
+               $0->array.vsize = NULL;
        } }$
 
 ###### Binode types
        } }$
 
 ###### Binode types
@@ -5950,15 +5935,12 @@ is a bit more interesting at this level.
                        struct value *vl = var_value(c, v->var);
                        struct value arg;
                        struct type *t;
                        struct value *vl = var_value(c, v->var);
                        struct value arg;
                        struct type *t;
-                       mpq_t argcq;
                        int i;
 
                        switch (anum++) {
                        case 0: /* argv */
                                t = v->var->type;
                        int i;
 
                        switch (anum++) {
                        case 0: /* argv */
                                t = v->var->type;
-                               mpq_init(argcq);
-                               mpq_set_ui(argcq, argc, 1);
-                               memcpy(var_value(c, t->array.vsize), &argcq, sizeof(argcq));
+                               t->array.size = argc;
                                t->prepare_type(c, t, 0);
                                array_init(v->var->type, vl);
                                for (i = 0; i < argc; i++) {
                                t->prepare_type(c, t, 0);
                                array_init(v->var->type, vl);
                                for (i = 0; i < argc; i++) {
@@ -6012,7 +5994,7 @@ things which will likely grow as the languages grows.
                name:string
                alive:Boolean
 
                name:string
                alive:Boolean
 
-       func main(argv:[argc::]string)
+       func main(argv:[]string)
                print "Hello World, what lovely oceans you have!"
                print "Are there", five, "?"
                print pi, pie, "but", cake
                print "Hello World, what lovely oceans you have!"
                print "Are there", five, "?"
                print pi, pie, "but", cake