summaryrefslogtreecommitdiff
path: root/pez.c
diff options
context:
space:
mode:
Diffstat (limited to 'pez.c')
-rw-r--r--pez.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/pez.c b/pez.c
index 98f7d08..92f9a47 100644
--- a/pez.c
+++ b/pez.c
@@ -1555,6 +1555,7 @@ exefn(PezContext *cx, Fn *fn, uint nargs)
TRY(push(cx, VOID));
++stktop;
}
+ /* Val *start = stktop; */
assert(pr->nstack > 0);
if (stktop + pr->nstack >= cx->stkend) {
return cx->err = PEZ_EStack, 0;
@@ -1576,7 +1577,7 @@ exefn(PezContext *cx, Fn *fn, uint nargs)
#define BADOP break; default:
#endif
#define push(x) (*stktop++ = (x))
-#define pop() (*--stktop)
+#define pop() (/*assert(start < stktop),*/ *--stktop)
#define peek() (&stktop[-1])
VMBEGIN
@@ -1924,7 +1925,7 @@ exefn(PezContext *cx, Fn *fn, uint nargs)
uint8_t n = code[ip++];
Record *rc;
TRY((rc = newrecord(cx, n, stktop - 2*n)) != NULL);
- stktop -= n + 1;
+ stktop -= 2*n;
push(box_obj(rc));
}
CASE(Ob) {
@@ -2203,6 +2204,13 @@ f_arraynew(PezContext *cx, int argc)
}
static bool
+f_typeof(PezContext *cx, int argc)
+{
+ TRY(pez_checksig(cx, argc, "typeof", "any"));
+ return pez_pushstring(cx, pez_typename(cx, -1), -1);
+}
+
+static bool
f_arraypush(PezContext *cx, int argc)
{
Array *arr;
@@ -2216,6 +2224,7 @@ static const struct coredef { const char *n; PezCFn *f; } core[] = {
{ "printf", f_printf },
{ "sprintf", f_sprintf },
{ "dilambda", f_dilambda },
+ { "typeof", f_typeof },
{ "array#new", f_arraynew },
{ "array#push", f_arraypush },
};