Created
May 29, 2009 05:56
-
-
Save durka/119805 to your computer and use it in GitHub Desktop.
This file contains 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
(defn subleq | |
([in out mem regs] ; in this case data and program memory are the same | |
(apply subleq in out mem regs (subvec mem (:ip regs) (+ 3 (:ip regs))))) | |
([in out mem regs a b c] | |
(let [a-ind (if (neg? a) (nth mem (- a)) a) | |
b-ind (if (neg? b) (nth mem (- b)) b) | |
c-ind (if (neg? c) (nth mem (- c)) c) | |
mem (assoc mem b-ind | |
(- (mem b-ind) (mem a-ind)))] | |
[mem (assoc regs | |
:ip (if (pos? (mem b-ind)) | |
(+ 3 (:ip regs)) | |
c-ind) | |
:in (= b-ind in) | |
:out (= b-ind out))]))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment