commit 390045cae16053d6bd1ff3bd914038ab9df89a62
parent 92be2fdd177503e315ae433b30bdc1c0c21faf38
Author: Quentin Carbonneaux <quentin.carbonneaux@yale.edu>
Date: Thu, 30 Jul 2015 21:58:52 -0400
compress parsref code a little
Diffstat:
1 file changed, 12 insertions(+), 20 deletions(-)
diff --git a/lisc/parse.c b/lisc/parse.c
@@ -275,36 +275,28 @@ varref(char *v)
static Ref
parseref()
{
- int64_t val;
- char *label;
- int i, ty;
+ int i;
+ Const c;
switch (next()) {
case TVar:
return varref(tokval.str);
case TNum:
- ty = CNum;
- val = tokval.num;
- label = "";
- for (i=0; i<ncst; i++)
- if (cst[i].type == CNum)
- if (cst[i].val == val)
- return CONST(i);
- goto New;
+ c = (Const){.type = CNum, .val = tokval.num};
+ strcpy(c.label, "");
+ if (0) {
case TAddr:
- ty = CAddr;
- val = 0;
- label = tokval.str;
+ c = (Const){.type = CAddr, .val = 0};
+ strcpy(c.label, tokval.str);
+ }
for (i=0; i<ncst; i++)
- if (cst[i].type == CAddr)
- if (strcmp(cst[i].label, label) == 0)
+ if (cst[i].type == c.type
+ && cst[i].val == c.val
+ && strcmp(cst[i].label, c.label) == 0)
return CONST(i);
- New:
if (i >= NCst)
err("too many constants");
- cst[i].type = ty;
- cst[i].val = val;
- strcpy(cst[i].label, label);
+ cst[i] = c;
ncst++;
return CONST(i);
default: