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