From ce849baec2315755c599518fca79c895e8998be8 Mon Sep 17 00:00:00 2001 From: Kai Stevenson Date: Wed, 1 Mar 2023 12:53:04 -0800 Subject: updated eq() function to handle types better --- src/eval.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'src/eval.c') diff --git a/src/eval.c b/src/eval.c index 8adcf8c..081f098 100644 --- a/src/eval.c +++ b/src/eval.c @@ -128,43 +128,43 @@ sym_t* try_eval_internal(sym_t* symbol, hashtable_t* symbolScope) { return init_sym_int(1); } else if (hash == get_hash("eq")) { - litType_t type = NO_TYPE; + litType_t firstType = NO_TYPE; int firstInt = 0; float firstFloat = 0; char* firstString; for (int i = 0; i < symbol->argCount; i++) { sym_t* v = eval(symbol->args[i], symbolScope); /* initialize */ - if (type == NO_TYPE) { - type = v->litType; - if (type == INT) { + if (firstType == NO_TYPE) { + firstType = v->litType; + if (firstType == INT) { firstInt = symtoi(v); } - else if (type == FLOAT) { + else if (firstType == FLOAT) { firstFloat = symtof(v); } - else if (type == STRING) { + else if (firstType == STRING) { firstString = symtos(v); } destroy_sym(v); } else { /* interpret type */ - if (type == INT) { + if (v->litType == INT) { int si = symtoi(v); destroy_sym(v); - if (si != firstInt) { + if (si != (firstType == FLOAT ? firstFloat : firstInt)) { return init_sym_int(0); } } - else if (type == FLOAT) { + else if (v->litType == FLOAT) { float sf = symtof(v); destroy_sym(v); - if (sf != firstFloat) { + if (sf != (firstType == FLOAT ? firstFloat : firstInt)) { return init_sym_int(0); } } - else if (type == STRING) { + else if (v->litType == STRING) { char* ss = symtos(v); if (strcmp(ss, firstString) != 0) { destroy_sym(v); @@ -175,7 +175,7 @@ sym_t* try_eval_internal(sym_t* symbol, hashtable_t* symbolScope) { } } } - if (type == STRING) { + if (firstType == STRING) { free(firstString); } return init_sym_int(1); -- cgit v1.3.1