Skip to content

Commit

Permalink
x {:: y support sparse arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
HenryHRich committed Dec 26, 2024
1 parent 6afe77c commit d129c9e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
15 changes: 9 additions & 6 deletions jsrc/p.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions jsrc/vfrom.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
8 changes: 8 additions & 0 deletions test/gpick.ijs
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit d129c9e

Please sign in to comment.