Skip to content

Commit

Permalink
pass dict by value
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Szczesny committed May 15, 2019
1 parent 2922216 commit 1f02a06
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/kx.c
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ K vf_ex(V q, K g)
if(t) cd(kV(f)[CACHE_WD]);
K fc = kclone(f); //clone the function to pass for _f
cd(kV(fc)[CONJ]); kV(fc)[CONJ]=0;
kV(fc)[DEPTH]++; fw=wd_(kC(o),o->n,&tree,fc); kV(f)[CACHE_WD]=fw; cd(fc); }
kV(fc)[DEPTH]++; fw=wd_(kC(o),o->n,tree,fc); kV(f)[CACHE_WD]=fw; cd(fc); }

#ifdef DEBUG
if(stk1>5) {cd(g); kerr("stack"); R _n();}
Expand Down
2 changes: 1 addition & 1 deletion src/kx.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ K ex1(V *w,K k,I *i,I n,I f);
K _n();
extern C errmsg[256];
I bk(V p);
K wd_(S s,int n,K *dict,K func);
K wd_(S s,int n,K dict,K func);
K ex(K a);
K DI(K d,I i);
K kcloneI(K a,const char*f,int n);
Expand Down
26 changes: 13 additions & 13 deletions src/p.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,15 +325,15 @@ I mark(I*m,I k,I t){DO(k, m[i]=i?t:-t) R k;}
// this rule doesn't apply to function argument lists, eg: f:{ [a] 1} is ok. however f: {\n\n [a;b;d] 1+1} not ok
// so the check probably has to do with whether some useful symbol occurred on the line already
//other errors: syntax error
K wd(S s, int n){lineA=s; fdc=0;R wd_(s,n,denameD(&KTREE,d_,1),0);}
K wd_(S s, int n, K*dict, K func) //parse: s input string, n length ;
K wd(S s, int n){lineA=s; fdc=0;R wd_(s,n,*denameD(&KTREE,d_,1),0);}
K wd_(S s, int n, K dict, K func) //parse: s input string, n length ;
//assumes: s does not contain a }])([{ mismatch, s is a "complete" expression
{
if(!s) R 0;
if(strstr(s,":\\t")) { show(kerr("\\t syntax")); R 0; }
//I z=0; if((z=syntaxChk(s))) {O("%lld\n",z); R SYE;}
if(syntaxChk(s)) R SYE;
if('\\'==s[0] && fbs){fbs=0; R backslash(s,n,dict);}
if('\\'==s[0] && fbs){fbs=0; R backslash(s,n,&dict);}

PDA p=0;
K km=newK(-1,1+n); U(km) I *m = kI(km);//marks
Expand Down Expand Up @@ -461,7 +461,7 @@ K* inKtree(K*d, S t, I create) {
}

//TODO: capture - oom all
I capture(S s,I n,I k,I*m,V*w,I*d,K*locals,K*dict,K func)
I capture(S s,I n,I k,I*m,V*w,I*d,K*locals,K dict,K func)
//IN string, string length, pos in string, markings;
//OUT words, current #words; IN locals-storage, names-storage, charfunc/NULL
{
Expand Down Expand Up @@ -581,23 +581,23 @@ I capture(S s,I n,I k,I*m,V*w,I*d,K*locals,K*dict,K func)
if(state) //Bracketed parameters exist and are well-formed
{
S a=strchr(s+k+1,'['); S b=strchr(a,']');
j=wd_(a+1,b-a-1,zdict,z); //Grab only params. This must create entries in *zdict
j=wd_(a+1,b-a-1,*zdict,z); //Grab only params. This must create entries in *zdict
M(z,j) //not g
cd(j);
}
else //Deal with any implicit Z,Y,X parameters
{
K t=Kd();
M(z,t)
j=wd_(s+k+1,r-2,&t,0); //Grab all local names
j=wd_(s+k+1,r-2,t,0); //Grab all local names
M(z,t,j);
I n=0;
DO(3, if(DE(t,IFP[2-i])){n=3-i;break;})
DO(n,denameD(zdict,IFP[i],1)) //TODO: oom
cd(t); cd(j);
}

j=wd_(s+k+1,r-2,ydict,z);
j=wd_(s+k+1,r-2,*ydict,z);
M(z,j)
cd(j);

Expand Down Expand Up @@ -655,20 +655,20 @@ I capture(S s,I n,I k,I*m,V*w,I*d,K*locals,K*dict,K func)
else z=((K(*)())vn_[charpos(n_s,u[1])])();
else if(func)
{
if(dict==(K*)kV(func)+PARAMS)
if(&dict==(K*)kV(func)+PARAMS)
{
V q=newEntry(u);
U(q)
M(q,kap(dict,&q))
M(q,kap(&dict,&q))
z=EV(q);
cd(q);
}
else if((q=DE(*dict,u))) z=EVP(q); //If func has its local, use it
else if((q=DE(dict,u))) z=EVP(q); //If func has its local, use it
//else if(':'==s[k+r] && ':'==s[k+r+1] && -MARK_VERB==m[k+r+1])
// {m[k+r]=MARK_NAME; r++; z=denameS(kV(func)[CONTeXT],u);} //m[]= probably superfluous
else if(-MARK_VERB==m[k+r] && ':'==s[k+r+1] && -MARK_VERB==m[k+r+1])
{if(':'==s[k+r])r++; z=denameS(kV(func)[CONTeXT],u,1);}
else if(dict==(K*)kV(func)+LOCALS && ':'==s[k+r] && -MARK_VERB==m[k+r]) z=denameD(dict,u,1);
else if(dict==*((K*)kV(func)+LOCALS) && ':'==s[k+r] && -MARK_VERB==m[k+r]) z=denameD(&dict,u,1);
//K3.2: a+:1 format applies to context-globals not locals
else z=denameS(kV(func)[CONTeXT],u,0);//Otherwise check the context (refactor with above?)
}
Expand All @@ -678,13 +678,13 @@ I capture(S s,I n,I k,I*m,V*w,I*d,K*locals,K*dict,K func)
I i;for(i=k;i<strlen(s);i++){
if(!fbr && s[i]==';')break;
else if(s[i]==':'|| (fbr && (s[i]=='x'||s[i]=='y'||s[i]=='z'))){fdc=1;break;}}
z=inKtree(dict,u,0);
z=inKtree(&dict,u,0);
if((!fdc)&&!z){L err=(L)VLE;
#ifndef DEBUG
oerr(); O("%s\n%c\n",u,'^');
#endif
R err;}
z=denameD(dict,u,fll&&fdc); }
z=denameD(&dict,u,fll&&fdc); }
)
CS(MARK_VERB , // "+" "4:" "_bin" ; grab "+:", "4::"
if(s[k]=='\\'){z=(V)0x7c; break;} //trace or scan
Expand Down
4 changes: 2 additions & 2 deletions src/p.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ extern V offsetSSR,offsetWhat,offsetAt,offsetDot,offsetColon;
extern S param_dfa;
I sz(I t,I n);
I lsz(I k);
I capture(S s,I n,I k,I *m,V *w,I *d,K *locals,K *dict,K func);
I capture(S s,I n,I k,I *m,V *w,I *d,K *locals,K dict,K func);
K Kv();
K cd(K a);
void pdafree(PDA p);
Expand All @@ -44,7 +44,7 @@ K backslash(S s,I n,K*dict);
extern S d_;
extern K KTREE;
K *denameD(K *d,S t,I create);
K wd_(S s,int n,K *dict,K func);
K wd_(S s,int n,K dict,K func);
K wd(S s,int n);
I maX(I a,I b);
I mark(I *m,I k,I t);
Expand Down
2 changes: 1 addition & 1 deletion src/v.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ K at_verb(K a, K b) { //[Internal Function]
else if( 0==at){DO(bn,kK(z)[i]=ci(kK(a)[kI(b)[i]])) if(bt==ABS(bt) || bn!=1)z=collapse(z);} }
else if(3==ABS(bt)) { //a is dict/directory & b is executable string like "1+1+c"
P(5!=at,TE)
z=ex(wd_(kC(b),bn,&a,0)); }
z=ex(wd_(kC(b),bn,a,0)); }
else if(4==ABS(bt)) {
P(5!=at,TE)
z=newK(0,bn);
Expand Down
2 changes: 1 addition & 1 deletion src/v.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ K collapse(K x); //ko.c
K of(K x, K y); //vd.c
extern V offsetSSR,offsetWhat,offsetAt,offsetDot,offsetColon; //k.c
extern K KTREE; //k.c
K wd_(S s,int n,K*dict,K func); //p.c
K wd_(S s,int n,K dict,K func); //p.c

1 comment on commit 1f02a06

@tavmem
Copy link
Collaborator

@tavmem tavmem commented on 1f02a06 May 15, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was uploaded to the wrong repository.
It was supposed to go to tavmem/tk.

Please sign in to comment.