From 2e327ef2ce5a1507d8e54a5a3fa510f1f625f884 Mon Sep 17 00:00:00 2001 From: lemon Date: Mon, 10 Oct 2022 23:56:16 +0200 Subject: fix minor misc bugs --- pez.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/pez.c b/pez.c index bfe40f7..c9a0a88 100644 --- a/pez.c +++ b/pez.c @@ -538,7 +538,7 @@ newfn(PezContext *cx, Proto *pr, Val *args, Val *locals, Fn *parent) } fn->upval[i] = up; } else { - assert(fn && upinfo->idx < parent->nupval); + assert(fn && parent && upinfo->idx < parent->nupval); fn->upval[i] = parent->upval[upinfo->idx]; } } @@ -2111,7 +2111,6 @@ static int peekchr(Comp *cm); static bool compconst(Comp *cm, Val v) { - int t; if (isvoid(v)) { TRY(compop(cm, Ovoid)); return 1; @@ -2148,7 +2147,7 @@ compconst(Comp *cm, Val v) TRY(compbytes(cm, s, n)); return 1; } - if (isobj(v) && (t = objtag(v)) == PEZ_TString) { + if (isobj_of(v, PEZ_TString)) { uint8_t idx = cm->con.len; for (uint i = 0; i < cm->con.len; ++i) { if (cm->con.at[i].r == v.r) { @@ -2590,6 +2589,7 @@ primaryexpr(Comp *cm) if (cm->stash_local) { local = cm->stash_local; cm->stash_local = NULL; + *buf = cm->spool.at[local->sref]; goto Local; } eatspaces(cm); @@ -3206,7 +3206,7 @@ logicexpr(Comp *cm) char kind, chr; int op, op2; TRY(cmpexpr(cm)); - op = getbinop(&kind, &chr, cm), op2 = op; + op = getbinop(&kind, &chr, cm); if (kind != 'L') { stashbinop(cm, op, kind, chr); return 1; @@ -3858,7 +3858,9 @@ pez_new(PezAllocFn *alloc, void *userdata, size_t stacksize) return cx; Err: - cx->err = PEZ_ENoMem; + if (cx) { + cx->err = PEZ_ENoMem; + } if (cx && cx->stack) { cxfree(cx, cx->stack, sizeof(Val) * stacksize); } @@ -4067,7 +4069,7 @@ pez_checksig(PezContext *cx, int argc, const char *fn, const char *sig) int thisn; int typ; typ = 1 << pez_typeof(cx, -argc + arg); - while (*sig && *sig != ',') { + do { const char *t = sigget(&sig); if (!strncmp(t, "any", 3)) mask |= ~0u; else if (!strncmp(t, "void", 4)) mask |= 1 << PEZ_TVoid; @@ -4098,7 +4100,7 @@ pez_checksig(PezContext *cx, int argc, const char *fn, const char *sig) assert(!*sig || *sig == '|' || *sig == ','); sig += *sig == '|'; skipspaces(&sig); - } + } while (*sig && *sig != ','); if ((typ & mask) == 0) { pez_error(cx, fn, "arg #%d mismatch: expected %.*s, got %s", arg, thisn, this, pez_typename(cx, -argc + arg)); -- cgit v1.2.3