|
|
1.1 root 1: # include <ingres.h>
2: # include <aux.h>
3: # include <symbol.h>
4: # include <tree.h>
5: # include "../decomp/globs.h"
6: # include <sccs.h>
7:
8: SCCSID(@(#)interp1.c 7.2 3/6/81)
9:
10:
11: /*
12: ** INTERP1.C
13: **
14: ** symbol I/O utility routines for OVQP interpreter.
15: **
16: */
17:
18: /*
19: ** GETSYMBOL
20: **
21: ** Gets (type, len, value) symbols from list
22: ** A ptr to the list is advanced after
23: ** call. Symbols are moved to a target location
24: ** (typically a slot on the interpreter's De.ov_stack).
25: ** Legality of symbol type and length is checked.
26: ** Returns 1 if no more symbols in list
27: ** 0 otherwise
28: **
29: */
30:
31: getsymbol(ts, p)
32: SYMBOL *ts; /* target location (on stack) */
33: SYMBOL ***p; /* pointer to list */
34: {
35: int len; /*length of target symbol*/
36: register union symvalue *d; /* ptr to data for target symbol */
37: register SYMBOL *cp; /* the item in the list */
38: register SYMBOL *tops; /* target location on stack */
39: register union symvalue *val;
40:
41: tops = ts; /* copy stack pointer */
42: cp = **p; /* get list pointer */
43:
44: # ifdef xOTR1
45: if (tTf(84, 0))
46: {
47: printf("GETSYM: ");
48: prsym(cp);
49: }
50: # endif
51:
52: if (tops >= (SYMBOL *) &De.ov_stack[STACKSIZ])
53: ov_err(STACKOVER);
54:
55: val = &cp->value;
56: /* decomp will put the s_var's value in the right place
57: * if this is the case
58: */
59: if (cp->type == VAR || cp->type == S_VAR)
60: {
61: tops->type = val->sym_var.varfrmt;
62: len = tops->len = val->sym_var.varfrml;
63: d = (union symvalue *) val->sym_var.valptr;
64: }
65: else
66: {
67: tops->type = cp->type;
68: len = tops->len = cp->len;
69: len &= 0377;
70: d = &cp->value;
71: }
72: /* advance De.ov_qvect sequencing pointer p */
73: *p += 1;
74:
75: switch(tops->type)
76: {
77: case INT:
78: switch (len)
79: {
80: case 1:
81: tops->value.sym_data.i2type = d->sym_data.i1type;
82: break;
83: case 2:
84: case 4:
85: bmove((char *) d, (char *) &tops->value.sym_data, len);
86: break;
87:
88: default:
89: syserr("getsym:bad int len %d",len);
90: }
91: break;
92:
93: case FLOAT:
94: switch (len)
95: {
96: case 4:
97: tops->value.sym_data.f8type = d->sym_data.f4type;
98: break;
99:
100: case 8:
101: tops->value.sym_data.f8type = d->sym_data.f8type;
102: break;
103:
104: default:
105: syserr("getsym:bad FLOAT len %d",len);
106: }
107: break;
108:
109: case CHAR:
110: tops->value.sym_data.cptype = d->sym_data.c0type;
111: break;
112:
113: case AOP:
114: case BOP:
115: case UOP:
116: case COP:
117: tops->value.sym_op.opno = d->sym_op.opno;
118: break;
119:
120: case RESDOM:
121: tops->value.sym_resdom.resno = d->sym_resdom.resno;
122: break;
123:
124: case AND:
125: case OR:
126: break;
127:
128: case AGHEAD:
129: case BYHEAD:
130: case ROOT:
131: case QLEND:
132: return (1); /* all these are delimitors between lists */
133:
134: default:
135: syserr("getsym:bad type %d", tops->type);
136: }
137: return(0);
138: }
139: /*
140: ** TOUT
141: **
142: ** Copies a symbol value into the Output tuple buffer.
143: ** Used to write target
144: ** list elements or aggregate values into the output tuple.&
145: */
146:
147: tout(s, offp, rlen)
148: register SYMBOL *s;
149: char *offp;
150: int rlen;
151: {
152: register int i;
153: register char *p;
154: int slen;
155:
156: # ifdef xOTR1
157: if (tTf(84, 3))
158: {
159: printf("TOUT: s=");
160: prstack(s);
161: printf(" offset=%d, rlen=%d\n", offp-De.ov_outtup, rlen);
162: }
163: # endif
164: if (s->type == CHAR)
165: {
166: slen = s->len & 0377;
167: rlen &= 0377;
168: i = rlen - slen; /* compute difference between sizes */
169: if (i <= 0)
170: {
171: bmove(s->value.sym_data.cptype, offp, rlen);
172: }
173: else
174: {
175: p = s->value.sym_data.cptype;
176: bmove(p, offp, slen);
177: p = &offp[slen];
178: while (i--)
179: *p++ = ' '; /* blank out remainder */
180: }
181: }
182: else
183: {
184: bmove((char *)&s->value, offp, rlen);
185: }
186: }
187: /*
188: ** RCVT
189: */
190: rcvt(tos, restype, reslen)
191: register SYMBOL *tos;
192: int restype, reslen;
193: {
194: register int rtype, rlen;
195: int stype, slen;
196:
197: rtype = restype;
198: rlen = reslen;
199: stype = tos->type;
200: slen= tos->len;
201: # ifdef xOTR1
202: if (tTf(84, 6))
203: {
204: printf("RCVT:type=");
205: xputchar(rtype);
206: printf("%3d, tos=", rlen);
207: prstack(tos);
208: }
209: # endif
210:
211: if (rtype != stype)
212: {
213: if (rtype == CHAR || stype == CHAR)
214: ov_err(BADCONV); /* bad char to numeric conversion requested */
215: if (rtype == FLOAT)
216: itof(tos);
217: else
218: {
219: if (rlen == 4)
220: ftoi4(tos);
221: else
222: ftoi2(tos);
223: }
224: tos->len = rlen; /* handles conversion to i1 or f4 */
225: }
226:
227: else
228: {
229: if (rtype != CHAR && rlen != slen)
230: {
231: if (rtype == INT)
232: {
233: if (rlen == 4)
234: i2toi4(tos);
235: else if (slen == 4)
236: i4toi2(tos);
237: }
238: tos->len = rlen; /* handles conversion to i1 or f4 */
239: }
240: }
241: # ifdef xOTR3
242: if (tTf(84, 6))
243: {
244: printf("RCVT rets: symbol: ");
245: prsym(tos);
246: }
247: # endif
248: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.