From: ceriel Date: Mon, 3 Oct 1988 10:09:19 +0000 (+0000) Subject: Coercion from int to float is now always done compile time X-Git-Tag: release-5-5~2816 X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=6b7a135b2b0c8f0dd1fb44a6d7f93d19bc2e9fc1;p=ack.git Coercion from int to float is now always done compile time --- diff --git a/lang/cem/cemcom/Makefile b/lang/cem/cemcom/Makefile index 74b5aacf1..5938cb1fd 100644 --- a/lang/cem/cemcom/Makefile +++ b/lang/cem/cemcom/Makefile @@ -51,9 +51,10 @@ GEN = $(EMHOME)/bin/LLgen GENOPTIONS = -v # Special #defines during compilation +PROF = #-pg CDEFS = $(EM_INCLUDES) $(LIB_INCLUDES) -CFLAGS = $(CDEFS) $(COPTIONS) -O -LDFLAGS = -i +CFLAGS = $(CDEFS) $(COPTIONS) -O $(PROF) +LDFLAGS = -i $(PROF) # Grammar files and their objects LSRC = tokenfile.g declar.g statement.g expression.g program.g ival.g diff --git a/lang/cem/cemcom/arith.c b/lang/cem/cemcom/arith.c index 04f9da612..5632e84e4 100644 --- a/lang/cem/cemcom/arith.c +++ b/lang/cem/cemcom/arith.c @@ -270,9 +270,22 @@ int2float(expp, tp) /* The expression *expp, which is of some integral type, is converted to the floating type tp. */ + register struct expr *exp = *expp; + char buf[32]; fp_used = 1; - *expp = arith2arith(tp, INT2FLOAT, *expp); + if (is_cp_cst(exp)) { + *expp = new_expr(); + **expp = *exp; + sprint(buf+1, "%ld", (long)(exp->VL_VALUE)); + buf[0] = '-'; + exp = *expp; + exp->ex_type = tp; + exp->ex_class = Float; + exp->FL_VALUE = Salloc(buf, (unsigned)strlen(buf)+1) + 1; + exp->FL_DATLAB = 0; + } + else *expp = arith2arith(tp, INT2FLOAT, *expp); } float2int(expp, tp) diff --git a/lang/cem/cemcom/ival.g b/lang/cem/cemcom/ival.g index 82a371e5e..3af7f1488 100644 --- a/lang/cem/cemcom/ival.g +++ b/lang/cem/cemcom/ival.g @@ -504,6 +504,13 @@ check_ival(expp, tp) #endif DEBUG if (expr->ex_class == Float) C_con_fcon(expr->FL_VALUE, expr->ex_type->tp_size); +#ifdef NOTDEF + +Coercion from int to float is now always done compile time. +This, to accept declarations like +double x = -(double)1; +and also to prevent runtime coercions for compile-time constants. + else if (expr->ex_class == Oper && expr->OP_OPER == INT2FLOAT) { /* float f = 1; */ @@ -514,6 +521,7 @@ check_ival(expp, tp) else illegal_init_cst(expr); } +#endif NOTDEF else illegal_init_cst(expr); break;