From f8c8d38ff2d74f1fec136626ce7946ceb40669fe Mon Sep 17 00:00:00 2001 From: Richard Harrington Date: Sun, 28 Jul 2013 15:00:05 -0400 Subject: [PATCH] got reading and evaling of operators working --- src/rw/core.clj | 8 +++++--- src/rw/exec.clj | 13 +++---------- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/rw/core.clj b/src/rw/core.clj index 5cfa85d..b258dc1 100644 --- a/src/rw/core.clj +++ b/src/rw/core.clj @@ -13,8 +13,10 @@ (def rc "AIM + 5 TO RADAR") (def rp (create/compile rc)) -(def rs (assoc-in (exec/init-robot rp) [:registers "AIM"] 6)) +(def t0 (assoc-in (exec/init-robot rp) [:registers "AIM"] 6)) -(def t0 (exec/tick-robot rs)) (def t1 (exec/tick-robot t0)) -(def t3 (exec/tick-robot t1)) +(def t2 (exec/tick-robot t1)) +(def t3 (exec/tick-robot t2)) + +(def iter (iterate exec/tick-robot t0)) diff --git a/src/rw/exec.clj b/src/rw/exec.clj index 68753d0..5d499ee 100644 --- a/src/rw/exec.clj +++ b/src/rw/exec.clj @@ -1,13 +1,12 @@ (ns rw.exec - (:require (rw [lexicon :as lexicon])) - (:use [clojure.pprint :only [pprint]])) + (:require (rw [lexicon :as lexicon]))) (def op-map (zipmap lexicon/op-commands (map (fn [op] (case op "/" #(int (Math/round (float (/ %1 %2)))) "#" not= - (read-string op))) + (-> op read-string eval))) lexicon/op-commands))) (defn resolve-register [registers reg] @@ -50,7 +49,6 @@ inc-instr-ptr #(assoc % :instr-ptr (inc instr-ptr)) skip-next-instr-ptr #(assoc % :instr-ptr (+ instr-ptr 2)) resolve #(resolve-arg % registers labels)] - ;(pprint [command (op-map command) acc arg (resolve arg)]) (case command "GOTO" (assoc state :instr-ptr (resolve arg)) "GOSUB" (assoc (assoc state :call-stack (conj call-stack (inc instr-ptr))) @@ -60,12 +58,7 @@ :instr-ptr (peek call-stack)) ("IF" ",") (inc-instr-ptr (assoc state :acc (resolve arg))) - ("+" "-" "*" "/") (do (pprint [(op-map command) - acc - (resolve arg) - state - (assoc state :acc ((op-map command) acc (resolve arg)))]) - (inc-instr-ptr (assoc state :acc ((op-map command) acc (resolve arg))))) + ("+" "-" "*" "/") (inc-instr-ptr (assoc state :acc ((op-map command) acc (resolve arg)))) ("=" ">" "<" "#") (if ((op-map command) acc (resolve arg)) (inc-instr-ptr state) (skip-next-instr-ptr state))