From 2d3b3f67a78d853da192c5568a29710fb8898a6c Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Sat, 18 Dec 2021 14:34:16 +1100 Subject: [PATCH] oceani: use new slice syntax for argv argument. 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 --- csrc/oceani-tests.mdc | 6 +++--- csrc/oceani.mdc | 38 ++++++++++---------------------------- 2 files changed, 13 insertions(+), 31 deletions(-) diff --git a/csrc/oceani-tests.mdc b/csrc/oceani-tests.mdc index 03aa850..9db8e93 100644 --- a/csrc/oceani-tests.mdc +++ b/csrc/oceani-tests.mdc @@ -113,7 +113,7 @@ calculations on them. ###### 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 ab, a>=b, aarray.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) - return 1; // UNTESTED + return 1; 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; } }$ -###### Grammar - $*type - OptType -> Type ${ $0 = $<1; }$ - | ${ $0 = NULL; }$ - ###### formal type grammar - | [ IDENTIFIER :: OptType ] Type ${ { - struct variable *v = var_decl(c, $ID.txt); - - v->type = $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 = $array.size = 0; $0->array.unspec = 1; - $0->array.vsize = v; + $0->array.vsize = NULL; } }$ ###### 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; - mpq_t argcq; 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++) { @@ -6012,7 +5994,7 @@ things which will likely grow as the languages grows. 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 -- 2.43.0