version 1.26, 2005/12/10 14:14:16 |
version 1.27, 2018/03/29 01:32:54 |
|
|
/* $OpenXM: OpenXM_contrib2/asir2000/parse/quote.c,v 1.25 2005/09/30 02:20:06 noro Exp $ */ |
/* $OpenXM: OpenXM_contrib2/asir2000/parse/quote.c,v 1.26 2005/12/10 14:14:16 noro Exp $ */ |
|
|
#include "ca.h" |
#include "ca.h" |
#include "parse.h" |
#include "parse.h" |
|
|
void addquote(VL vl,QUOTE a,QUOTE b,QUOTE *c) |
void addquote(VL vl,QUOTE a,QUOTE b,QUOTE *c) |
{ |
{ |
FNODE fn; |
FNODE fn; |
QUOTE t; |
QUOTE t; |
|
|
objtoquote((Obj)a,&t); a = t; objtoquote((Obj)b,&t); b = t; |
objtoquote((Obj)a,&t); a = t; objtoquote((Obj)b,&t); b = t; |
fn = mkfnode(3,I_BOP,addfs,BDY(a),BDY(b)); |
fn = mkfnode(3,I_BOP,addfs,BDY(a),BDY(b)); |
MKQUOTE(*c,fn); |
MKQUOTE(*c,fn); |
} |
} |
|
|
void subquote(VL vl,QUOTE a,QUOTE b,QUOTE *c) |
void subquote(VL vl,QUOTE a,QUOTE b,QUOTE *c) |
{ |
{ |
FNODE fn; |
FNODE fn; |
QUOTE t; |
QUOTE t; |
|
|
objtoquote((Obj)a,&t); a = t; objtoquote((Obj)b,&t); b = t; |
objtoquote((Obj)a,&t); a = t; objtoquote((Obj)b,&t); b = t; |
fn = mkfnode(3,I_BOP,subfs,BDY(a),BDY(b)); |
fn = mkfnode(3,I_BOP,subfs,BDY(a),BDY(b)); |
MKQUOTE(*c,fn); |
MKQUOTE(*c,fn); |
} |
} |
|
|
void mulquote(VL vl,QUOTE a,QUOTE b,QUOTE *c) |
void mulquote(VL vl,QUOTE a,QUOTE b,QUOTE *c) |
{ |
{ |
FNODE fn; |
FNODE fn; |
QUOTE t; |
QUOTE t; |
|
|
objtoquote((Obj)a,&t); a = t; objtoquote((Obj)b,&t); b = t; |
objtoquote((Obj)a,&t); a = t; objtoquote((Obj)b,&t); b = t; |
fn = mkfnode(3,I_BOP,mulfs,BDY(a),BDY(b)); |
fn = mkfnode(3,I_BOP,mulfs,BDY(a),BDY(b)); |
MKQUOTE(*c,fn); |
MKQUOTE(*c,fn); |
} |
} |
|
|
void divquote(VL vl,QUOTE a,QUOTE b,QUOTE *c) |
void divquote(VL vl,QUOTE a,QUOTE b,QUOTE *c) |
{ |
{ |
FNODE fn; |
FNODE fn; |
QUOTE t; |
QUOTE t; |
|
|
objtoquote((Obj)a,&t); a = t; objtoquote((Obj)b,&t); b = t; |
objtoquote((Obj)a,&t); a = t; objtoquote((Obj)b,&t); b = t; |
fn = mkfnode(3,I_BOP,divfs,BDY(a),BDY(b)); |
fn = mkfnode(3,I_BOP,divfs,BDY(a),BDY(b)); |
MKQUOTE(*c,fn); |
MKQUOTE(*c,fn); |
} |
} |
|
|
void pwrquote(VL vl,QUOTE a,QUOTE b,QUOTE *c) |
void pwrquote(VL vl,QUOTE a,QUOTE b,QUOTE *c) |
{ |
{ |
FNODE fn; |
FNODE fn; |
QUOTE t; |
QUOTE t; |
|
|
objtoquote((Obj)a,&t); a = t; objtoquote((Obj)b,&t); b = t; |
objtoquote((Obj)a,&t); a = t; objtoquote((Obj)b,&t); b = t; |
fn = mkfnode(3,I_BOP,pwrfs,BDY(a),BDY(b)); |
fn = mkfnode(3,I_BOP,pwrfs,BDY(a),BDY(b)); |
MKQUOTE(*c,fn); |
MKQUOTE(*c,fn); |
} |
} |
|
|
void chsgnquote(QUOTE a,QUOTE *c) |
void chsgnquote(QUOTE a,QUOTE *c) |
{ |
{ |
FNODE fn; |
FNODE fn; |
QUOTE t; |
QUOTE t; |
|
|
objtoquote((Obj)a,&t); a = t; |
objtoquote((Obj)a,&t); a = t; |
fn = mkfnode(1,I_MINUS,BDY(a)); |
fn = mkfnode(1,I_MINUS,BDY(a)); |
MKQUOTE(*c,fn); |
MKQUOTE(*c,fn); |
} |
} |
|
|
void objtoquote(Obj a,QUOTE *c) |
void objtoquote(Obj a,QUOTE *c) |
{ |
{ |
QUOTE nm,dn; |
QUOTE nm,dn; |
NODE arg,t0,t,t1,t2,t3; |
NODE arg,t0,t,t1,t2,t3; |
FNODE fn; |
FNODE fn; |
Obj obj; |
Obj obj; |
Obj *b; |
Obj *b; |
Obj **m; |
Obj **m; |
int i,j,len,row,col; |
int i,j,len,row,col; |
Q q,qrow,qcol; |
Q q,qrow,qcol; |
FUNC f; |
FUNC f; |
|
|
if ( !a ) { |
if ( !a ) { |
MKQUOTE(*c,mkfnode(1,I_FORMULA,(pointer)a)); |
MKQUOTE(*c,mkfnode(1,I_FORMULA,(pointer)a)); |
return; |
return; |
} |
} |
switch ( OID(a) ) { |
switch ( OID(a) ) { |
case O_N: |
case O_N: |
if ( negative_number((Num)a) ) { |
if ( negative_number((Num)a) ) { |
arf_chsgn(a,&obj); |
arf_chsgn(a,&obj); |
MKQUOTE(*c,mkfnode(1,I_MINUS, |
MKQUOTE(*c,mkfnode(1,I_MINUS, |
mkfnode(1,I_FORMULA,(pointer)obj))); |
mkfnode(1,I_FORMULA,(pointer)obj))); |
} else { |
} else { |
MKQUOTE(*c,mkfnode(1,I_FORMULA,(pointer)a)); |
MKQUOTE(*c,mkfnode(1,I_FORMULA,(pointer)a)); |
} |
} |
break; |
break; |
case O_STR: |
case O_STR: |
MKQUOTE(*c,mkfnode(1,I_FORMULA,(pointer)a)); |
MKQUOTE(*c,mkfnode(1,I_FORMULA,(pointer)a)); |
break; |
break; |
case O_P: |
case O_P: |
polytoquote((P)a,c); |
polytoquote((P)a,c); |
break; |
break; |
case O_R: |
case O_R: |
polytoquote(NM((R)a),&nm); |
polytoquote(NM((R)a),&nm); |
polytoquote(DN((R)a),&dn); |
polytoquote(DN((R)a),&dn); |
divquote(CO,nm,dn,c); |
divquote(CO,nm,dn,c); |
break; |
break; |
case O_LIST: |
case O_LIST: |
t0 = 0; |
t0 = 0; |
for ( arg = BDY((LIST)a); arg; arg = NEXT(arg) ) { |
for ( arg = BDY((LIST)a); arg; arg = NEXT(arg) ) { |
NEXTNODE(t0,t); |
NEXTNODE(t0,t); |
objtoquote(BDY(arg),&nm); |
objtoquote(BDY(arg),&nm); |
BDY(t) = BDY(nm); |
BDY(t) = BDY(nm); |
} |
} |
if ( t0 ) |
if ( t0 ) |
NEXT(t) = 0; |
NEXT(t) = 0; |
MKQUOTE(*c,mkfnode(1,I_LIST,t0)); |
MKQUOTE(*c,mkfnode(1,I_LIST,t0)); |
break; |
break; |
case O_VECT: |
case O_VECT: |
len = ((VECT)a)->len; |
len = ((VECT)a)->len; |
b = (Obj *)BDY(((VECT)a)); |
b = (Obj *)BDY(((VECT)a)); |
t = 0; |
t = 0; |
for ( i = len-1; i >= 0; i-- ) { |
for ( i = len-1; i >= 0; i-- ) { |
objtoquote(b[i],&nm); |
objtoquote(b[i],&nm); |
MKNODE(t1,BDY(nm),t); |
MKNODE(t1,BDY(nm),t); |
t = t1; |
t = t1; |
} |
} |
STOQ(len,q); |
STOQ(len,q); |
t = mknode(2,mkfnode(1,I_FORMULA,q),mkfnode(1,I_LIST,t)); |
t = mknode(2,mkfnode(1,I_FORMULA,q),mkfnode(1,I_LIST,t)); |
gen_searchf("vector",&f); |
gen_searchf("vector",&f); |
MKQUOTE(*c,mkfnode(2,I_FUNC,f,mkfnode(1,I_LIST,t))); |
MKQUOTE(*c,mkfnode(2,I_FUNC,f,mkfnode(1,I_LIST,t))); |
break; |
break; |
case O_MAT: |
case O_MAT: |
row = ((MAT)a)->row; |
row = ((MAT)a)->row; |
col = ((MAT)a)->row; |
col = ((MAT)a)->row; |
m = (Obj **)BDY(((MAT)a)); |
m = (Obj **)BDY(((MAT)a)); |
t2 = 0; |
t2 = 0; |
for ( i = row-1; i >= 0; i-- ) { |
for ( i = row-1; i >= 0; i-- ) { |
t = 0; |
t = 0; |
for ( j = col-1; j >= 0; j-- ) { |
for ( j = col-1; j >= 0; j-- ) { |
objtoquote(m[i][j],&nm); |
objtoquote(m[i][j],&nm); |
MKNODE(t1,BDY(nm),t); |
MKNODE(t1,BDY(nm),t); |
t = t1; |
t = t1; |
} |
} |
fn = mkfnode(1,I_LIST,t); |
fn = mkfnode(1,I_LIST,t); |
MKNODE(t3,fn,t2); |
MKNODE(t3,fn,t2); |
t2 = t3; |
t2 = t3; |
} |
} |
fn = mkfnode(1,I_LIST,t2); |
fn = mkfnode(1,I_LIST,t2); |
|
|
STOQ(row,qrow); |
STOQ(row,qrow); |
STOQ(col,qcol); |
STOQ(col,qcol); |
t = mknode(3, |
t = mknode(3, |
mkfnode(1,I_FORMULA,qrow),mkfnode(1,I_FORMULA,qcol),fn); |
mkfnode(1,I_FORMULA,qrow),mkfnode(1,I_FORMULA,qcol),fn); |
gen_searchf("matrix",&f); |
gen_searchf("matrix",&f); |
MKQUOTE(*c,mkfnode(2,I_FUNC,f,mkfnode(1,I_LIST,t))); |
MKQUOTE(*c,mkfnode(2,I_FUNC,f,mkfnode(1,I_LIST,t))); |
break; |
break; |
case O_DP: |
case O_DP: |
dptoquote((DP)a,c); |
dptoquote((DP)a,c); |
break; |
break; |
case O_QUOTE: |
case O_QUOTE: |
*c = (QUOTE)a; |
*c = (QUOTE)a; |
break; |
break; |
default: |
default: |
error("objtoquote : not implemented"); |
error("objtoquote : not implemented"); |
} |
} |
} |
} |
|
|
void polytoquote(P a,QUOTE *c) |
void polytoquote(P a,QUOTE *c) |
{ |
{ |
DCP dc,t; |
DCP dc,t; |
DCP *dca; |
DCP *dca; |
int n,i,sgn; |
int n,i,sgn; |
QUOTE v,r,s,u; |
QUOTE v,r,s,u; |
|
|
if ( !a ) { |
if ( !a ) { |
MKQUOTE(*c,mkfnode(1,I_FORMULA,(pointer)a)); |
MKQUOTE(*c,mkfnode(1,I_FORMULA,(pointer)a)); |
return; |
return; |
} else if ( OID(a) == O_N ) { |
} else if ( OID(a) == O_N ) { |
MKQUOTE(*c,mkfnode(1,I_FORMULA,(pointer)a)); |
MKQUOTE(*c,mkfnode(1,I_FORMULA,(pointer)a)); |
return; |
return; |
} |
} |
vartoquote(VR((P)a),&v); |
vartoquote(VR((P)a),&v); |
dc = DC((P)a); |
dc = DC((P)a); |
dctoquote(dc,v,&r,&sgn); |
dctoquote(dc,v,&r,&sgn); |
if ( sgn == -1 ) { |
if ( sgn == -1 ) { |
MKQUOTE(u,mkfnode(1,I_MINUS,BDY(r))); |
MKQUOTE(u,mkfnode(1,I_MINUS,BDY(r))); |
r = u; |
r = u; |
} |
} |
for (dc = NEXT(dc); dc; dc = NEXT(dc) ) { |
for (dc = NEXT(dc); dc; dc = NEXT(dc) ) { |
dctoquote(dc,v,&s,&sgn); |
dctoquote(dc,v,&s,&sgn); |
if ( sgn == -1 ) |
if ( sgn == -1 ) |
subquote(CO,r,s,&u); |
subquote(CO,r,s,&u); |
else |
else |
addquote(CO,r,s,&u); |
addquote(CO,r,s,&u); |
r = u; |
r = u; |
} |
} |
*c = r; |
*c = r; |
} |
} |
|
|
void dptoquote(DP a,QUOTE *c) |
void dptoquote(DP a,QUOTE *c) |
{ |
{ |
MP t; |
MP t; |
MP m; |
MP m; |
int i,n,nv,sgn; |
int i,n,nv,sgn; |
QUOTE s,r,u; |
QUOTE s,r,u; |
|
|
if ( !a ) { |
if ( !a ) { |
MKQUOTE(*c,mkfnode(1,I_FORMULA,(pointer)a)); |
MKQUOTE(*c,mkfnode(1,I_FORMULA,(pointer)a)); |
return; |
return; |
} |
} |
nv = NV(a); |
nv = NV(a); |
m = BDY(a); |
m = BDY(a); |
mptoquote(m,nv,&r,&sgn); |
mptoquote(m,nv,&r,&sgn); |
if ( sgn == -1 ) { |
if ( sgn == -1 ) { |
MKQUOTE(u,mkfnode(1,I_MINUS,BDY(r))); |
MKQUOTE(u,mkfnode(1,I_MINUS,BDY(r))); |
r = u; |
r = u; |
} |
} |
for ( m = NEXT(m); m; m = NEXT(m) ) { |
for ( m = NEXT(m); m; m = NEXT(m) ) { |
mptoquote(m,nv,&s,&sgn); |
mptoquote(m,nv,&s,&sgn); |
if ( sgn < 0 ) |
if ( sgn < 0 ) |
subquote(CO,r,s,&u); |
subquote(CO,r,s,&u); |
else |
else |
addquote(CO,r,s,&u); |
addquote(CO,r,s,&u); |
r = u; |
r = u; |
} |
} |
*c = r; |
*c = r; |
} |
} |
|
|
void dctoquote(DCP dc,QUOTE v,QUOTE *q,int *sgn) |
void dctoquote(DCP dc,QUOTE v,QUOTE *q,int *sgn) |
{ |
{ |
QUOTE t,s,u,r; |
QUOTE t,s,u,r; |
P c; |
P c; |
Q d; |
Q d; |
|
|
if ( mmono(COEF(dc)) ) { |
if ( mmono(COEF(dc)) ) { |
/* -xyz... */ |
/* -xyz... */ |
chsgnp(COEF(dc),&c); |
chsgnp(COEF(dc),&c); |
*sgn = -1; |
*sgn = -1; |
} else { |
} else { |
c = COEF(dc); |
c = COEF(dc); |
*sgn = 1; |
*sgn = 1; |
} |
} |
d = DEG(dc); |
d = DEG(dc); |
if ( UNIQ(c) ) { |
if ( UNIQ(c) ) { |
if ( d ) { |
if ( d ) { |
if ( UNIQ(d) ) |
if ( UNIQ(d) ) |
r = v; |
r = v; |
else { |
else { |
objtoquote((Obj)d,&t); |
objtoquote((Obj)d,&t); |
pwrquote(CO,v,t,&r); |
pwrquote(CO,v,t,&r); |
} |
} |
} else |
} else |
objtoquote((Obj)ONE,&r); |
objtoquote((Obj)ONE,&r); |
} else { |
} else { |
objtoquote((Obj)c,&u); |
objtoquote((Obj)c,&u); |
if ( !NUM(c) && NEXT(DC(c)) && d ) { |
if ( !NUM(c) && NEXT(DC(c)) && d ) { |
MKQUOTE(t,mkfnode(1,I_PAREN,BDY(u))); |
MKQUOTE(t,mkfnode(1,I_PAREN,BDY(u))); |
u = t; |
u = t; |
} |
} |
if ( d ) { |
if ( d ) { |
if ( UNIQ(d) ) |
if ( UNIQ(d) ) |
s = v; |
s = v; |
else { |
else { |
objtoquote((Obj)d,&t); |
objtoquote((Obj)d,&t); |
pwrquote(CO,v,t,&s); |
pwrquote(CO,v,t,&s); |
} |
} |
mulquote(CO,u,s,&r); |
mulquote(CO,u,s,&r); |
} else |
} else |
r = u; |
r = u; |
} |
} |
*q = r; |
*q = r; |
} |
} |
|
|
void mptoquote(MP m,int n,QUOTE *r,int *sgn) |
void mptoquote(MP m,int n,QUOTE *r,int *sgn) |
{ |
{ |
QUOTE s,u; |
QUOTE s,u; |
P c; |
P c; |
NODE t,t1; |
NODE t,t1; |
FNODE f; |
FNODE f; |
Q q; |
Q q; |
DL dl; |
DL dl; |
int i; |
int i; |
|
|
if ( mmono(C(m)) ) { |
if ( mmono(C(m)) ) { |
chsgnp(C(m),&c); |
chsgnp(C(m),&c); |
*sgn = -1; |
*sgn = -1; |
} else { |
} else { |
c = C(m); |
c = C(m); |
*sgn = 1; |
*sgn = 1; |
} |
} |
objtoquote((Obj)c,&s); |
objtoquote((Obj)c,&s); |
if ( !NUM(c) && NEXT(DC(c)) ) { |
if ( !NUM(c) && NEXT(DC(c)) ) { |
MKQUOTE(u,mkfnode(1,I_PAREN,BDY(s))); |
MKQUOTE(u,mkfnode(1,I_PAREN,BDY(s))); |
s = u; |
s = u; |
} |
} |
dl = m->dl; |
dl = m->dl; |
for ( i = n-1, t = 0; i >= 0; i-- ) { |
for ( i = n-1, t = 0; i >= 0; i-- ) { |
STOQ(dl->d[i],q); |
STOQ(dl->d[i],q); |
f = mkfnode(1,I_FORMULA,q); |
f = mkfnode(1,I_FORMULA,q); |
MKNODE(t1,f,t); |
MKNODE(t1,f,t); |
t = t1; |
t = t1; |
} |
} |
MKQUOTE(u,mkfnode(1,I_EV,t)); |
MKQUOTE(u,mkfnode(1,I_EV,t)); |
if ( UNIQ(c) ) |
if ( UNIQ(c) ) |
*r = u; |
*r = u; |
else |
else |
mulquote(CO,s,u,r); |
mulquote(CO,s,u,r); |
} |
} |
|
|
void vartoquote(V v,QUOTE *c) |
void vartoquote(V v,QUOTE *c) |
{ |
{ |
P x; |
P x; |
PF pf; |
PF pf; |
PFAD ad; |
PFAD ad; |
QUOTE a,b,u; |
QUOTE a,b,u; |
int i; |
int i; |
FUNC f; |
FUNC f; |
NODE t,t1; |
NODE t,t1; |
|
|
if ( NAME(v) ) { |
if ( NAME(v) ) { |
MKV(v,x); |
MKV(v,x); |
MKQUOTE(*c,mkfnode(1,I_FORMULA,(pointer)x)); |
MKQUOTE(*c,mkfnode(1,I_FORMULA,(pointer)x)); |
} else if ( (vid)v->attr == V_PF ) { |
} else if ( (vid)v->attr == V_PF ) { |
/* pure function */ |
/* pure function */ |
pf = ((PFINS)v->priv)->pf; |
pf = ((PFINS)v->priv)->pf; |
ad = ((PFINS)v->priv)->ad; |
ad = ((PFINS)v->priv)->ad; |
if ( !strcmp(NAME(pf),"pow") ) { |
if ( !strcmp(NAME(pf),"pow") ) { |
/* pow(a,b) = a^b */ |
/* pow(a,b) = a^b */ |
objtoquote(ad[0].arg,&a); |
objtoquote(ad[0].arg,&a); |
x = (P)ad[0].arg; |
x = (P)ad[0].arg; |
/* check whether x is a variable */ |
/* check whether x is a variable */ |
if ( x && OID(x)==O_P && !NEXT(DC(x)) |
if ( x && OID(x)==O_P && !NEXT(DC(x)) |
&& UNIQ(DEG(DC(x))) && UNIQ(COEF(DC(x))) ) { |
&& UNIQ(DEG(DC(x))) && UNIQ(COEF(DC(x))) ) { |
/* use a as is */ |
/* use a as is */ |
} else { |
} else { |
/* a => (a) */ |
/* a => (a) */ |
MKQUOTE(u,mkfnode(1,I_PAREN,BDY(a))); a = u; |
MKQUOTE(u,mkfnode(1,I_PAREN,BDY(a))); a = u; |
} |
} |
objtoquote(ad[1].arg,&b); |
objtoquote(ad[1].arg,&b); |
pwrquote(CO,a,b,c); |
pwrquote(CO,a,b,c); |
} else { |
} else { |
for ( i = 0; i < pf->argc; i++ ) |
for ( i = 0; i < pf->argc; i++ ) |
if ( ad[i].d ) |
if ( ad[i].d ) |
break; |
break; |
if ( i < pf->argc ) |
if ( i < pf->argc ) |
error("vartoquote : not implemented"); |
error("vartoquote : not implemented"); |
gen_searchf(NAME(pf),&f); |
gen_searchf(NAME(pf),&f); |
t = 0; |
t = 0; |
for ( i = pf->argc-1; i >= 0; i-- ) { |
for ( i = pf->argc-1; i >= 0; i-- ) { |
objtoquote(ad[i].arg,&a); |
objtoquote(ad[i].arg,&a); |
MKNODE(t1,BDY(a),t); |
MKNODE(t1,BDY(a),t); |
t = t1; |
t = t1; |
} |
} |
MKQUOTE(*c,mkfnode(2,I_FUNC,f,mkfnode(1,I_LIST,t))); |
MKQUOTE(*c,mkfnode(2,I_FUNC,f,mkfnode(1,I_LIST,t))); |
} |
} |
} |
} |
} |
} |
|
|
/* |
/* |
Line 365 void vartoquote(V v,QUOTE *c) |
|
Line 365 void vartoquote(V v,QUOTE *c) |
|
*/ |
*/ |
|
|
struct fid_spec fid_spec_tab[] = { |
struct fid_spec fid_spec_tab[] = { |
{I_BOP,A_arf,A_fnode,A_fnode,A_end}, |
{I_BOP,A_arf,A_fnode,A_fnode,A_end}, |
{I_COP,A_int,A_fnode,A_fnode,A_end}, |
{I_COP,A_int,A_fnode,A_fnode,A_end}, |
{I_AND,A_fnode,A_fnode,A_end}, |
{I_AND,A_fnode,A_fnode,A_end}, |
{I_OR,A_fnode,A_fnode,A_end}, |
{I_OR,A_fnode,A_fnode,A_end}, |
{I_NOT,A_fnode,A_end}, |
{I_NOT,A_fnode,A_end}, |
{I_CE,A_fnode,A_fnode,A_end}, |
{I_CE,A_fnode,A_fnode,A_end}, |
{I_PRESELF,A_arf,A_fnode,A_end}, |
{I_PRESELF,A_arf,A_fnode,A_end}, |
{I_POSTSELF,A_arf,A_fnode,A_end}, |
{I_POSTSELF,A_arf,A_fnode,A_end}, |
{I_FUNC,A_func,A_fnode,A_end}, |
{I_FUNC,A_func,A_fnode,A_end}, |
{I_FUNC_OPT,A_func,A_fnode,A_fnode,A_end}, |
{I_FUNC_OPT,A_func,A_fnode,A_fnode,A_end}, |
{I_IFUNC,A_fnode,A_fnode,A_end}, |
{I_IFUNC,A_fnode,A_fnode,A_end}, |
{I_MAP,A_func,A_fnode,A_end}, |
{I_MAP,A_func,A_fnode,A_end}, |
{I_RECMAP,A_func,A_fnode,A_end}, |
{I_RECMAP,A_func,A_fnode,A_end}, |
{I_PFDERIV,A_notimpl,A_end}, |
{I_PFDERIV,A_notimpl,A_end}, |
{I_ANS,A_int,A_end}, |
{I_ANS,A_int,A_end}, |
{I_PVAR,A_int,A_node,A_end}, |
{I_PVAR,A_int,A_node,A_end}, |
{I_ASSPVAR,A_fnode,A_fnode,A_end}, |
{I_ASSPVAR,A_fnode,A_fnode,A_end}, |
{I_FORMULA,A_internal,A_end}, |
{I_FORMULA,A_internal,A_end}, |
{I_LIST,A_node,A_end}, |
{I_LIST,A_node,A_end}, |
{I_STR,A_str,A_end}, |
{I_STR,A_str,A_end}, |
{I_NEWCOMP,A_int,A_end}, |
{I_NEWCOMP,A_int,A_end}, |
{I_CAR,A_fnode,A_end}, |
{I_CAR,A_fnode,A_end}, |
{I_CDR,A_fnode,A_end}, |
{I_CDR,A_fnode,A_end}, |
{I_CAST,A_notimpl,A_end}, |
{I_CAST,A_notimpl,A_end}, |
{I_INDEX,A_fnode,A_node,A_end}, |
{I_INDEX,A_fnode,A_node,A_end}, |
{I_EV,A_node,A_end}, |
{I_EV,A_node,A_end}, |
{I_TIMER,A_fnode,A_fnode,A_fnode,A_end}, |
{I_TIMER,A_fnode,A_fnode,A_fnode,A_end}, |
{I_GF2NGEN,A_end}, |
{I_GF2NGEN,A_end}, |
{I_GFPNGEN,A_end}, |
{I_GFPNGEN,A_end}, |
{I_GFSNGEN,A_end}, |
{I_GFSNGEN,A_end}, |
{I_LOP,A_int,A_fnode,A_fnode,A_end}, |
{I_LOP,A_int,A_fnode,A_fnode,A_end}, |
{I_OPT,A_str,A_fnode,A_end}, |
{I_OPT,A_str,A_fnode,A_end}, |
{I_GETOPT,A_str,A_end}, |
{I_GETOPT,A_str,A_end}, |
{I_POINT,A_fnode,A_str,A_end}, |
{I_POINT,A_fnode,A_str,A_end}, |
{I_PAREN,A_fnode,A_end}, |
{I_PAREN,A_fnode,A_end}, |
{I_MINUS,A_fnode,A_end}, |
{I_MINUS,A_fnode,A_end}, |
{I_NARYOP,A_arf,A_node,A_end}, |
{I_NARYOP,A_arf,A_node,A_end}, |
{I_CONS,A_node,A_fnode,A_end}, |
{I_CONS,A_node,A_fnode,A_end}, |
{I_FUNC_QARG,A_func,A_fnode,A_end}, |
{I_FUNC_QARG,A_func,A_fnode,A_end}, |
{I_FUNC_HEAD,A_func,A_end}, |
{I_FUNC_HEAD,A_func,A_end}, |
}; |
}; |
|
|
#define N_FID_SPEC (sizeof(fid_spec_tab)/sizeof(struct fid_spec)) |
#define N_FID_SPEC (sizeof(fid_spec_tab)/sizeof(struct fid_spec)) |
|
|
void get_fid_spec(fid id,fid_spec_p *spec) |
void get_fid_spec(fid id,fid_spec_p *spec) |
{ |
{ |
int i; |
int i; |
|
|
for ( i = 0; i < N_FID_SPEC; i++ ) |
for ( i = 0; i < N_FID_SPEC; i++ ) |
if ( fid_spec_tab[i].id == id ) { |
if ( fid_spec_tab[i].id == id ) { |
*spec = &fid_spec_tab[i]; |
*spec = &fid_spec_tab[i]; |
return; |
return; |
} |
} |
*spec = 0; |
*spec = 0; |
} |
} |
|
|
FNODE strip_paren(FNODE f) |
FNODE strip_paren(FNODE f) |
{ |
{ |
if ( !f || f->id != I_PAREN ) return f; |
if ( !f || f->id != I_PAREN ) return f; |
else { |
else { |
return strip_paren((FNODE)FA0(f)); |
return strip_paren((FNODE)FA0(f)); |
} |
} |
} |
} |
|
|
NODE flatten_fnodenode(NODE n,char *opname); |
NODE flatten_fnodenode(NODE n,char *opname); |
Line 434 FNODE flatten_fnode(FNODE f,char *opname); |
|
Line 434 FNODE flatten_fnode(FNODE f,char *opname); |
|
|
|
NODE flatten_fnodenode(NODE n,char *opname) |
NODE flatten_fnodenode(NODE n,char *opname) |
{ |
{ |
NODE r0,r,t; |
NODE r0,r,t; |
|
|
r0 = 0; |
r0 = 0; |
for ( t = n; t; t = NEXT(t) ) { |
for ( t = n; t; t = NEXT(t) ) { |
NEXTNODE(r0,r); |
NEXTNODE(r0,r); |
BDY(r) = (pointer)flatten_fnode((FNODE)BDY(t),opname); |
BDY(r) = (pointer)flatten_fnode((FNODE)BDY(t),opname); |
} |
} |
if ( r0 ) NEXT(r) = 0; |
if ( r0 ) NEXT(r) = 0; |
return r0; |
return r0; |
} |
} |
|
|
FNODE flatten_fnode(FNODE f,char *opname) |
FNODE flatten_fnode(FNODE f,char *opname) |
{ |
{ |
fid_spec_p spec; |
fid_spec_p spec; |
farg_type *type; |
farg_type *type; |
fid id; |
fid id; |
FNODE f1,f2,r; |
FNODE f1,f2,r; |
int i; |
int i; |
|
|
if ( !f ) return f; |
if ( !f ) return f; |
id = f->id; |
id = f->id; |
get_fid_spec(id,&spec); |
get_fid_spec(id,&spec); |
/* unknown fid */ |
/* unknown fid */ |
if ( !spec ) return f; |
if ( !spec ) return f; |
if ( id == I_BOP && !strcmp(((ARF)FA0(f))->name,opname) ) { |
if ( id == I_BOP && !strcmp(((ARF)FA0(f))->name,opname) ) { |
f1 = (pointer)flatten_fnode(FA1(f),opname); |
f1 = (pointer)flatten_fnode(FA1(f),opname); |
f1 = strip_paren(f1); |
f1 = strip_paren(f1); |
f2 = (pointer)flatten_fnode(FA2(f),opname); |
f2 = (pointer)flatten_fnode(FA2(f),opname); |
f2 = strip_paren(f2); |
f2 = strip_paren(f2); |
if ( f1->id == I_BOP && !strcmp(((ARF)FA0(f1))->name,opname) ) { |
if ( f1->id == I_BOP && !strcmp(((ARF)FA0(f1))->name,opname) ) { |
/* [op [op A B] C] => [op A [op B C]] */ |
/* [op [op A B] C] => [op A [op B C]] */ |
f2 = flatten_fnode(mkfnode(3,I_BOP,(ARF)FA0(f),FA2(f1),f2),opname); |
f2 = flatten_fnode(mkfnode(3,I_BOP,(ARF)FA0(f),FA2(f1),f2),opname); |
return mkfnode(3,I_BOP,(ARF)FA0(f),FA1(f1),f2); |
return mkfnode(3,I_BOP,(ARF)FA0(f),FA1(f1),f2); |
} else |
} else |
return mkfnode(3,I_BOP,(ARF)FA0(f),f1,f2); |
return mkfnode(3,I_BOP,(ARF)FA0(f),f1,f2); |
} else { |
} else { |
type = spec->type; |
type = spec->type; |
for ( i = 0; type[i] != A_end; i++ ); |
for ( i = 0; type[i] != A_end; i++ ); |
NEWFNODE(r,i); ID(r) = f->id; |
NEWFNODE(r,i); ID(r) = f->id; |
for ( i = 0; type[i] != A_end; i++ ) { |
for ( i = 0; type[i] != A_end; i++ ) { |
if ( type[i] == A_fnode ) |
if ( type[i] == A_fnode ) |
r->arg[i] = (pointer)flatten_fnode(f->arg[i],opname); |
r->arg[i] = (pointer)flatten_fnode(f->arg[i],opname); |
else if ( type[i] == A_node ) |
else if ( type[i] == A_node ) |
r->arg[i] = (pointer)flatten_fnodenode(f->arg[i],opname); |
r->arg[i] = (pointer)flatten_fnodenode(f->arg[i],opname); |
else |
else |
r->arg[i] = f->arg[i]; |
r->arg[i] = f->arg[i]; |
} |
} |
return r; |
return r; |
} |
} |
} |
} |
|
|
/* comparison of QUOTE */ |
/* comparison of QUOTE */ |
|
|
int compquote(VL vl,QUOTE q1,QUOTE q2) |
int compquote(VL vl,QUOTE q1,QUOTE q2) |
{ |
{ |
return compfnode(BDY(q1),BDY(q2)); |
return compfnode(BDY(q1),BDY(q2)); |
} |
} |
|
|
/* comparison of QUOTEARG */ |
/* comparison of QUOTEARG */ |
Line 497 int compquote(VL vl,QUOTE q1,QUOTE q2) |
|
Line 497 int compquote(VL vl,QUOTE q1,QUOTE q2) |
|
|
|
int compqa(VL vl,QUOTEARG q1,QUOTEARG q2) |
int compqa(VL vl,QUOTEARG q1,QUOTEARG q2) |
{ |
{ |
if ( !q1 ) return q2?-1:0; |
if ( !q1 ) return q2?-1:0; |
else if ( !q2 ) return 1; |
else if ( !q2 ) return 1; |
else if ( OID(q1) > OID(q2) ) return 1; |
else if ( OID(q1) > OID(q2) ) return 1; |
else if ( OID(q1) < OID(q2) ) return -1; |
else if ( OID(q1) < OID(q2) ) return -1; |
else if ( q1->type > q2->type ) return 1; |
else if ( q1->type > q2->type ) return 1; |
else if ( q1->type < q2->type ) return -1; |
else if ( q1->type < q2->type ) return -1; |
else switch ( q1->type ) { |
else switch ( q1->type ) { |
case A_func: |
case A_func: |
return strcmp(((FUNC)q1->body)->name,((FUNC)q2->body)->name); |
return strcmp(((FUNC)q1->body)->name,((FUNC)q2->body)->name); |
case A_arf: |
case A_arf: |
return strcmp(((ARF)q1->body)->name,((ARF)q2->body)->name); |
return strcmp(((ARF)q1->body)->name,((ARF)q2->body)->name); |
default: |
default: |
if ( (unsigned)q1->body > (unsigned)q2->body ) return 1; |
if ( (unsigned)q1->body > (unsigned)q2->body ) return 1; |
else if ( (unsigned)q1->body < (unsigned)q2->body ) return -1; |
else if ( (unsigned)q1->body < (unsigned)q2->body ) return -1; |
else return 0; |
else return 0; |
} |
} |
} |
} |
|
|
int compfnode(FNODE f1,FNODE f2) |
int compfnode(FNODE f1,FNODE f2) |
{ |
{ |
fid_spec_p spec; |
fid_spec_p spec; |
int t,s1,s2,i; |
int t,s1,s2,i; |
NODE n1,n2; |
NODE n1,n2; |
|
|
if ( !f1 ) return f2 ? -1 : 1; |
if ( !f1 ) return f2 ? -1 : 1; |
else if ( !f2 ) return 1; |
else if ( !f2 ) return 1; |
else if ( f1->id > f2->id ) return 1; |
else if ( f1->id > f2->id ) return 1; |
else if ( f1->id < f2->id ) return -1; |
else if ( f1->id < f2->id ) return -1; |
spec = fid_spec_tab+f1->id; |
spec = fid_spec_tab+f1->id; |
for ( i = 0; spec->type[i] != A_end; i++ ) { |
for ( i = 0; spec->type[i] != A_end; i++ ) { |
switch ( spec->type[i] ) { |
switch ( spec->type[i] ) { |
case A_fnode: |
case A_fnode: |
t = compfnode((FNODE)f1->arg[i],(FNODE)f2->arg[i]); |
t = compfnode((FNODE)f1->arg[i],(FNODE)f2->arg[i]); |
if ( t ) return t; |
if ( t ) return t; |
break; |
break; |
case A_int: |
case A_int: |
s1 = (int)f1->arg[i]; |
s1 = (int)f1->arg[i]; |
s2 = (int)f2->arg[i]; |
s2 = (int)f2->arg[i]; |
if ( s1 > s2 ) return 1; |
if ( s1 > s2 ) return 1; |
else if ( s1 < s2 ) return -1; |
else if ( s1 < s2 ) return -1; |
break; |
break; |
case A_str: |
case A_str: |
t = strcmp((char *)f1->arg[i],(char *)f2->arg[i]); |
t = strcmp((char *)f1->arg[i],(char *)f2->arg[i]); |
if ( t ) return t; |
if ( t ) return t; |
break; |
break; |
case A_internal: |
case A_internal: |
t = arf_comp(CO,(Obj)f1->arg[i],(Obj)f2->arg[i]); |
t = arf_comp(CO,(Obj)f1->arg[i],(Obj)f2->arg[i]); |
if ( t ) return t; |
if ( t ) return t; |
break; |
break; |
case A_node: |
case A_node: |
n1 = (NODE)f1->arg[i]; |
n1 = (NODE)f1->arg[i]; |
n2 = (NODE)f2->arg[i]; |
n2 = (NODE)f2->arg[i]; |
for ( ; n1 && n2; n1 = NEXT(n1), n2 = NEXT(n2) ) { |
for ( ; n1 && n2; n1 = NEXT(n1), n2 = NEXT(n2) ) { |
t = compfnode(BDY(n1),BDY(n2)); |
t = compfnode(BDY(n1),BDY(n2)); |
if ( t ) return t; |
if ( t ) return t; |
} |
} |
if ( n1 ) return 1; |
if ( n1 ) return 1; |
else if ( n2 ) return -1; |
else if ( n2 ) return -1; |
break; |
break; |
case A_arf: |
case A_arf: |
t = strcmp(((ARF)f1->arg[i])->name,((ARF)f2->arg[i])->name); |
t = strcmp(((ARF)f1->arg[i])->name,((ARF)f2->arg[i])->name); |
if ( t ) return t; |
if ( t ) return t; |
break; |
break; |
case A_func: |
case A_func: |
t = strcmp(((FUNC)f1->arg[i])->name,((FUNC)f2->arg[i])->name); |
t = strcmp(((FUNC)f1->arg[i])->name,((FUNC)f2->arg[i])->name); |
if ( t ) return t; |
if ( t ) return t; |
break; |
break; |
case A_notimpl: |
case A_notimpl: |
default: |
default: |
error("compfnode : not implemented"); |
error("compfnode : not implemented"); |
break; |
break; |
} |
} |
} |
} |
return 0; |
return 0; |
} |
} |