simplified compile time floating point somewhat

This commit is contained in:
ceriel 1991-01-15 18:21:16 +00:00
parent 0267340564
commit e7b7aa3944
7 changed files with 17 additions and 39 deletions

View file

@ -379,9 +379,7 @@ int2float(expp, tp)
exp->ex_type = tp; exp->ex_type = tp;
exp->ex_class = Float; exp->ex_class = Float;
exp->FL_VALUE = 0;
flt_arith2flt(exp->VL_VALUE, &(exp->FL_ARITH), uns); flt_arith2flt(exp->VL_VALUE, &(exp->FL_ARITH), uns);
exp->FL_DATLAB = 0;
} }
else { else {
fp_used = 1; fp_used = 1;
@ -623,6 +621,4 @@ switch_sign_fp(expr)
register struct expr *expr; register struct expr *expr;
{ {
flt_umin(&(expr->FL_ARITH)); flt_umin(&(expr->FL_ARITH));
if (expr->FL_VALUE) free(expr->FL_VALUE);
expr->FL_VALUE = 0;
} }

View file

@ -480,12 +480,13 @@ p1_expr(lvl, expr)
break; break;
} }
case Float: case Float:
if (!expr->FL_VALUE) { {
expr->FL_VALUE = Malloc(FLT_STRLEN); char buf[FLT_STRLEN];
flt_flt2str(&(expr->FL_ARITH), expr->FL_VALUE, FLT_STRLEN);
} flt_flt2str(&(expr->FL_ARITH), buf, FLT_STRLEN);
print("%s\n", expr->FL_VALUE); print("%s\n", buf);
break; break;
}
case Oper: case Oper:
o = &expr->ex_object.ex_oper; o = &expr->ex_object.ex_oper;
print("\n"); print("\n");

View file

@ -101,14 +101,12 @@ EVAL(expr, val, code, true_label, false_label)
case Float: /* a floating constant */ case Float: /* a floating constant */
if (gencode) { if (gencode) {
label datlab = data_label(); label datlab = data_label();
char buf[FLT_STRLEN];
fp_used = 1; fp_used = 1;
if (!expr->FL_VALUE) { flt_flt2str(&(expr->FL_ARITH), buf, FLT_STRLEN);
expr->FL_VALUE = Malloc(FLT_STRLEN);
flt_flt2str(&(expr->FL_ARITH), expr->FL_VALUE, FLT_STRLEN);
}
C_df_dlb(datlab); C_df_dlb(datlab);
C_rom_fcon(expr->FL_VALUE, expr->ex_type->tp_size); C_rom_fcon(buf, expr->ex_type->tp_size);
C_lae_dlb(datlab, (arith)0); C_lae_dlb(datlab, (arith)0);
C_loi(expr->ex_type->tp_size); C_loi(expr->ex_type->tp_size);
} }

View file

@ -223,7 +223,6 @@ string2expr(expp, str, len)
ex->ex_class = String; ex->ex_class = String;
ex->SG_VALUE = str; ex->SG_VALUE = str;
ex->SG_LEN = len; ex->SG_LEN = len;
/* ex->SG_DATLAB = 0; */
} }
int2expr(expr) int2expr(expr)
@ -258,12 +257,11 @@ float2expr(expr)
crash("(float2expr) bad fund %s\n", symbol2str(fund)); crash("(float2expr) bad fund %s\n", symbol2str(fund));
} }
expr->ex_class = Float; expr->ex_class = Float;
expr->FL_VALUE = dot.tk_fval; flt_str2flt(dot.tk_fval, &(expr->FL_ARITH));
flt_str2flt(expr->FL_VALUE, &(expr->FL_ARITH)); free(dot.tk_fval);
ASSERT(flt_status != FLT_NOFLT); ASSERT(flt_status != FLT_NOFLT);
if (flt_status == FLT_OVFL) if (flt_status == FLT_OVFL)
expr_warning(expr,"internal floating point overflow"); expr_warning(expr,"internal floating point overflow");
expr->FL_DATLAB = 0;
} }
struct expr* struct expr*
@ -501,8 +499,6 @@ free_expression(expr)
/* The expression expr is freed recursively. /* The expression expr is freed recursively.
*/ */
if (expr) { if (expr) {
if (expr->ex_class == Float && expr->FL_VALUE)
free(expr->FL_VALUE);
if (expr->ex_class == Oper) { if (expr->ex_class == Oper) {
free_expression(expr->OP_LEFT); free_expression(expr->OP_LEFT);
free_expression(expr->OP_RIGHT); free_expression(expr->OP_RIGHT);

View file

@ -26,13 +26,6 @@ struct value {
struct string { struct string {
char *sg_value; /* row of bytes repr. the constant */ char *sg_value; /* row of bytes repr. the constant */
int sg_len; /* length of the row */ int sg_len; /* length of the row */
label sg_datlab; /* global data-label */
};
struct floating {
char *fl_value; /* pointer to string repr. the fp const. */
flt_arith fl_arith; /* the value in high precision */
label fl_datlab; /* global data_label */
}; };
struct oper { struct oper {
@ -60,7 +53,7 @@ struct expr {
union { union {
struct value ex_value; struct value ex_value;
struct string ex_string; struct string ex_string;
struct floating ex_float; flt_arith ex_fl_arith;
struct oper ex_oper; struct oper ex_oper;
} ex_object; } ex_object;
}; };
@ -73,10 +66,7 @@ struct expr {
#define VL_LBL EX_VALUE.vl_data.vl_lbl #define VL_LBL EX_VALUE.vl_data.vl_lbl
#define SG_VALUE ex_object.ex_string.sg_value #define SG_VALUE ex_object.ex_string.sg_value
#define SG_LEN ex_object.ex_string.sg_len #define SG_LEN ex_object.ex_string.sg_len
#define SG_DATLAB ex_object.ex_string.sg_datlab #define FL_ARITH ex_object.ex_fl_arith
#define FL_VALUE ex_object.ex_float.fl_value
#define FL_ARITH ex_object.ex_float.fl_arith
#define FL_DATLAB ex_object.ex_float.fl_datlab
#define OP_TYPE ex_object.ex_oper.op_type #define OP_TYPE ex_object.ex_oper.op_type
#define OP_LEFT ex_object.ex_oper.op_left #define OP_LEFT ex_object.ex_oper.op_left
#define OP_OPER ex_object.ex_oper.op_oper #define OP_OPER ex_object.ex_oper.op_oper

View file

@ -91,8 +91,6 @@ fltcstbin(expp, oper, expr)
default: /* there can't be another status */ default: /* there can't be another status */
crash("(fltcstoper) bad status"); crash("(fltcstoper) bad status");
} }
if ((*expp)->FL_VALUE) free((*expp)->FL_VALUE);
(*expp)->FL_VALUE = 0;
if (compar) { if (compar) {
fill_int_expr(*expp, (arith)cmpval, INT); fill_int_expr(*expp, (arith)cmpval, INT);
} else { } else {

View file

@ -514,11 +514,10 @@ check_ival(expp, tp)
print_expr("init-expr after cast", expr); print_expr("init-expr after cast", expr);
#endif DEBUG #endif DEBUG
if (expr->ex_class == Float) { if (expr->ex_class == Float) {
if (!expr->FL_VALUE) { char buf[FLT_STRLEN];
expr->FL_VALUE = Malloc(FLT_STRLEN);
flt_flt2str(&(expr->FL_ARITH), expr->FL_VALUE, FLT_STRLEN); flt_flt2str(&(expr->FL_ARITH), buf, FLT_STRLEN);
} C_con_fcon(buf, expr->ex_type->tp_size);
C_con_fcon(expr->FL_VALUE, expr->ex_type->tp_size);
} }
#ifdef NOTDEF #ifdef NOTDEF