From d129c9ee4965d4ba58dc3b14bf23e2a58fd7a39f Mon Sep 17 00:00:00 2001 From: Henry Rich Date: Thu, 26 Dec 2024 16:03:06 -0500 Subject: [PATCH] x {:: y support sparse arguments --- jsrc/p.c | 15 +++++++++------ jsrc/vfrom.c | 6 ++++++ test/gpick.ijs | 8 ++++++++ 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/jsrc/p.c b/jsrc/p.c index dfc1f3270..2c920411e 100644 --- a/jsrc/p.c +++ b/jsrc/p.c @@ -563,13 +563,9 @@ A jtparsea(J jt, A *queue, I nwds){F1PREFIP;PSTK *stack;A z,*v; // value. m has the index of the word we just moved. y = *queue // We have the value/typeclass of the next word (QCSENTENCE semantics). If it is an unassigned name, we have to resolve it and perhaps use the new name/type - if(!((I)y&QCISLKPNAME)){ - // not a name requiring lookup. enqueue() set the QC flags, which we will use below. We have just checked the NAMED flag, off here. Now we notionally switch to - // QCFAOWED semantics, in which QCISLKPNAME is repurposed to QCFAOWED (& known to be 0). enqueue() sets QCNAMED in blocks that are known to need no pretection from deletion: - // those are PERMANENT blocks and sentence words (together these amount to the entire sentence except for NAMEs). With FAOWED off we will know that the block needs no fa(), and the flags - // guarantee that the block is never protected from deletion + if(((I)y&QCISLKPNAME)){ // obsolete if((I)y&QCNAMED+QCISLKPNAME)SEGFAULT; y=CLRQCFAOWEDMSK(y); // y is now addr/00/type index - }else{ // Replace a name (not to left of ASGN) with its value + // Replace a name (not to left of ASGN) with its value // Name, not being assigned // Resolve the name. If the name is x. m. u. etc, always resolve the name to its current value; // otherwise resolve nouns to values, and others to 'name~' references @@ -670,6 +666,13 @@ rdglob: ; // here when we tried the buckets and failed } endname: ; // obsolete y=SETNAMED(y); // turn on the flag bit indicating this was NAMED + }else{ + // not a name requiring lookup. enqueue() set the QC flags, which we will use below. We have just checked the NAMED flag, off here. Now we notionally switch to + // QCFAOWED semantics, in which QCISLKPNAME is repurposed to QCFAOWED (& known to be 0). enqueue() sets QCNAMED in blocks that are known to need no pretection from deletion: + // those are PERMANENT blocks and sentence words (together these amount to the entire sentence except for NAMEs). With FAOWED off we will know that the block needs no fa(), and the flags + // guarantee that the block is never protected from deletion + + // All this takes no code. } // names have been resolved diff --git a/jsrc/vfrom.c b/jsrc/vfrom.c index ef459664f..7cfe56924 100644 --- a/jsrc/vfrom.c +++ b/jsrc/vfrom.c @@ -686,6 +686,12 @@ static F2(jtquicksel){I index; DF2(jtfetch){A*av, z;I n;F2PREFIP; F2RANKW(1,RMAX,jtfetch,self); // body of verb applies to rank-1 a, and must turn pristine off if used higher, since there may be repetitions. + if(unlikely(ISSPARSE(AT(w)|AT(a)))){ // sparse x or y + ASSERT(!ISSPARSE(AT(a)),EVNONCE) // selector must be dense + if(!(AT(a)&BOX))RZ(a=box(a)); // box open a + ASSERT(AN(a)==1,EVLENGTH) // must be a single selector, implement as (boxopen x) { y + RETF(from(a,w)); + } if(!(BOX&AT(a))){ // look for the common special case scalar { boxed vector. This path doesn't run EPILOG if(((AT(w)>>BOXX)&1)>=(2*AR(a)+AR(w))){ // a is an atom, w is atom or list of boxes AR(a)==0 && (AR(w)==0 || (AR(w)==1 && AT(w)&BOX)) diff --git a/test/gpick.ijs b/test/gpick.ijs index 680ea3f3a..d1b2b8e3b 100644 --- a/test/gpick.ijs +++ b/test/gpick.ijs @@ -60,6 +60,14 @@ t -: 3;4 NB. Verify the value fetched from t was non-inplaceable 'a' -: (0;0) {:: <"0 'abc' 'a' -: (0;0) {:: <@,"0 'abc' +'nonce error' -: ($. 1 1) {:: etx 6 +'length error' -: (1;2) {:: etx $. i. 5 6 +'length error' -: (1 2) {:: etx $. i. 7 +1 2 ((<@[ { ]) etx -: {:: etx) $. 2 3 4 5 +1 2 ((<@[ { ]) -: {::) $. i. 2 3 4 5 +1 2 ((<@[ { ]) -: {::) $. 0. + i. 2 3 4 5 +1 2 ((<@[ { ]) -: {::) $. 1 = i. 2 3 4 5 + 'spelling error' -: ". etx'}::' 4!:55 ;:'boxed cat map mapp pick S sc spread_temp si sz t'