| version 1.55, 2005/07/26 01:33:46 |
version 1.56, 2005/09/13 06:40:45 |
|
|
| * 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/strobj.c,v 1.54 2005/07/15 00:23:26 noro Exp $ |
* $OpenXM: OpenXM_contrib2/asir2000/builtin/strobj.c,v 1.55 2005/07/26 01:33:46 noro Exp $ |
| */ |
*/ |
| #include "ca.h" |
#include "ca.h" |
| #include "parse.h" |
#include "parse.h" |
| Line 88 void tb_to_string(TB tb,STRING *rp); |
|
| Line 88 void tb_to_string(TB tb,STRING *rp); |
|
| void fnodenodetotex_tb(NODE n,TB tb); |
void fnodenodetotex_tb(NODE n,TB tb); |
| void fargstotex_tb(char *opname,FNODE f,TB tb); |
void fargstotex_tb(char *opname,FNODE f,TB tb); |
| int top_is_minus(FNODE f); |
int top_is_minus(FNODE f); |
| NODE quote_unify(Obj f,Obj pat); |
int quote_unify(Obj f,Obj pat,NODE *rp); |
| |
|
| struct ftab str_tab[] = { |
struct ftab str_tab[] = { |
| {"sprintf",Psprintf,-99999999}, |
{"sprintf",Psprintf,-99999999}, |
| Line 510 void Pwrite_to_tb(NODE arg,Q *rp) |
|
| Line 510 void Pwrite_to_tb(NODE arg,Q *rp) |
|
| void Pquote_unify(NODE arg,LIST *rp) |
void Pquote_unify(NODE arg,LIST *rp) |
| { |
{ |
| NODE r; |
NODE r; |
| |
int ret; |
| |
|
| r = quote_unify((Obj)ARG0(arg),(Obj)ARG1(arg)); |
ret = quote_unify((Obj)ARG0(arg),(Obj)ARG1(arg),&r); |
| MKLIST(*rp,r); |
if ( ret ) |
| |
MKLIST(*rp,r); |
| |
else |
| |
*rp = 0; |
| } |
} |
| |
|
| |
void do_assign(NODE arg) |
| |
{ |
| |
NODE t,pair; |
| |
int pv; |
| |
|
| |
QUOTE value; |
| |
|
| |
for ( t = arg; t; t = NEXT(t) ) { |
| |
pair = BDY((LIST)BDY(t)); |
| |
pv = (int)FA0((FNODE)BDY((QUOTE)BDY(pair))); |
| |
value = (QUOTE)(BDY(NEXT(pair))); |
| |
ASSPV(pv,value); |
| |
} |
| |
} |
| |
|
| /* |
/* |
| /* consistency check and merge */ |
/* consistency check and merge |
| |
*/ |
| |
|
| NODE merge_matching_node(NODE n,NODE a) |
int merge_matching_node(NODE n,NODE a,NODE *rp) |
| { |
{ |
| NODE ta,ba,tn,bn; |
NODE ta,ba,tn,bn; |
| QUOTE pa,va,pn,vn; |
QUOTE pa,va,pn,vn; |
| |
|
| if ( !n ) |
if ( !n ) { |
| return a; |
*rp = a; |
| |
return 1; |
| |
} |
| for ( ta = a; ta; ta = NEXT(ta) ) { |
for ( ta = a; ta; ta = NEXT(ta) ) { |
| ba = BDY((LIST)BDY(ta)); |
ba = BDY((LIST)BDY(ta)); |
| if ( !ba ) continue; |
if ( !ba ) continue; |
| Line 543 NODE merge_matching_node(NODE n,NODE a) |
|
| Line 565 NODE merge_matching_node(NODE n,NODE a) |
|
| n = tn; |
n = tn; |
| } |
} |
| } |
} |
| return n; |
*rp = n; |
| |
return 1; |
| } |
} |
| |
|
| NODE quote_unify_node(NODE f,NODE pat) { |
int quote_unify_node(NODE f,NODE pat,NODE *rp) { |
| NODE r,a,tf,tp; |
NODE r,a,tf,tp,r1; |
| |
int ret; |
| |
|
| if ( length(f) != length(pat) ) return 0; |
if ( length(f) != length(pat) ) return 0; |
| r = 0; |
r = 0; |
| for ( tf = f, tp = pat; tf; tf = NEXT(tf), tp = NEXT(tp) ) { |
for ( tf = f, tp = pat; tf; tf = NEXT(tf), tp = NEXT(tp) ) { |
| a = quote_unify((Obj)BDY(tf),(Obj)BDY(tp)); |
ret = quote_unify((Obj)BDY(tf),(Obj)BDY(tp),&a); |
| if ( !a ) return 0; |
if ( !ret ) return 0; |
| r = merge_matching_node(r,a); |
ret = merge_matching_node(r,a,&r1); |
| if ( !r ) return 0; |
if ( !ret ) return 0; |
| |
else r = r1; |
| } |
} |
| return r; |
*rp = r; |
| |
return 1; |
| } |
} |
| |
|
| void get_quote_id_arg(QUOTE f,int *id,NODE *r) |
void get_quote_id_arg(QUOTE f,int *id,NODE *r) |
| Line 569 void get_quote_id_arg(QUOTE f,int *id,NODE *r) |
|
| Line 595 void get_quote_id_arg(QUOTE f,int *id,NODE *r) |
|
| *id = QTOS((Q)BDY(fab)); *r = NEXT(fab); |
*id = QTOS((Q)BDY(fab)); *r = NEXT(fab); |
| } |
} |
| |
|
| /* ret : [[quote(A),quote(1)],...] */ |
/* *rp : [[quote(A),quote(1)],...] */ |
| |
|
| NODE quote_unify(Obj f, Obj pat) |
int quote_unify(Obj f, Obj pat, NODE *rp) |
| { |
{ |
| NODE tf,tp,head,body; |
NODE tf,tp,head,body; |
| NODE parg,farg,r; |
NODE parg,farg,r; |
| LIST fa,l; |
LIST fa,l; |
| int pid,id; |
int pid,id; |
| FUNC ff,pf; |
FUNC ff,pf; |
| |
int ret; |
| |
|
| if ( OID(pat) == O_LIST ) { |
if ( OID(pat) == O_LIST ) { |
| if ( OID(f) == O_LIST ) |
if ( OID(f) == O_LIST ) |
| return quote_unify_node(BDY((LIST)f),BDY((LIST)pat)); |
return quote_unify_node(BDY((LIST)f),BDY((LIST)pat),rp); |
| else |
else |
| return 0; |
return 0; |
| } else if ( OID(pat) == O_QUOTE ) { |
} else if ( OID(pat) == O_QUOTE ) { |
| Line 593 NODE quote_unify(Obj f, Obj pat) |
|
| Line 620 NODE quote_unify(Obj f, Obj pat) |
|
| if ( compquote(CO,f,pat) ) |
if ( compquote(CO,f,pat) ) |
| return 0; |
return 0; |
| else { |
else { |
| MKLIST(l,0); |
*rp = 0; |
| return mknode(1,l); |
return 1; |
| } |
} |
| break; |
break; |
| case I_LIST: |
case I_LIST: |
| return quote_unify_node(BDY((LIST)BDY(farg)),BDY((LIST)BDY(parg))); |
return quote_unify_node(BDY((LIST)BDY(farg)), |
| |
BDY((LIST)BDY(parg)),rp); |
| case I_PVAR: |
case I_PVAR: |
| /* [[pat,f]] */ |
/* [[pat,f]] */ |
| r = mknode(2,pat,f); MKLIST(l,r); |
r = mknode(2,pat,f); MKLIST(l,r); |
| return mknode(1,l); |
*rp = mknode(1,l); |
| |
return 1; |
| case I_IFUNC: |
case I_IFUNC: |
| /* F(X,Y,...) = ... */ |
/* F(X,Y,...) = ... */ |
| if ( id == I_FUNC ) { |
if ( id == I_FUNC ) { |
| r = mknode(2,BDY(parg),BDY(farg)); MKLIST(l,r); |
r = mknode(2,BDY(parg),BDY(farg)); MKLIST(l,r); |
| head = mknode(1,l); |
head = mknode(1,l); |
| body = quote_unify(BDY(NEXT(farg)),BDY(NEXT(parg))); |
ret = quote_unify(BDY(NEXT(farg)), |
| if ( !body ) return 0; |
BDY(NEXT(parg)),&body); |
| return merge_matching_node(head,body); |
if ( !ret ) return 0; |
| |
else return merge_matching_node(head,body,rp); |
| } else |
} else |
| return 0; |
return 0; |
| case I_BOP: |
case I_BOP: |
| Line 618 NODE quote_unify(Obj f, Obj pat) |
|
| Line 648 NODE quote_unify(Obj f, Obj pat) |
|
| /* X+Y = ... */ |
/* X+Y = ... */ |
| /* f(...) = ... */ |
/* f(...) = ... */ |
| if ( compqa(CO,BDY(farg),BDY(parg)) ) return 0; |
if ( compqa(CO,BDY(farg),BDY(parg)) ) return 0; |
| return quote_unify_node(NEXT(farg),NEXT(parg)); |
return quote_unify_node(NEXT(farg),NEXT(parg),rp); |
| break; |
break; |
| default: |
default: |
| if ( pid == id ) |
if ( pid == id ) |
| return quote_unify_node(farg,parg); |
return quote_unify_node(farg,parg,rp); |
| else |
else |
| return 0; |
return 0; |
| } |
} |