summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pez.c126
1 files changed, 42 insertions, 84 deletions
diff --git a/pez.c b/pez.c
index d894bc0..edf305d 100644
--- a/pez.c
+++ b/pez.c
@@ -1283,14 +1283,12 @@ checkindex(PezContext *cx, int *idx, Fn *srcfn, int srcpc, const char *what, int
}
num = unbox_num(arg);
if (fixtrunc(num) != num) {
- runerr(cx, srcfn, srcpc, "non-integer %s index", what);
- return 0;
+ return runerr(cx, srcfn, srcpc, "non-integer %s index", what), 0;
}
*idx = fixtoint(num);
*idx = *idx < 0 ? len + *idx : *idx;
if (*idx >= len) {
- runerr(cx, srcfn, srcpc, "%s index out of range", what);
- return 0;
+ return runerr(cx, srcfn, srcpc, "%s index out of range", what), 0;
}
return 1;
}
@@ -1329,8 +1327,7 @@ apply(PezContext *cx, Val *ret, void *srcfn, int srcpc, Val recv, uint n)
} else if (isobj_of(recv, PEZ_TArray)) {
Array *arr = unbox_obj(recv);
if (n != 1) {
- runerr(cx, srcfn, srcpc, "array indexing takes one argument (got %d)", n);
- return 0;
+ return runerr(cx, srcfn, srcpc, "array indexing takes one argument (got %d)", n), 0;
}
arg = args[0];
if (arg.r == length_sstr.r) {
@@ -1351,8 +1348,7 @@ apply(PezContext *cx, Val *ret, void *srcfn, int srcpc, Val recv, uint n)
str = ((Str *)unbox_obj(recv))->dat;
}
if (n != 1) {
- runerr(cx, srcfn, srcpc, "string indexing takes one argument (got %d)", n);
- return 0;
+ return runerr(cx, srcfn, srcpc, "string indexing takes one argument (got %d)", n), 0;
}
arg = args[0];
if (arg.r == length_sstr.r) {
@@ -1362,8 +1358,7 @@ apply(PezContext *cx, Val *ret, void *srcfn, int srcpc, Val recv, uint n)
TRY(checkindex(cx, &idx, srcfn, srcpc, "string", len, arg));
*ret = (Val){(uint64_t)str[idx] << 56 | TAGSStr | 1 << 4};
} else {
- runerr(cx, srcfn, srcpc, "%s value is not applicable", typestr(recv));
- return 0;
+ return runerr(cx, srcfn, srcpc, "%s value is not applicable", typestr(recv)), 0;
}
return 1;
}
@@ -1374,8 +1369,7 @@ setapply(PezContext *cx, Val *ret, void *srcfn, int srcpc, Val recv, uint n, Val
int idx;
Val *args = cx->stktop - n, arg;
if (isobj_of(recv, PEZ_TFn) || iscfn(recv)) {
- runerr(cx, srcfn, srcpc, "procedure has no setter");
- return 0;
+ return runerr(cx, srcfn, srcpc, "procedure has no setter"), 0;
} else if (isobj_of(recv, PEZ_TDilambda)) {
Fn *setf = ((Dilambda *)unbox_obj(recv))->setf;
int nparams = setf->proto->nparams - 1;
@@ -1392,22 +1386,18 @@ setapply(PezContext *cx, Val *ret, void *srcfn, int srcpc, Val recv, uint n, Val
} else if (isobj_of(recv, PEZ_TArray)) {
Array *arr = unbox_obj(recv);
if (n != 1) {
- runerr(cx, srcfn, srcpc, "array indexing takes one argument");
- return 0;
+ return runerr(cx, srcfn, srcpc, "array indexing takes one argument"), 0;
}
arg = args[0];
if (arg.r == length_sstr.r) {
- runerr(cx, srcfn, srcpc, "cannot mutate array length");
- return 0;
+ return runerr(cx, srcfn, srcpc, "cannot mutate array length"), 0;
}
TRY(checkindex(cx, &idx, srcfn, srcpc, "array", arr->len, arg));
*ret = arr->at[idx] = rval;
} else if (issstr(recv) || isobj_of(recv, PEZ_TString)) {
- runerr(cx, srcfn, srcpc, "cannot mutate string");
- return 0;
+ return runerr(cx, srcfn, srcpc, "cannot mutate string"), 0;
} else {
- runerr(cx, srcfn, srcpc, "%s value is not settable", typestr(recv));
- return 0;
+ return runerr(cx, srcfn, srcpc, "%s value is not settable", typestr(recv)), 0;
}
return 1;
}
@@ -1539,8 +1529,7 @@ exefn(PezContext *cx, Fn *fn, uint nargs)
CASE(Oneg) {
Val *p = peek(cx);
if (!isnum(*p)) {
- runerr(cx, fn, ip, "attempt to negate %s value", typestr(*p));
- return 0;
+ return runerr(cx, fn, ip, "attempt to negate %s value", typestr(*p)), 0;
}
*p = box_num(-(uint32_t)unbox_num(*p));
}
@@ -1650,8 +1639,7 @@ exefn(PezContext *cx, Fn *fn, uint nargs)
fixnum num = unbox_num(a);
int idx = fixtoint(num) + pr->nparams;
if (!isnum(a) || num < 0 || fixtrunc(num) != num) {
- runerr(cx, fn, ip, "SEL expected positive integer index");
- return 0;
+ return runerr(cx, fn, ip, "SEL expected positive integer index"), 0;
}
TRY(push(cx, idx >= nargs ? VOID : args[idx]));
}
@@ -1676,8 +1664,7 @@ exefn(PezContext *cx, Fn *fn, uint nargs)
Str *s = unbox_obj(k);
name = s->dat;
} else { assert(0); }
- runerr(cx, fn, ip, "no such global \"%s\"", name);
- return 0;
+ return runerr(cx, fn, ip, "no such global \"%s\"", name), 0;
}
}
CASE(Osetglo) {
@@ -1696,8 +1683,7 @@ exefn(PezContext *cx, Fn *fn, uint nargs)
Str *s = unbox_obj(k);
name = s->dat;
} else { assert(0); }
- runerr(cx, fn, ip, "no such global \"%s\"", name);
- return 0;
+ return runerr(cx, fn, ip, "no such global \"%s\"", name), 0;
}
}
CASE(Oputglo) {
@@ -1803,8 +1789,7 @@ exefn(PezContext *cx, Fn *fn, uint nargs)
}
}
BADOP {
- runerr(cx, fn, ip, "bad opcode %#x", code[ip-1]);
- return 0;
+ return runerr(cx, fn, ip, "bad opcode %#x", code[ip-1]), 0;
}
VMEND
#undef BADOP
@@ -2195,8 +2180,7 @@ compconst(Comp *cm, Val v)
}
}
if (cm->con.len == UINT8_MAX) {
- comperr(cm, peekchr(cm), "too many consts");
- return 0;
+ return comperr(cm, peekchr(cm), "too many consts"), 0;
}
K:
vecpush(cm->cx, &cm->con, &v, 1);
@@ -2435,8 +2419,7 @@ static bool
expectchr(Comp *cm, int chr)
{
if (!matchchr(cm, chr)) {
- comperr(cm, peekchr(cm), "expected '%c'", chr);
- return 0;
+ return comperr(cm, peekchr(cm), "expected '%c'", chr), 0;
}
return 1;
}
@@ -2499,8 +2482,7 @@ readident(Comp *cm, char *dst, size_t size)
size_t i = 0;
while (!aissep(peekchr(cm))) {
if (i == size - 2) {
- comperr(cm, peekchr(cm), "identifier too long");
- return 0;
+ return comperr(cm, peekchr(cm), "identifier too long"), 0;
}
dst[i++] = nextchr(cm);
}
@@ -2516,8 +2498,7 @@ compclosure(Comp *cm, Proto *pr)
{
Val k = box_obj(pr);
if (cm->con.len == UINT8_MAX) {
- comperr(cm, peekchr(cm), "too many consts");
- return 0;
+ return comperr(cm, peekchr(cm), "too many consts"), 0;
}
TRY(vecpush(cm->cx, &cm->con, &k, 1));
TRY(compop(cm, Olambda));
@@ -2641,20 +2622,17 @@ primaryexpr(Comp *cm)
c = nextchr(cm);
begin:
if (i == sizeof buf - 1) {
- comperr(cm, c, "number literal too long");
- return 0;
+ return comperr(cm, c, "number literal too long"), 0;
}
buf[i++] = c;
} while ((c = peekchr(cm)) == '.' || !aissep(c));
buf[i++] = 0;
dbl = strtod(buf, &eptr);
if (eptr != buf + i - 1) {
- comperr(cm, c, "bad number literal '%s'", buf);
- return 0;
+ return comperr(cm, c, "bad number literal '%s'", buf), 0;
}
if (dbl > 0x80000) {
- comperr(cm, c, "number literal overflow '%s'", buf);
- return 0;
+ return comperr(cm, c, "number literal overflow '%s'", buf), 0;
}
num = ftofix(dbl);
cm->has_k = 1;
@@ -2681,8 +2659,7 @@ primaryexpr(Comp *cm)
return 1;
}
if (reserved(buf)) {
- comperr(cm, *buf, "'%s' is a reserved keyword", buf);
- return 0;
+ return comperr(cm, *buf, "'%s' is a reserved keyword", buf), 0;
}
Ident:
local = findlocal(cm, buf);
@@ -2736,8 +2713,7 @@ primaryexpr(Comp *cm)
}
if (i == 0) {
BadE:
- comperr(cm, c, "expected enum-like string constant");
- return 0;
+ return comperr(cm, c, "expected enum-like string constant"), 0;
}
buf[i] = 0;
TRY(box_str(cm->cx, &cm->k, buf, i));
@@ -2751,8 +2727,7 @@ primaryexpr(Comp *cm)
assert(i < sizeof buf - 2);
if (c == EOF) {
Eof:
- comperr(cm, c, "unterminated string constant");
- return 0;
+ return comperr(cm, c, "unterminated string constant"), 0;
}
if (c == '\\') {
switch ((c = nextchr(cm))) {
@@ -2812,8 +2787,7 @@ primaryexpr(Comp *cm)
do {
buf[i++] = c;
if (i == sizeof buf - 1) {
- comperr(cm, c, "bad literal '#%.*s'", i, buf);
- return 0;
+ return comperr(cm, c, "bad literal '#%.*s'", i, buf), 0;
}
c = nextchr(cm);
} while (!aissep(peekchr(cm)));
@@ -2825,8 +2799,7 @@ primaryexpr(Comp *cm)
return 1;
}
- comperr(cm, c, "bad literal '#%.*s'", i, buf);
- return 0;
+ return comperr(cm, c, "bad literal '#%.*s'", i, buf), 0;
} else if (c == '[') {
// array
int n = 0;
@@ -2851,14 +2824,11 @@ primaryexpr(Comp *cm)
TRY(compbyte(cm, n));
return 1;
} else if (c == EOF || aisspace(c)) {
- comperr(cm, c, "stray '#'");
- return 0;
+ return comperr(cm, c, "stray '#'"), 0;
}
- comperr(cm, c, "bad literal '#%c'", c);
- return 0;
+ return comperr(cm, c, "bad literal '#%c'", c), 0;
}
- comperr(cm, c, "expected expression");
- return 0;
+ return comperr(cm, c, "expected expression"), 0;
}
static bool
@@ -2892,8 +2862,7 @@ postfixexpr(Comp *cm)
eatspaces(cm);
if ((c = peekchr(cm)) != '_' && !aisalpha(c)) {
- comperr(cm, c, "expected identifier");
- return 0;
+ return comperr(cm, c, "expected identifier"), 0;
}
TRY(readident(cm, name, sizeof name));
if (!strcmp(name, "length")) {
@@ -3354,13 +3323,11 @@ setexpr(Comp *cm)
int idx = -1, argc = -1, opcode;
vec_of(uint8_t) *code = (void *)&cm->code.at;
if (!cm->lvalue) {
- comperr(cm, chr, "not an lvalue");
- return 0;
+ return comperr(cm, chr, "not an lvalue"), 0;
}
if (cm->lvalue_const) {
assert(cm->lvalue_name);
- comperr(cm, chr, "local '%s' is not mutable", cm->lvalue_name);
- return 0;
+ return comperr(cm, chr, "local '%s' is not mutable", cm->lvalue_name), 0;
}
/*
@@ -3464,8 +3431,7 @@ expr(Comp *cm)
cm->lvalue = 0;
TRY(setexpr(cm));
if (cm->stash_binopop) {
- comperr(cm, cm->stash_binopchr, "unexpected operator");
- return 0;
+ return comperr(cm, cm->stash_binopchr, "unexpected operator"), 0;
}
return 1;
}
@@ -3515,13 +3481,11 @@ decl(Comp *cm, Local **pl, bool nofold)
eatspaces(cm);
if ((c = peekchr(cm)) != '_' && !aisalpha(c)) {
- comperr(cm, c, "expected identifier");
- return 0;
+ return comperr(cm, c, "expected identifier"), 0;
}
TRY(readident(cm, name, sizeof name));
if (reserved(name)) {
- comperr(cm, *name, "'%s' is a reserved keyword", name);
- return 0;
+ return comperr(cm, *name, "'%s' is a reserved keyword", name), 0;
}
eatspaces(cm);
switch ((c = nextchr(cm))) {
@@ -3532,8 +3496,7 @@ decl(Comp *cm, Local **pl, bool nofold)
mutable = 1;
break;
default:
- comperr(cm, c, "expected ':' or '='");
- return 0;
+ return comperr(cm, c, "expected ':' or '='"), 0;
}
if (matchspchr(cm, '{')) {
@@ -3552,8 +3515,7 @@ decl(Comp *cm, Local **pl, bool nofold)
}
if (!cm->has_k || mutable) {
if (idx > 255) {
- comperr(cm, c, "too many locals");
- return 0;
+ return comperr(cm, c, "too many locals"), 0;
}
TRY(compop(cm, Odup));
TRY(compop(cm, Osetloc) && compbyte(cm, idx));
@@ -3629,8 +3591,7 @@ forstmt(Comp *cm)
TRY(expectspchr(cm, '['));
b_jumpto = *ip;
if (matchspchr(cm, ']')) {
- comperr(cm, ']', "expected operator");
- return 0;
+ return comperr(cm, ']', "expected operator"), 0;
}
cm->stash_local = &cm->fenv.locals.at[ilocal];
TRY(expr(cm));
@@ -3644,8 +3605,7 @@ forstmt(Comp *cm)
TRY(expectspchr(cm, '['));
cont = *ip;
if (matchspchr(cm, ']')) {
- comperr(cm, ']', "expected operator");
- return 0;
+ return comperr(cm, ']', "expected operator"), 0;
}
cm->stash_local = &cm->fenv.locals.at[ilocal];
TRY(expr(cm));
@@ -3696,8 +3656,7 @@ stmt(Comp *cm)
eatspaces(cm);
if ((c = peekchr(cm)) != '_' && !aisalpha(c)) {
- comperr(cm, c, "expected identifier");
- return 0;
+ return comperr(cm, c, "expected identifier"), 0;
}
TRY(readident(cm, name, sizeof name));
TRY(expectspchr(cm, '='));
@@ -3748,8 +3707,7 @@ block(Comp *cm, int endchr)
TRY(compop(cm, Ovoid));
}
if (eof) {
- comperr(cm, EOF, "unexpected end of input");
- return 0;
+ return comperr(cm, EOF, "unexpected end of input"), 0;
}
nextchr(cm);
endscope(cm);