Re: compiling the instructions of a simple vm into a function

2010-06-19 Thread Nicolas Oury
There is two way to make a domain-specific language with a clojure back-end : - if you want the language to be an extension of Clojure, still to be used in a REPL or by clojure source -> you write macros. That's what I call embedded. There is a lot of litterature on Embedded Domain Specific

Re: compiling the instructions of a simple vm into a function

2010-06-18 Thread Eugen Dück
Thanks Nicolas, your first variant resembles the generated code much closer than my initial approach, which is great. I need the eval though, to be able to pass in non literals. In my real program I'm reading the instructions from a binary file. So if I want to be able to do something like this:

Re: compiling the instructions of a simple vm into a function

2010-06-18 Thread Nicolas Oury
First a simple version, equivalent to yours but more readable. (defmacro compile-instructions [instructions] (let [memory (gensym "memory-")] `(fn [~memory] ~@(map (fn [[op m1 m2]] `(aset ~memory ~m1 (~op (aget ~memory ~m1) (aget ~memory ~m2 inst

compiling the instructions of a simple vm into a function

2010-06-18 Thread Eugen Dück
Recently, I implemented last year's ICFP problem. Part of it is writing a VM that consists of memory slots, some registers and input and input ports. It takes a list of instructions, works them off one after the other, reading from input or memory, calculating something and the changing registers o