]> ocean-lang.org Git - ocean/commitdiff
oceani: don't store 'tail' in 'struct value'.
authorNeilBrown <neil@brown.name>
Tue, 2 Apr 2019 01:36:35 +0000 (12:36 +1100)
committerNeilBrown <neil@brown.name>
Tue, 2 Apr 2019 01:36:35 +0000 (12:36 +1100)
It is never used so there isn't much point
storing it.  If/When we do use it, we'll
parse it immediately and store the meaning.
And in any case, it should be char[3].

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

index 90b14921c588d4baab4f6c6fbb8f8f4760a15e50..a8da9fbf8037804ef6b6ad87a0d50985be7cf28b 100644 (file)
@@ -399,10 +399,7 @@ fractions, strings, Booleans and labels.  When analysing the program
 we also need to allow for places where no value is meaningful
 (`Vnone`) and where we don't know what type to expect yet (`Vunknown`
 which can be anything and `Vnolabel` which can be anything except a
-label).  A 2 character 'tail' is included in each value as the scanner
-wants to parse that from the end of numbers and we need somewhere to
-put it.  It is currently ignored but one day might allow for
-e.g. "imaginary" numbers.
+label).
 
 Values are never shared, they are always copied when used, and freed
 when no longer needed.
@@ -440,7 +437,6 @@ to parse each type from a string.
                        int bool;
                        void *label;
                };
-               char tail[2];
        };
 
        char *vtype_names[] = {"nolabel", "unknown", "none", "string",
@@ -582,6 +578,8 @@ to parse each type from a string.
        {
                struct text tx;
                int neg = 0;
+               char tail[3] = "";
+
                switch(vl->vtype) {
                case Vnolabel:
                case Vlabel:
@@ -599,10 +597,14 @@ to parse each type from a string.
                                arg++;
                        }
                        tx.txt = arg; tx.len = strlen(tx.txt);
-                       if (number_parse(vl->num, vl->tail, tx) == 0)
+                       if (number_parse(vl->num, tail, tx) == 0)
                                mpq_init(vl->num);
                        else if (neg)
                                mpq_neg(vl->num, vl->num);
+                       if (tail[0]) {
+                               printf("Unsupported suffix: %s\n", arg);
+                               return 0;
+                       }
                        break;
                case Vbool:
                        if (strcasecmp(arg, "true") == 0 ||
@@ -1291,27 +1293,36 @@ an executable.
                | NUMBER ${
                        $0 = new_pos(val, $1);
                        $0->val.vtype = Vnum;
-                       if (number_parse($0->val.num, $0->val.tail, $1.txt) == 0)
+                       {
+                       char tail[3];
+                       if (number_parse($0->val.num, tail, $1.txt) == 0)
                                mpq_init($0->val.num);
-                               if ($0->val.tail[0])
+                               if (tail[0])
                                        tok_err(config2context(config), "error: unsupported number suffix.",
                                                &$1);
+                       }
                        }$
                | STRING ${
                        $0 = new_pos(val, $1);
                        $0->val.vtype = Vstr;
-                       string_parse(&$1, '\\', &$0->val.str, $0->val.tail);
-                       if ($0->val.tail[0])
+                       {
+                       char tail[3];
+                       string_parse(&$1, '\\', &$0->val.str, tail);
+                       if (tail[0])
                                tok_err(config2context(config), "error: unsupported string suffix.",
                                        &$1);
+                       }
                        }$
                | MULTI_STRING ${
                        $0 = new_pos(val, $1);
                        $0->val.vtype = Vstr;
-                       string_parse(&$1, '\\', &$0->val.str, $0->val.tail);
-                       if ($0->val.tail[0])
+                       {
+                       char tail[3];
+                       string_parse(&$1, '\\', &$0->val.str, tail);
+                       if (tail[0])
                                tok_err(config2context(config), "error: unsupported string suffix.",
                                        &$1);
+                       }
                        }$
 
 ###### print exec cases