Yes, you are right! But the Wikipedia article talks about many
different techniques. It talks about storing subroutine addresses into
arrays and having the system execute code by calling each of those
addresses in turn, like a byte-code interpreter. That's not what
Factor does because indirectly calling addresses in arrays is bad for
performance.

The method Factor uses is to generate one CALL instruction for each
word in the quotation being compiled. It's a really trivial technique.
A quotation like [ word-a word-b + ] would become roughly:

    (word-prologue)
    CALL address-of(word-a)
    CALL address-of(word-b)
    (word-epilogue)
    JMP address-of(+)

2017-02-01 3:13 GMT+01:00 Levi Pearson <levipear...@gmail.com>:
> https://concatenative.org/wiki/view/Factor/Non-optimizing%20compiler
>
> Apparently the JIT for the interactive non-optimizing compiler generates
> subroutine threaded code with some inlining.
>
> I wouldn't call it a compiler optimization; maybe an interpreter
> optimization or a simple compiling technique. I think you hear about it a
> lot with respect to Forth and its family because of the proportion of Forth
> users who implemented the language or at least learned how it was
> implemented, although often modern Forth implementations have optimizing
> compilers. But the earliest academic reference I've seen for threaded code
> was in reference to a Fortran compiler for the PDP-11:
> http://home.claranet.nl/users/mhx/Forth_Bell.pdf
>
> I'm pretty sure that 1971 article was more of a description of a technique
> already widely in practice (i.e. a description of "folklore") rather than a
> new invention, so it's definitely been around a whlie.
>
> I wrote a simple threaded code interpreter in C as an exercise to understand
> them better a while back; including some conditionally-compiled debug code
> and a fairly small complement of core Forth words and an outer interpreter
> loop, it's still well under 1k lines of source.
>
>     --Levi
>
> On Tue, Jan 31, 2017 at 3:23 PM, Björn Lindqvist <bjou...@gmail.com> wrote:
>>
>> Probably not! I've never heard of that technique. From skimming that
>> Wikipedia article it seem to be a compiler optimization invented a
>> long time ago. We have an instruction called ##dispatch, used for
>> method dispatching, but it is not nearly as dynamic as the method
>> described. Probably for the best because on modern processors jumping
>> to addresses kept in memory or in registers is very bad for
>> performance.
>>
>>
>> 2017-01-31 21:11 GMT+01:00 Alexander Ilin <ajs...@yandex.ru>:
>> > Hello!
>> >
>> >   Does Factor use threaded code in any way?
>> >   https://en.wikipedia.org/wiki/Threaded_code
>> >
>
>
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, SlashDot.org! http://sdm.link/slashdot
> _______________________________________________
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk
>



-- 
mvh/best regards Björn Lindqvist

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to