~akarle/fisl

aac74e196655b29072cf69f17b81b9416dbd15e2 — Alex Karle 2 years ago 75369e7
interpreter: Fix assignment not evaluating RHS

This was a funny find :)

Before

$ ./fisl.scm
> var x = 1;
> print x = 1 + 1;
(+ 1 1)

After:
> var x;
> print x = 1 + 1;
2
> print x;
2
1 files changed, 3 insertions(+), 3 deletions(-)

M interpreter.scm
M interpreter.scm => interpreter.scm +3 -3
@@ 44,9 44,9 @@
   ((assignment? expr)
    (let ((tok (assignment-name expr)))
      (if (hash-table-exists? global-env (token-lexeme tok))
        (begin
          (hash-table-set! global-env (token-lexeme tok) (assignment-value expr))
          (assignment-value expr))
        (let ((res (evaluate (assignment-value expr))))
          (hash-table-set! global-env (token-lexeme tok) res)
          res)
        (runtime-err! (format "Unbound variable ~A at line ~A"
                              (token-lexeme tok) (token-line tok))))))
   ((unary? expr)