jed-users mailing list

[2002 Date Index] [2002 Thread Index] [Other years]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]

Re: Template function




On Tue, 3 Dec 2002, John E. Davis wrote:

> Paul Boekholt <p.boekholt@xxxxxxxxx> wrote:
> >      insert( () + () + () + "\n"); %apparently the () are filled right to left
> >    }
> >  pop_spot;
> >}
> >add_to_hook( "_jed_save_buffer_before_hooks", &save_point_hook);
> >
> >This raises a question with me: if you have a bunch of ()'s with operators
> >between them, in what order are values popped off the stack?
> 

Surely this can be written more graphically ?


> If you have:
> 
>     a;---------+
>     b;------+  |
>     c;--\   v  v
>     x = ()+()+();
> 

so it ends up being

>     x = (c)+(b)+(a);


> then the following code will get generated:
> 
>     PUSH a
>     PUSH b
>     PUSH c
>     POP _TMP2              ; _TMP2=c
>     POP _TMP1              ; _TMP1=b
>     PUSH _TMP1 + _TMP2     ; b+c
>     POP _TMP2              ; _TMP2=(b+c)
>     POP _TMP1              ; _TMP1=a
>     PUSH _TMP1 + _TMP2     ; a+(b+c)
>     POP x                  ; x=a+(b+c)
> 
> But:
> 
>     a;---------+
>     b;-----+   |
>     c;--\  v   v
>     x = ()*()+();
> 

which ends up being

>     x = (c)*(b)+(a);

which is equivalent to the below, but with (to my eye) a more obvious
correspondence between the () and the values.  I'm curious how
 x = ()+()*();  would be handled, and perhaps I'm wrong anyway?


> generates:
> 
>     PUSH a
>     PUSH b
>     PUSH c
>     POP _TMP2              ; _TMP2=c
>     POP _TMP1              ; _TMP1=b
>     PUSH _TMP1 + _TMP2     ; b*c
>     POP _TMP2              ; _TMP2=(b*c)
>     POP _TMP1              ; _TMP1=a
>     PUSH _TMP1 + _TMP2     ; a+(b*c)
>     POP x                  ; x=a+(b*c)
> 
> which is probably not the desired answer.  If you are in doubt, then I
> would avoid using the stack this way.
> 
> Thanks,
> --John
> 
> --------------------------
> To unsubscribe send email to <jed-users-request@xxxxxxxxxxx> with
> the word "unsubscribe" in the message body.
> Need help? Email <jed-users-owner@xxxxxxxxxxx>.
> 


--------------------------
To unsubscribe send email to <jed-users-request@xxxxxxxxxxx> with
the word "unsubscribe" in the message body.
Need help? Email <jed-users-owner@xxxxxxxxxxx>.


[2002 date index] [2002 thread index]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]