On Dec 22, 12:27 pm, verec <jeanfrancois.brouil...@googlemail.com>
wrote:
> The design simplicity is certainly very appealing, though it appears
> that you can only operate on a predetermined fixed set of
> "registers" (ie: a and b in your example) and would need to define as
> many add_, sub_, mul_ ... variants as there are 'registers' in your
> model.
>
Yes, although we can generalize:

(defn addi [st reg i] {reg (+ (reg st) i)})
(defn subi [st reg i] {reg (- (reg st) i)})
(defn addr [st reg1 reg2] {reg1 (+ (reg1 st) (reg2 st))})

user=> (vm-exec [[:addi :a 1] [:addi :a 3] [:subi :b 1]
[:addr :a :b]])
{:b -1, :a 3}

> Also, simple arithmetic seems easy to implement, what about control
> flow (tests, branches, calls...) ?
Yes, the way I envisage it is to have explicit program counter and
then assume instructions just increments it unless they set a new
value for it. Instead of reduce in the vm-exec I have to loop and set
the pc after each instruction.

Cheers,

Robert

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to