Simplify type coercion in condition evaluation

Change nstr_mkselval() to generate values with promoted types only,
and replace nstr_coerce_val() by new and simpler nstr_optype() in
nstr_comp().

Replace the only remaining use of nstr_coerce_val() in surv() by
nstr_promote(), and remove nstr_coerce_val().

This loses one half of the unimplemented sketch of coercions to
NSC_STRING.  Drop the other half from nstr_exec_val().
This commit is contained in:
Markus Armbruster 2008-12-27 16:59:53 +01:00
parent d2fba584e8
commit 9115c03949
4 changed files with 36 additions and 90 deletions

View file

@ -66,8 +66,7 @@ nstr_mksymval(struct valstr *val, struct castr *ca, int idx)
* PTR points to a context object of the type that was used to compile
* the value.
* Unless WANT is NSC_NOTYPE, coerce the value to promoted value type
* WANT. VAL must be coercible. That's the case if a previous
* nstr_coerce_val(VAL, WANT, STR) succeeded.
* WANT. VAL must be coercible.
*/
struct valstr *
nstr_exec_val(struct valstr *val, natid cnum, void *ptr, enum nsc_type want)
@ -186,6 +185,7 @@ nstr_exec_val(struct valstr *val, natid cnum, void *ptr, enum nsc_type want)
valtype = NSC_NOTYPE;
}
/* coerce */
if (valtype == want)
;
else if (want == NSC_DOUBLE) {
@ -193,8 +193,7 @@ nstr_exec_val(struct valstr *val, natid cnum, void *ptr, enum nsc_type want)
valtype = want;
val->val_as.dbl = val->val_as.lng;
}
} else if (want == NSC_STRING)
CANT_REACH(); /* FIXME implement */
}
if (CANT_HAPPEN(valtype != want && want != NSC_NOTYPE)) {
/* make up an error value */