aboutsummaryrefslogtreecommitdiff
path: root/bootstrap
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2022-08-18 09:47:54 +0200
committerlemon <lsof@mailbox.org>2022-08-18 09:47:54 +0200
commitf0214ff61b5a94b9629db6f43d7a5b010bd4ffbc (patch)
treec8517b4950bc3937e82ff49c757fb24a7364e3b0 /bootstrap
parent8c81c70b904a41b8a0d44dc418b7c39bf325c2a2 (diff)
fix bodyarg
Diffstat (limited to 'bootstrap')
-rw-r--r--bootstrap/all.h4
-rw-r--r--bootstrap/parse.c8
2 files changed, 9 insertions, 3 deletions
diff --git a/bootstrap/all.h b/bootstrap/all.h
index 720c7ea..bebdaf5 100644
--- a/bootstrap/all.h
+++ b/bootstrap/all.h
@@ -130,6 +130,8 @@ struct parser {
struct toktree toks;
const char *name;
struct span span;
+ struct tok peektok;
+ bool have_peektok;
int idx;
bool tepl;
} *curexpan; // macro expansions
@@ -226,7 +228,7 @@ struct fn {
};
struct macrocase {
- bool variadic;
+ bool variadic, bodyarg;
slice_t(const char *) params;
struct toktree body;
};
diff --git a/bootstrap/parse.c b/bootstrap/parse.c
index 078e3dd..c018262 100644
--- a/bootstrap/parse.c
+++ b/bootstrap/parse.c
@@ -308,6 +308,8 @@ lex(struct parser *P) {
--P->expanno;
free(ep->args.d);
P->curexpan = ep->prev;
+ P->have_peektok = ep->have_peektok;
+ P->peektok = ep->peektok;
free(ep);
return lex(P);
}
@@ -2319,8 +2321,7 @@ parseexpandmacro(struct parser *P, const struct macro *macro) {
break;
}
}
- eatspaces(P);
- if (chrpeek(P) == '{') {
+ if (lexpeek(P).t == '{') {
for (int i = 0; i < macro->cs.n; ++i) {
c = macro->cs.d[i];
if (args.length == c.params.n - 1 && c.bodyarg) {
@@ -2375,6 +2376,9 @@ ok:
expan.name = macro->name;
expan.args.d = expanargs;
expan.args.n = c.params.n;
+ expan.peektok = P->peektok;
+ expan.have_peektok = P->have_peektok;
+ P->have_peektok = 0;
expan.toks = c.body;
++P->expanno;
P->curexpan = memcpy(xmalloc(sizeof expan), &expan, sizeof expan);