version 1.9, 2004/12/17 03:09:08 |
version 1.14, 2008/09/02 17:23:33 |
|
|
* DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE, |
* DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE, |
* PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE. |
* PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE. |
* |
* |
* $OpenXM: OpenXM_contrib2/asir2000/builtin/pf.c,v 1.8 2004/06/27 03:15:57 noro Exp $ |
* $OpenXM: OpenXM_contrib2/asir2000/builtin/pf.c,v 1.13 2008/09/01 07:53:59 ohara Exp $ |
*/ |
*/ |
#include "ca.h" |
#include "ca.h" |
#include "math.h" |
#include "math.h" |
Line 63 void make_tri(void); |
|
Line 63 void make_tri(void); |
|
void make_exp(void); |
void make_exp(void); |
void simplify_pow(PFINS,Obj *); |
void simplify_pow(PFINS,Obj *); |
|
|
void Pfunctor(),Pargs(),Pfunargs(),Pvtype(),Pcall(),Pdeval(); |
void Pfunctor(),Pargs(),Pfunargs(),Pvtype(),Pcall(),Pdeval(),Pfunargs_ext(); |
void Pregister_handler(); |
void Pregister_handler(); |
void Peval_quote(); |
void Peval_quote(); |
void Pmapat(); |
void Pmapat(), Pmap(); |
void Padd_handler(); |
void Padd_handler(); |
void Plist_handler(); |
void Plist_handler(); |
void Pclear_handler(); |
void Pclear_handler(); |
|
|
struct ftab puref_tab[] = { |
struct ftab puref_tab[] = { |
{"mapat",Pmapat,-99999999}, |
{"mapat",Pmapat,-99999999}, |
|
{"map",Pmap,-99999999}, |
{"functor",Pfunctor,1}, |
{"functor",Pfunctor,1}, |
{"args",Pargs,1}, |
{"args",Pargs,1}, |
{"funargs",Pfunargs,1}, |
{"funargs",Pfunargs,1}, |
|
{"funargs_ext",Pfunargs_ext,1}, |
{"register_handler",Pregister_handler,1}, |
{"register_handler",Pregister_handler,1}, |
{"add_handler",Padd_handler,2}, |
{"add_handler",Padd_handler,2}, |
{"list_handler",Plist_handler,1}, |
{"list_handler",Plist_handler,1}, |
Line 83 struct ftab puref_tab[] = { |
|
Line 85 struct ftab puref_tab[] = { |
|
{"call",Pcall,2}, |
{"call",Pcall,2}, |
{"vtype",Pvtype,1}, |
{"vtype",Pvtype,1}, |
{"deval",Pdeval,1}, |
{"deval",Pdeval,1}, |
{"eval_quote",Peval_quote,1}, |
{"eval_quote",Peval_quote,-2}, |
{0,0,0}, |
{0,0,0}, |
}; |
}; |
|
|
|
|
} |
} |
|
|
#define ISPFINS(p)\ |
#define ISPFINS(p)\ |
(p)&&(ID(p) == O_P)&&((int)VR((P)p)->attr!=V_PF)&&\ |
((p)&&(ID(p) == O_P)&&((int)VR((P)p)->attr==V_PF)&&\ |
UNIQ(DEG(DC((P)p)))&&UNIQ(COEF(DC((P)p))) |
UNIQ(DEG(DC((P)p)))&&UNIQ(COEF(DC((P)p)))) |
|
|
void Pfunctor(arg,rp) |
void Pfunctor(arg,rp) |
NODE arg; |
NODE arg; |
|
|
} |
} |
} |
} |
|
|
|
void Pfunargs_ext(arg,rp) |
|
NODE arg; |
|
LIST *rp; |
|
{ |
|
P p; |
|
P f; |
|
FUNC t; |
|
PF pf; |
|
PFINS ins; |
|
PFAD ad; |
|
NODE n,n0,d,d0,a,a0; |
|
LIST alist,dlist; |
|
Q q; |
|
int i; |
|
|
|
p = (P)ARG0(arg); |
|
if ( !ISPFINS(p) ) |
|
*rp = 0; |
|
else { |
|
ins = (PFINS)VR(p)->priv; ad = ins->ad; pf = ins->pf; |
|
t = (FUNC)MALLOC(sizeof(struct oFUNC)); |
|
t->name = t->fullname = pf->name; t->id = A_PURE; t->argc = pf->argc; |
|
t->f.puref = pf; |
|
makesrvar(t,&f); |
|
|
|
d0 = a0 = 0; |
|
for ( i = 0; i < pf->argc; i++ ) { |
|
NEXTNODE(d0,d); STOQ(ad[i].d,q); BDY(d) = (pointer)q; |
|
NEXTNODE(a0,a); BDY(a) = (pointer)ad[i].arg; |
|
} |
|
NEXT(d) = 0; NEXT(a) = 0; MKLIST(alist,a0); MKLIST(dlist,d0); |
|
|
|
n0 = mknode(3,f,dlist,alist); |
|
MKLIST(*rp,n0); |
|
} |
|
} |
|
|
void Pvtype(arg,rp) |
void Pvtype(arg,rp) |
NODE arg; |
NODE arg; |
Q *rp; |
Q *rp; |
Line 525 void Pcall(NODE arg,Obj *rp) |
|
Line 564 void Pcall(NODE arg,Obj *rp) |
|
{ |
{ |
P p; |
P p; |
V v; |
V v; |
|
NODE n,n1; |
|
LIST list; |
|
VECT vect; |
|
pointer *a; |
|
int len,i; |
|
|
p = (P)ARG0(arg); |
p = (P)ARG0(arg); |
if ( !p || OID(p) != 2 ) |
if ( !p || OID(p) != 2 ) |
Line 532 void Pcall(NODE arg,Obj *rp) |
|
Line 576 void Pcall(NODE arg,Obj *rp) |
|
v = VR(p); |
v = VR(p); |
if ( (int)v->attr != V_SR ) |
if ( (int)v->attr != V_SR ) |
error("call : no such function"); |
error("call : no such function"); |
|
else { |
else |
list = (LIST) ARG1(arg); |
*rp = (Obj)bevalf((FUNC)v->priv,BDY((LIST)ARG1(arg))); |
if ( list ) { |
|
switch (OID(list)) { |
|
case O_VECT: |
|
vect = (VECT)list; len = vect->len; a = BDY(vect); |
|
for ( i = len - 1, n = 0; i >= 0; i-- ) { |
|
MKNODE(n1,a[i],n); n = n1; |
|
} |
|
MKLIST(list,n); |
|
/* falling next case */ |
|
case O_LIST: |
|
*rp = (Obj)bevalf((FUNC)v->priv,BDY(list)); |
|
return; |
|
default: |
|
break; |
|
} |
|
} |
|
error("call : invalid argument"); |
|
} |
} |
} |
|
|
/* at=position of arg to be used for iteration */ |
/* at=position of arg to be used for iteration */ |
Line 615 void Pmapat(NODE arg,Obj *rp) |
|
Line 676 void Pmapat(NODE arg,Obj *rp) |
|
} |
} |
} |
} |
|
|
|
/* An implementation of 'map' as builtin function. */ |
|
void Pmap(NODE arg,Obj *rp) |
|
{ |
|
LIST args; |
|
NODE node,rest,t0,t,n,r,r0; |
|
P fpoly; |
|
V fvar; |
|
FUNC f; |
|
VECT v,rv; |
|
MAT m,rm; |
|
LIST rl; |
|
int len,row,col,i,j; |
|
Obj iter; |
|
pointer val; |
|
|
|
if ( argc(arg) < 2 ) |
|
error("mapat : too few arguments"); |
|
|
|
fpoly = (P)ARG0(arg); |
|
if ( !fpoly || OID(fpoly) != O_P ) |
|
error("map : invalid function specification"); |
|
fvar = VR(fpoly); |
|
if ( fvar->attr != (pointer)V_SR || !(f=(FUNC)fvar->priv) ) |
|
error("map : invalid function specification"); |
|
|
|
node = NEXT(arg); |
|
len = length(node); |
|
if ( 0 >= len ) |
|
error("evalmapf : invalid position"); |
|
r0 = 0; |
|
NEXTNODE(r0,r); |
|
iter = BDY(t); rest = NEXT(t); |
|
if ( !iter ) { |
|
*rp = bevalf(f,node); |
|
return; |
|
} |
|
switch ( OID(iter) ) { |
|
case O_VECT: |
|
v = (VECT)iter; len = v->len; MKVECT(rv,len); |
|
for ( i = 0; i < len; i++ ) { |
|
BDY(r) = BDY(v)[i]; NEXT(r) = rest; |
|
BDY(rv)[i] = bevalf(f,r0); |
|
} |
|
*rp = (Obj)rv; |
|
break; |
|
case O_MAT: |
|
m = (MAT)iter; row = m->row; col = m->col; MKMAT(rm,row,col); |
|
for ( i = 0; i < row; i++ ) |
|
for ( j = 0; j < col; j++ ) { |
|
BDY(r) = BDY(m)[i][j]; NEXT(r) = rest; |
|
BDY(rm)[i][j] = bevalf(f,r0); |
|
} |
|
*rp = (Obj)rm; |
|
break; |
|
case O_LIST: |
|
n = BDY((LIST)iter); |
|
for ( t0 = t = 0; n; n = NEXT(n) ) { |
|
BDY(r) = BDY(n); NEXT(r) = rest; |
|
NEXTNODE(t0,t); BDY(t) = bevalf(f,r0); |
|
} |
|
if ( t0 ) |
|
NEXT(t) = 0; |
|
MKLIST(rl,t0); |
|
*rp = (Obj)rl; |
|
break; |
|
default: |
|
*rp = bevalf(f,node); |
|
break; |
|
} |
|
} |
|
|
void Pdeval(arg,rp) |
void Pdeval(arg,rp) |
NODE arg; |
NODE arg; |
Obj *rp; |
Obj *rp; |
Line 627 void Peval_quote(arg,rp) |
|
Line 759 void Peval_quote(arg,rp) |
|
NODE arg; |
NODE arg; |
Obj *rp; |
Obj *rp; |
{ |
{ |
asir_assert(ARG0(arg),O_QUOTE,"eval_quote"); |
FNODE a; |
*rp = eval((FNODE)BDY((QUOTE)ARG0(arg))); |
QUOTE q; |
|
Obj f; |
|
|
|
f = (Obj)ARG0(arg); |
|
if ( !f || OID(f) != O_QUOTE ) { |
|
*rp = f; |
|
return; |
|
} |
|
if ( argc(arg) == 2 && ARG1(arg) ) { |
|
a = partial_eval((FNODE)BDY((QUOTE)ARG0(arg))); |
|
MKQUOTE(q,a); |
|
*rp = (Obj)q; |
|
} else |
|
*rp = eval((FNODE)BDY((QUOTE)ARG0(arg))); |
} |
} |