Hi<div><br></div><div>Sorry but I found that what I wrote about macros is non-sense in most times</div><div><br></div><div>i have to be more careful and it is better that I ponder twice before i write something</div><div><br>
</div><div>sorry again, I have to go back to my books and be more careful on details this time</div><div><br></div><div>PS: i decided to use a vector of functions in my simulator</div><div><br></div><div>Kind regards</div>
<div>Taoufik<br><br><div class="gmail_quote">On Wed, Dec 8, 2010 at 11:02 PM, Taoufik Dachraoui <span dir="ltr"><<a href="mailto:dachraoui.taoufik@gmail.com">dachraoui.taoufik@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
I think that I will use a vector with body of code, and a macro, as my tests show it is 3 times faster<div>than having a compiled lambdas that I funcall.</div><div><br></div><div>It is something like the following:</div><div>
(defvar *opcode* 0)</div><div>(defvar *codes* (make-array 100 :element-type 'cons))</div><div>(defmacro run-inst () `,(svref *codes* *opcode*))</div><div>(setf (svref *codes* 10) '(setf r3 (+ r1 r2))) ; add</div>
<div>(setf (svref *codes* 20) '(setf r3 (* r1 r2))) ; mul</div><div><div>(setf *opcode* 10) ; addition</div><div>(run-inst)</div><div><div>(setf *opcode* 20) ; multiplication</div><div>(run-inst)</div><div>....</div>
<div>
<br></div><div>The tests in my previous posting show that using a vector and a macro </div><div>is 3 times faster than using compiled lambdas</div><div><br></div></div></div><div>Kind regards</div><div>Taoufik<div><div></div>
<div class="h5"><br><div><br>
</div><div><br><div class="gmail_quote">On Wed, Dec 8, 2010 at 10:33 PM, Robert Goldman <span dir="ltr"><<a href="mailto:rpgoldman@sift.info" target="_blank">rpgoldman@sift.info</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>On 12/8/10 Dec 8 -3:20 PM, Taoufik Dachraoui wrote:<br>
> I am writing a compiler for a pure functional language with completely<br>
> lazy evaluation (sharing).<br>
><br>
> The compiler generates binary code for a virtual machine. I am trying to<br>
> implement a simulator for it.<br>
><br>
> It is easy to implement the simulator using cond (or ecase), but I<br>
> thought if it does not cost me<br>
> time why not implement it more efficiently. So, for performance issues I<br>
> would like the simulator,<br>
> for each encountered instruction (the opcode is represented by 1 byte),<br>
> to directly jump to the<br>
> corresponding code.<br>
<br>
</div>Apologies if I'm being foolish, but why can't you just make a vector<br>
that's full of thunks (compiled lambdas of no arguments)?<br>
<br>
Best,<br>
<font color="#888888">r<br>
</font></blockquote></div><br></div></div></div></div>
</blockquote></div><br></div>