<div dir="ltr">I am not expecting the compiler to use consing, I want to do the same thing as the compiler is doing, how to do it?<div><br></div><div>Taoufik</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">
On Tue, May 14, 2013 at 6:01 PM, Tom Emerson <span dir="ltr"><<a href="mailto:tremerson@gmail.com" target="_blank">tremerson@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">If you disassemble your fact function you'll see that there is no consing going on: the machine stack is being used directly. I'm not sure why you would expect the compiler to use conses for this.<div>
<br></div></div><div class="gmail_extra"><div><div class="h5"><br><br><div class="gmail_quote">On Tue, May 14, 2013 at 11:52 AM, Taoufik Dachraoui <span dir="ltr"><<a href="mailto:dachraoui.taoufik@gmail.com" target="_blank">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"><div dir="ltr">What is not true? I am not saying that stacks are conses; we can push and pop elements from a stack and macroexpanding (PUSH 1 X) gives (SETQ X (CONS 1 X)); so the stack, used by pop/push, in CCL is implemented<div>
using conses; we can implement stacks using arrays (no consing) if we wish so.<div><div><br></div><div>Now, the reason I am asking, is that I am implementing an interpreter for a small language and I am using 3 stacks with a lot of consing. I wanted to find a solution so that I can avoid consing; I recalled when we call a function the passed parameters are pushed into a stack (implemented with registers ESP/EBP), I am wondering if I can find a way to use the processor's stack as for function calls to avoid consing.</div>
<div><br></div><div>Or, how do you implement a VM using CCL for a new language? (any thing offered by CCL even if it is not</div><div>standard would be acceptable).</div><span><font color="#888888"><div><br>
</div><div>Taoufik</div><div><br></div></font></span></div>
</div></div><div><div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, May 14, 2013 at 5:12 PM, Ron Garret <span dir="ltr"><<a href="mailto:ron@flownet.com" target="_blank">ron@flownet.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">This kind of question is better posed to a general Lisp newsgroup. This list is specific to CCL (f.k.a. OpenMCL).<br>
<br>
But the answer is simple:<br>
<div><br>
> pushing an element on the stack, (PUSH 1 X) is equivalent<br>
> to (SETQ X (CONS 1 X)),<br>
<br>
</div>That is not true. Stacks and cons cells are fundamentally different data structures. You can build a stack out of cons cells, but you can't build cons cells out of a stack. A stack is *strictly* a last-in-first-out data structure, which is the reason it doesn't need to be garbage collected.<br>
<span><font color="#888888"><br>
rg<br>
</font></span><div><div><br>
On May 14, 2013, at 3:37 AM, Taoufik Dachraoui wrote:<br>
<br>
> Hi<br>
><br>
> This is probably simple but I could not figure out the explanation, I hope that<br>
> someone could help me out<br>
><br>
> CL-USER> (defun fac (n) (if (= n 0) 1 (* n (fac (- n 1)))))<br>
> FAC<br>
> CL-USER> (time (fac 3))<br>
> (FAC 3)<br>
> took 0 milliseconds (0.000 seconds) to run.<br>
> During that period, and with 1 available CPU core,<br>
> 0 milliseconds (0.000 seconds) were spent in user mode<br>
> 0 milliseconds (0.000 seconds) were spent in system mode<br>
> 6<br>
><br>
> As you can see, there is no consing when FAC is called<br>
><br>
> Now, knowing that pushing an element on the stack, (PUSH 1 X) is equivalent<br>
> to (SETQ X (CONS 1 X)), and since FAC is using a stack and thus pushing<br>
> values on the stack why there is no consing when (FAC 3) is called?<br>
><br>
> I believe there is a simple explanation but I could not figure it out<br>
><br>
> Kind regards<br>
> Taoufik<br>
><br>
</div></div><div><div>> _______________________________________________<br>
> Openmcl-devel mailing list<br>
> <a href="mailto:Openmcl-devel@clozure.com" target="_blank">Openmcl-devel@clozure.com</a><br>
> <a href="http://clozure.com/mailman/listinfo/openmcl-devel" target="_blank">http://clozure.com/mailman/listinfo/openmcl-devel</a><br>
<br>
</div></div></blockquote></div><br></div>
</div></div><br>_______________________________________________<br>
Openmcl-devel mailing list<br>
<a href="mailto:Openmcl-devel@clozure.com" target="_blank">Openmcl-devel@clozure.com</a><br>
<a href="http://clozure.com/mailman/listinfo/openmcl-devel" target="_blank">http://clozure.com/mailman/listinfo/openmcl-devel</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div></div></div><span class="HOEnZb"><font color="#888888">-- <br>Tom Emerson<br><a href="mailto:tremerson@gmail.com" target="_blank">tremerson@gmail.com</a><br><a href="http://www.dreamersrealm.net/tree" target="_blank">http://www.dreamersrealm.net/tree</a>
</font></span></div>
</blockquote></div><br></div>