version 1.2, 2000/08/21 08:31:46 |
version 1.8, 2018/03/29 01:32:54 |
|
|
* shall be made on your publication or presentation in any form of the |
* shall be made on your publication or presentation in any form of the |
* results obtained by use of the SOFTWARE. |
* results obtained by use of the SOFTWARE. |
* (4) In the event that you modify the SOFTWARE, you shall notify FLL by |
* (4) In the event that you modify the SOFTWARE, you shall notify FLL by |
* e-mail at risa-admin@flab.fujitsu.co.jp of the detailed specification |
* e-mail at risa-admin@sec.flab.fujitsu.co.jp of the detailed specification |
* for such modification or the source code of the modified part of the |
* for such modification or the source code of the modified part of the |
* SOFTWARE. |
* SOFTWARE. |
* |
* |
|
|
* 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/parse/compile.c,v 1.1.1.1 1999/12/03 07:39:12 noro Exp $ |
* $OpenXM: OpenXM_contrib2/asir2000/parse/compile.c,v 1.7 2015/08/14 13:51:56 fujimoto Exp $ |
*/ |
*/ |
#include <ctype.h> |
#include <ctype.h> |
#include "ca.h" |
#include "ca.h" |
Line 63 pointer bcompilef(), compilemapf(); |
|
Line 63 pointer bcompilef(), compilemapf(); |
|
pointer compile(f) |
pointer compile(f) |
FNODE f; |
FNODE f; |
{ |
{ |
LIST t; |
LIST t; |
STRING str; |
STRING str; |
pointer val = 0; |
pointer val = 0; |
pointer a,a1,a2; |
pointer a,a1,a2; |
NODE tn,ind; |
NODE tn,ind; |
R s,u; |
R s,u; |
DP dp; |
DP dp; |
int pv,c; |
int pv,c; |
FNODE f1; |
FNODE f1; |
Obj expired; |
Obj expired; |
int interval; |
int interval; |
|
|
if ( !f ) |
if ( !f ) |
return ( 0 ); |
return ( 0 ); |
switch ( f->id ) { |
switch ( f->id ) { |
case I_BOP: |
case I_BOP: |
a1 = compile((FNODE)FA1(f)); a2 = compile((FNODE)FA2(f)); |
a1 = compile((FNODE)FA1(f)); a2 = compile((FNODE)FA2(f)); |
val = emit_bop(((ARF)FA0(f)),a1,a2); |
val = emit_bop(((ARF)FA0(f)),a1,a2); |
break; |
break; |
case I_COP: |
case I_COP: |
a1 = compile((FNODE)FA1(f)); a2 = compile((FNODE)FA2(f)); |
a1 = compile((FNODE)FA1(f)); a2 = compile((FNODE)FA2(f)); |
val = emit_cop((cid)FA0(f),a1,a2); |
val = emit_cop((cid)FA0(f),a1,a2); |
break; |
break; |
case I_AND: |
case I_AND: |
a1 = compile((FNODE)FA0(f)); a2 = compile((FNODE)FA1(f)); |
a1 = compile((FNODE)FA0(f)); a2 = compile((FNODE)FA1(f)); |
val = emit_and(a1,a2); |
val = emit_and(a1,a2); |
break; |
break; |
case I_OR: |
case I_OR: |
a1 = compile((FNODE)FA0(f)); a2 = compile((FNODE)FA1(f)); |
a1 = compile((FNODE)FA0(f)); a2 = compile((FNODE)FA1(f)); |
val = emit_or(a1,a2); |
val = emit_or(a1,a2); |
break; |
break; |
case I_NOT: |
case I_NOT: |
a1 = compile((FNODE)FA0(f)); |
a1 = compile((FNODE)FA0(f)); |
val = emit_not(a1); |
val = emit_not(a1); |
break; |
break; |
case I_CE: |
case I_CE: |
a1 = compile((FNODE)FA0(f)); a2 = compile((FNODE)FA1(f)); |
a1 = compile((FNODE)FA0(f)); a2 = compile((FNODE)FA1(f)); |
a3 = compile((FNODE)FA0(f)); |
a3 = compile((FNODE)FA0(f)); |
emit_ce(a1,a2,a3); |
emit_ce(a1,a2,a3); |
break; |
break; |
case I_FUNC: |
case I_FUNC: |
val = compilef((FUNC)FA0(f),(FNODE)FA1(f)); break; |
val = compilef((FUNC)FA0(f),(FNODE)FA1(f)); break; |
case I_PVAR: |
case I_PVAR: |
pv = (int)FA0(f); ind = (NODE)FA1(f); GETPV(pv,a); |
pv = (int)FA0(f); ind = (NODE)FA1(f); GETPV(pv,a); |
if ( !ind ) |
if ( !ind ) |
val = a; |
val = a; |
else { |
else { |
compilenodebody(ind,&tn); getarray(a,tn,&val); |
compilenodebody(ind,&tn); getarray(a,tn,&val); |
} |
} |
break; |
break; |
case I_ASSPVAR: |
case I_ASSPVAR: |
f1 = (FNODE)FA0(f); |
f1 = (FNODE)FA0(f); |
if ( ID(f1) == I_PVAR ) { |
if ( ID(f1) == I_PVAR ) { |
pv = (int)FA0(f1); ind = (NODE)FA1(f1); |
pv = (int)FA0(f1); ind = (NODE)FA1(f1); |
if ( !ind ) { |
if ( !ind ) { |
val = compile((FNODE)FA1(f)); ASSPV(pv,val); |
val = compile((FNODE)FA1(f)); ASSPV(pv,val); |
} else { |
} else { |
GETPV(pv,a); |
GETPV(pv,a); |
compilenodebody(ind,&tn); |
compilenodebody(ind,&tn); |
putarray(a,tn,val = compile((FNODE)FA1(f))); |
putarray(a,tn,val = compile((FNODE)FA1(f))); |
} |
} |
} else |
} else |
val = compilepv(ID(f),(FNODE)FA0(f),FA1(f)); |
val = compilepv(ID(f),(FNODE)FA0(f),FA1(f)); |
break; |
break; |
case I_PRESELF: |
case I_PRESELF: |
f1 = (FNODE)FA1(f); |
f1 = (FNODE)FA1(f); |
if ( ID(f1) == I_PVAR ) { |
if ( ID(f1) == I_PVAR ) { |
pv = (int)FA0(f1); ind = (NODE)FA1(f1); GETPV(pv,a); |
pv = (int)FA0(f1); ind = (NODE)FA1(f1); GETPV(pv,a); |
if ( !ind ) { |
if ( !ind ) { |
(*((ARF)FA0(f))->fp)(CO,a,ONE,&val); ASSPV(pv,val); |
(*((ARF)FA0(f))->fp)(CO,a,ONE,&val); ASSPV(pv,val); |
} else if ( a ) { |
} else if ( a ) { |
compilenodebody(ind,&tn); getarray(a,tn,(pointer *)&u); |
compilenodebody(ind,&tn); getarray(a,tn,(pointer *)&u); |
(*((ARF)FA0(f))->fp)(CO,u,ONE,&val); putarray(a,tn,val); |
(*((ARF)FA0(f))->fp)(CO,u,ONE,&val); putarray(a,tn,val); |
} |
} |
} else |
} else |
val = compilepv(f->id,(FNODE)FA1(f),FA0(f)); |
val = compilepv(f->id,(FNODE)FA1(f),FA0(f)); |
break; |
break; |
case I_POSTSELF: |
case I_POSTSELF: |
f1 = (FNODE)FA1(f); |
f1 = (FNODE)FA1(f); |
if ( ID(f1) == I_PVAR ) { |
if ( ID(f1) == I_PVAR ) { |
pv = (int)FA0(f1); ind = (NODE)FA1(f1); GETPV(pv,val); |
pv = (int)FA0(f1); ind = (NODE)FA1(f1); GETPV(pv,val); |
if ( !ind ) { |
if ( !ind ) { |
(*((ARF)FA0(f))->fp)(CO,val,ONE,&u); ASSPV(pv,u); |
(*((ARF)FA0(f))->fp)(CO,val,ONE,&u); ASSPV(pv,u); |
} else if ( val ) { |
} else if ( val ) { |
compilenodebody(ind,&tn); getarray(val,tn,&a); |
compilenodebody(ind,&tn); getarray(val,tn,&a); |
(*((ARF)FA0(f))->fp)(CO,a,ONE,&u); putarray(val,tn,(pointer)u); |
(*((ARF)FA0(f))->fp)(CO,a,ONE,&u); putarray(val,tn,(pointer)u); |
val = a; |
val = a; |
} |
} |
} else |
} else |
val = compilepv(f->id,(FNODE)FA1(f),FA0(f)); |
val = compilepv(f->id,(FNODE)FA1(f),FA0(f)); |
break; |
break; |
case I_STR: |
case I_STR: |
MKSTR(str,FA0(f)); val = (pointer)str; break; |
MKSTR(str,FA0(f)); val = (pointer)str; break; |
case I_FORMULA: |
case I_FORMULA: |
val = FA0(f); break; |
val = FA0(f); break; |
case I_LIST: |
case I_LIST: |
compilenodebody((NODE)FA0(f),&tn); MKLIST(t,tn); val = (pointer)t; break; |
compilenodebody((NODE)FA0(f),&tn); MKLIST(t,tn); val = (pointer)t; break; |
case I_INDEX: |
case I_INDEX: |
a = compile((FNODE)FA0(f)); ind = (NODE)FA1(f); |
a = compile((FNODE)FA0(f)); ind = (NODE)FA1(f); |
compilenodebody(ind,&tn); getarray(a,tn,&val); |
compilenodebody(ind,&tn); getarray(a,tn,&val); |
break; |
break; |
default: |
default: |
fprintf(stderr,"compile: unknown id"); |
fprintf(stderr,"compile: unknown id"); |
error(""); |
error(""); |
break; |
break; |
} |
} |
return ( val ); |
return ( val ); |
} |
} |
|
|
pointer compilestat(f) |
pointer compilestat(f) |
SNODE f; |
SNODE f; |
{ |
{ |
pointer val = 0,t,s,s1,u; |
pointer val = 0,t,s,s1,u; |
NODE tn; |
NODE tn; |
int i,ac; |
int i,ac; |
V *a; |
V *a; |
char *buf; |
char *buf; |
|
|
if ( !f ) |
if ( !f ) |
return ( 0 ); |
return ( 0 ); |
if ( nextbp && nextbplevel <= 0 && f->id != S_CPLX ) { |
if ( nextbp && nextbplevel <= 0 && f->id != S_CPLX ) { |
nextbp = 0; |
nextbp = 0; |
bp(f); |
bp(f); |
} |
} |
compilestatline = f->ln; |
compilestatline = f->ln; |
|
|
switch ( f->id ) { |
switch ( f->id ) { |
case S_BP: |
case S_BP: |
if ( !nextbp && (!FA1(f) || compile((FNODE)FA1(f))) ) { |
if ( !nextbp && (!FA1(f) || compile((FNODE)FA1(f))) ) { |
if ( (FNODE)FA2(f) ) { |
if ( (FNODE)FA2(f) ) { |
#if PARI |
#if defined(PARI) |
extern FILE *outfile; |
extern FILE *outfile; |
outfile = stderr; |
outfile = stderr; |
#endif |
#endif |
asir_out = stderr; |
asir_out = stderr; |
printexpr(CO,compile((FNODE)FA2(f))); |
printexpr(CO,compile((FNODE)FA2(f))); |
putc('\n',asir_out); fflush(asir_out); |
putc('\n',asir_out); fflush(asir_out); |
#if PARI |
#if defined(PARI) |
outfile = stdout; |
outfile = stdout; |
#endif |
#endif |
asir_out = stdout; |
asir_out = stdout; |
} else { |
} else { |
nextbp = 1; nextbplevel = 0; |
nextbp = 1; nextbplevel = 0; |
} |
} |
} |
} |
val = compilestat((SNODE)FA0(f)); |
val = compilestat((SNODE)FA0(f)); |
break; |
break; |
case S_PFDEF: |
case S_PFDEF: |
ac = argc(FA1(f)); a = (V *)MALLOC(ac*sizeof(V)); |
ac = argc(FA1(f)); a = (V *)MALLOC(ac*sizeof(V)); |
s = compile((FNODE)FA2(f)); |
s = compile((FNODE)FA2(f)); |
buf = (char *)ALLOCA(BUFSIZ); |
buf = (char *)ALLOCA(BUFSIZ); |
for ( i = 0, tn = (NODE)FA1(f); tn; tn = NEXT(tn), i++ ) { |
for ( i = 0, tn = (NODE)FA1(f); tn; tn = NEXT(tn), i++ ) { |
t = compile((FNODE)tn->body); sprintf(buf,"_%s",NAME(VR((P)t))); |
t = compile((FNODE)tn->body); sprintf(buf,"_%s",NAME(VR((P)t))); |
makevar(buf,&u); a[i] = VR((P)u); |
makevar(buf,&u); a[i] = VR((P)u); |
substr(CO,0,(Obj)s,VR((P)t),(Obj)u,(Obj *)&s1); s = s1; |
substr(CO,0,(Obj)s,VR((P)t),(Obj)u,(Obj *)&s1); s = s1; |
} |
} |
mkpf((char *)FA0(f),(Obj)s,ac,a,0,0,(PF *)&val); val = 0; break; |
mkpf((char *)FA0(f),(Obj)s,ac,a,0,0,(PF *)&val); val = 0; break; |
case S_SINGLE: |
case S_SINGLE: |
val = compile((FNODE)FA0(f)); break; |
val = compile((FNODE)FA0(f)); break; |
case S_CPLX: |
case S_CPLX: |
for ( tn = (NODE)FA0(f); tn; tn = NEXT(tn) ) { |
for ( tn = (NODE)FA0(f); tn; tn = NEXT(tn) ) { |
if ( BDY(tn) ) |
if ( BDY(tn) ) |
val = compilestat((SNODE)BDY(tn)); |
val = compilestat((SNODE)BDY(tn)); |
if ( f_break || f_return || f_continue ) |
if ( f_break || f_return || f_continue ) |
break; |
break; |
} |
} |
break; |
break; |
case S_BREAK: |
case S_BREAK: |
if ( GPVS != CPVS ) |
if ( GPVS != CPVS ) |
f_break = 1; |
f_break = 1; |
break; |
break; |
case S_CONTINUE: |
case S_CONTINUE: |
if ( GPVS != CPVS ) |
if ( GPVS != CPVS ) |
f_continue = 1; |
f_continue = 1; |
break; |
break; |
case S_RETURN: |
case S_RETURN: |
if ( GPVS != CPVS ) { |
if ( GPVS != CPVS ) { |
val = compile((FNODE)FA0(f)); f_return = 1; |
val = compile((FNODE)FA0(f)); f_return = 1; |
} |
} |
break; |
break; |
case S_IFELSE: |
case S_IFELSE: |
if ( compilenode((NODE)FA1(f)) ) |
if ( compilenode((NODE)FA1(f)) ) |
val = compilestat((SNODE)FA2(f)); |
val = compilestat((SNODE)FA2(f)); |
else if ( FA3(f) ) |
else if ( FA3(f) ) |
val = compilestat((SNODE)FA3(f)); |
val = compilestat((SNODE)FA3(f)); |
break; |
break; |
case S_FOR: |
case S_FOR: |
compilenode((NODE)FA1(f)); |
compilenode((NODE)FA1(f)); |
while ( 1 ) { |
while ( 1 ) { |
if ( !compilenode((NODE)FA2(f)) ) |
if ( !compilenode((NODE)FA2(f)) ) |
break; |
break; |
val = compilestat((SNODE)FA4(f)); |
val = compilestat((SNODE)FA4(f)); |
if ( f_break || f_return ) |
if ( f_break || f_return ) |
break; |
break; |
f_continue = 0; |
f_continue = 0; |
compilenode((NODE)FA3(f)); |
compilenode((NODE)FA3(f)); |
} |
} |
f_break = 0; break; |
f_break = 0; break; |
case S_DO: |
case S_DO: |
while ( 1 ) { |
while ( 1 ) { |
val = compilestat((SNODE)FA1(f)); |
val = compilestat((SNODE)FA1(f)); |
if ( f_break || f_return ) |
if ( f_break || f_return ) |
break; |
break; |
f_continue = 0; |
f_continue = 0; |
if ( !compilenode((NODE)FA2(f)) ) |
if ( !compilenode((NODE)FA2(f)) ) |
break; |
break; |
} |
} |
f_break = 0; break; |
f_break = 0; break; |
default: |
default: |
fprintf(stderr,"compilestat: unknown id"); |
fprintf(stderr,"compilestat: unknown id"); |
error(""); |
error(""); |
break; |
break; |
} |
} |
return ( val ); |
return ( val ); |
} |
} |
|
|
pointer compilenode(node) |
pointer compilenode(node) |
NODE node; |
NODE node; |
{ |
{ |
NODE tn; |
NODE tn; |
pointer val; |
pointer val; |
|
|
for ( tn = node, val = 0; tn; tn = NEXT(tn) ) |
for ( tn = node, val = 0; tn; tn = NEXT(tn) ) |
if ( BDY(tn) ) |
if ( BDY(tn) ) |
val = compile((FNODE)BDY(tn)); |
val = compile((FNODE)BDY(tn)); |
return ( val ); |
return ( val ); |
} |
} |
|
|
extern FUNC cur_binf; |
extern FUNC cur_binf; |
Line 298 pointer compilef(f,a) |
|
Line 298 pointer compilef(f,a) |
|
FUNC f; |
FUNC f; |
FNODE a; |
FNODE a; |
{ |
{ |
LIST args; |
LIST args; |
pointer val; |
pointer val; |
int i,n,level; |
int i,n,level; |
NODE tn,sn; |
NODE tn,sn; |
VS pvs; |
VS pvs; |
|
|
if ( f->id == A_UNDEF ) { |
if ( f->id == A_UNDEF ) { |
fprintf(stderr,"%s undefined",NAME(f)); |
fprintf(stderr,"%s undefined",NAME(f)); |
error(""); |
error(""); |
} |
} |
if ( f->id != A_PARI ) { |
if ( f->id != A_PARI ) { |
for ( i = 0, tn = a?(NODE)FA0(a):0; tn; i++, tn = NEXT(tn) ); |
for ( i = 0, tn = a?(NODE)FA0(a):0; tn; i++, tn = NEXT(tn) ); |
if ( ((n = f->argc)>= 0 && i != n) || (n < 0 && i > -n) ) { |
if ( ((n = f->argc)>= 0 && i != n) || (n < 0 && i > -n) ) { |
fprintf(stderr,"argument mismatch in %s()",NAME(f)); |
fprintf(stderr,"argument mismatch in %s()",NAME(f)); |
error(""); |
error(""); |
} |
} |
} |
} |
switch ( f->id ) { |
switch ( f->id ) { |
case A_BIN: |
case A_BIN: |
if ( !n ) { |
if ( !n ) { |
cur_binf = f; |
cur_binf = f; |
(*f->f.binf)(&val); |
(*f->f.binf)(&val); |
} else { |
} else { |
args = (LIST)compile(a); |
args = (LIST)compile(a); |
cur_binf = f; |
cur_binf = f; |
(*f->f.binf)(args?BDY(args):0,&val); |
(*f->f.binf)(args?BDY(args):0,&val); |
} |
} |
cur_binf = 0; |
cur_binf = 0; |
break; |
break; |
case A_PARI: |
case A_PARI: |
args = (LIST)compile(a); |
args = (LIST)compile(a); |
cur_binf = f; |
cur_binf = f; |
val = compileparif(f,args?BDY(args):0); |
val = compileparif(f,args?BDY(args):0); |
cur_binf = 0; |
cur_binf = 0; |
break; |
break; |
case A_USR: |
case A_USR: |
args = (LIST)compile(a); |
args = (LIST)compile(a); |
pvs = f->f.usrf->pvs; |
pvs = f->f.usrf->pvs; |
if ( PVSS ) { |
if ( PVSS ) { |
((VS)BDY(PVSS))->at = compilestatline; |
((VS)BDY(PVSS))->at = compilestatline; |
level = ((VS)BDY(PVSS))->level+1; |
level = ((VS)BDY(PVSS))->level+1; |
} else |
} else |
level = 1; |
level = 1; |
MKNODE(tn,pvs,PVSS); PVSS = tn; |
MKNODE(tn,pvs,PVSS); PVSS = tn; |
CPVS = (VS)ALLOCA(sizeof(struct oVS)); BDY(PVSS) = (pointer)CPVS; |
CPVS = (VS)ALLOCA(sizeof(struct oVS)); BDY(PVSS) = (pointer)CPVS; |
CPVS->usrf = f; CPVS->n = CPVS->asize = pvs->n; |
CPVS->usrf = f; CPVS->n = CPVS->asize = pvs->n; |
CPVS->level = level; |
CPVS->level = level; |
if ( CPVS->n ) { |
if ( CPVS->n ) { |
CPVS->va = (struct oPV *)ALLOCA(CPVS->n*sizeof(struct oPV)); |
CPVS->va = (struct oPV *)ALLOCA(CPVS->n*sizeof(struct oPV)); |
bcopy((char *)pvs->va,(char *)CPVS->va, |
bcopy((char *)pvs->va,(char *)CPVS->va, |
(int)(pvs->n*sizeof(struct oPV))); |
(int)(pvs->n*sizeof(struct oPV))); |
} |
} |
if ( nextbp ) |
if ( nextbp ) |
nextbplevel++; |
nextbplevel++; |
for ( tn = f->f.usrf->args, sn = BDY(args); |
for ( tn = f->f.usrf->args, sn = BDY(args); |
sn; tn = NEXT(tn), sn = NEXT(sn) ) |
sn; tn = NEXT(tn), sn = NEXT(sn) ) |
ASSPV((int)FA0((FNODE)BDY(tn)),BDY(sn)); |
ASSPV((int)FA0((FNODE)BDY(tn)),BDY(sn)); |
val = compilestat((SNODE)BDY(f->f.usrf)); |
val = compilestat((SNODE)BDY(f->f.usrf)); |
f_return = f_break = f_continue = 0; poppvs(); |
f_return = f_break = f_continue = 0; poppvs(); |
break; |
break; |
case A_PURE: |
case A_PURE: |
val = compilepf(f->f.puref,a); break; |
val = compilepf(f->f.puref,a); break; |
default: |
default: |
fprintf(stderr,"%s undefined",NAME(f)); |
fprintf(stderr,"%s undefined",NAME(f)); |
error(""); |
error(""); |
break; |
break; |
} |
} |
return val; |
return val; |
} |
} |
|
|
pointer compilemapf(f,a) |
pointer compilemapf(f,a) |
FUNC f; |
FUNC f; |
FNODE a; |
FNODE a; |
{ |
{ |
LIST args; |
LIST args; |
NODE node,rest,t,n,l,r,r0; |
NODE node,rest,t,n,l,r,r0; |
Obj head; |
Obj head; |
VECT v,rv; |
VECT v,rv; |
MAT m,rm; |
MAT m,rm; |
LIST rl; |
LIST rl; |
int len,row,col,i,j; |
int len,row,col,i,j; |
pointer val; |
pointer val; |
|
|
args = (LIST)compile(a); |
args = (LIST)compile(a); |
node = BDY(args); head = (Obj)BDY(node); rest = NEXT(node); |
node = BDY(args); head = (Obj)BDY(node); rest = NEXT(node); |
switch ( OID(head) ) { |
switch ( OID(head) ) { |
case O_VECT: |
case O_VECT: |
v = (VECT)head; len = v->len; MKVECT(rv,len); |
v = (VECT)head; len = v->len; MKVECT(rv,len); |
for ( i = 0; i < len; i++ ) { |
for ( i = 0; i < len; i++ ) { |
MKNODE(t,BDY(v)[i],rest); BDY(rv)[i] = bcompilef(f,t); |
MKNODE(t,BDY(v)[i],rest); BDY(rv)[i] = bcompilef(f,t); |
} |
} |
val = (pointer)rv; |
val = (pointer)rv; |
break; |
break; |
case O_MAT: |
case O_MAT: |
m = (MAT)head; row = m->row; col = m->col; MKMAT(rm,row,col); |
m = (MAT)head; row = m->row; col = m->col; MKMAT(rm,row,col); |
for ( i = 0; i < row; i++ ) |
for ( i = 0; i < row; i++ ) |
for ( j = 0; j < col; j++ ) { |
for ( j = 0; j < col; j++ ) { |
MKNODE(t,BDY(m)[i][j],rest); BDY(rm)[i][j] = bcompilef(f,t); |
MKNODE(t,BDY(m)[i][j],rest); BDY(rm)[i][j] = bcompilef(f,t); |
} |
} |
val = (pointer)rm; |
val = (pointer)rm; |
break; |
break; |
case O_LIST: |
case O_LIST: |
n = BDY((LIST)head); |
n = BDY((LIST)head); |
for ( r0 = r = 0; n; n = NEXT(n) ) { |
for ( r0 = r = 0; n; n = NEXT(n) ) { |
NEXTNODE(r0,r); MKNODE(t,BDY(n),rest); BDY(r) = bcompilef(f,t); |
NEXTNODE(r0,r); MKNODE(t,BDY(n),rest); BDY(r) = bcompilef(f,t); |
} |
} |
if ( r0 ) |
if ( r0 ) |
NEXT(r) = 0; |
NEXT(r) = 0; |
MKLIST(rl,r0); |
MKLIST(rl,r0); |
val = (pointer)rl; |
val = (pointer)rl; |
break; |
break; |
default: |
default: |
val = bcompilef(f,node); |
val = bcompilef(f,node); |
break; |
break; |
} |
} |
return val; |
return val; |
} |
} |
|
|
pointer bcompilef(f,a) |
pointer bcompilef(f,a) |
FUNC f; |
FUNC f; |
NODE a; |
NODE a; |
{ |
{ |
LIST args; |
LIST args; |
pointer val; |
pointer val; |
int i,n; |
int i,n; |
NODE tn,sn; |
NODE tn,sn; |
VS pvs; |
VS pvs; |
|
|
if ( f->id == A_UNDEF ) { |
if ( f->id == A_UNDEF ) { |
fprintf(stderr,"%s undefined",NAME(f)); |
fprintf(stderr,"%s undefined",NAME(f)); |
error(""); |
error(""); |
} |
} |
if ( f->id != A_PARI ) { |
if ( f->id != A_PARI ) { |
for ( i = 0, tn = a; tn; i++, tn = NEXT(tn) ); |
for ( i = 0, tn = a; tn; i++, tn = NEXT(tn) ); |
if ( ((n = f->argc)>= 0 && i != n) || (n < 0 && i > -n) ) { |
if ( ((n = f->argc)>= 0 && i != n) || (n < 0 && i > -n) ) { |
fprintf(stderr,"argument mismatch in %s()",NAME(f)); |
fprintf(stderr,"argument mismatch in %s()",NAME(f)); |
error(""); |
error(""); |
} |
} |
} |
} |
switch ( f->id ) { |
switch ( f->id ) { |
case A_BIN: |
case A_BIN: |
if ( !n ) { |
if ( !n ) { |
cur_binf = f; |
cur_binf = f; |
(*f->f.binf)(&val); |
(*f->f.binf)(&val); |
} else { |
} else { |
cur_binf = f; |
cur_binf = f; |
(*f->f.binf)(a,&val); |
(*f->f.binf)(a,&val); |
} |
} |
cur_binf = 0; |
cur_binf = 0; |
break; |
break; |
case A_PARI: |
case A_PARI: |
cur_binf = f; |
cur_binf = f; |
val = compileparif(f,a); |
val = compileparif(f,a); |
cur_binf = 0; |
cur_binf = 0; |
break; |
break; |
case A_USR: |
case A_USR: |
pvs = f->f.usrf->pvs; |
pvs = f->f.usrf->pvs; |
if ( PVSS ) |
if ( PVSS ) |
((VS)BDY(PVSS))->at = compilestatline; |
((VS)BDY(PVSS))->at = compilestatline; |
MKNODE(tn,pvs,PVSS); PVSS = tn; |
MKNODE(tn,pvs,PVSS); PVSS = tn; |
CPVS = (VS)ALLOCA(sizeof(struct oVS)); BDY(PVSS) = (pointer)CPVS; |
CPVS = (VS)ALLOCA(sizeof(struct oVS)); BDY(PVSS) = (pointer)CPVS; |
CPVS->usrf = f; CPVS->n = CPVS->asize = pvs->n; |
CPVS->usrf = f; CPVS->n = CPVS->asize = pvs->n; |
if ( CPVS->n ) { |
if ( CPVS->n ) { |
CPVS->va = (struct oPV *)ALLOCA(CPVS->n*sizeof(struct oPV)); |
CPVS->va = (struct oPV *)ALLOCA(CPVS->n*sizeof(struct oPV)); |
bcopy((char *)pvs->va,(char *)CPVS->va, |
bcopy((char *)pvs->va,(char *)CPVS->va, |
(int)(pvs->n*sizeof(struct oPV))); |
(int)(pvs->n*sizeof(struct oPV))); |
} |
} |
if ( nextbp ) |
if ( nextbp ) |
nextbplevel++; |
nextbplevel++; |
for ( tn = f->f.usrf->args, sn = a; |
for ( tn = f->f.usrf->args, sn = a; |
sn; tn = NEXT(tn), sn = NEXT(sn) ) |
sn; tn = NEXT(tn), sn = NEXT(sn) ) |
ASSPV((int)FA0((FNODE)BDY(tn)),BDY(sn)); |
ASSPV((int)FA0((FNODE)BDY(tn)),BDY(sn)); |
val = compilestat((SNODE)BDY(f->f.usrf)); |
val = compilestat((SNODE)BDY(f->f.usrf)); |
f_return = f_break = f_continue = 0; poppvs(); |
f_return = f_break = f_continue = 0; poppvs(); |
break; |
break; |
default: |
default: |
fprintf(stderr,"%s undefined",NAME(f)); |
fprintf(stderr,"%s undefined",NAME(f)); |
error(""); |
error(""); |
break; |
break; |
} |
} |
return val; |
return val; |
} |
} |
|
|
pointer compileif(f,a) |
pointer compileif(f,a) |
FNODE f,a; |
FNODE f,a; |
{ |
{ |
Obj g; |
Obj g; |
|
|
g = (Obj)compile(f); |
g = (Obj)compile(f); |
if ( g && (OID(g) == O_P) && (VR((P)g)->attr == (pointer)V_SR) ) |
if ( g && (OID(g) == O_P) && (VR((P)g)->attr == (pointer)V_SR) ) |
return compilef((FUNC)VR((P)g)->priv,a); |
return compilef((FUNC)VR((P)g)->priv,a); |
else { |
else { |
fprintf(stderr,"invalid function pointer"); |
fprintf(stderr,"invalid function pointer"); |
error(""); |
error(""); |
} |
} |
} |
} |
|
|
pointer compilepf(pf,a) |
pointer compilepf(pf,a) |
PF pf; |
PF pf; |
FNODE a; |
FNODE a; |
{ |
{ |
LIST args; |
LIST args; |
pointer val; |
pointer val; |
Obj s,s1; |
Obj s,s1; |
int i; |
int i; |
NODE node; |
NODE node; |
PFINS ins; |
PFINS ins; |
PFAD ad; |
PFAD ad; |
|
|
for ( i = 0, node = a?(NODE)FA0(a):0; node; i++, node = NEXT(node) ); |
for ( i = 0, node = a?(NODE)FA0(a):0; node; i++, node = NEXT(node) ); |
if ( pf->argc != i ) { |
if ( pf->argc != i ) { |
fprintf(stderr,"argument mismatch in %s()",NAME(pf)); |
fprintf(stderr,"argument mismatch in %s()",NAME(pf)); |
error(""); |
error(""); |
} |
} |
args = (LIST)compile(a); |
args = (LIST)compile(a); |
if ( !pf->body ) { |
if ( !pf->body ) { |
ins = (PFINS)CALLOC(1,sizeof(PF)+pf->argc*sizeof(struct oPFAD)); |
ins = (PFINS)CALLOC(1,sizeof(PF)+pf->argc*sizeof(struct oPFAD)); |
ins->pf = pf; |
ins->pf = pf; |
for ( i = 0, node = args->body, ad = ins->ad; |
for ( i = 0, node = args->body, ad = ins->ad; |
node; node = NEXT(node), i++ ) { |
node; node = NEXT(node), i++ ) { |
ad[i].d = 0; ad[i].arg = (Obj)node->body; |
ad[i].d = 0; ad[i].arg = (Obj)node->body; |
} |
} |
simplify_ins(ins,&s); return (pointer)s; |
simplify_ins(ins,&s); return (pointer)s; |
} else { |
} else { |
for ( i = 0, s = pf->body, node = args->body; |
for ( i = 0, s = pf->body, node = args->body; |
node; node = NEXT(node), i++ ) { |
node; node = NEXT(node), i++ ) { |
substr(CO,0,s,pf->args[i],(Obj)node->body,&s1); s = s1; |
substr(CO,0,s,pf->args[i],(Obj)node->body,&s1); s = s1; |
} |
} |
return (pointer)s; |
return (pointer)s; |
} |
} |
} |
} |
|
|
void compilenodebody(sn,dnp) |
void compilenodebody(sn,dnp) |
NODE sn; |
NODE sn; |
NODE *dnp; |
NODE *dnp; |
{ |
{ |
NODE n,n0,tn; |
NODE n,n0,tn; |
int line; |
int line; |
|
|
if ( !sn ) { |
if ( !sn ) { |
*dnp = 0; |
*dnp = 0; |
return; |
return; |
} |
} |
line = compilestatline; |
line = compilestatline; |
for ( tn = sn, n0 = 0; tn; tn = NEXT(tn) ) { |
for ( tn = sn, n0 = 0; tn; tn = NEXT(tn) ) { |
NEXTNODE(n0,n); |
NEXTNODE(n0,n); |
BDY(n) = compile((FNODE)BDY(tn)); |
BDY(n) = compile((FNODE)BDY(tn)); |
compilestatline = line; |
compilestatline = line; |
} |
} |
NEXT(n) = 0; *dnp = n0; |
NEXT(n) = 0; *dnp = n0; |
} |
} |
|
|
void searchf(fn,name,r) |
void searchf(fn,name,r) |
|
|
char *name; |
char *name; |
FUNC *r; |
FUNC *r; |
{ |
{ |
NODE tn; |
NODE tn; |
|
|
for ( tn = fn; |
for ( tn = fn; |
tn && strcmp(NAME((FUNC)BDY(tn)),name); tn = NEXT(tn) ); |
tn && strcmp(NAME((FUNC)BDY(tn)),name); tn = NEXT(tn) ); |
if ( tn ) { |
if ( tn ) { |
*r = (FUNC)BDY(tn); |
*r = (FUNC)BDY(tn); |
return; |
return; |
} |
} |
*r = 0; |
*r = 0; |
} |
} |
|
|
void appenduf(name,r) |
void appenduf(name,r) |
char *name; |
char *name; |
FUNC *r; |
FUNC *r; |
{ |
{ |
NODE tn; |
NODE tn; |
FUNC f; |
FUNC f; |
|
|
f=(FUNC)MALLOC(sizeof(struct oFUNC)); |
f=(FUNC)MALLOC(sizeof(struct oFUNC)); |
f->name = name; f->id = A_UNDEF; f->argc = 0; f->f.binf = 0; |
f->name = name; f->id = A_UNDEF; f->argc = 0; f->f.binf = 0; |
MKNODE(tn,f,usrf); usrf = tn; |
MKNODE(tn,f,usrf); usrf = tn; |
*r = f; |
*r = f; |
} |
} |
|
|
void mkparif(name,r) |
void mkparif(name,r) |
char *name; |
char *name; |
FUNC *r; |
FUNC *r; |
{ |
{ |
NODE tn; |
NODE tn; |
FUNC f; |
FUNC f; |
|
|
*r = f =(FUNC)MALLOC(sizeof(struct oFUNC)); |
*r = f =(FUNC)MALLOC(sizeof(struct oFUNC)); |
f->name = name; f->id = A_PARI; f->argc = 0; f->f.binf = 0; |
f->name = name; f->id = A_PARI; f->argc = 0; f->f.binf = 0; |
} |
} |
|
|
void mkuf(name,fname,args,body,startl,endl,desc) |
void mkuf(name,fname,args,body,startl,endl,desc,module) |
char *name,*fname; |
char *name,*fname; |
NODE args; |
NODE args; |
SNODE body; |
SNODE body; |
int startl,endl; |
int startl,endl; |
char *desc; |
char *desc; |
|
MODULE module; |
{ |
{ |
FUNC f; |
FUNC f; |
USRF t; |
USRF t; |
NODE sn,tn; |
NODE sn,tn; |
FNODE fn; |
FNODE fn; |
int argc; |
int argc; |
|
|
searchf(sysf,name,&f); |
searchf(sysf,name,&f); |
if ( f ) { |
if ( f ) { |
fprintf(stderr,"def : builtin function %s() cannot be redefined.\n",name); |
fprintf(stderr,"def : builtin function %s() cannot be redefined.\n",name); |
CPVS = GPVS; return; |
CPVS = GPVS; return; |
} |
} |
for ( argc = 0, sn = args; sn; argc++, sn = NEXT(sn) ) { |
for ( argc = 0, sn = args; sn; argc++, sn = NEXT(sn) ) { |
fn = (FNODE)BDY(sn); |
fn = (FNODE)BDY(sn); |
if ( !fn || ID(fn) != I_PVAR ) { |
if ( !fn || ID(fn) != I_PVAR ) { |
fprintf(stderr,"illegal argument in %s()\n",name); |
fprintf(stderr,"illegal argument in %s()\n",name); |
CPVS = GPVS; return; |
CPVS = GPVS; return; |
} |
} |
} |
} |
for ( sn = usrf; sn && strcmp(NAME((FUNC)BDY(sn)),name); sn = NEXT(sn) ); |
for ( sn = usrf; sn && strcmp(NAME((FUNC)BDY(sn)),name); sn = NEXT(sn) ); |
if ( sn ) |
if ( sn ) |
f = (FUNC)BDY(sn); |
f = (FUNC)BDY(sn); |
else { |
else { |
f=(FUNC)MALLOC(sizeof(struct oFUNC)); |
f=(FUNC)MALLOC(sizeof(struct oFUNC)); |
f->name = name; |
f->name = name; |
MKNODE(tn,f,usrf); usrf = tn; |
MKNODE(tn,f,usrf); usrf = tn; |
} |
} |
if ( Verbose && f->id != A_UNDEF ) |
if ( Verbose && f->id != A_UNDEF ) |
fprintf(stderr,"Warning : %s() redefined.\n",name); |
fprintf(stderr,"Warning : %s() redefined.\n",name); |
/* else |
/* else |
fprintf(stderr,"%s() defined.\n",name); */ |
fprintf(stderr,"%s() defined.\n",name); */ |
t=(USRF)MALLOC(sizeof(struct oUSRF)); |
t=(USRF)MALLOC(sizeof(struct oUSRF)); |
t->args=args; BDY(t)=body; t->pvs = CPVS; t->fname = fname; |
t->args=args; BDY(t)=body; t->pvs = CPVS; t->fname = fname; |
t->startl = startl; t->endl = endl; t->vol = asir_infile->vol; |
t->startl = startl; t->endl = endl; |
t->desc = desc; |
t->desc = desc; t->module = module; |
f->id = A_USR; f->argc = argc; f->f.usrf = t; |
f->id = A_USR; f->argc = argc; f->f.usrf = t; |
CPVS = GPVS; |
CPVS = GPVS; |
clearbp(f); |
clearbp(f); |
} |
} |