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_class = Float;
exp->FL_VALUE = 0;
flt_arith2flt(exp->VL_VALUE, &(exp->FL_ARITH), uns);
exp->FL_DATLAB = 0;
}
else {
fp_used = 1;
@ -623,6 +621,4 @@ switch_sign_fp(expr)
register struct expr *expr;
{
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;
}
case Float:
if (!expr->FL_VALUE) {
expr->FL_VALUE = Malloc(FLT_STRLEN);
flt_flt2str(&(expr->FL_ARITH), expr->FL_VALUE, FLT_STRLEN);
}
print("%s\n", expr->FL_VALUE);
{
char buf[FLT_STRLEN];
flt_flt2str(&(expr->FL_ARITH), buf, FLT_STRLEN);
print("%s\n", buf);
break;
}
case Oper:
o = &expr->ex_object.ex_oper;
print("\n");

View file

@ -101,14 +101,12 @@ EVAL(expr, val, code, true_label, false_label)
case Float: /* a floating constant */
if (gencode) {
label datlab = data_label();
char buf[FLT_STRLEN];
fp_used = 1;
if (!expr->FL_VALUE) {
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_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_loi(expr->ex_type->tp_size);
}

View file

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

View file

@ -26,13 +26,6 @@ struct value {
struct string {
char *sg_value; /* row of bytes repr. the constant */
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 {
@ -60,7 +53,7 @@ struct expr {
union {
struct value ex_value;
struct string ex_string;
struct floating ex_float;
flt_arith ex_fl_arith;
struct oper ex_oper;
} ex_object;
};
@ -73,10 +66,7 @@ struct expr {
#define VL_LBL EX_VALUE.vl_data.vl_lbl
#define SG_VALUE ex_object.ex_string.sg_value
#define SG_LEN ex_object.ex_string.sg_len
#define SG_DATLAB ex_object.ex_string.sg_datlab
#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 FL_ARITH ex_object.ex_fl_arith
#define OP_TYPE ex_object.ex_oper.op_type
#define OP_LEFT ex_object.ex_oper.op_left
#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 */
crash("(fltcstoper) bad status");
}
if ((*expp)->FL_VALUE) free((*expp)->FL_VALUE);
(*expp)->FL_VALUE = 0;
if (compar) {
fill_int_expr(*expp, (arith)cmpval, INT);
} else {

View file

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