2 * Copyright (C) 1991,1992 Erik Schoenfelder (schoenfr@ibr.cs.tu-bs.de)
4 * This file is part of NASE A60.
6 * NASE A60 is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
11 * NASE A60 is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with NASE A60; see the file COPYING. If not, write to the Free
18 * Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
22 * Erik Schoenfelder (schoenfr@ibr.cs.tu-bs.de)
24 * here is some code about runtime evaluation; it is mixed with
25 * eval.c and used from run.c
37 * evaluate a switch expression.
41 do_eval_switchexpr (sym, ex)
51 printf ("** do_eval_switchexpr: sym is `%s' ...\n", sym->name);
54 if (sym->tag == s_byname)
55 xabort ("INTERNAL: do_eval_switchexpr: s_byname");
57 swact = get_swact (sym);
59 a60_error (ex->source, ex->lineno,
60 "uninitialized switch list (symbol is `%s').\n",
62 xabort ("runtime error");
65 /* now eval the index: */
67 DO_DEREF(ex->source, ex->lineno);
69 if (ev.tag == ev_ival)
71 else if (ev.tag == ev_rval)
72 idx = RVAL2IVAL (ev.u.rval);
74 a60_error (ex->source, ex->lineno,
75 "subscript of designational expression must be of numerical type.\n");
76 a60_error (ex->source, ex->lineno,
77 "(but the type is `%s').\n",
78 eval_tag_name [ev.tag]);
79 xabort ("runtime error");
84 printf ("** do_eval_switchexpr: idx is %ld.\n", idx);
87 if (idx < 1 || idx > swact->nelm) {
89 * an undefined design. expr. leads to a dummy
92 /* +++++ add runtime warning +++++ */
96 printf ("** index out of range: dummy.\n");
99 evp = PUSH_EVALST(ex->source, ex->lineno, ev_label);
100 evp->u.sym = (SYMTAB *) 0;
103 evp = PUSH_EVALST(ex->source, ex->lineno, ev_label);
104 /* ***** 16 bit idx ***** */
105 evp->u.sym = swact->targs [(int) idx - 1];
111 do_eval_arrval (lhelm)
114 SYMTAB *sym = lhelm->sym;
121 #ifdef MEMORY_STATISTICS
125 mindex = lhelm->mindex;
127 xabort ("INTERNAL: do_eval_arrval: no mindex");
129 while (sym->tag == s_byname) {
130 CBLOCK *cb = act_cblock;
134 printf ("* do_eval_arrval: sym is `%s'...\n",
137 while (cb->block != sym->block)
139 act = cb->activ + sym->actidx;
140 if (act->data->u.pexpr.expr->tag != e_symbol)
141 xabort ("INTERNAL: do_eval_arrval: no symbol");
142 sym = act->data->u.pexpr.expr->u.lhelm->sym;
147 printf ("* do_eval_arrval: sym is `%s' !\n", sym->name);
150 if (sym->type == ty_switch) {
152 * got you: this is parsed as an array access, but
153 * actual ans des-expression.
154 * its a bad hack - yeh.
159 printf ("** do_eval_arrval: is a switch ...\n");
162 do_eval_switchexpr (sym, mindex->expr);
166 if (! TIS_ARR(sym->type)) {
167 a60_error (lhelm->source, lhelm->lineno,
168 "not an array: `%s'\n", sym->name);
169 xabort ("runtime error");
173 while (cb->block != sym->block)
175 act = cb->activ + sym->actidx;
177 * this can happen, if the array declaration is interrupted by
180 if (! act || ! act->arract) {
181 a60_error (lhelm->source, lhelm->lineno,
182 "uninitialized array\n");
183 xabort ("runtime error");
186 bound = act->arract->act_bound;
189 do_eval_expr (mindex->expr);
190 DO_DEREF(mindex->expr->source, mindex->expr->lineno);
193 if (ev->tag == ev_rval) {
195 ev->u.ival = RVAL2IVAL(ev->u.rval);
197 else if (ev->tag != ev_ival) {
198 a60_error (ev->source, ev->lineno,
199 "array index must be of numerical type (found `%s')\n",
200 eval_tag_name[ev->tag]);
201 xabort ("runtime error");
204 if (ev->u.ival < bound->from
205 || ev->u.ival > bound->til) {
206 a60_error (ev->source, ev->lineno,
207 "index not in bound; index is %ld, bounds are [%ld : %ld]\n",
208 ev->u.ival, bound->from, bound->til);
209 xabort ("runtime error");
212 idx = idx + (ev->u.ival - bound->from) * bound->mpl;
214 mindex = mindex->next;
220 printf ("* do_eval_arrval: idx is %ld.\n", idx);
223 push_valaddr (lhelm->source, lhelm->lineno, sym, idx);
229 do_push_lhelm (lhelm)
232 SYMTAB *sym = lhelm->sym;
236 do_eval_arrval (lhelm);
242 printf ("* do_push_lhelm: sym is `%s'...\n", sym->name);
245 while (sym->tag == s_byname) {
246 CBLOCK *cb = act_cblock;
249 while (cb->block != sym->block)
251 act = cb->activ + sym->actidx;
252 tag = act->data->u.pexpr.expr->tag;
253 if (tag != e_symbol && tag != e_fcall) {
254 a60_error (lhelm->source, lhelm->lineno,
255 "no valid lefthand type (type is `%s')\n",
257 xabort ("runtime error");
259 if (act->data->u.pexpr.expr->u.lhelm->mindex) {
260 do_eval_arrval (act->data->u.pexpr.expr->u.lhelm);
263 sym = act->data->u.pexpr.expr->u.lhelm->sym;
269 printf ("* do_push_lhelm: sym is `%s' !\n", sym->name);
272 if (! TIS_SVALT(sym->type)) {
273 a60_error (lhelm->source, lhelm->lineno,
274 "illegal lefthand side (type is `%s')\n",
275 type_tag_name[sym->type]);
276 xabort ("runtime error");
279 push_valaddr (lhelm->source, lhelm->lineno, sym, (long) 0);
285 do_eval_lhelm (lhelm)
288 SYMTAB *sym = lhelm->sym;
290 #ifdef MEMORY_STATISTICS
295 do_eval_arrval (lhelm);
301 printf ("* do_eval_lhelm: sym is `%s'...\n", sym->name);
304 if (sym->tag == s_byname) {
305 CBLOCK *cb = act_cblock;
307 while (cb->block != sym->block)
309 act = cb->activ + sym->actidx;
310 tag = act->data->u.pexpr.expr->tag;
311 if (tag != e_symbol) {
312 do_eval_pexpr (& act->data->u.pexpr);
315 do_eval_pexpr (& act->data->u.pexpr);
321 printf ("* do_eval_lhelm: sym is `%s' !\n", sym->name);
324 if (TIS_BASET(sym->type) || TIS_FUNC(sym->type)) {
325 push_valaddr (lhelm->source, lhelm->lineno, sym, (long) 0);
327 else if (TIS_SPECT(sym->type)) {
328 push_spec (lhelm->source, lhelm->lineno, sym);
330 else if (TIS_ARR(sym->type)) {
331 push_spec (lhelm->source, lhelm->lineno, sym);
334 a60_error (lhelm->source, lhelm->lineno,
335 "INTERNAL: do_eval_lhelm: bad sym type `%s'\n",
336 sym_tag_name[sym->type]);
344 ENUM expr_tag tag = ex->tag;
347 #ifdef MEMORY_STATISTICS
353 printf ("** do_eval_expr: have here a `%s' (type is `%s').\n",
354 expr_tag_name [tag], type_tag_name [ex->type]);
357 if (tag == e_switch) {
358 sym = ex->u.eswitch->sym;
359 while (sym->tag == s_byname) {
361 while (sym->tag == s_byname) {
362 CBLOCK *cb = act_cblock;
367 "* do_eval_expr: switch sym is `%s'...\n",
370 while (cb->block != sym->block)
372 act = cb->activ + sym->actidx;
373 if (act->data->u.pexpr.expr->tag != e_symbol)
375 "INTERNAL: do_eval_expr: switch: no symbol");
376 sym = act->data->u.pexpr.expr->u.lhelm->sym;
380 "* do_eval_expr: now it is `%s'...\n",
385 do_eval_switchexpr (sym, ex->u.eswitch->expr);
388 else if (tag == e_label) {
390 while (sym->tag == s_byname) {
395 printf ("** label with s_byname (%s)...\n",
399 data = get_sym_data (sym);
400 do_eval_pexpr (&(data->u.pexpr));
403 ev = PUSH_EVALST(ex->source, ex->lineno, ev_label);
406 else if (tag == e_symbol) {
408 * hmmm - may be its a numerical expression or it is a
409 * designational expression...
411 do_eval_lhelm (ex->u.lhelm);
413 else if (tag == e_fcall) {
415 printf ("line %d: executing func call (`%s')\n",
416 ex->lineno, ex->u.lhelm->sym->name);
418 sym = ex->u.lhelm->sym;
419 while ((TIS_PROC(sym->type) || sym->type == ty_unknown)
420 && sym->tag == s_byname) {
425 printf ("** call with func parm (%s):\n",
428 data = get_sym_data (sym);
429 push_spec_pexpr (&(data->u.pexpr));
434 printf (" -> now it is func parm (%s).\n",
439 if (! TIS_FUNC(sym->type) && sym->tag == s_defined) {
440 a60_error (ex->source, ex->lineno,
441 "must return a value (`%s')\n",
442 ex->u.lhelm->sym->name);
443 xabort ("runtime error");
446 exec_fcall (ex->source, ex->lineno,
447 sym, ex->u.lhelm->u.fcall);
449 else if (tag == e_ival) {
450 ev = PUSH_EVALST(ex->source, ex->lineno, ev_ival);
451 ev->u.ival = ex->u.ival;
453 else if (tag == e_rval) {
454 ev = PUSH_EVALST(ex->source, ex->lineno, ev_rval);
455 ev->u.rval = ex->u.rval;
457 else if (tag == e_bool) {
458 ev = PUSH_EVALST(ex->source, ex->lineno, ev_bool);
459 ev->u.bool = ex->u.bool;
461 else if (tag == e_string) {
462 ev = PUSH_EVALST(ex->source, ex->lineno, ev_string);
463 ev->u.string = ex->u.string;
465 else if (EIS_UNEXP(tag)) {
466 do_eval_expr (ex->u.expr[0]);
467 DO_DEREF(ex->source, ex->lineno);
470 else if (EIS_BINEXP(tag)) {
471 do_eval_expr (ex->u.expr[1]);
472 DO_DEREF(ex->source, ex->lineno);
473 do_eval_expr (ex->u.expr[0]);
474 DO_DEREF(ex->source, ex->lineno);
477 else if (tag == e_condexpr) {
478 do_eval_expr (ex->u.expr[0]);
479 DO_DEREF(ex->source, ex->lineno);
480 top_ev = * POP_EVALST;
481 if (top_ev.tag != ev_bool)
482 a60_error ("INTERNAL", 0, "INTERNAL: No Bool!\n");
484 do_eval_expr (ex->u.expr[1]);
486 do_eval_expr (ex->u.expr[2]);
488 else if (EIS_NOP(tag)) {
489 do_eval_expr (ex->u.expr[0]);
492 a60_error (ex->source, ex->lineno,
493 "INTERNAL: do_eval_expr: unknown expr_tag `%s'\n",
495 xabort ("INTERNAL error");
505 push_cblock (pex->cblock);
507 do_eval_expr (pex->expr);
514 /* end of doeval.c */