Annotation of OpenXM_contrib2/asir2000/builtin/print.c, Revision 1.12
1.2 noro 1: /*
2: * Copyright (c) 1994-2000 FUJITSU LABORATORIES LIMITED
3: * All rights reserved.
4: *
5: * FUJITSU LABORATORIES LIMITED ("FLL") hereby grants you a limited,
6: * non-exclusive and royalty-free license to use, copy, modify and
7: * redistribute, solely for non-commercial and non-profit purposes, the
8: * computer program, "Risa/Asir" ("SOFTWARE"), subject to the terms and
9: * conditions of this Agreement. For the avoidance of doubt, you acquire
10: * only a limited right to use the SOFTWARE hereunder, and FLL or any
11: * third party developer retains all rights, including but not limited to
12: * copyrights, in and to the SOFTWARE.
13: *
14: * (1) FLL does not grant you a license in any way for commercial
15: * purposes. You may use the SOFTWARE only for non-commercial and
16: * non-profit purposes only, such as academic, research and internal
17: * business use.
18: * (2) The SOFTWARE is protected by the Copyright Law of Japan and
19: * international copyright treaties. If you make copies of the SOFTWARE,
20: * with or without modification, as permitted hereunder, you shall affix
21: * to all such copies of the SOFTWARE the above copyright notice.
22: * (3) An explicit reference to this SOFTWARE and its copyright owner
23: * shall be made on your publication or presentation in any form of the
24: * results obtained by use of the SOFTWARE.
25: * (4) In the event that you modify the SOFTWARE, you shall notify FLL by
1.3 noro 26: * e-mail at risa-admin@sec.flab.fujitsu.co.jp of the detailed specification
1.2 noro 27: * for such modification or the source code of the modified part of the
28: * SOFTWARE.
29: *
30: * THE SOFTWARE IS PROVIDED AS IS WITHOUT ANY WARRANTY OF ANY KIND. FLL
31: * MAKES ABSOLUTELY NO WARRANTIES, EXPRESSED, IMPLIED OR STATUTORY, AND
32: * EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS
33: * FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT OF THIRD PARTIES'
34: * RIGHTS. NO FLL DEALER, AGENT, EMPLOYEES IS AUTHORIZED TO MAKE ANY
35: * MODIFICATIONS, EXTENSIONS, OR ADDITIONS TO THIS WARRANTY.
36: * UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, TORT, CONTRACT,
37: * OR OTHERWISE, SHALL FLL BE LIABLE TO YOU OR ANY OTHER PERSON FOR ANY
38: * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, PUNITIVE OR CONSEQUENTIAL
39: * DAMAGES OF ANY CHARACTER, INCLUDING, WITHOUT LIMITATION, DAMAGES
40: * ARISING OUT OF OR RELATING TO THE SOFTWARE OR THIS AGREEMENT, DAMAGES
41: * FOR LOSS OF GOODWILL, WORK STOPPAGE, OR LOSS OF DATA, OR FOR ANY
42: * DAMAGES, EVEN IF FLL SHALL HAVE BEEN INFORMED OF THE POSSIBILITY OF
43: * SUCH DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY. EVEN IF A PART
44: * OF THE SOFTWARE HAS BEEN DEVELOPED BY A THIRD PARTY, THE THIRD PARTY
45: * DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE,
46: * PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE.
47: *
1.12 ! noro 48: * $OpenXM: OpenXM_contrib2/asir2000/builtin/print.c,v 1.11 2001/09/04 03:12:20 noro Exp $
1.2 noro 49: */
1.1 noro 50: #include "ca.h"
51: #include "parse.h"
52:
53: void Pprint();
1.4 noro 54: void Pquotetolist();
1.9 noro 55: void Peval_variables_in_quote();
1.11 noro 56: void Pset_print_function();
1.9 noro 57: FNODE eval_pvar_in_fnode();
1.12 ! noro 58: FNODE subst_in_fnode();
1.1 noro 59:
60: struct ftab print_tab[] = {
61: {"print",Pprint,-2},
1.4 noro 62: {"quotetolist",Pquotetolist,1},
1.9 noro 63: {"eval_variables_in_quote",Peval_variables_in_quote,1},
1.11 noro 64: {"set_print_function",Pset_print_function,-1},
1.1 noro 65: {0,0,0},
66: };
67:
68: void Pprint(arg,rp)
69: NODE arg;
70: pointer *rp;
71: {
72: printexpr(CO,ARG0(arg));
73: if ( argc(arg) == 2 )
74: switch ( QTOS((Q)ARG1(arg)) ) {
75: case 0:
76: break;
77: case 2:
78: fflush(asir_out); break;
79: break;
80: case 1: default:
81: putc('\n',asir_out); break;
82: }
83: else
84: putc('\n',asir_out);
85: *rp = 0;
1.4 noro 86: }
87:
88: void fnodetotree();
89:
90: void Pquotetolist(arg,rp)
91: NODE arg;
92: Obj *rp;
93: {
94: asir_assert(ARG0(arg),O_QUOTE,"quotetolist");
95: fnodetotree((FNODE)BDY((QUOTE)(ARG0(arg))),rp);
96: }
97:
1.9 noro 98: void Peval_variables_in_quote(arg,rp)
99: NODE arg;
100: QUOTE *rp;
101: {
102: FNODE fn;
103:
104: asir_assert(ARG0(arg),O_QUOTE,"eval_variables_in_quote");
105: fn = eval_pvar_in_fnode((FNODE)BDY((QUOTE)(ARG0(arg))));
106: MKQUOTE(*rp,fn);
107: }
108:
1.7 noro 109: /* fnode -> [tag,name,arg0,arg1,...] */
110:
1.4 noro 111: void fnodetotree(f,rp)
112: FNODE f;
113: Obj *rp;
114: {
1.7 noro 115: Obj a1,a2,a3;
1.4 noro 116: NODE n,t,t0;
1.7 noro 117: STRING head,op,str;
1.4 noro 118: LIST r,arg;
119: char *opname;
120:
121: if ( !f ) {
1.7 noro 122: MKSTR(head,"internal");
123: n = mknode(2,head,0);
124: MKLIST(r,n);
125: *rp = (Obj)r;
1.4 noro 126: return;
127: }
128: switch ( f->id ) {
1.7 noro 129: /* unary operators */
130: case I_NOT: case I_PAREN:
131: MKSTR(head,"u_op");
132: switch ( f->id ) {
133: case I_NOT:
134: MKSTR(op,"!");
135: break;
136: case I_PAREN:
137: MKSTR(op,"()");
138: break;
139: }
140: fnodetotree((FNODE)FA0(f),&a1);
141: n = mknode(3,head,op,a1);
142: MKLIST(r,n);
143: *rp = (Obj)r;
144: break;
145:
146: /* binary operators */
147: case I_BOP: case I_COP: case I_LOP: case I_AND: case I_OR:
148: /* head */
149: MKSTR(head,"b_op");
150:
1.4 noro 151: /* arg list */
1.7 noro 152: switch ( f->id ) {
153: case I_AND: case I_OR:
154: fnodetotree((FNODE)FA0(f),&a1);
155: fnodetotree((FNODE)FA1(f),&a2);
156: break;
157: default:
158: fnodetotree((FNODE)FA1(f),&a1);
159: fnodetotree((FNODE)FA2(f),&a2);
160: break;
161: }
1.4 noro 162:
1.7 noro 163: /* op */
1.4 noro 164: switch ( f->id ) {
165: case I_BOP:
1.7 noro 166: MKSTR(op,((ARF)FA0(f))->name); break;
167:
1.4 noro 168: case I_COP:
169: switch( (cid)FA0(f) ) {
170: case C_EQ: opname = "=="; break;
171: case C_NE: opname = "!="; break;
172: case C_GT: opname = ">"; break;
173: case C_LT: opname = "<"; break;
174: case C_GE: opname = ">="; break;
175: case C_LE: opname = "<="; break;
176: }
1.7 noro 177: MKSTR(op,opname); break;
178:
1.4 noro 179: case I_LOP:
180: switch( (lid)FA0(f) ) {
181: case L_EQ: opname = "@=="; break;
182: case L_NE: opname = "@!="; break;
183: case L_GT: opname = "@>"; break;
184: case L_LT: opname = "@<"; break;
185: case L_GE: opname = "@>="; break;
186: case L_LE: opname = "@<="; break;
187: case L_AND: opname = "@&&"; break;
188: case L_OR: opname = "@||"; break;
1.7 noro 189:
190: case L_NOT: opname = "@!";
191: /* XXX : L_NOT is a unary operator */
192: MKSTR(head,"u_op");
193: MKSTR(op,opname);
194: n = mknode(3,head,op,a1);
195: MKLIST(r,n);
196: *rp = (Obj)r;
197: return;
1.4 noro 198: }
1.7 noro 199: MKSTR(op,opname); break;
200:
201: case I_AND:
202: MKSTR(op,"&&"); break;
203:
204: case I_OR:
205: MKSTR(op,"||"); break;
1.4 noro 206: }
1.7 noro 207: n = mknode(4,head,op,a1,a2);
1.4 noro 208: MKLIST(r,n);
209: *rp = (Obj)r;
210: break;
1.7 noro 211:
212: /* ternary operators */
1.4 noro 213: case I_CE:
1.7 noro 214: MKSTR(head,"t_op");
215: MKSTR(op,"?:");
1.4 noro 216: fnodetotree((FNODE)FA0(f),&a1);
217: fnodetotree((FNODE)FA1(f),&a2);
1.7 noro 218: fnodetotree((FNODE)FA2(f),&a3);
219: n = mknode(5,head,op,a1,a2,a3);
1.4 noro 220: MKLIST(r,n);
221: *rp = (Obj)r;
222: break;
1.7 noro 223:
224: /* lists */
1.8 noro 225: case I_LIST:
1.4 noro 226: n = (NODE)FA0(f);
227: for ( t0 = 0; n; n = NEXT(n) ) {
228: NEXTNODE(t0,t);
229: fnodetotree(BDY(n),&BDY(t));
230: }
231: if ( t0 )
232: NEXT(t) = 0;
1.8 noro 233: MKSTR(head,"list");
1.7 noro 234: MKNODE(n,head,t0);
1.6 noro 235: MKLIST(r,n);
236: *rp = (Obj)r;
1.4 noro 237: break;
1.7 noro 238:
239: /* function */
1.8 noro 240: case I_FUNC: case I_CAR: case I_CDR: case I_EV:
1.7 noro 241: MKSTR(head,"function");
242: switch ( f->id ) {
243: case I_FUNC:
244: MKSTR(op,((FUNC)FA0(f))->name);
245: fnodetotree((FNODE)FA1(f),&arg);
246: break;
247: case I_CAR:
248: MKSTR(op,"car");
249: fnodetotree((FNODE)FA0(f),&arg);
250: break;
251: case I_CDR:
252: MKSTR(op,"cdr");
253: fnodetotree((FNODE)FA0(f),&arg);
254: break;
1.8 noro 255: case I_EV:
256: /* exponent vector; should be treated as function call */
257: MKSTR(op,"exponent_vector");
258: fnodetotree(mkfnode(1,I_LIST,FA0(f)),&arg);
259: break;
1.7 noro 260: }
261: t0 = NEXT(BDY(arg)); /* XXX : skip the headers */
262: MKNODE(t,op,t0);
263: MKNODE(n,head,t);
1.4 noro 264: MKLIST(r,n);
265: *rp = (Obj)r;
266: break;
1.7 noro 267:
268: case I_STR:
269: MKSTR(head,"internal");
270: MKSTR(str,FA0(f));
271: n = mknode(2,head,str);
1.4 noro 272: MKLIST(r,n);
273: *rp = (Obj)r;
274: break;
1.7 noro 275:
276: case I_FORMULA:
277: MKSTR(head,"internal");
278: n = mknode(2,head,FA0(f));
1.4 noro 279: MKLIST(r,n);
280: *rp = (Obj)r;
281: break;
1.9 noro 282:
283: case I_PVAR:
1.10 noro 284: if ( FA1(f) )
285: error("fnodetotree : not implemented yet");
1.9 noro 286: MKSTR(head,"variable");
287: GETPVNAME(FA0(f),opname);
288: MKSTR(op,opname);
289: n = mknode(2,head,op);
290: MKLIST(r,n);
291: *rp = (Obj)r;
292: break;
293:
1.4 noro 294: default:
295: error("fnodetotree : not implemented yet");
1.9 noro 296: }
297: }
298:
299: FNODE eval_pvar_in_fnode(f)
300: FNODE f;
301: {
302: FNODE a1,a2,a3;
303: pointer r;
304: NODE n,t,t0;
1.10 noro 305: QUOTE q;
1.9 noro 306:
307: if ( !f )
308: return 0;
309:
310: switch ( f->id ) {
311: /* unary operators */
312: case I_NOT: case I_PAREN:
313: a1 = eval_pvar_in_fnode((FNODE)FA0(f));
314: return mkfnode(1,f->id,a1);
315:
316: /* binary operators */
317: case I_AND: case I_OR:
318: a1 = eval_pvar_in_fnode((FNODE)FA0(f));
319: a2 = eval_pvar_in_fnode((FNODE)FA1(f));
320: return mkfnode(3,f->id,a1,a2);
321:
322: case I_BOP: case I_COP: case I_LOP:
323: a1 = eval_pvar_in_fnode((FNODE)FA1(f));
324: a2 = eval_pvar_in_fnode((FNODE)FA2(f));
325: return mkfnode(4,f->id,FA0(f),a1,a2);
326:
327: /* ternary operators */
328: case I_CE:
329: a1 = eval_pvar_in_fnode((FNODE)FA0(f));
330: a2 = eval_pvar_in_fnode((FNODE)FA1(f));
331: a3 = eval_pvar_in_fnode((FNODE)FA2(f));
332: return mkfnode(5,f->id,a1,a2,a3);
333:
334: /* lists */
335: case I_LIST:
336: n = (NODE)FA0(f);
337: for ( t0 = 0; n; n = NEXT(n) ) {
338: NEXTNODE(t0,t);
339: BDY(t) = (pointer)eval_pvar_in_fnode(BDY(n));
340: }
341: if ( t0 )
342: NEXT(t) = 0;
343: return mkfnode(1,f->id,t0);
344:
345: /* function */
346: case I_FUNC:
347: a1 = eval_pvar_in_fnode((FNODE)FA1(f));
348: return mkfnode(2,f->id,FA0(f),a1);
349: break;
350: case I_CAR: case I_CDR:
351: a1 = eval_pvar_in_fnode((FNODE)FA0(f));
352: return mkfnode(1,f->id,a1);
353: case I_EV:
354: /* exponent vector */
355: a1 = eval_pvar_in_fnode(mkfnode(1,I_LIST,FA0(f)));
356: return mkfnode(1,f->id,a1);
357:
358: case I_STR: case I_FORMULA:
359: return f;
360:
361: case I_PVAR: case I_INDEX:
362: case I_POSTSELF: case I_PRESELF:
363: r = eval(f);
1.10 noro 364: objtoquote(r,&q);
365: return BDY(q);
1.9 noro 366:
367: default:
368: error("eval_pvar_in_fnode : not implemented yet");
1.12 ! noro 369: }
! 370: }
! 371:
! 372: FNODE subst_in_fnode(f,v,g)
! 373: FNODE f;
! 374: V v;
! 375: FNODE g;
! 376: {
! 377: FNODE a1,a2,a3;
! 378: DCP dc;
! 379: pointer r;
! 380: V vf;
! 381: NODE n,t,t0;
! 382: QUOTE q;
! 383: Obj obj;
! 384:
! 385: if ( !f )
! 386: return 0;
! 387:
! 388: switch ( f->id ) {
! 389: /* unary operators */
! 390: case I_NOT: case I_PAREN:
! 391: a1 = subst_in_fnode((FNODE)FA0(f),v,g);
! 392: return mkfnode(1,f->id,a1);
! 393:
! 394: /* binary operators */
! 395: case I_AND: case I_OR:
! 396: a1 = subst_in_fnode((FNODE)FA0(f),v,g);
! 397: a2 = subst_in_fnode((FNODE)FA1(f),v,g);
! 398: return mkfnode(3,f->id,a1,a2);
! 399:
! 400: case I_BOP: case I_COP: case I_LOP:
! 401: a1 = subst_in_fnode((FNODE)FA1(f),v,g);
! 402: a2 = subst_in_fnode((FNODE)FA2(f),v,g);
! 403: return mkfnode(4,f->id,FA0(f),a1,a2);
! 404:
! 405: /* ternary operators */
! 406: case I_CE:
! 407: a1 = subst_in_fnode((FNODE)FA0(f),v,g);
! 408: a2 = subst_in_fnode((FNODE)FA1(f),v,g);
! 409: a3 = subst_in_fnode((FNODE)FA2(f),v,g);
! 410: return mkfnode(5,f->id,a1,a2,a3);
! 411:
! 412: /* lists */
! 413: case I_LIST:
! 414: n = (NODE)FA0(f);
! 415: for ( t0 = 0; n; n = NEXT(n) ) {
! 416: NEXTNODE(t0,t);
! 417: BDY(t) = (pointer)subst_in_fnode(BDY(n),v,g);
! 418: }
! 419: if ( t0 )
! 420: NEXT(t) = 0;
! 421: return mkfnode(1,f->id,t0);
! 422:
! 423: /* function */
! 424: case I_FUNC:
! 425: a1 = subst_in_fnode((FNODE)FA1(f),v,g);
! 426: return mkfnode(2,f->id,FA0(f),a1);
! 427: break;
! 428: case I_CAR: case I_CDR:
! 429: a1 = subst_in_fnode((FNODE)FA0(f),v,g);
! 430: return mkfnode(1,f->id,a1);
! 431: case I_EV:
! 432: /* exponent vector */
! 433: a1 = subst_in_fnode(mkfnode(1,I_LIST,FA0(f)),v,g);
! 434: return mkfnode(1,f->id,a1);
! 435:
! 436: case I_STR:
! 437: return f;
! 438:
! 439: case I_FORMULA:
! 440: obj = (Obj)FA0(f);
! 441: if ( !obj )
! 442: return f;
! 443:
! 444: switch ( OID(obj) ) {
! 445: case O_N:
! 446: return f;
! 447: case O_P:
! 448: vf = VR((P)obj);
! 449: dc = DC((P)obj);
! 450: if ( vf != v )
! 451: return f;
! 452: else if ( UNIQ(DEG(dc)) && UNIQ((Q)COEF(dc)) )
! 453: return g;
! 454: else break;
! 455: default:
! 456: break;
! 457: }
! 458:
! 459: default:
! 460: error("subst_in_fnode : not implemented yet");
1.4 noro 461: }
1.1 noro 462: }
1.8 noro 463:
464: char *get_attribute(key,attr)
465: char *key;
466: LIST attr;
467: {}
468:
469: void treetofnode(obj,f)
470: Obj obj;
471: FNODE *f;
472: {
473: NODE n;
474: LIST attr;
475: char *prop;
476:
477: if ( obj || OID(obj) != O_LIST ) {
478: /* internal object */
479: *f = mkfnode(1,I_FORMULA,obj);
480: } else {
481: /* [attr(list),name(string),args(node)] */
482: n = BDY((LIST)obj);
483: attr = (LIST)BDY(n); n = NEXT(n);
484: prop = get_attribute("asir",attr);
485: if ( !strcmp(prop,"u_op") ) {
486: } else if ( !strcmp(prop,"b_op") ) {
487: } else if ( !strcmp(prop,"t_op") ) {
488: } else if ( !strcmp(prop,"function") ) {
489: }
490: /* default will be set to P_FUNC */
491: }
492: }
493:
1.11 noro 494: FUNC user_print_function;
495:
496: void Pset_print_function(arg,rp)
497: NODE arg;
498: pointer *rp;
499: {
500: if ( !arg )
501: user_print_function = 0;
502: else {
503: gen_searchf(BDY((STRING)ARG0(arg)),&user_print_function);
504: }
505: *rp = 0;
506: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>