Tuesday, November 29, 2011

a lazy explicit evaluator - solution of SICP exercise 5.25

Modified the explicit evaluator to a lazy one. And here are the main blocks I added.

actual-value
    (save continue)
    (save env)
    (save exp)
    (assign continue (label force-it))
    (goto (label eval-dispatch))
force-it
    (test (op thunk?) (reg val))
    (branch (label thunk-extract))
    (restore exp)
    (restore env)
    (restore continue)
    (goto (reg continue))
thunk-extract
    (assign env (op thunk-env) (reg val))
    (assign exp (op thunk-exp) (reg val))
    (goto (label actual-value))

Here is the whole source file

No comments:

Post a Comment