Annotation of OpenXM_contrib2/asir2000/builtin/print.c, Revision 1.8
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.8 ! noro 48: * $OpenXM: OpenXM_contrib2/asir2000/builtin/print.c,v 1.7 2001/08/22 04:20:45 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.1 noro 55:
56: struct ftab print_tab[] = {
57: {"print",Pprint,-2},
1.4 noro 58: {"quotetolist",Pquotetolist,1},
1.1 noro 59: {0,0,0},
60: };
61:
62: void Pprint(arg,rp)
63: NODE arg;
64: pointer *rp;
65: {
66: printexpr(CO,ARG0(arg));
67: if ( argc(arg) == 2 )
68: switch ( QTOS((Q)ARG1(arg)) ) {
69: case 0:
70: break;
71: case 2:
72: fflush(asir_out); break;
73: break;
74: case 1: default:
75: putc('\n',asir_out); break;
76: }
77: else
78: putc('\n',asir_out);
79: *rp = 0;
1.4 noro 80: }
81:
82: void fnodetotree();
83:
84: void Pquotetolist(arg,rp)
85: NODE arg;
86: Obj *rp;
87: {
88: asir_assert(ARG0(arg),O_QUOTE,"quotetolist");
89: fnodetotree((FNODE)BDY((QUOTE)(ARG0(arg))),rp);
90: }
91:
1.7 noro 92: /* fnode -> [tag,name,arg0,arg1,...] */
93:
1.4 noro 94: void fnodetotree(f,rp)
95: FNODE f;
96: Obj *rp;
97: {
1.7 noro 98: Obj a1,a2,a3;
1.4 noro 99: NODE n,t,t0;
1.7 noro 100: STRING head,op,str;
1.4 noro 101: LIST r,arg;
102: char *opname;
103:
104: if ( !f ) {
1.7 noro 105: MKSTR(head,"internal");
106: n = mknode(2,head,0);
107: MKLIST(r,n);
108: *rp = (Obj)r;
1.4 noro 109: return;
110: }
111: switch ( f->id ) {
1.7 noro 112: /* unary operators */
113: case I_NOT: case I_PAREN:
114: MKSTR(head,"u_op");
115: switch ( f->id ) {
116: case I_NOT:
117: MKSTR(op,"!");
118: break;
119: case I_PAREN:
120: MKSTR(op,"()");
121: break;
122: }
123: fnodetotree((FNODE)FA0(f),&a1);
124: n = mknode(3,head,op,a1);
125: MKLIST(r,n);
126: *rp = (Obj)r;
127: break;
128:
129: /* binary operators */
130: case I_BOP: case I_COP: case I_LOP: case I_AND: case I_OR:
131: /* head */
132: MKSTR(head,"b_op");
133:
1.4 noro 134: /* arg list */
1.7 noro 135: switch ( f->id ) {
136: case I_AND: case I_OR:
137: fnodetotree((FNODE)FA0(f),&a1);
138: fnodetotree((FNODE)FA1(f),&a2);
139: break;
140: default:
141: fnodetotree((FNODE)FA1(f),&a1);
142: fnodetotree((FNODE)FA2(f),&a2);
143: break;
144: }
1.4 noro 145:
1.7 noro 146: /* op */
1.4 noro 147: switch ( f->id ) {
148: case I_BOP:
1.7 noro 149: MKSTR(op,((ARF)FA0(f))->name); break;
150:
1.4 noro 151: case I_COP:
152: switch( (cid)FA0(f) ) {
153: case C_EQ: opname = "=="; break;
154: case C_NE: opname = "!="; break;
155: case C_GT: opname = ">"; break;
156: case C_LT: opname = "<"; break;
157: case C_GE: opname = ">="; break;
158: case C_LE: opname = "<="; break;
159: }
1.7 noro 160: MKSTR(op,opname); break;
161:
1.4 noro 162: case I_LOP:
163: switch( (lid)FA0(f) ) {
164: case L_EQ: opname = "@=="; break;
165: case L_NE: opname = "@!="; break;
166: case L_GT: opname = "@>"; break;
167: case L_LT: opname = "@<"; break;
168: case L_GE: opname = "@>="; break;
169: case L_LE: opname = "@<="; break;
170: case L_AND: opname = "@&&"; break;
171: case L_OR: opname = "@||"; break;
1.7 noro 172:
173: case L_NOT: opname = "@!";
174: /* XXX : L_NOT is a unary operator */
175: MKSTR(head,"u_op");
176: MKSTR(op,opname);
177: n = mknode(3,head,op,a1);
178: MKLIST(r,n);
179: *rp = (Obj)r;
180: return;
1.4 noro 181: }
1.7 noro 182: MKSTR(op,opname); break;
183:
184: case I_AND:
185: MKSTR(op,"&&"); break;
186:
187: case I_OR:
188: MKSTR(op,"||"); break;
1.4 noro 189: }
1.7 noro 190: n = mknode(4,head,op,a1,a2);
1.4 noro 191: MKLIST(r,n);
192: *rp = (Obj)r;
193: break;
1.7 noro 194:
195: /* ternary operators */
1.4 noro 196: case I_CE:
1.7 noro 197: MKSTR(head,"t_op");
198: MKSTR(op,"?:");
1.4 noro 199: fnodetotree((FNODE)FA0(f),&a1);
200: fnodetotree((FNODE)FA1(f),&a2);
1.7 noro 201: fnodetotree((FNODE)FA2(f),&a3);
202: n = mknode(5,head,op,a1,a2,a3);
1.4 noro 203: MKLIST(r,n);
204: *rp = (Obj)r;
205: break;
1.7 noro 206:
207: /* lists */
1.8 ! noro 208: case I_LIST:
1.4 noro 209: n = (NODE)FA0(f);
210: for ( t0 = 0; n; n = NEXT(n) ) {
211: NEXTNODE(t0,t);
212: fnodetotree(BDY(n),&BDY(t));
213: }
214: if ( t0 )
215: NEXT(t) = 0;
1.8 ! noro 216: MKSTR(head,"list");
1.7 noro 217: MKNODE(n,head,t0);
1.6 noro 218: MKLIST(r,n);
219: *rp = (Obj)r;
1.4 noro 220: break;
1.7 noro 221:
222: /* function */
1.8 ! noro 223: case I_FUNC: case I_CAR: case I_CDR: case I_EV:
1.7 noro 224: MKSTR(head,"function");
225: switch ( f->id ) {
226: case I_FUNC:
227: MKSTR(op,((FUNC)FA0(f))->name);
228: fnodetotree((FNODE)FA1(f),&arg);
229: break;
230: case I_CAR:
231: MKSTR(op,"car");
232: fnodetotree((FNODE)FA0(f),&arg);
233: break;
234: case I_CDR:
235: MKSTR(op,"cdr");
236: fnodetotree((FNODE)FA0(f),&arg);
237: break;
1.8 ! noro 238: case I_EV:
! 239: /* exponent vector; should be treated as function call */
! 240: MKSTR(op,"exponent_vector");
! 241: fnodetotree(mkfnode(1,I_LIST,FA0(f)),&arg);
! 242: break;
1.7 noro 243: }
244: t0 = NEXT(BDY(arg)); /* XXX : skip the headers */
245: MKNODE(t,op,t0);
246: MKNODE(n,head,t);
1.4 noro 247: MKLIST(r,n);
248: *rp = (Obj)r;
249: break;
1.7 noro 250:
251: case I_STR:
252: MKSTR(head,"internal");
253: MKSTR(str,FA0(f));
254: n = mknode(2,head,str);
1.4 noro 255: MKLIST(r,n);
256: *rp = (Obj)r;
257: break;
1.7 noro 258:
259: case I_FORMULA:
260: MKSTR(head,"internal");
261: n = mknode(2,head,FA0(f));
1.4 noro 262: MKLIST(r,n);
263: *rp = (Obj)r;
264: break;
265: default:
266: error("fnodetotree : not implemented yet");
267: }
1.1 noro 268: }
1.8 ! noro 269:
! 270: char *get_attribute(key,attr)
! 271: char *key;
! 272: LIST attr;
! 273: {}
! 274:
! 275: void treetofnode(obj,f)
! 276: Obj obj;
! 277: FNODE *f;
! 278: {
! 279: NODE n;
! 280: LIST attr;
! 281: char *prop;
! 282:
! 283: if ( obj || OID(obj) != O_LIST ) {
! 284: /* internal object */
! 285: *f = mkfnode(1,I_FORMULA,obj);
! 286: } else {
! 287: /* [attr(list),name(string),args(node)] */
! 288: n = BDY((LIST)obj);
! 289: attr = (LIST)BDY(n); n = NEXT(n);
! 290: prop = get_attribute("asir",attr);
! 291: if ( !strcmp(prop,"u_op") ) {
! 292: } else if ( !strcmp(prop,"b_op") ) {
! 293: } else if ( !strcmp(prop,"t_op") ) {
! 294: } else if ( !strcmp(prop,"function") ) {
! 295: }
! 296: /* default will be set to P_FUNC */
! 297: }
! 298: }
! 299:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>