diff options
author | Clyne Sullivan <clyne@bitgloo.com> | 2018-03-28 11:56:35 -0400 |
---|---|---|
committer | Clyne Sullivan <clyne@bitgloo.com> | 2018-03-28 11:56:35 -0400 |
commit | 7faeef296d8b0041ae340c3febf7eb0a78e60b0f (patch) | |
tree | 2527c849fc6c843752abac8229178b941716e88c /parser.c | |
parent | 2f3ffd11097470095d8e5d7c989ce201d9d6d011 (diff) |
allow solve to error safely
Diffstat (limited to 'parser.c')
-rw-r--r-- | parser.c | 25 |
1 files changed, 19 insertions, 6 deletions
@@ -290,12 +290,13 @@ int idoline(instance *it, const char *s) return 0; it->lines[it->lnidx] = ops; + variable **copy; loop: - if (it->ret != 0) - itryfree(it->ret); - it->ret = 0; + //if (it->ret != 0) + // itryfree(it->ret); + //it->ret = 0; - variable **copy = (variable **)malloc(32 * sizeof(variable *)); + copy = (variable **)malloc(32 * sizeof(variable *)); for (int i = 0; i < 32; i++) { variable *v = it->lines[it->lnidx][i]; if (v != 0) { @@ -317,8 +318,15 @@ loop: } } it->ret = isolve(it, copy, 0); - if (it->ret == 0) + if (it->ret == 0) { idelline(copy); + } else { + variable *ret = igetvar(it, "ANS"); + ret->type = it->ret->type; + ret->value.p = it->ret->value.p; + it->ret = ret; + } + free(copy); it->lnidx++; @@ -580,7 +588,12 @@ variable **iparse(instance *it, const char *s) goto fail; } else { if (ooffset == 0) { - ops[ooffset++] = make_varf(0, 0.0f); + variable *a; + if (it->ret != 0) + a = it->ret; + else + a = make_varf(0, 0.0f); + ops[ooffset++] = a; } else if (ops[ooffset - 1]->type == OPERATOR) { free(word); goto fail; |