diff options
| -rw-r--r-- | pez.c | 13 | ||||
| -rw-r--r-- | test.pez | 15 |
2 files changed, 25 insertions, 3 deletions
@@ -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 }, }; @@ -49,4 +49,17 @@ printf["test %a\n", gather[-1, (), 'x]] ys } -printf["%a\n", map["abcd", #[1,2,0]]] +printf["maps %a\n", map["abcd", #[1,2,0]]] + +@inspect: {[m] + printf["%a\n", m] +} + +@r: #{"a" 1, "b" 2, 0 "a"} +r[0]=r + +printf["r: "] inspect[r] +printf["r.a -> %a\n", r[0].a] +{ + inspect [#{0 3,"a" 3}] +}[] |