summaryrefslogtreecommitdiff
path: root/parse/tok.c
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2014-12-13 23:21:11 -0800
committerOri Bernstein <ori@eigenstate.org>2014-12-13 23:21:44 -0800
commit24a3d753f2ac998c0b10579191984d79cfed0b7d (patch)
tree1b9733502a435451ce5ecf8785c14bbe1fc6705a /parse/tok.c
parent008887ccd998a43db6980fa57f1e210ec26c4acf (diff)
downloadmc-24a3d753f2ac998c0b10579191984d79cfed0b7d.tar.gz
Add plan9 instruction formats.
Work towards a plan9 port. This commit also fixes a bug with strings that contain '\0'. The commits got tangled, and I'm too lazy to detangle them.
Diffstat (limited to 'parse/tok.c')
-rw-r--r--parse/tok.c26
1 files changed, 15 insertions, 11 deletions
diff --git a/parse/tok.c b/parse/tok.c
index db9895f..f4ff221 100644
--- a/parse/tok.c
+++ b/parse/tok.c
@@ -233,7 +233,7 @@ static Tok *kwident(void)
if (!identstr(buf, sizeof buf))
return NULL;
t = mktok(kwd(buf));
- t->str = strdup(buf);
+ t->id = strdup(buf);
return t;
}
@@ -248,7 +248,8 @@ static void append(char **buf, size_t *len, size_t *sz, int c)
*buf = realloc(*buf, *sz);
}
- buf[0][len[0]++] = c;
+ buf[0][*len] = c;
+ (*len)++;
}
@@ -408,10 +409,13 @@ static Tok *strlit(void)
else
append(&buf, &len, &sz, c);
};
- append(&buf, &len, &sz, '\0');
-
t = mktok(Tstrlit);
- t->str = buf;
+ t->strval.len = len;
+
+ /* null terminator should not count towards length */
+ append(&buf, &len, &sz, '\0');
+ t->strval.buf = buf;
+ t->id = buf;
return t;
}
@@ -472,7 +476,7 @@ static Tok *charlit(void)
t = mktok(Tchrlit);
t->chrval = val;
- t->str = buf;
+ t->id = buf;
return t;
}
@@ -656,11 +660,11 @@ static Tok *number(int base)
/* we only support base 10 floats */
if (isfloat && base == 10) {
t = mktok(Tfloatlit);
- t->str = strdupn(&fbuf[start], fidx - start);
+ t->id = strdupn(&fbuf[start], fidx - start);
t->fltval = strtod(buf, NULL);
} else {
t = mktok(Tintlit);
- t->str = strdupn(&fbuf[start], fidx - start);
+ t->id = strdupn(&fbuf[start], fidx - start);
t->intval = strtoull(buf, NULL, base);
/* check suffixes:
* u -> unsigned
@@ -748,7 +752,7 @@ static Tok *typaram(void)
if (!identstr(buf, 1024))
return NULL;
t = mktok(Ttyparam);
- t->str = strdup(buf);
+ t->id = strdup(buf);
return t;
}
@@ -829,8 +833,8 @@ int yylex(void)
void yyerror(const char *s)
{
fprintf(stderr, "%s:%d: %s", filename, curloc.line, s);
- if (curtok->str)
- fprintf(stderr, " near \"%s\"", curtok->str);
+ if (curtok->id)
+ fprintf(stderr, " near \"%s\"", curtok->id);
fprintf(stderr, "\n");
exit(1);
}