Annotation of OpenXM_contrib2/asir2000/builtin/print.c, Revision 1.9
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.9 ! noro 48: * $OpenXM: OpenXM_contrib2/asir2000/builtin/print.c,v 1.8 2001/08/31 09:17:12 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:
! 281: MKSTR(head,"variable");
! 282: GETPVNAME(FA0(f),opname);
! 283: MKSTR(op,opname);
! 284: n = mknode(2,head,op);
! 285: MKLIST(r,n);
! 286: *rp = (Obj)r;
! 287: break;
! 288:
1.4 noro 289: default:
290: error("fnodetotree : not implemented yet");
1.9 ! noro 291: }
! 292: }
! 293:
! 294: FNODE eval_pvar_in_fnode(f)
! 295: FNODE f;
! 296: {
! 297: FNODE a1,a2,a3;
! 298: pointer r;
! 299: NODE n,t,t0;
! 300:
! 301: if ( !f )
! 302: return 0;
! 303:
! 304: switch ( f->id ) {
! 305: /* unary operators */
! 306: case I_NOT: case I_PAREN:
! 307: a1 = eval_pvar_in_fnode((FNODE)FA0(f));
! 308: return mkfnode(1,f->id,a1);
! 309:
! 310: /* binary operators */
! 311: case I_AND: case I_OR:
! 312: a1 = eval_pvar_in_fnode((FNODE)FA0(f));
! 313: a2 = eval_pvar_in_fnode((FNODE)FA1(f));
! 314: return mkfnode(3,f->id,a1,a2);
! 315:
! 316: case I_BOP: case I_COP: case I_LOP:
! 317: a1 = eval_pvar_in_fnode((FNODE)FA1(f));
! 318: a2 = eval_pvar_in_fnode((FNODE)FA2(f));
! 319: return mkfnode(4,f->id,FA0(f),a1,a2);
! 320:
! 321: /* ternary operators */
! 322: case I_CE:
! 323: a1 = eval_pvar_in_fnode((FNODE)FA0(f));
! 324: a2 = eval_pvar_in_fnode((FNODE)FA1(f));
! 325: a3 = eval_pvar_in_fnode((FNODE)FA2(f));
! 326: return mkfnode(5,f->id,a1,a2,a3);
! 327:
! 328: /* lists */
! 329: case I_LIST:
! 330: n = (NODE)FA0(f);
! 331: for ( t0 = 0; n; n = NEXT(n) ) {
! 332: NEXTNODE(t0,t);
! 333: BDY(t) = (pointer)eval_pvar_in_fnode(BDY(n));
! 334: }
! 335: if ( t0 )
! 336: NEXT(t) = 0;
! 337: return mkfnode(1,f->id,t0);
! 338:
! 339: /* function */
! 340: case I_FUNC:
! 341: a1 = eval_pvar_in_fnode((FNODE)FA1(f));
! 342: return mkfnode(2,f->id,FA0(f),a1);
! 343: break;
! 344: case I_CAR: case I_CDR:
! 345: a1 = eval_pvar_in_fnode((FNODE)FA0(f));
! 346: return mkfnode(1,f->id,a1);
! 347: case I_EV:
! 348: /* exponent vector */
! 349: a1 = eval_pvar_in_fnode(mkfnode(1,I_LIST,FA0(f)));
! 350: return mkfnode(1,f->id,a1);
! 351:
! 352: case I_STR: case I_FORMULA:
! 353: return f;
! 354:
! 355: case I_PVAR: case I_INDEX:
! 356: case I_POSTSELF: case I_PRESELF:
! 357: r = eval(f);
! 358: return mkfnode(1,I_FORMULA,r);
! 359:
! 360: default:
! 361: error("eval_pvar_in_fnode : not implemented yet");
1.4 noro 362: }
1.1 noro 363: }
1.8 noro 364:
365: char *get_attribute(key,attr)
366: char *key;
367: LIST attr;
368: {}
369:
370: void treetofnode(obj,f)
371: Obj obj;
372: FNODE *f;
373: {
374: NODE n;
375: LIST attr;
376: char *prop;
377:
378: if ( obj || OID(obj) != O_LIST ) {
379: /* internal object */
380: *f = mkfnode(1,I_FORMULA,obj);
381: } else {
382: /* [attr(list),name(string),args(node)] */
383: n = BDY((LIST)obj);
384: attr = (LIST)BDY(n); n = NEXT(n);
385: prop = get_attribute("asir",attr);
386: if ( !strcmp(prop,"u_op") ) {
387: } else if ( !strcmp(prop,"b_op") ) {
388: } else if ( !strcmp(prop,"t_op") ) {
389: } else if ( !strcmp(prop,"function") ) {
390: }
391: /* default will be set to P_FUNC */
392: }
393: }
394:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>