=================================================================== RCS file: /home/cvs/OpenXM_contrib2/asir2000/parse/eval.c,v retrieving revision 1.28 retrieving revision 1.60 diff -u -p -r1.28 -r1.60 --- OpenXM_contrib2/asir2000/parse/eval.c 2003/05/24 10:42:18 1.28 +++ OpenXM_contrib2/asir2000/parse/eval.c 2006/02/25 06:33:31 1.60 @@ -45,7 +45,7 @@ * DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE, * PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE. * - * $OpenXM: OpenXM_contrib2/asir2000/parse/eval.c,v 1.27 2003/05/20 06:15:01 noro Exp $ + * $OpenXM: OpenXM_contrib2/asir2000/parse/eval.c,v 1.59 2005/12/11 07:21:43 noro Exp $ */ #include #include "ca.h" @@ -59,11 +59,16 @@ #endif extern JMP_BUF timer_env; +extern FUNC cur_binf; +extern NODE PVSS; int f_break,f_return,f_continue; int evalstatline; int recv_intr; int show_crossref; +int at_root; +void gen_searchf_searchonly(char *name,FUNC *r); +LIST eval_arg(FNODE a,unsigned int quote); pointer eval(FNODE f) { @@ -71,11 +76,11 @@ pointer eval(FNODE f) STRING str; pointer val = 0; pointer a,a1,a2; - NODE tn,ind; + NODE tn,tn1,ind,match; R u; DP dp; unsigned int pv; - int c; + int c,ret; FNODE f1; UP2 up2; UP up; @@ -84,6 +89,8 @@ pointer eval(FNODE f) GF2N gf2n; GFPN gfpn; GFSN gfsn; + RANGE range; + QUOTE expr,pattern; #if defined(VISUAL) if ( recv_intr ) { @@ -112,6 +119,16 @@ pointer eval(FNODE f) a1 = eval((FNODE)FA1(f)); a2 = eval((FNODE)FA2(f)); (*((ARF)FA0(f))->fp)(CO,a1,a2,&val); break; + case I_NARYOP: + tn = (NODE)FA1(f); + a = eval((FNODE)BDY(tn)); + for ( tn = NEXT(tn); tn; tn = NEXT(tn) ) { + a1 = eval((FNODE)BDY(tn)); + (*((ARF)FA0(f))->fp)(CO,a,a1,&a2); + a = a2; + } + val = a; + break; case I_COP: a1 = eval((FNODE)FA1(f)); a2 = eval((FNODE)FA2(f)); c = arf_comp(CO,a1,a2); @@ -165,9 +182,11 @@ pointer eval(FNODE f) val = evalf((FUNC)FA0(f),(FNODE)FA1(f),0); break; case I_FUNC_OPT: val = evalf((FUNC)FA0(f),(FNODE)FA1(f),(FNODE)FA2(f)); break; + case I_FUNC_QARG: + tn = BDY(eval_arg((FNODE)FA1(f),(unsigned int)0xffffffff)); + val = bevalf((FUNC)FA0(f),tn); break; case I_PFDERIV: - error("eval : not implemented yet"); - break; + val = evalf_deriv((FUNC)FA0(f),(FNODE)FA1(f),(FNODE)FA2(f)); break; case I_MAP: val = evalmapf((FUNC)FA0(f),(FNODE)FA1(f)); break; case I_RECMAP: @@ -222,7 +241,9 @@ pointer eval(FNODE f) error("-- : not implemented yet"); break; case I_PVAR: - pv = (unsigned int)FA0(f); ind = (NODE)FA1(f); GETPV(pv,a); + pv = (unsigned int)FA0(f); + ind = (NODE)FA1(f); + GETPV(pv,a); if ( !ind ) val = a; else { @@ -286,6 +307,14 @@ pointer eval(FNODE f) val = FA0(f); break; case I_LIST: evalnodebody((NODE)FA0(f),&tn); MKLIST(t,tn); val = (pointer)t; break; + case I_CONS: + evalnodebody((NODE)FA0(f),&tn); a2 = eval(FA1(f)); + if ( !a2 || OID(a2) != O_LIST ) + error("cons : invalid argument"); + for ( tn1 = tn; NEXT(tn1); tn1 = NEXT(tn1) ); + NEXT(tn1) = BDY((LIST)a2); + MKLIST(t,tn); val = (pointer)t; + break; case I_NEWCOMP: newstruct((int)FA0(f),(struct oCOMP **)&val); break; case I_CAR: @@ -305,8 +334,6 @@ pointer eval(FNODE f) MKLIST(t,NEXT(BDY((LIST)a))); val = (pointer)t; } break; - case I_PROC: - val = (pointer)FA0(f); break; case I_INDEX: a = eval((FNODE)FA0(f)); ind = (NODE)FA1(f); evalnodebody(ind,&tn); getarray(a,tn,&val); @@ -331,14 +358,364 @@ pointer eval(FNODE f) return ( val ); } +NODE fnode_to_nary_node(NODE); +NODE fnode_to_bin_node(NODE,int); + +FNODE fnode_to_nary(FNODE f) +{ + FNODE a0,a1,a2; + NODE n,t,t0; + pointer val; + char *op; + + if ( !f ) + return f; + switch ( f->id ) { + case I_NARYOP: + n = fnode_to_nary_node((NODE)FA1(f)); + return mkfnode(2,I_NARYOP,FA0(f),n); + + case I_BOP: + a1 = fnode_to_nary((FNODE)FA1(f)); + a2 = fnode_to_nary((FNODE)FA2(f)); + op = ((ARF)FA0(f))->name; + if ( !strcmp(op,"+") || !strcmp(op,"*") ) { + if ( a1->id == I_NARYOP && !strcmp(op,((ARF)FA0(a1))->name) ) { + for ( n = (NODE)FA1(a1); NEXT(n); n = NEXT(n) ); + if ( a2->id == I_NARYOP && !strcmp(op,((ARF)FA0(a2))->name) ) + NEXT(n) = (NODE)FA1(a2); + else + MKNODE(NEXT(n),a2,0); + return a1; + } else if ( a2->id == I_NARYOP && !strcmp(op,((ARF)FA0(a2))->name) ) { + MKNODE(t,a1,(NODE)FA1(a2)); + return mkfnode(2,I_NARYOP,FA0(f),t); + } else { + t = mknode(2,a1,a2); + return mkfnode(2,I_NARYOP,FA0(f),t); + } + } else + return mkfnode(3,f->id,FA0(f),a1,a2); + + case I_NOT: case I_PAREN: case I_MINUS: + case I_CAR: case I_CDR: + a0 = fnode_to_nary((FNODE)FA0(f)); + return mkfnode(1,f->id,a0); + + case I_COP: case I_LOP: + a1 = fnode_to_nary((FNODE)FA1(f)); + a2 = fnode_to_nary((FNODE)FA2(f)); + return mkfnode(3,f->id,FA0(f),a1,a2); + + case I_AND: case I_OR: + a0 = fnode_to_nary((FNODE)FA0(f)); + a1 = fnode_to_nary((FNODE)FA1(f)); + return mkfnode(2,f->id,a0,a1); + + /* ternary operators */ + case I_CE: + a0 = fnode_to_nary((FNODE)FA0(f)); + a1 = fnode_to_nary((FNODE)FA1(f)); + a2 = fnode_to_nary((FNODE)FA2(f)); + return mkfnode(3,f->id,a0,a1,a2); + break; + + /* function */ + case I_FUNC: + a1 = fnode_to_nary((FNODE)FA1(f)); + return mkfnode(2,f->id,FA0(f),a1); + + case I_LIST: case I_EV: + n = fnode_to_nary_node((NODE)FA0(f)); + return mkfnode(1,f->id,n); + + case I_STR: case I_FORMULA: case I_PVAR: + return f; + + default: + error("fnode_to_nary : not implemented yet"); + } +} + +FNODE fnode_to_bin(FNODE f,int dir) +{ + FNODE a0,a1,a2; + NODE n,t; + pointer val; + ARF fun; + int len,i; + FNODE *arg; + + if ( !f ) + return f; + switch ( f->id ) { + case I_NARYOP: + fun = (ARF)FA0(f); + len = length((NODE)FA1(f)); + if ( len==1 ) return BDY((NODE)(FA1(f))); + + arg = (FNODE *)ALLOCA(len*sizeof(FNODE)); + for ( i = 0, t = (NODE)FA1(f); i < len; i++, t = NEXT(t) ) + arg[i] = fnode_to_bin((FNODE)BDY(t),dir); + if ( dir ) { + a2 = mkfnode(3,I_BOP,fun,arg[len-2],arg[len-1]); + for ( i = len-3; i >= 0; i-- ) + a2 = mkfnode(3,I_BOP,fun,arg[i],a2); + } else { + a2 = mkfnode(3,I_BOP,fun,arg[0],arg[1]); + for ( i = 2; i < len; i++ ) + a2 = mkfnode(3,I_BOP,fun,a2,arg[i]); + } + return a2; + + case I_NOT: case I_PAREN: case I_MINUS: + case I_CAR: case I_CDR: + a0 = fnode_to_bin((FNODE)FA0(f),dir); + return mkfnode(1,f->id,a0); + + case I_BOP: case I_COP: case I_LOP: + a1 = fnode_to_bin((FNODE)FA1(f),dir); + a2 = fnode_to_bin((FNODE)FA2(f),dir); + return mkfnode(3,f->id,FA0(f),a1,a2); + + case I_AND: case I_OR: + a0 = fnode_to_bin((FNODE)FA0(f),dir); + a1 = fnode_to_bin((FNODE)FA1(f),dir); + return mkfnode(2,f->id,a0,a1); + + /* ternary operators */ + case I_CE: + a0 = fnode_to_bin((FNODE)FA0(f),dir); + a1 = fnode_to_bin((FNODE)FA1(f),dir); + a2 = fnode_to_bin((FNODE)FA2(f),dir); + return mkfnode(3,f->id,a0,a1,a2); + break; + + /* function */ + case I_FUNC: + a1 = fnode_to_bin((FNODE)FA1(f),dir); + return mkfnode(2,f->id,FA0(f),a1); + + case I_LIST: case I_EV: + n = fnode_to_bin_node((NODE)FA0(f),dir); + return mkfnode(1,f->id,n); + + case I_STR: case I_FORMULA: case I_PVAR: + return f; + + default: + error("fnode_to_bin : not implemented yet"); + } +} + +NODE partial_eval_node(NODE n); +FNODE partial_eval(FNODE f); + +FNODE partial_eval(FNODE f) +{ + FNODE a0,a1,a2; + NODE n; + Obj obj; + QUOTE q; + pointer val; + FUNC func; + + if ( !f ) + return f; + switch ( f->id ) { + case I_NOT: case I_PAREN: case I_MINUS: + case I_CAR: case I_CDR: + a0 = partial_eval((FNODE)FA0(f)); + return mkfnode(1,f->id,a0); + + case I_BOP: case I_COP: case I_LOP: + a1 = partial_eval((FNODE)FA1(f)); + a2 = partial_eval((FNODE)FA2(f)); + return mkfnode(3,f->id,FA0(f),a1,a2); + + case I_NARYOP: + n = partial_eval_node((NODE)FA1(f)); + return mkfnode(2,f->id,FA0(f),n); + + case I_AND: case I_OR: + a0 = partial_eval((FNODE)FA0(f)); + a1 = partial_eval((FNODE)FA1(f)); + return mkfnode(2,f->id,a0,a1); + + /* ternary operators */ + case I_CE: + a0 = partial_eval((FNODE)FA0(f)); + a1 = partial_eval((FNODE)FA1(f)); + a2 = partial_eval((FNODE)FA2(f)); + return mkfnode(3,f->id,a0,a1,a2); + break; + + /* XXX : function is evaluated with QUOTE args */ + case I_FUNC: + a1 = partial_eval((FNODE)FA1(f)); + func = (FUNC)FA0(f); + if ( func->id == A_UNDEF || func->id != A_USR ) { + a1 = mkfnode(2,I_FUNC,func,a1); + return a1; + } else { + n = BDY(eval_arg(a1,(unsigned int)0xffffffff)); + obj = bevalf(func,n); + objtoquote(obj,&q); + return BDY(q); + } + break; + + case I_LIST: case I_EV: + n = partial_eval_node((NODE)FA0(f)); + return mkfnode(1,f->id,n); + + case I_STR: case I_FORMULA: + return f; + + /* program variable */ + case I_PVAR: + val = eval(f); + if ( val && OID((Obj)val) == O_QUOTE ) + return partial_eval((FNODE)BDY((QUOTE)val)); + else + return mkfnode(1,I_FORMULA,val); + + default: + error("partial_eval : not implemented yet"); + } +} + +NODE partial_eval_node(NODE n) +{ + NODE r0,r,t; + + for ( r0 = 0, t = n; t; t = NEXT(t) ) { + NEXTNODE(r0,r); + BDY(r) = partial_eval((FNODE)BDY(t)); + } + if ( r0 ) NEXT(r) = 0; + return r0; +} + +NODE rewrite_fnode_node(NODE n,NODE arg,int qarg); +FNODE rewrite_fnode(FNODE f,NODE arg,int qarg); + +FNODE rewrite_fnode(FNODE f,NODE arg,int qarg) +{ + FNODE a0,a1,a2,value; + NODE n,t,pair; + pointer val; + int pv,ind; + + if ( !f ) + return f; + switch ( f->id ) { + case I_NOT: case I_PAREN: case I_MINUS: + case I_CAR: case I_CDR: + a0 = rewrite_fnode((FNODE)FA0(f),arg,qarg); + return mkfnode(1,f->id,a0); + + case I_BOP: case I_COP: case I_LOP: + a1 = rewrite_fnode((FNODE)FA1(f),arg,qarg); + a2 = rewrite_fnode((FNODE)FA2(f),arg,qarg); + return mkfnode(3,f->id,FA0(f),a1,a2); + + case I_AND: case I_OR: + a0 = rewrite_fnode((FNODE)FA0(f),arg,qarg); + a1 = rewrite_fnode((FNODE)FA1(f),arg,qarg); + return mkfnode(2,f->id,a0,a1); + + /* ternary operators */ + case I_CE: + a0 = rewrite_fnode((FNODE)FA0(f),arg,qarg); + a1 = rewrite_fnode((FNODE)FA1(f),arg,qarg); + a2 = rewrite_fnode((FNODE)FA2(f),arg,qarg); + return mkfnode(3,f->id,a0,a1,a2); + break; + + /* nary operators */ + case I_NARYOP: + n = rewrite_fnode_node((NODE)FA1(f),arg,qarg); + return mkfnode(2,f->id,FA0(f),n); + + /* and function */ + case I_FUNC: + a1 = rewrite_fnode((FNODE)FA1(f),arg,qarg); + return mkfnode(2,qarg?I_FUNC_QARG:f->id,FA0(f),a1); + + case I_LIST: case I_EV: + n = rewrite_fnode_node((NODE)FA0(f),arg,qarg); + return mkfnode(1,f->id,n); + + case I_STR: case I_FORMULA: + return f; + + /* program variable */ + case I_PVAR: + pv = (int)FA0(f); + for ( t = arg; t; t = NEXT(t) ) { + pair = (NODE)BDY(t); + ind = (int)BDY(pair); + value = (FNODE)BDY(NEXT(pair)); + if ( pv == ind ) + return value; + } + return f; + break; + + default: + error("rewrite_fnode : not implemented yet"); + } +} + +NODE rewrite_fnode_node(NODE n,NODE arg,int qarg) +{ + NODE r0,r,t; + + for ( r0 = 0, t = n; t; t = NEXT(t) ) { + NEXTNODE(r0,r); + BDY(r) = rewrite_fnode((FNODE)BDY(t),arg,qarg); + } + if ( r0 ) NEXT(r) = 0; + return r0; +} + +NODE fnode_to_nary_node(NODE n) +{ + NODE r0,r,t; + + for ( r0 = 0, t = n; t; t = NEXT(t) ) { + NEXTNODE(r0,r); + BDY(r) = fnode_to_nary((FNODE)BDY(t)); + } + if ( r0 ) NEXT(r) = 0; + return r0; +} + +NODE fnode_to_bin_node(NODE n,int dir) +{ + NODE r0,r,t; + + for ( r0 = 0, t = n; t; t = NEXT(t) ) { + NEXTNODE(r0,r); + BDY(r) = fnode_to_bin((FNODE)BDY(t),dir); + } + if ( r0 ) NEXT(r) = 0; + return r0; +} + +V searchvar(char *name); + pointer evalstat(SNODE f) { pointer val = 0,t,s,s1; P u; NODE tn; int i,ac; + V v; V *a; char *buf; + FUNC func; if ( !f ) return ( 0 ); @@ -347,6 +724,7 @@ pointer evalstat(SNODE f) bp(f); } evalstatline = f->ln; + if ( !PVSS ) at_root = evalstatline; switch ( f->id ) { case S_BP: @@ -377,7 +755,13 @@ pointer evalstat(SNODE f) makevar(buf,&u); a[i] = VR(u); substr(CO,0,(Obj)s,VR((P)t),(Obj)u,(Obj *)&s1); s = s1; } - mkpf((char *)FA0(f),(Obj)s,ac,a,0,0,0,(PF *)&val); val = 0; break; + mkpf((char *)FA0(f),(Obj)s,ac,a,0,0,0,(PF *)&val); val = 0; + v = searchvar((char *)FA0(f)); + if ( v ) { + searchpf((char *)FA0(f),&func); + makesrvar(func,&u); + } + break; case S_SINGLE: val = eval((FNODE)FA0(f)); break; case S_CPLX: @@ -429,6 +813,13 @@ pointer evalstat(SNODE f) break; } f_break = 0; break; + case S_MODULE: + CUR_MODULE = (MODULE)FA0(f); + if ( CUR_MODULE ) + MPVS = CUR_MODULE->pvs; + else + MPVS = 0; + break; default: error("evalstat : unknown id"); break; @@ -447,22 +838,56 @@ pointer evalnode(NODE node) return ( val ); } -extern FUNC cur_binf; -extern NODE PVSS; +LIST eval_arg(FNODE a,unsigned int quote) +{ + LIST l; + FNODE fn; + NODE n,n0,tn; + QUOTE q; + int i; + + for ( tn = (NODE)FA0(a), n0 = 0, i = 0; tn; tn = NEXT(tn), i++ ) { + NEXTNODE(n0,n); + if ( quote & (1<id == I_FORMULA && FA0(fn) + && OID((Obj)FA0(fn))== O_QUOTE ) + BDY(n) = FA0(fn); + else { + MKQUOTE(q,(FNODE)BDY(tn)); + BDY(n) = (pointer)q; + } + } else + BDY(n) = eval((FNODE)BDY(tn)); + } + if ( n0 ) NEXT(n) = 0; + MKLIST(l,n0); + return l; +} + pointer evalf(FUNC f,FNODE a,FNODE opt) { LIST args; pointer val; int i,n,level; - NODE tn,sn,opts,opt1; - VS pvs,prev_mpvs; + NODE tn,sn,opts,opt1,dmy; + VS pvs,prev_mpvs; char errbuf[BUFSIZ]; static unsigned int stack_size; static void *stack_base; + FUNC f1; if ( f->id == A_UNDEF ) { - sprintf(errbuf,"evalf : %s undefined",NAME(f)); + gen_searchf_searchonly(f->fullname,&f1); + if ( f1->id == A_UNDEF ) { + sprintf(errbuf,"evalf : %s undefined",NAME(f)); + error(errbuf); + } else + *f = *f1; + } + if ( getsecuremode() && !PVSS && !f->secure ) { + sprintf(errbuf,"evalf : %s not permitted",NAME(f)); error(errbuf); } if ( f->id != A_PARI ) { @@ -474,11 +899,26 @@ pointer evalf(FUNC f,FNODE a,FNODE opt) } switch ( f->id ) { case A_BIN: + if ( opt ) { + opts = BDY((LIST)eval(opt)); + /* opts = ["opt1",arg1],... */ + opt1 = BDY((LIST)BDY(opts)); + if ( !strcmp(BDY((STRING)BDY(opt1)),"option_list") ) { + /* + * the special option specification: + * option_list=[["o1","a1"],...] + */ + asir_assert(BDY(NEXT(opt1)),O_LIST,"evalf"); + opts = BDY((LIST)BDY(NEXT(opt1))); + } + } else + opts = 0; if ( !n ) { cur_binf = f; (*f->f.binf)(&val); } else { - args = (LIST)eval(a); + args = (LIST)eval_arg(a,f->quote); + current_option = opts; cur_binf = f; (*f->f.binf)(args?BDY(args):0,&val); } @@ -503,7 +943,7 @@ pointer evalf(FUNC f,FNODE a,FNODE opt) if ( (stack_base - (void *)&args) +0x100000 > stack_size ) error("stack overflow"); #endif - args = (LIST)eval(a); + args = (LIST)eval_arg(a,f->quote); if ( opt ) { opts = BDY((LIST)eval(opt)); /* opts = ["opt1",arg1],... */ @@ -550,7 +990,7 @@ pointer evalf(FUNC f,FNODE a,FNODE opt) break; case A_PURE: args = (LIST)eval(a); - val = evalpf(f->f.puref,args?BDY(args):0); + val = evalpf(f->f.puref,args?BDY(args):0,0); break; default: sprintf(errbuf,"evalf : %s undefined",NAME(f)); @@ -560,6 +1000,28 @@ pointer evalf(FUNC f,FNODE a,FNODE opt) return val; } +pointer evalf_deriv(FUNC f,FNODE a,FNODE deriv) +{ + LIST args,dargs; + pointer val; + char errbuf[BUFSIZ]; + + switch ( f->id ) { + case A_PURE: + args = (LIST)eval(a); + dargs = (LIST)eval(deriv); + val = evalpf(f->f.puref, + args?BDY(args):0,dargs?BDY(dargs):0); + break; + default: + sprintf(errbuf, + "evalf : %s is not a pure function",NAME(f)); + error(errbuf); + break; + } + return val; +} + pointer evalmapf(FUNC f,FNODE a) { LIST args; @@ -571,7 +1033,7 @@ pointer evalmapf(FUNC f,FNODE a) int len,row,col,i,j; pointer val; - args = (LIST)eval(a); + args = (LIST)eval_arg(a,f->quote); node = BDY(args); head = (Obj)BDY(node); rest = NEXT(node); if ( !head ) { val = bevalf(f,node); @@ -614,7 +1076,7 @@ pointer eval_rec_mapf(FUNC f,FNODE a) { LIST args; - args = (LIST)eval(a); + args = (LIST)eval_arg(a,f->quote); return beval_rec_mapf(f,BDY(args)); } @@ -673,13 +1135,17 @@ pointer bevalf(FUNC f,NODE a) pointer val; int i,n; NODE tn,sn; - VS pvs; + VS pvs,prev_mpvs; char errbuf[BUFSIZ]; if ( f->id == A_UNDEF ) { sprintf(errbuf,"bevalf : %s undefined",NAME(f)); error(errbuf); } + if ( getsecuremode() && !PVSS && !f->secure ) { + sprintf(errbuf,"bevalf : %s not permitted",NAME(f)); + error(errbuf); + } if ( f->id != A_PARI ) { for ( i = 0, tn = a; tn; i++, tn = NEXT(tn) ); if ( ((n = f->argc)>= 0 && i != n) || (n < 0 && i > -n) ) { @@ -721,11 +1187,17 @@ pointer bevalf(FUNC f,NODE a) for ( tn = f->f.usrf->args, sn = a; sn; tn = NEXT(tn), sn = NEXT(sn) ) ASSPV((int)FA0((FNODE)BDY(tn)),BDY(sn)); - val = evalstat((SNODE)BDY(f->f.usrf)); + if ( f->f.usrf->module ) { + prev_mpvs = MPVS; + MPVS = f->f.usrf->module->pvs; + val = evalstat((SNODE)BDY(f->f.usrf)); + MPVS = prev_mpvs; + } else + val = evalstat((SNODE)BDY(f->f.usrf)); f_return = f_break = f_continue = 0; poppvs(); break; case A_PURE: - val = evalpf(f->f.puref,a); + val = evalpf(f->f.puref,a,0); break; default: sprintf(errbuf,"bevalf : %s undefined",NAME(f)); @@ -738,36 +1210,56 @@ pointer bevalf(FUNC f,NODE a) pointer evalif(FNODE f,FNODE a) { Obj g; + QUOTE q; + FNODE t; + LIST l; g = (Obj)eval(f); if ( g && (OID(g) == O_P) && (VR((P)g)->attr == (pointer)V_SR) ) return evalf((FUNC)VR((P)g)->priv,a,0); - else { + else if ( g && OID(g) == O_QUOTEARG && ((QUOTEARG)g)->type == A_func ) { + t = mkfnode(2,I_FUNC,((QUOTEARG)g)->body,a); + MKQUOTE(q,t); + return q; + } else { error("invalid function pointer"); /* NOTREACHED */ return (pointer)-1; } } -pointer evalpf(PF pf,NODE args) +pointer evalpf(PF pf,NODE args,NODE dargs) { Obj s,s1; - int i; - NODE node; + int i,di,j; + NODE node,dnode; PFINS ins; PFAD ad; if ( !pf->body ) { ins = (PFINS)CALLOC(1,sizeof(PF)+pf->argc*sizeof(struct oPFAD)); ins->pf = pf; - for ( i = 0, node = args, ad = ins->ad; - node; node = NEXT(node), i++ ) { - ad[i].d = 0; ad[i].arg = (Obj)node->body; + for ( i = 0, node = args, dnode = dargs, ad = ins->ad; + node; i++ ) { + ad[i].arg = (Obj)node->body; + if ( !dnode ) ad[i].d = 0; + else + ad[i].d = QTOS((Q)dnode->body); + node = NEXT(node); + if ( dnode ) dnode = NEXT(dnode); } simplify_ins(ins,&s); } else { - for ( i = 0, s = pf->body, node = args; - node; node = NEXT(node), i++ ) { + s = pf->body; + if ( dnode ) { + for ( i = 0, dnode = dargs; dnode; dnode = NEXT(dnode), i++ ) { + di = QTOS((Q)dnode->body); + for ( j = 0; j < di; j++ ) { + derivr(CO,s,pf->args[i],&s1); s = s1; + } + } + } + for ( i = 0, node = args; node; node = NEXT(node), i++ ) { substr(CO,0,s,pf->args[i],(Obj)node->body,&s1); s = s1; } } @@ -830,8 +1322,12 @@ void searchuf(char *name,FUNC *r) void gen_searchf(char *name,FUNC *r) { FUNC val = 0; - - if ( CUR_MODULE ) + int global = 0; + if ( *name == ':' ) { + global = 1; + name += 2; + } + if ( CUR_MODULE && !global ) searchf(CUR_MODULE->usrf_list,name,&val); if ( !val ) searchf(sysf,name,&val); @@ -846,6 +1342,27 @@ void gen_searchf(char *name,FUNC *r) *r = val; } +void gen_searchf_searchonly(char *name,FUNC *r) +{ + FUNC val = 0; + int global = 0; + if ( *name == ':' ) { + global = 1; + name += 2; + } + if ( CUR_MODULE && !global ) + searchf(CUR_MODULE->usrf_list,name,&val); + if ( !val ) + searchf(sysf,name,&val); + if ( !val ) + searchf(ubinf,name,&val); + if ( !val ) + searchpf(name,&val); + if ( !val ) + searchuf(name,&val); + *r = val; +} + void searchf(NODE fn,char *name,FUNC *r) { NODE tn; @@ -941,6 +1458,11 @@ void mkuf(char *name,char *fname,NODE args,SNODE body, char *longname; int argc; + if ( getsecuremode() ) { + error("defining function is not permitted in the secure mode"); + } + if ( *name == ':' ) + name += 2; if ( !module ) { searchf(sysf,name,&f); if ( f ) {