diff options
| author | Kai Stevenson <kai@kaistevenson.com> | 2023-03-01 12:53:04 -0800 |
|---|---|---|
| committer | Kai Stevenson <kai@kaistevenson.com> | 2023-03-01 12:53:04 -0800 |
| commit | ce849baec2315755c599518fca79c895e8998be8 (patch) | |
| tree | 1fa3bea05bde5e1fdfadbb301368fe774e60b47e /src/eval.c | |
| parent | a3af974ab4e079f9000c4c34cd5ff468986ca609 (diff) | |
updated eq() function to handle types better
Diffstat (limited to 'src/eval.c')
| -rw-r--r-- | src/eval.c | 24 |
1 files changed, 12 insertions, 12 deletions
@@ -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); |
