Created
October 29, 2010 13:00
-
-
Save jccc/653508 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (def ctl #{" > "}) | |
| (defn interpret [[regs branch] [op arg1 arg2 arg3]] | |
| ;(println op arg1 arg2 arg3 regs branch) | |
| (if branch | |
| (if (contains? ctl op) | |
| (case op | |
| " > " (if (> (regs arg1)(regs arg2)) | |
| [regs (not branch)] | |
| [regs branch])) | |
| [(assoc regs arg1 (case op | |
| "add" (+ (regs arg2) (regs arg3)) | |
| "sub" (- (regs arg2) (regs arg3)) | |
| "mul" (* (regs arg2) (regs arg3)) | |
| "div" (if (not (zero? (regs arg3))) | |
| (/ (regs arg2) (regs arg3)) | |
| (regs arg1)) | |
| "cpy" (regs arg2) | |
| "dec" (dec (regs arg1)) | |
| "inc" (inc (regs arg1)) | |
| :else (println "Error")) branch]) | |
| [regs (not branch)])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment