commit 1671be35a24f26108bd967f439caa2c7654adec5
parent a7e362e3fe8a5abde59ea1e91bec132b1fb0c2f7
Author: thing1 <thing1@seacrossedlovers.xyz>
Date: Sat, 29 Nov 2025 23:45:41 +0000
fixed bug caused by forgetting an alloc
Diffstat:
| M | spl.c | | | 23 | ++++++++++++++++------- |
1 file changed, 16 insertions(+), 7 deletions(-)
diff --git a/spl.c b/spl.c
@@ -138,7 +138,7 @@ findlowest(tok *start, tok *end) {
rexpr *
parsesimple(tok *start, tok *end, tok *lowest, mctx *ctx) {
- rexpr *e;
+ rexpr *e = alloczctx(ctx, sizeof(rexpr));
switch (lowest->op) {
case INT:
if (start != end) {
@@ -173,9 +173,11 @@ parsebin(tok *start, tok *end, tok *lowest, mctx *ctx) {
return NULL;
}
+ // I think this is the spot!
+
e->op = lowest->op;
- if (!(e->expr[0] = parserexpr(start, &lowest[-1], ctx))) return NULL;
- else if (!(e->expr[1] = parserexpr(&lowest[1], end, ctx))) return NULL;
+ e->expr[0] = parserexpr(start, &lowest[-1], ctx);
+ e->expr[1] = parserexpr(&lowest[1], end, ctx);
return e;
}
@@ -235,7 +237,7 @@ parseassign(lex *l, tok name, mctx *ctx) {
SAVE(l);
lexpr *le;
type *ty;
- rexpr *r;
+ rexpr *r = NULL;
tok *arr, t;
int count = 1;
@@ -243,13 +245,14 @@ parseassign(lex *l, tok name, mctx *ctx) {
RESTORE(l);
return NULL;
}
- if (next(l).op != ASSIGN) {
+ if ((t = next(l)).op != ASSIGN) {
+ if (t.op == SEMI) goto shortdec;
RESTORE(l);
return NULL;
}
arr = alloczctx(ctx, sizeof(tok));
- while ((t = next(l)).op != LEOF && t.op != SEMI) {
+ while ((t = next(l)).op != LEOF && t.op != SEMI) { /* TODO switch this check out for some kind is termiating thing */
arr[count++ - 1] = t;
arr = realloczctx(ctx, arr, sizeof(tok) * count);
}
@@ -261,6 +264,7 @@ parseassign(lex *l, tok name, mctx *ctx) {
return NULL;
}
+shortdec:
le = alloczctx(ctx, sizeof(lexpr));
le->op = LEXPR_ASSIGN;
le->name = name.name;
@@ -291,12 +295,17 @@ parselexpr(lex *l, mctx *ctx) {
int
main() {
- lex l = mklexer("a int = 5 +);");
+ lex l = mklexer("a int;");
mctx *ctx = newctx();
lexpr *e = parselexpr(&l, ctx);
if (!e) {
parserErr("failed to parse lexpr");
+ goto cleanup;
}
+ if (e->rexpr) printf("%s is of type %s = %d\n", e->name, e->type->name, eval(e->rexpr));
+ else printf("%s is of type %s\n", e->name, e->type->name);
+
+cleanup:
freectx(ctx);
}