Annotation of OpenXM_contrib2/asir2000/builtin/print.c, Revision 1.11
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.11 ! noro 48: * $OpenXM: OpenXM_contrib2/asir2000/builtin/print.c,v 1.10 2001/09/04 02:45:32 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.1 noro 58:
59: struct ftab print_tab[] = {
60: {"print",Pprint,-2},
1.4 noro 61: {"quotetolist",Pquotetolist,1},
1.9 noro 62: {"eval_variables_in_quote",Peval_variables_in_quote,1},
1.11 ! noro 63: {"set_print_function",Pset_print_function,-1},
1.1 noro 64: {0,0,0},
65: };
66:
67: void Pprint(arg,rp)
68: NODE arg;
69: pointer *rp;
70: {
71: printexpr(CO,ARG0(arg));
72: if ( argc(arg) == 2 )
73: switch ( QTOS((Q)ARG1(arg)) ) {
74: case 0:
75: break;
76: case 2:
77: fflush(asir_out); break;
78: break;
79: case 1: default:
80: putc('\n',asir_out); break;
81: }
82: else
83: putc('\n',asir_out);
84: *rp = 0;
1.4 noro 85: }
86:
87: void fnodetotree();
88:
89: void Pquotetolist(arg,rp)
90: NODE arg;
91: Obj *rp;
92: {
93: asir_assert(ARG0(arg),O_QUOTE,"quotetolist");
94: fnodetotree((FNODE)BDY((QUOTE)(ARG0(arg))),rp);
95: }
96:
1.9 noro 97: void Peval_variables_in_quote(arg,rp)
98: NODE arg;
99: QUOTE *rp;
100: {
101: FNODE fn;
102:
103: asir_assert(ARG0(arg),O_QUOTE,"eval_variables_in_quote");
104: fn = eval_pvar_in_fnode((FNODE)BDY((QUOTE)(ARG0(arg))));
105: MKQUOTE(*rp,fn);
106: }
107:
1.7 noro 108: /* fnode -> [tag,name,arg0,arg1,...] */
109:
1.4 noro 110: void fnodetotree(f,rp)
111: FNODE f;
112: Obj *rp;
113: {
1.7 noro 114: Obj a1,a2,a3;
1.4 noro 115: NODE n,t,t0;
1.7 noro 116: STRING head,op,str;
1.4 noro 117: LIST r,arg;
118: char *opname;
119:
120: if ( !f ) {
1.7 noro 121: MKSTR(head,"internal");
122: n = mknode(2,head,0);
123: MKLIST(r,n);
124: *rp = (Obj)r;
1.4 noro 125: return;
126: }
127: switch ( f->id ) {
1.7 noro 128: /* unary operators */
129: case I_NOT: case I_PAREN:
130: MKSTR(head,"u_op");
131: switch ( f->id ) {
132: case I_NOT:
133: MKSTR(op,"!");
134: break;
135: case I_PAREN:
136: MKSTR(op,"()");
137: break;
138: }
139: fnodetotree((FNODE)FA0(f),&a1);
140: n = mknode(3,head,op,a1);
141: MKLIST(r,n);
142: *rp = (Obj)r;
143: break;
144:
145: /* binary operators */
146: case I_BOP: case I_COP: case I_LOP: case I_AND: case I_OR:
147: /* head */
148: MKSTR(head,"b_op");
149:
1.4 noro 150: /* arg list */
1.7 noro 151: switch ( f->id ) {
152: case I_AND: case I_OR:
153: fnodetotree((FNODE)FA0(f),&a1);
154: fnodetotree((FNODE)FA1(f),&a2);
155: break;
156: default:
157: fnodetotree((FNODE)FA1(f),&a1);
158: fnodetotree((FNODE)FA2(f),&a2);
159: break;
160: }
1.4 noro 161:
1.7 noro 162: /* op */
1.4 noro 163: switch ( f->id ) {
164: case I_BOP:
1.7 noro 165: MKSTR(op,((ARF)FA0(f))->name); break;
166:
1.4 noro 167: case I_COP:
168: switch( (cid)FA0(f) ) {
169: case C_EQ: opname = "=="; break;
170: case C_NE: opname = "!="; break;
171: case C_GT: opname = ">"; break;
172: case C_LT: opname = "<"; break;
173: case C_GE: opname = ">="; break;
174: case C_LE: opname = "<="; break;
175: }
1.7 noro 176: MKSTR(op,opname); break;
177:
1.4 noro 178: case I_LOP:
179: switch( (lid)FA0(f) ) {
180: case L_EQ: opname = "@=="; break;
181: case L_NE: opname = "@!="; break;
182: case L_GT: opname = "@>"; break;
183: case L_LT: opname = "@<"; break;
184: case L_GE: opname = "@>="; break;
185: case L_LE: opname = "@<="; break;
186: case L_AND: opname = "@&&"; break;
187: case L_OR: opname = "@||"; break;
1.7 noro 188:
189: case L_NOT: opname = "@!";
190: /* XXX : L_NOT is a unary operator */
191: MKSTR(head,"u_op");
192: MKSTR(op,opname);
193: n = mknode(3,head,op,a1);
194: MKLIST(r,n);
195: *rp = (Obj)r;
196: return;
1.4 noro 197: }
1.7 noro 198: MKSTR(op,opname); break;
199:
200: case I_AND:
201: MKSTR(op,"&&"); break;
202:
203: case I_OR:
204: MKSTR(op,"||"); break;
1.4 noro 205: }
1.7 noro 206: n = mknode(4,head,op,a1,a2);
1.4 noro 207: MKLIST(r,n);
208: *rp = (Obj)r;
209: break;
1.7 noro 210:
211: /* ternary operators */
1.4 noro 212: case I_CE:
1.7 noro 213: MKSTR(head,"t_op");
214: MKSTR(op,"?:");
1.4 noro 215: fnodetotree((FNODE)FA0(f),&a1);
216: fnodetotree((FNODE)FA1(f),&a2);
1.7 noro 217: fnodetotree((FNODE)FA2(f),&a3);
218: n = mknode(5,head,op,a1,a2,a3);
1.4 noro 219: MKLIST(r,n);
220: *rp = (Obj)r;
221: break;
1.7 noro 222:
223: /* lists */
1.8 noro 224: case I_LIST:
1.4 noro 225: n = (NODE)FA0(f);
226: for ( t0 = 0; n; n = NEXT(n) ) {
227: NEXTNODE(t0,t);
228: fnodetotree(BDY(n),&BDY(t));
229: }
230: if ( t0 )
231: NEXT(t) = 0;
1.8 noro 232: MKSTR(head,"list");
1.7 noro 233: MKNODE(n,head,t0);
1.6 noro 234: MKLIST(r,n);
235: *rp = (Obj)r;
1.4 noro 236: break;
1.7 noro 237:
238: /* function */
1.8 noro 239: case I_FUNC: case I_CAR: case I_CDR: case I_EV:
1.7 noro 240: MKSTR(head,"function");
241: switch ( f->id ) {
242: case I_FUNC:
243: MKSTR(op,((FUNC)FA0(f))->name);
244: fnodetotree((FNODE)FA1(f),&arg);
245: break;
246: case I_CAR:
247: MKSTR(op,"car");
248: fnodetotree((FNODE)FA0(f),&arg);
249: break;
250: case I_CDR:
251: MKSTR(op,"cdr");
252: fnodetotree((FNODE)FA0(f),&arg);
253: break;
1.8 noro 254: case I_EV:
255: /* exponent vector; should be treated as function call */
256: MKSTR(op,"exponent_vector");
257: fnodetotree(mkfnode(1,I_LIST,FA0(f)),&arg);
258: break;
1.7 noro 259: }
260: t0 = NEXT(BDY(arg)); /* XXX : skip the headers */
261: MKNODE(t,op,t0);
262: MKNODE(n,head,t);
1.4 noro 263: MKLIST(r,n);
264: *rp = (Obj)r;
265: break;
1.7 noro 266:
267: case I_STR:
268: MKSTR(head,"internal");
269: MKSTR(str,FA0(f));
270: n = mknode(2,head,str);
1.4 noro 271: MKLIST(r,n);
272: *rp = (Obj)r;
273: break;
1.7 noro 274:
275: case I_FORMULA:
276: MKSTR(head,"internal");
277: n = mknode(2,head,FA0(f));
1.4 noro 278: MKLIST(r,n);
279: *rp = (Obj)r;
280: break;
1.9 noro 281:
282: case I_PVAR:
1.10 noro 283: if ( FA1(f) )
284: error("fnodetotree : not implemented yet");
1.9 noro 285: MKSTR(head,"variable");
286: GETPVNAME(FA0(f),opname);
287: MKSTR(op,opname);
288: n = mknode(2,head,op);
289: MKLIST(r,n);
290: *rp = (Obj)r;
291: break;
292:
1.4 noro 293: default:
294: error("fnodetotree : not implemented yet");
1.9 noro 295: }
296: }
297:
298: FNODE eval_pvar_in_fnode(f)
299: FNODE f;
300: {
301: FNODE a1,a2,a3;
302: pointer r;
303: NODE n,t,t0;
1.10 noro 304: QUOTE q;
1.9 noro 305:
306: if ( !f )
307: return 0;
308:
309: switch ( f->id ) {
310: /* unary operators */
311: case I_NOT: case I_PAREN:
312: a1 = eval_pvar_in_fnode((FNODE)FA0(f));
313: return mkfnode(1,f->id,a1);
314:
315: /* binary operators */
316: case I_AND: case I_OR:
317: a1 = eval_pvar_in_fnode((FNODE)FA0(f));
318: a2 = eval_pvar_in_fnode((FNODE)FA1(f));
319: return mkfnode(3,f->id,a1,a2);
320:
321: case I_BOP: case I_COP: case I_LOP:
322: a1 = eval_pvar_in_fnode((FNODE)FA1(f));
323: a2 = eval_pvar_in_fnode((FNODE)FA2(f));
324: return mkfnode(4,f->id,FA0(f),a1,a2);
325:
326: /* ternary operators */
327: case I_CE:
328: a1 = eval_pvar_in_fnode((FNODE)FA0(f));
329: a2 = eval_pvar_in_fnode((FNODE)FA1(f));
330: a3 = eval_pvar_in_fnode((FNODE)FA2(f));
331: return mkfnode(5,f->id,a1,a2,a3);
332:
333: /* lists */
334: case I_LIST:
335: n = (NODE)FA0(f);
336: for ( t0 = 0; n; n = NEXT(n) ) {
337: NEXTNODE(t0,t);
338: BDY(t) = (pointer)eval_pvar_in_fnode(BDY(n));
339: }
340: if ( t0 )
341: NEXT(t) = 0;
342: return mkfnode(1,f->id,t0);
343:
344: /* function */
345: case I_FUNC:
346: a1 = eval_pvar_in_fnode((FNODE)FA1(f));
347: return mkfnode(2,f->id,FA0(f),a1);
348: break;
349: case I_CAR: case I_CDR:
350: a1 = eval_pvar_in_fnode((FNODE)FA0(f));
351: return mkfnode(1,f->id,a1);
352: case I_EV:
353: /* exponent vector */
354: a1 = eval_pvar_in_fnode(mkfnode(1,I_LIST,FA0(f)));
355: return mkfnode(1,f->id,a1);
356:
357: case I_STR: case I_FORMULA:
358: return f;
359:
360: case I_PVAR: case I_INDEX:
361: case I_POSTSELF: case I_PRESELF:
362: r = eval(f);
1.10 noro 363: objtoquote(r,&q);
364: return BDY(q);
1.9 noro 365:
366: default:
367: error("eval_pvar_in_fnode : not implemented yet");
1.4 noro 368: }
1.1 noro 369: }
1.8 noro 370:
371: char *get_attribute(key,attr)
372: char *key;
373: LIST attr;
374: {}
375:
376: void treetofnode(obj,f)
377: Obj obj;
378: FNODE *f;
379: {
380: NODE n;
381: LIST attr;
382: char *prop;
383:
384: if ( obj || OID(obj) != O_LIST ) {
385: /* internal object */
386: *f = mkfnode(1,I_FORMULA,obj);
387: } else {
388: /* [attr(list),name(string),args(node)] */
389: n = BDY((LIST)obj);
390: attr = (LIST)BDY(n); n = NEXT(n);
391: prop = get_attribute("asir",attr);
392: if ( !strcmp(prop,"u_op") ) {
393: } else if ( !strcmp(prop,"b_op") ) {
394: } else if ( !strcmp(prop,"t_op") ) {
395: } else if ( !strcmp(prop,"function") ) {
396: }
397: /* default will be set to P_FUNC */
398: }
399: }
400:
1.11 ! noro 401: FUNC user_print_function;
! 402:
! 403: void Pset_print_function(arg,rp)
! 404: NODE arg;
! 405: pointer *rp;
! 406: {
! 407: if ( !arg )
! 408: user_print_function = 0;
! 409: else {
! 410: gen_searchf(BDY((STRING)ARG0(arg)),&user_print_function);
! 411: }
! 412: *rp = 0;
! 413: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>