From: ceriel Date: Wed, 14 Jan 1987 09:58:51 +0000 (+0000) Subject: added EX_SIDEEFFECTS, options['p'] --> ! options['L'], fixed some bugs X-Git-Tag: release-5-5~5000 X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=493efb1bf764b6d082f7bea264b05b94bf72a74d;p=ack.git added EX_SIDEEFFECTS, options['p'] --> ! options['L'], fixed some bugs --- diff --git a/lang/cem/cemcom/Makefile.erik b/lang/cem/cemcom/Makefile.erik index de577f40b..0ba8e0f7a 100644 --- a/lang/cem/cemcom/Makefile.erik +++ b/lang/cem/cemcom/Makefile.erik @@ -14,7 +14,7 @@ LINT = /usr/new/lint SYSLIB = $(EMHOME)/modules/lib/libsystem.a EMKLIB = $(EMHOME)/modules/lib/libemk.a EMELIB = $(EMHOME)/modules/lib/libeme.a -STRLIB = $(EMHOME)/modules/lib/libstr.a +STRLIB = $(EMHOME)/modules/lib/libstring.a PRTLIB = $(EMHOME)/modules/lib/libprint.a EMMESLIB = $(EMHOME)/modules/lib/libem_mes.a INPLIB = $(EMHOME)/modules/lib/libinput.a diff --git a/lang/cem/cemcom/cemcom.1 b/lang/cem/cemcom/cemcom.1 index 64aa283ed..87c7f7665 100644 --- a/lang/cem/cemcom/cemcom.1 +++ b/lang/cem/cemcom/cemcom.1 @@ -42,8 +42,9 @@ set maximum identifier length to \fIn\fP. do not generate EM register messages. The user-declared variables are not stored into registers on the target machine. -.IP \fB\-p\fR -generate the EM \fBfil\fR and \fBlin\fR instructions in order to enable +.IP \fB\-L\fR +don't generate the EM \fBfil\fR and \fBlin\fR instructions +that usually are generated to enable an interpreter to keep track of the current location in the source code. .IP \fB\-P\fR like \fB\-E\fR but without #\fBline\fR control lines. diff --git a/lang/cem/cemcom/ch7.c b/lang/cem/cemcom/ch7.c index a4da640b6..bd7fcce2a 100644 --- a/lang/cem/cemcom/ch7.c +++ b/lang/cem/cemcom/ch7.c @@ -333,6 +333,7 @@ ch7asgn(expp, oper, expr) *expp = new_oper((*expp)->ex_type, *expp, oper, expr); #endif NOBITFIELD (*expp)->OP_TYPE = tp; /* for EVAL() */ + (*expp)->ex_flags |= EX_SIDEEFFECTS; } /* Some interesting (?) questions answered. diff --git a/lang/cem/cemcom/ch7bin.c b/lang/cem/cemcom/ch7bin.c index 90211bb6c..7f9ff0841 100644 --- a/lang/cem/cemcom/ch7bin.c +++ b/lang/cem/cemcom/ch7bin.c @@ -77,6 +77,7 @@ ch7bin(expp, oper, expr) else *expp = new_oper((*expp)->ex_type->tp_up, *expp, '(', expr); + (*expp)->ex_flags |= EX_SIDEEFFECTS; break; case PARCOMMA: /* RM 7.1 */ if ((*expp)->ex_type->tp_fund == FUNCTION) @@ -149,8 +150,8 @@ ch7bin(expp, oper, expr) } break; case LEFT: - case LEFTAB: case RIGHT: + case LEFTAB: case RIGHTAB: opnd2integral(expp, oper); opnd2integral(&expr, oper); diff --git a/lang/cem/cemcom/code.c b/lang/cem/cemcom/code.c index e7cadc6ae..688a338a6 100644 --- a/lang/cem/cemcom/code.c +++ b/lang/cem/cemcom/code.c @@ -201,7 +201,7 @@ begin_proc(name, def) /* to be called when entering a procedure */ lab_count = (label) 1; return_label = text_label(); return_expr_occurred = 0; - if (options['p']) { /* profiling */ + if (! options['L']) { /* profiling */ if (strcmp(last_fn_given, FileName) != 0) { /* previous function came from other file */ C_df_dlb(file_name_label = data_label()); @@ -479,7 +479,7 @@ code_expr(expr, val, code, tlbl, flbl) generator. If line number trace is wanted, it generates a lin instruction. EVAL() is called directly. */ - if (options['p']) /* profiling */ + if (! options['L']) /* profiling */ C_lin((arith)LineNumber); EVAL(expr, val, code, tlbl, flbl); } diff --git a/lang/cem/cemcom/domacro.c b/lang/cem/cemcom/domacro.c index ba92c11eb..cb8173f78 100644 --- a/lang/cem/cemcom/domacro.c +++ b/lang/cem/cemcom/domacro.c @@ -337,8 +337,10 @@ PRIVATE do_endif() { SkipRestOfLine(); - if (nestlevel-- < 0) + if (nestlevel < 0) { lexerror("#endif without corresponding #if"); + } + else nestlevel--; } PRIVATE diff --git a/lang/cem/cemcom/eval.c b/lang/cem/cemcom/eval.c index 12f924373..ee501954a 100644 --- a/lang/cem/cemcom/eval.c +++ b/lang/cem/cemcom/eval.c @@ -94,8 +94,10 @@ EVAL(expr, val, code, true_label, false_label) register struct expr *right = expr->OP_RIGHT; register struct type *tp = expr->OP_TYPE; - if (tp->tp_fund == ERRONEOUS) /* stop immediately */ + if (tp->tp_fund == ERRONEOUS || (expr->ex_flags & EX_ERROR)) { + /* stop immediately */ break; + } if (tp->tp_fund == VOID) gencode = 0; switch (oper) { @@ -298,15 +300,7 @@ EVAL(expr, val, code, true_label, false_label) C_bra(false_label); } else { - label l_true = text_label(); - label l_end = text_label(); - - compare(oper, l_true); - C_loc((arith)0); - C_bra(l_end); - C_df_ilb(l_true); - C_loc((arith)1); - C_df_ilb(l_end); + truthvalue(oper); } } break; @@ -384,9 +378,9 @@ EVAL(expr, val, code, true_label, false_label) load_val(left, RVAL); } else - if (left->ex_depth == 1 && left->OP_OPER == ARROW) { - compl = 1; /* Value->sel */ - ASSERT(left->OP_LEFT->ex_class == Value); + if (left->ex_depth == 1 && + !(left->ex_flags & EX_SIDEEFFECTS)) { + compl = 1; EVAL(left, RVAL, newcode, NO_LABEL, NO_LABEL); } else { @@ -662,6 +656,35 @@ compare(relop, lbl) } } +/* truthvalue() serves as an auxiliary function of EVAL */ +truthvalue(relop) + int relop; +{ + switch (relop) { + case '<': + C_tlt(); + break; + case LESSEQ: + C_tle(); + break; + case '>': + C_tgt(); + break; + case GREATEREQ: + C_tge(); + break; + case EQUAL: + C_teq(); + break; + case NOTEQUAL: + C_tne(); + break; + default: + CRASH(); + } +} + + /* assop() generates the opcode of an assignment operators op= */ assop(type, oper) register struct type *type; diff --git a/lang/cem/cemcom/expr.str b/lang/cem/cemcom/expr.str index c80f9a7ba..47d0f07c9 100644 --- a/lang/cem/cemcom/expr.str +++ b/lang/cem/cemcom/expr.str @@ -94,6 +94,7 @@ struct expr { #define EX_LOGICAL 0004 /* contains logical operator */ #define EX_COMMA 0010 /* contains expression comma */ #define EX_PARENS 0020 /* the top level is parenthesized */ +#define EX_SIDEEFFECTS 0040 /* expression has side effects */ #define EX_ERROR 0200 /* the expression is wrong */ #define NILEXPR ((struct expr *)0) diff --git a/lang/cem/cemcom/options.c b/lang/cem/cemcom/options.c index 38525c0f9..cebf13e12 100644 --- a/lang/cem/cemcom/options.c +++ b/lang/cem/cemcom/options.c @@ -115,7 +115,7 @@ do_option(text) break; case 'L' : - warning("-L: default no EM profiling; use -p for EM profiling"); + options['L'] = 1; /* no fil/lin */ break; case 'M': /* maximum identifier length */ @@ -126,10 +126,6 @@ do_option(text) fatal("maximum identifier length is %d", IDFSIZE); break; - case 'p' : /* generate profiling code (fil/lin) */ - options['p'] = 1; - break; - case 'P' : /* run preprocessor stand-alone, without #'s */ #ifndef NOPP options['E'] = 1; diff --git a/lang/cem/cemcom/replace.c b/lang/cem/cemcom/replace.c index 169f0a161..7f99c8797 100644 --- a/lang/cem/cemcom/replace.c +++ b/lang/cem/cemcom/replace.c @@ -155,7 +155,7 @@ macro2buffer(idef, actpars, siztext) /* copy the text of the actual parameter into the replacement text */ - for (p = actpars[n - 1]; p && *p; p++) { + for (p = actpars[n - 1]; *p; p++) { text[pos++] = *p; if (pos == size) text = Srealloc(text, size += RSTRSIZE);