• Re: EXECUTE implementation in native-code systems

    From albert@spenarnc.xs4all.nl@21:1/5 to dxforth@gmail.com on Mon Mar 17 12:54:53 2025
    In article <88dd79f886cd3b889c04f6fabb835587ce0cf724@i2pn2.org>,
    dxf <dxforth@gmail.com> wrote:
    On 17/03/2025 5:12 pm, Anton Ertl wrote:
    dxf <dxforth@gmail.com> writes:
    Would you agree 'nest-sys' are peculiar to colon definitions. That
    EXECUTE is a different class of function. It's not doing a 'call'
    as such and not leaving anything on the 'return stack'?

    That's certainly the case for threaded-code implementations.

    For native-code implementations the implementation of EXECUTE is
    usually an indirect call; sometimes an indirect tail-call, i.e. a
    jump.
    ...

    Yes. Also for optimizing native-code it may be 'xt EXECUTE' itself will
    be optimized away. Since the Standard doesn't specify a nest-sys in
    relation to EXECUTE we can safely assume there isn't one? If not, when
    would it be an issue?


    If xt is a dictionary level word, I can optimise
    ['] FORTHWORD EXECUTE
    by
    FORTHWORD
    This has nothing to do with threading, or native code.

    Groetjes Albert
    --
    Temu exploits Christians: (Disclaimer, only 10 apostles)
    Last Supper Acrylic Suncatcher - 15Cm Round Stained Glass- Style Wall
    Art For Home, Office And Garden Decor - Perfect For Windows, Bars,
    And Gifts For Friends Family And Colleagues.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Anton Ertl@21:1/5 to dxf on Mon Mar 17 17:46:56 2025
    dxf <dxforth@gmail.com> writes:
    Also for optimizing native-code it may be 'xt EXECUTE' itself will
    be optimized away.

    Yes:

    Gforth (development):
    : foo ['] . execute ; ok
    see foo
    : foo
    . ; ok

    That's a result of the constant-folding optimization. I wonder how
    often it triggers. Probably not much in real-world code.

    Since the Standard doesn't specify a nest-sys in
    relation to EXECUTE we can safely assume there isn't one?

    That's the question: The standard does not specify the nest-sys, so
    how can the native-code systems get away with implementing EXECUTE as
    call? It's because there is no standard way to observe the return
    address pushed by that call.

    The way the standard describes what happens corresponds to an
    indirect-threaded code system: EXECUTE does not push a return
    address/nest-sys, and for, e.g., constants, there is never a return
    address pushed. The initiation semantics of a colon definition (i.e.,
    docol) pushes the return address/nest-sys.

    Native-code systems deal with it a little differently, but that
    difference causes no standard-observable change in behaviour.

    - anton
    --
    M. Anton Ertl http://www.complang.tuwien.ac.at/anton/home.html
    comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
    New standard: https://forth-standard.org/
    EuroForth 2023 proceedings: http://www.euroforth.org/ef23/papers/
    EuroForth 2024 proceedings: http://www.euroforth.org/ef24/papers/

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From albert@spenarnc.xs4all.nl@21:1/5 to Anton Ertl on Tue Mar 18 11:17:14 2025
    In article <2025Mar17.184656@mips.complang.tuwien.ac.at>,
    Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote:
    dxf <dxforth@gmail.com> writes:
    Also for optimizing native-code it may be 'xt EXECUTE' itself will
    be optimized away.

    Yes:

    Gforth (development):
    : foo ['] . execute ; ok
    see foo
    : foo
    . ; ok

    That's a result of the constant-folding optimization. I wonder how
    often it triggers. Probably not much in real-world code.

    With good optimisers it can trigger often. You have revectored
    something. As least as the optimiser noticed the vector
    has been set and not changed this optimisation kicks in.
    This is a special case of:
    optimisation in Forth that notices that data fetched need not
    be fetched over again. This requires that analysis guarantees
    that the data cannot be changed. This is hard.

    - anton

    Groetjes Albert
    --
    Temu exploits Christians: (Disclaimer, only 10 apostles)
    Last Supper Acrylic Suncatcher - 15Cm Round Stained Glass- Style Wall
    Art For Home, Office And Garden Decor - Perfect For Windows, Bars,
    And Gifts For Friends Family And Colleagues.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)