diff options
| author | 2025-06-17 10:34:08 +0200 | |
|---|---|---|
| committer | 2025-06-17 10:35:15 +0200 | |
| commit | 1f48ccf32a0a7690d042da25fffe5c64ed216991 (patch) | |
| tree | 80afc649c4263eab3535fdcc5423c3f790f30a89 | |
| parent | 3a8dcfa8b8ee6311cc6426e12580cfd179d3eb1d (diff) | |
len fixes
| -rw-r--r-- | pez.c | 12 |
1 files changed, 7 insertions, 5 deletions
@@ -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))); |