summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pez.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/pez.c b/pez.c
index 72272ca..bcc8f8e 100644
--- a/pez.c
+++ b/pez.c
@@ -1954,11 +1954,13 @@ exefn(PezContext *cx, Fn *fn, uint nargs)
Val a = *peek();
if (isobj_of(a, PEZ_TArray)) {
*peek() = box_num(inttofix(((Array *)unbox_obj(a))->len));
+ } else if (isobj_of(a, PEZ_TString)) {
+ *peek() = box_num(inttofix(((Str *)unbox_obj(a))->len));
+ } else if (issstr(a)) {
+ *peek() = box_num(inttofix(sstr_len(a)));
} else {
- Val arg, ret;
- bool ok = box_str(cx, &arg, "length", 6);
- assert(ok);
- push(arg);
+ Val ret;
+ push(len_sstr);
cx->stktop = stktop;
ETRY(apply(cx, &ret, fn, ip, a, 1));
stktop = cx->stktop;
@@ -3402,7 +3404,7 @@ postfixexpr(Comp *cm)
return comperr(cm, c, "expected identifier"), 0;
}
TRY(readident(cm, name, sizeof name));
- if (!strcmp(name, "length")) {
+ if (!strcmp(name, "len")) {
TRY(compop(cm, Olength));
} else {
TRY(box_str(cm->cx, &s, name, strlen(name)));