quipu mercurial repository
Révision | aed7a79b97e67f92fabb7f60ee84effcd13b2a69 (tree) |
---|---|
l'heure | 2019-11-15 04:04:20 |
Auteur | Agustina Arzille <avarzille@rise...> |
Commiter | Agustina Arzille |
Start using the 'len_a' interface
@@ -62,12 +62,12 @@ | ||
62 | 62 | if (!array_p (argv[i])) |
63 | 63 | interp->raise ("type-error", "arguments must be arrays"); |
64 | 64 | |
65 | - nlen += as_array(argv[i])->len; | |
65 | + nlen += len_a (argv[i]); | |
66 | 66 | } |
67 | 67 | |
68 | 68 | object *dstp = as_array(alloc_array (interp, nlen))->data; |
69 | 69 | for (int i = 0; i < argc; ++i) |
70 | - dstp = copy_objs (dstp, as_array(argv[i])->data, as_array(argv[i])->len); | |
70 | + dstp = copy_objs (dstp, &xaref(argv[i], 0), len_a (argv[i])); | |
71 | 71 | |
72 | 72 | qp_return (interp->alval); |
73 | 73 | } |
@@ -182,7 +182,7 @@ | ||
182 | 182 | uint32_t ret = ARRAY_HASH_SEED; |
183 | 183 | valref objp (interp, fixint (0)); |
184 | 184 | |
185 | - for (uint32_t i = 0; i < as_array(obj)->len; ++i) | |
185 | + for (uint32_t i = 0; i < len_a (obj); ++i) | |
186 | 186 | ret = mix_hash (ret, xhash (interp, *objp = xaref (obj, i))); |
187 | 187 | |
188 | 188 | return (ret); |
@@ -305,14 +305,14 @@ | ||
305 | 305 | object iter_a (interpreter *interp, object obj, object token, bool adv) |
306 | 306 | { |
307 | 307 | if (token == UNBOUND) |
308 | - qp_return (as_array(obj)->len == 0 ? NIL : fixint (0)); | |
308 | + qp_return (len_a (obj) == 0 ? NIL : fixint (0)); | |
309 | 309 | else if (!adv) |
310 | 310 | return (get_a (interp, obj, token, UNBOUND)); |
311 | 311 | else if (!fixint_p (token)) |
312 | 312 | interp->raise ("type-error", "token must be an int"); |
313 | 313 | |
314 | 314 | int ix = as_int (token) + 1; |
315 | - qp_return ((uint32_t)ix >= as_array(obj)->len ? NIL : fixint (ix)); | |
315 | + qp_return ((uint32_t)ix >= len_a (obj) ? NIL : fixint (ix)); | |
316 | 316 | } |
317 | 317 | |
318 | 318 | object nzap_a (interpreter *interp, object obj, object key, |
@@ -66,7 +66,7 @@ | ||
66 | 66 | } |
67 | 67 | |
68 | 68 | inline uint32_t |
69 | -alen (object __obj) | |
69 | +len_a (object __obj) | |
70 | 70 | { |
71 | 71 | return (as_array(__obj)->len); |
72 | 72 | } |
@@ -134,7 +134,7 @@ | ||
134 | 134 | |
135 | 135 | if (obj == NIL) |
136 | 136 | return (strm->putb (interp, PACK_NIL)); |
137 | - else if (array_p (obj) && as_array(obj)->len == 0) | |
137 | + else if (array_p (obj) && len_a (obj) == 0) | |
138 | 138 | return (strm->putb (interp, PACK_EMPTY_ARRAY)); |
139 | 139 | else if ((str_p (obj) || bvector_p (obj)) && as_bvector(obj)->nbytes == 0) |
140 | 140 | return (strm->putb (interp, str_p (obj) ? |
@@ -379,7 +379,7 @@ | ||
379 | 379 | switch (itype (obj)) |
380 | 380 | { |
381 | 381 | case typecode::ARRAY: |
382 | - return (as_array(obj)->len); | |
382 | + return (len_a (obj)); | |
383 | 383 | case typecode::TUPLE: |
384 | 384 | return (len_o (interp, obj)); |
385 | 385 | case typecode::BVECTOR: |
@@ -53,7 +53,7 @@ | ||
53 | 53 | uint32_t saved_objlen; |
54 | 54 | |
55 | 55 | coro_state (interpreter *ip) : call_guard (ip), |
56 | - stkobj (ip, ip->stkobj), saved_objlen (as_array(ip->stkobj)->len) | |
56 | + stkobj (ip, ip->stkobj), saved_objlen (len_a (ip->stkobj)) | |
57 | 57 | { // Make sure the GC doesn't scan past the interpreter's stack end. |
58 | 58 | as_array(ip->stkobj)->len = this->sp; |
59 | 59 | } |
@@ -86,7 +86,7 @@ | ||
86 | 86 | interp->exc_offset = crp->exc_off; |
87 | 87 | |
88 | 88 | if (qp_unlikely (array_p (crp->dbinds))) |
89 | - for (uint32_t i = 0; i < as_array(crp->dbinds)->len; i += 2) | |
89 | + for (uint32_t i = 0; i < len_a (crp->dbinds); i += 2) | |
90 | 90 | interp->tl_syms[symtlidx (xaref (crp->dbinds, i)) - 1] = |
91 | 91 | xaref (crp->dbinds, i + 1); |
92 | 92 |
@@ -31,7 +31,7 @@ | ||
31 | 31 | for (ix = 0; ix < extra; ++ix) |
32 | 32 | argv[ix] = UNBOUND; |
33 | 33 | |
34 | - uint32_t n = as_array(kwtab)->len / 2; | |
34 | + uint32_t n = len_a (kwtab) / 2; | |
35 | 35 | |
36 | 36 | for (ix = nreq; ix < nargs; ++ix) |
37 | 37 | { |
@@ -159,7 +159,7 @@ | ||
159 | 159 | interp->push (xcar (seq)); |
160 | 160 | } |
161 | 161 | else if (array_p (seq)) |
162 | - for (; ret < as_array(seq)->len; ++ret) | |
162 | + for (; ret < len_a (seq); ++ret) | |
163 | 163 | interp->push (xaref (seq, ret)); |
164 | 164 | else if (table_p (seq)) |
165 | 165 | for (table::iterator it (interp, seq); it.valid (); ++it, ++ret) |
@@ -185,8 +185,7 @@ | ||
185 | 185 | static inline int |
186 | 186 | meth_cmptypes (interpreter *interp, object x, object y) |
187 | 187 | { |
188 | - if (!array_p (x) || !array_p (y) || | |
189 | - as_array(x)->len < 2 || as_array(y)->len < 2) | |
188 | + if (!array_p (x) || !array_p (y) || len_a (x) < 2 || len_a (y) < 2) | |
190 | 189 | return (-1); |
191 | 190 | |
192 | 191 | auto a1 = as_array (x), a2 = as_array (y); |
@@ -238,7 +237,7 @@ | ||
238 | 237 | static inline bool |
239 | 238 | meth_try (const array *tp, object elem) |
240 | 239 | { |
241 | - for (uint32_t i = 1; i < as_array(elem)->len; ++i) | |
240 | + for (uint32_t i = 1; i < len_a (elem); ++i) | |
242 | 241 | if (xaref (elem, i) != fixint (0) && |
243 | 242 | subtype_p (tp->data[i], xaref (elem, i)) != 1) |
244 | 243 | return (false); |
@@ -342,7 +341,7 @@ | ||
342 | 341 | object node = *vals->data; |
343 | 342 | auto next = tuple::iterator::make (interp, node); |
344 | 343 | object curr_key = *next++; |
345 | - uint32_t nreq = alen (curr_key) - 1; | |
344 | + uint32_t nreq = len_a (curr_key) - 1; | |
346 | 345 | |
347 | 346 | if (argc) |
348 | 347 | { |
@@ -400,7 +399,7 @@ | ||
400 | 399 | |
401 | 400 | uint32_t ntypes = as_fct(fct)->min_argc; |
402 | 401 | array *ret = array::alloc_raw (ntypes + nargs + 1); |
403 | - ret->data[0] = xaref (fct_vals (fct), alen (fct_vals (fct)) - 1); | |
402 | + ret->data[0] = xaref (fct_vals (fct), len_a (fct_vals (fct)) - 1); | |
404 | 403 | |
405 | 404 | for (uint32_t i = 0; i < ntypes; ++i) |
406 | 405 | ret->data[i + 1] = type (interp->stack[off]); |
@@ -463,7 +462,7 @@ | ||
463 | 462 | interp->raise ("arg-error", "first argument " |
464 | 463 | "is not a generic function"); |
465 | 464 | else if (!array_p (argv[2]) || |
466 | - as_array(argv[2])->len != (uint32_t)as_fct(argv[1])->min_argc + 1) | |
465 | + len_a (argv[2]) != (uint32_t)as_fct(argv[1])->min_argc + 1) | |
467 | 466 | interp->raise ("arg-error", |
468 | 467 | QP_SPRINTF (interp, "second argument is not an array of len %Q", |
469 | 468 | fixint (as_fct(argv[1])->min_argc + 1))); |
@@ -484,7 +483,7 @@ | ||
484 | 483 | else |
485 | 484 | { |
486 | 485 | object vals = fct_vals (*fn); |
487 | - uint32_t len = alen (vals); | |
486 | + uint32_t len = len_a (vals); | |
488 | 487 | object nv = alloc_array (interp, len + 1); |
489 | 488 | |
490 | 489 | copy_objs (&xaref(nv, 0), &xaref(vals, 0), len); |
@@ -497,7 +496,7 @@ | ||
497 | 496 | |
498 | 497 | object node = tuple_nearest (interp, cache, argv[2]); |
499 | 498 | nput_a (interp, fct_vals (*fn), |
500 | - fixint (alen (fct_vals (*fn)) - 1), node); | |
499 | + fixint (len_a (fct_vals (*fn)) - 1), node); | |
501 | 500 | |
502 | 501 | qp_return (*fn); |
503 | 502 | } |
@@ -1683,7 +1683,7 @@ | ||
1683 | 1683 | |
1684 | 1684 | uint32_t pack_cache::size () const |
1685 | 1685 | { |
1686 | - return (as_array(*this->ref)->len / 2); | |
1686 | + return (len_a (*this->ref) / 2); | |
1687 | 1687 | } |
1688 | 1688 | |
1689 | 1689 | object* pack_cache::data () |
@@ -46,7 +46,7 @@ | ||
46 | 46 | do |
47 | 47 | { |
48 | 48 | object vec = xcar (tr), caller = xaref (vec, 0); |
49 | - uint32_t vl = as_array(vec)->len; | |
49 | + uint32_t vl = len_a (vec); | |
50 | 50 | char sbuf[64]; |
51 | 51 | |
52 | 52 | strmp->write (interp, sbuf, sprintf (sbuf, " %d: (", idx++)); |
@@ -359,7 +359,7 @@ | ||
359 | 359 | |
360 | 360 | bool package::iterator::valid () const |
361 | 361 | { |
362 | - return (this->idx < as_array(*this->symtab)->len); | |
362 | + return (this->idx < len_a (*this->symtab)); | |
363 | 363 | } |
364 | 364 | |
365 | 365 | package::iterator& package::iterator::operator++ () |
@@ -803,7 +803,7 @@ | ||
803 | 803 | |
804 | 804 | object vec, ival; |
805 | 805 | |
806 | - if (!array_p (token) || as_array(token)->len != 4 || | |
806 | + if (!array_p (token) || len_a (token) != 4 || | |
807 | 807 | !fixint_p (ival = xaref (token, 3)) || !array_p (vec = xaref (token, 2))) |
808 | 808 | interp->raise ("arg-error", "invalid token"); |
809 | 809 | else if (!adv) |
@@ -38,7 +38,7 @@ | ||
38 | 38 | static inline int |
39 | 39 | node_nlvl (object obj) |
40 | 40 | { |
41 | - return (as_array(obj)->len); | |
41 | + return (len_a (obj)); | |
42 | 42 | } |
43 | 43 | |
44 | 44 | static inline object& |
@@ -652,7 +652,7 @@ | ||
652 | 652 | |
653 | 653 | return (interp->retval); |
654 | 654 | } |
655 | - else if (!array_p (token) || as_array(token)->len <= NODE_OVERHEAD) | |
655 | + else if (!array_p (token) || len_a (token) <= NODE_OVERHEAD) | |
656 | 656 | interp->raise ("arg-error", "invalid token"); |
657 | 657 | else if (!adv) |
658 | 658 | qp_return (node_key (token)); |
@@ -662,7 +662,7 @@ | ||
662 | 662 | { |
663 | 663 | if (*tmp == UNBOUND) |
664 | 664 | break; |
665 | - else if (!array_p (*tmp) || as_array(*tmp)->len <= NODE_OVERHEAD) | |
665 | + else if (!array_p (*tmp) || len_a (*tmp) <= NODE_OVERHEAD) | |
666 | 666 | interp->raise ("arg-error", "invalid token"); |
667 | 667 | |
668 | 668 | *tmp = node_next (*tmp, 0); |
@@ -367,7 +367,7 @@ | ||
367 | 367 | object sh = xaref(ts, TSPEC_SHARED) = |
368 | 368 | alloc_array (interp, nshared, fixint (0)); |
369 | 369 | |
370 | - for (uint32_t j = 0; j < as_array(*sd)->len; ++j) | |
370 | + for (uint32_t j = 0; j < len_a (*sd); ++j) | |
371 | 371 | { |
372 | 372 | object tmp = ptr[j]; |
373 | 373 | if (tmp == fixint (0) || |
@@ -529,7 +529,7 @@ | ||
529 | 529 | slotname_list_t slots; |
530 | 530 | slots.cmp.ip = interp; |
531 | 531 | |
532 | - for (uint32_t tidx = 0; tidx < as_array(*tmp)->len; ++tidx) | |
532 | + for (uint32_t tidx = 0; tidx < len_a (*tmp); ++tidx) | |
533 | 533 | add_slot_names (interp, xaref (*tmp, tidx), slots, tidx + 1); |
534 | 534 | |
535 | 535 | xaref(*ts, TSPEC_NAME) = name; |
@@ -697,7 +697,7 @@ | ||
697 | 697 | |
698 | 698 | instance::slotdef_iter& instance::slotdef_iter::operator++ () |
699 | 699 | { |
700 | - while (++this->idx < as_array(*this->slots)->len) | |
700 | + while (++this->idx < len_a (*this->slots)) | |
701 | 701 | { |
702 | 702 | object sdef = xaref (*this->slots, this->idx); |
703 | 703 | if (sdef != fixint (0)) |