mirror of
https://github.com/richardharrington/robotwar.git
synced 2024-07-11 21:28:57 +00:00
got reading and evaling of operators working
This commit is contained in:
parent
bab5171d80
commit
f8c8d38ff2
@ -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))
|
||||
|
@ -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))
|
||||
|
Loading…
Reference in New Issue
Block a user