jed-users mailing list

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

Re: Template function


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?

If you have:

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

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;
    x = ()*()+();

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>.


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