local buffers and tail-call optimization
  Home FAQ Contact Sign in
comp.lang.forth only
 
Advanced search
POPULAR GROUPS

more...

comp.lang.forth Profile…
 Up
local buffers and tail-call optimization         


Author: Anton Ertl
Date: Aug 29, 2008 05:20

If a Forth system supports local buffers (or another locals extension
that produces addresses of local memory, e.g., Gforth's
variable-flavoured locals), then it has to define the lifetime of the
memory the address points to. Typically the lifetime will be until
the end of the definition that the buffer was defined in.

This inhibits tail-call optimization; consider:

: bar ( addr -- )
... ;

: foo { | [ 1 ] x } x bar ;

in the syntax proposed by Stephen Pelc or

: foo 1 lbuffer bar ;

in a syntax suggested by others. The allocated buffer must stay alive
across the call to BAR, because it is used in BAR, so the deallocation
of the buffer must happen after the call to BAR, and BAR is no longer
a tail-call and can therefore not be optimized.

Consider the contrast to ordinary (value-flavoured locals):

: flip { a } a bar ;
Show full article (1.67Kb)
5 Comments
Re: local buffers and tail-call optimization         


Author: Stephen Pelc
Date: Aug 29, 2008 07:34

On Fri, 29 Aug 2008 12:20:25 GMT, anton@mips.complang.tuwien.ac.at
(Anton Ertl) wrote:
>If a Forth system supports local buffers (or another locals extension
>that produces addresses of local memory, e.g., Gforth's
>variable-flavoured locals), then it has to define the lifetime of the
>memory the address points to. Typically the lifetime will be until
>the end of the definition that the buffer was defined in.
>
>This inhibits tail-call optimization; consider:
>
>: bar ( addr -- )
> ... ;
>
>: foo { | [ 1 ] x } x bar ;
>
>in the syntax proposed by Stephen Pelc or
>
>: foo 1 lbuffer bar ;
Show full article (1.60Kb)
no comments
Re: local buffers and tail-call optimization         


Author: Anton Ertl
Date: Aug 30, 2008 01:02

stephenXXX@mpeforth.com (Stephen Pelc) writes:
>On Fri, 29 Aug 2008 12:20:25 GMT, anton@mips.complang.tuwien.ac.at
>(Anton Ertl) wrote:
>
>>If a Forth system supports local buffers (or another locals extension
>>that produces addresses of local memory, e.g., Gforth's
>>variable-flavoured locals), then it has to define the lifetime of the
>>memory the address points to. Typically the lifetime will be until
>>the end of the definition that the buffer was defined in.
>>
>>This inhibits tail-call optimization; consider:
>>
>>: bar ( addr -- )
>> ... ;
>>
>>: foo { | [ 1 ] x } x bar ;
>>
>>in the syntax proposed by Stephen Pelc or
>>
>>: foo 1 lbuffer bar ; ...
Show full article (2.14Kb)
no comments
Re: local buffers and tail-call optimization         


Author: Peter Fälth
Date: Aug 30, 2008 01:49

On Aug 30, 10:02 am, an...@mips.complang.tuwien.ac.at (Anton Ertl)
wrote:
> stephen...@mpeforth.com (Stephen Pelc) writes:
>>On Fri, 29 Aug 2008 12:20:25 GMT, an...@mips.complang.tuwien.ac.at
>>(Anton Ertl) wrote:
>
>>>If a Forth system supports local buffers (or another locals extension
>>>that produces addresses of local memory, e.g., Gforth's
>>>variable-flavoured locals), then it has to define the lifetime of the
>>>memory the address points to.  Typically the lifetime will be until
>>>the end of the definition that the buffer was defined in.
>
>>>This inhibits tail-call optimization; consider:
>
>>>: bar ( addr -- )
>>>  ... ;
>
>>>: foo { | [ 1 ] x } x bar ;
>
>>>in the syntax proposed by Stephen Pelc or ...
Show full article (3.85Kb)
no comments
Re: local buffers and tail-call optimization         


Author: Andrew Haley
Date: Sep 3, 2008 11:22

Anton Ertl mips.complang.tuwien.ac.at> wrote:
> If a Forth system supports local buffers (or another locals extension
> that produces addresses of local memory, e.g., Gforth's
> variable-flavoured locals), then it has to define the lifetime of the
> memory the address points to. Typically the lifetime will be until
> the end of the definition that the buffer was defined in.
> This inhibits tail-call optimization; consider:
> : bar ( addr -- )
> ... ;
> : foo { | [ 1 ] x } x bar ;
> in the syntax proposed by Stephen Pelc or
> : foo 1 lbuffer bar ;
> in a syntax suggested by others. The allocated buffer must stay
> alive across the call to BAR, because it is used in BAR, so the
> deallocation of the buffer must happen after the call to BAR, and
> BAR is no longer a tail-call and can therefore not be optimized.
Show full article (1.13Kb)
no comments
Re: local buffers and tail-call optimization         


Author: Albert van der Horst
Date: Sep 4, 2008 11:07

In article supernews.com>,
Andrew Haley wrote:
>Anton Ertl mips.complang.tuwien.ac.at> wrote:
>> If a Forth system supports local buffers (or another locals extension
>> that produces addresses of local memory, e.g., Gforth's
>> variable-flavoured locals), then it has to define the lifetime of the
>> memory the address points to. Typically the lifetime will be until
>> the end of the definition that the buffer was defined in.
>
>> This inhibits tail-call optimization; consider:
>
>> : bar ( addr -- )
>> ... ;
>
>> : foo { | [ 1 ] x } x bar ;
>
>> in the syntax proposed by Stephen Pelc or
>
>> : foo 1 lbuffer bar ;
> ...
Show full article (2.06Kb)
no comments