From 1f48ccf32a0a7690d042da25fffe5c64ed216991 Mon Sep 17 00:00:00 2001 From: lemon Date: Tue, 17 Jun 2025 10:34:08 +0200 Subject: len fixes --- pez.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'pez.c') 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))); -- cgit v1.2.3