Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.compilers > #1961

Re: Add nested-function support in a language the based on a stack-machine

Path csiph.com!weretis.net!feeder6.news.weretis.net!tncsrv06.tnetconsulting.net!news.snarked.org!border2.nntp.dca1.giganews.com!nntp.giganews.com!news.iecc.com!.POSTED.news.iecc.com!nerds-end
From George Neuner <gneuner2@comcast.net>
Newsgroups comp.compilers
Subject Re: Add nested-function support in a language the based on a stack-machine
Date Thu, 15 Feb 2018 11:41:43 -0500
Organization A noiseless patient Spider
Lines 73
Sender news@iecc.com
Approved comp.compilers@iecc.com
Message-ID <18-02-029@comp.compilers> (permalink)
References <18-02-009@comp.compilers> <18-02-012@comp.compilers> <18-02-016@comp.compilers> <18-02-018@comp.compilers> <18-02-023@comp.compilers>
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
Content-Transfer-Encoding 8bit
Injection-Info gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970"; logging-data="73098"; mail-complaints-to="abuse@iecc.com"
Keywords code
Posted-Date 17 Feb 2018 10:42:45 EST
X-submission-address compilers@iecc.com
X-moderator-address compilers-request@iecc.com
X-FAQ-and-archives http://compilers.iecc.com
Xref csiph.com comp.compilers:1961

Show key headers only | View raw


On Wed, 14 Feb 2018 18:06:40 +0000 (UTC), Kaz Kylheku
<217-679-0842@kylheku.com> wrote:

>On 2018-02-14, George Neuner <gneuner2@comcast.net> wrote:
>
>> As long as each function creates a new stack frame when called, then
>> recursion is not relevant and a single display is sufficient to handle
>> the nesting.
>>
>> The display tracks lexical parentage [who defined  who], not call
>> chain parentage.  Each display entry points to the stack frame of the
>> last function invoked that was defined at the corresponding lexical
>> level.
>>
>> The preamble of a function at, e.g., level 3, preserves display[3] in
>> its own stack frame, and sets display[3] to point to its own frame.
>> The postscript of the function restores the original display[3] value
>> when the function ends.
>> [Obviously, the compiler must keep track of lexical levels in order
>> that each function update the proper display entry.]
>
>Yes; it is clear that there can be a single display vector which is
>associated with the entire lexical scope as a whole, and then the
>local scopes just mutate the entries in the vector, taking care
>to save and restore them (which requires some local storage, by the
>way, but less than in the scheme I describe).
>
>The problem with this saving and restoring is that it's not thread safe.
>If there are multiple invocations of the p2 scope, and they can be
>entered by independent threads, we're in trouble if there is a single
>pointer to that scope in a single display.  (Excluding that from being a
>requirement is fairly reasonable.)
>
>The model I described simply replicates the display, allowing immutable
>local copies of it in each frame. When a scope is entered via
>indirection, it just installs a context pointer referencing the display.
>(Of course, that context pointer has to be saved and restored.
>It could just be the regular frame pointer, with the display being
>at some well known offset in the frame.)

I understand, and you're correct that the display needs to be counted
as part of the thread switch context.  But each thread also would be
using from a separate stack, so having the entire display saved in
each frame is overkill when all that's needed is a single pointer.

If you're suggesting that the stacks be shared among threads, then
you're no longer talking about "threads" per se, but rather about
"scheduler activations", which are subtly different from threads.
I'm not aware of any non-research system that is based on activations.


>> When a function at level 4 needs something at level 2, it just looks
>> to display[2] to find the proper stack frame.  Regardless of
>> intervening recursions, the lexical environment is maintained:
>> display[2] always will point to the latest invocation of the level 2
>> function which contains the current (level 4) function.
>
>(Under what I described, that display[2] is in that function's own
>display[] array rather than a shared one.  That display[2] is
>initialized and never mutated.)
>
>> No, you're missing something.  I just haven't figured out what.
>
>I'm missing the space optimization that a single display can be
>(serially) shared, in spite of multiple activations of scopes, as long
>as the entries are saved and restored.

No worries.  IME, displays don't get much respect from modern
textbooks - they are mentioned mostly in passing.  The basic problem
is that, while they are quite useful for an Algol-like language, they
can be problematic for an OO or functional language.

George

Back to comp.compilers | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Add nested-function support in a language the based on a stack-machine dror.openu@gmail.com - 2018-02-12 11:25 -0800
  Re: Add nested-function support in a language the based on a stack-machine dror.openu@gmail.com - 2018-02-12 14:16 -0800
    Re: Add nested-function support in a language the based on a stack-machine Hans-Peter Diettrich <DrDiettrich1@netscape.net> - 2018-02-13 12:10 +0100
  Re: Add nested-function support in a language the based on a stack-machine Louis Krupp <lkrupp@nospam.pssw.com.invalid> - 2018-02-13 00:42 -0700
    Re: Add nested-function support in a language the based on a stack-machine Kaz Kylheku <217-679-0842@kylheku.com> - 2018-02-14 00:59 +0000
      Re: Add nested-function support in a language the based on a stack-machine George Neuner <gneuner2@comcast.net> - 2018-02-13 22:04 -0500
        Re: Add nested-function support in a language the based on a stack-machine Kaz Kylheku <217-679-0842@kylheku.com> - 2018-02-14 18:06 +0000
          Re: Add nested-function support in a language the based on a stack-machine George Neuner <gneuner2@comcast.net> - 2018-02-15 11:41 -0500
            Re: Add nested-function support in a language the based on a stack-machine Kaz Kylheku <217-679-0842@kylheku.com> - 2018-02-17 16:13 +0000
              Re: Add nested-function support in a language the based on a stack-machine anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2018-02-17 16:39 +0000
                Re: Add nested-function support in a language the based on a stack-machine George Neuner <gneuner2@comcast.net> - 2018-03-01 13:48 -0500
                Re: Add nested-function support in a language the based on a stack-machine Kaz Kylheku <217-679-0842@kylheku.com> - 2018-03-01 19:26 +0000
                Re: Add nested-function support in a language the based on a stack-machine Kaz Kylheku <217-679-0842@kylheku.com> - 2018-03-02 00:38 +0000
                Re: Add nested-function support in a language the based on a stack-machine George Neuner <gneuner2@comcast.net> - 2018-03-02 02:48 -0500
                Re: Add nested-function support in a language the based on a stack-machine rpw3@rpw3.org (Rob Warnock) - 2018-03-03 16:00 +0000
                Re: Add nested-function support in a language the based on a stack-machine anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2018-03-02 09:30 +0000
                Re: Add nested-function support in a language the based on a stack-machine anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2018-03-05 15:01 +0000
                Re: Add nested-function support in a language the based on a stack-machine George Neuner <gneuner2@comcast.net> - 2018-03-05 15:51 -0500
                Re: Add nested-function support in a language the based on a stack-machine George Neuner <gneuner2@comcast.net> - 2018-03-05 14:39 -0500
                Re: Add nested-function support in a language the based on a stack-machine John Levine <johnl@taugh.com> - 2018-03-06 04:31 +0000
                Re: Add nested-function support in a language the based on a stack-machine Kaz Kylheku <217-679-0842@kylheku.com> - 2018-03-06 18:17 +0000
                Re: Add nested-function support in a language the based on a stack-machine Kaz Kylheku <157-073-9834@kylheku.com> - 2018-03-11 03:19 +0000
                Re: Add nested-function support in a language the based on a stack-machine Tomasz Kowaltowski <tk@ic.unicamp.br> - 2018-03-06 12:10 -0300
                Re: Add nested-function support in a language the based on a stack-machine bartc <bc@freeuk.com> - 2018-03-06 19:02 +0000
                Re: Add nested-function support in a language the based on a stack-machine antispam@math.uni.wroc.pl - 2018-04-29 16:29 +0000
              Re: Add nested-function support in a language the based on a stack-machine George Neuner <gneuner2@comcast.net> - 2018-03-01 13:49 -0500
    Re: Add nested-function support in a language the based on a stack-machine George Neuner <gneuner2@comcast.net> - 2018-02-13 22:37 -0500
  Re: Add nested-function support in a language the based on a stack-machine George Neuner <gneuner2@comcast.net> - 2018-02-13 23:27 -0500
  Re: Add nested-function support in a language the based on a stack-machine Shoefoot <shoefoot@gmail.com> - 2018-02-14 12:27 -0800

csiph-web