ref: a7bb3ba3b42eaed8425699bbff9a45510ec895af
parent: c400506dffc50ab1b939714d64c8edccd4a73a41
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Tue Dec 10 00:52:54 EST 2024
aref: apply + multiple indices
--- a/flisp.c
+++ b/flisp.c
@@ -1072,6 +1072,7 @@
case OP_SUB: goto apply_sub;
case OP_MUL: goto apply_mul;
case OP_DIV: goto apply_div;
+ case OP_AREF: goto apply_aref;
default:
#if defined(COMPUTED_GOTO)
goto *ops[i];
@@ -1252,28 +1253,15 @@
NEXT_OP;
OP(OP_AREF2)
- FL(stack)[ipd] = (uintptr_t)ip;
- v = FL(stack)[FL(sp)-2];
- if(isvector(v)){
- e = FL(stack)[FL(sp)-1];
- isz = tosize(e);
- if(__unlikely(isz >= vector_size(v)))
- bounds_error(v, e);
- v = vector_elt(v, isz);
- }else if(__likely(isarray(v))){
- v = cvalue_array_aref(&FL(stack)[FL(sp)-2]);
- }else{
- type_error("sequence", v);
- }
- POPN(1);
- FL(stack)[FL(sp)-1] = v;
- NEXT_OP;
-
+ n = 2;
+ if(0){
OP(OP_AREF)
FL(stack)[ipd] = (uintptr_t)ip;
- n = 2 + *ip++;
- v = FL(stack)[FL(sp)-n-1];
- for(i = n; i > 0; i--){
+ n = 3 + *ip++;
+ }
+ apply_aref:
+ v = FL(stack)[FL(sp)-n];
+ for(i = n-1; i > 0; i--){
if(isvector(v)){
e = FL(stack)[FL(sp)-i];
isz = tosize(e);
@@ -1287,7 +1275,7 @@
type_error("sequence", v);
}
}
- POPN(n+1);
+ POPN(n);
PUSH(v);
NEXT_OP;
--- a/test/unittest.lsp
+++ b/test/unittest.lsp
@@ -414,6 +414,7 @@
;; aref with multiple indices
(define a #(#(0 1 2) #(3 #(4 5 6) 7)))
(assert (equal? 0 (aref a 0 0)))
+(assert (equal? 0 (apply aref (list a 0 0))))
(assert (equal? 2 (aref a 0 2)))
(assert (equal? 3 (aref a 1 0)))
(assert (equal? 7 (aref a 1 2)))