unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* a rehash of the question of optimizing some prompt ideoms
@ 2013-08-30 18:54 Stefan Israelsson Tampe
  2013-08-31  4:35 ` Mark H Weaver
  2013-09-01 20:34 ` Stefan Israelsson Tampe
  0 siblings, 2 replies; 4+ messages in thread
From: Stefan Israelsson Tampe @ 2013-08-30 18:54 UTC (permalink / raw)
  To: guile-devel

Hi all,

In the wake of the wowely code Andy Mark and Noah have been producing
I want to lift the question of what we can do to compile some
delimeted continuation code effeciently.

Delimeted continuations can be looked upon as a generalization of
common lisps tagbody e.g. it's trivial to produce tagbody semantics
with the help of prompts. Now a quesiton is how we should make sure
that most sane code that can be compiled to goto's in the rtl backend
really get that far. As I understand the cps compiler is well suited
to take on this task. But we should not aim towards atgbody, but also
generators and similar constructs. To see what kind of semantics to
support maybe the code in 
 
  https://gitorious.org/guile-coroutines/guile-
coroutines/source/fc49d41dfa0cc0647aaeeddf8fb15d55dc2fb6ef:stis/coroutine.scm

Can help as well as the example in the same repo,

https://gitorious.org/guile-coroutines/guile-
coroutines/source/fc49d41dfa0cc0647aaeeddf8fb15d55dc2fb6ef:stis/coroutine/test.scm

So what can we do in rtl that we cannot do before? To note here is
that in rtl we can basically allocate a region of the register space
for e.g. a generator. The nice thing with rtl is that all functions
are executed at the end of the register space and therefore we could
basically use named gotos to jump between the different
generators located at different stack areas. This is not possible in a
stack based VM. So not only do we skip expensive function call's but
tear down and setup of the stack is not needed. Of cause to be
able to take advantage of this not all generators can be used in such
a scheme. (It would be nice to get Academic references for this) but
it should be doable. 

We would need some more one more instruction from RTL, namely named
gotos.

It's also perhaps possible to enlarge the ideas to separate where
functions are evaluated and where the "local rigister area" of the 
generator is 
situated. E.g. An area allocated from the heap. But this lead to a
complete redesign of RTL but it would could be a cool concept.

WDYT?




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: a rehash of the question of optimizing some prompt ideoms
  2013-08-30 18:54 a rehash of the question of optimizing some prompt ideoms Stefan Israelsson Tampe
@ 2013-08-31  4:35 ` Mark H Weaver
  2013-08-31  4:56   ` Mark H Weaver
  2013-09-01 20:34 ` Stefan Israelsson Tampe
  1 sibling, 1 reply; 4+ messages in thread
From: Mark H Weaver @ 2013-08-31  4:35 UTC (permalink / raw)
  To: Stefan Israelsson Tampe; +Cc: guile-devel

Hi Stefan,

Stefan Israelsson Tampe <stefan.itampe@gmail.com> writes:
> Delimeted continuations can be looked upon as a generalization of
> common lisps tagbody e.g. it's trivial to produce tagbody semantics
> with the help of prompts.

I haven't yet digested the rest of your email, but I wanted to point out
that prompts are not needed to produce Common Lisp 'tagbody' semantics.
All that's needed is a set of mutually-recursive local procedures that
tail call each other.  Each local procedure corresponds to a label, and
the tail calls correspond to GOTOs.

In fact, one of the earliest papers on Scheme, "LAMBDA, The Ultimate
Imperative" published in 1976, showed how to convert arbitrary Lisp
'PROG' forms into a very early version of Scheme.  Note that Lisp 'PROG'
was a combined 'let', 'block', and 'tagbody', and can do everything that
Common Lisp's 'tagbody' can do.

    Regards,
      Mark



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: a rehash of the question of optimizing some prompt ideoms
  2013-08-31  4:35 ` Mark H Weaver
@ 2013-08-31  4:56   ` Mark H Weaver
  0 siblings, 0 replies; 4+ messages in thread
From: Mark H Weaver @ 2013-08-31  4:56 UTC (permalink / raw)
  To: Stefan Israelsson Tampe; +Cc: guile-devel

Mark H Weaver <mhw@netris.org> writes:

> Hi Stefan,
>
> Stefan Israelsson Tampe <stefan.itampe@gmail.com> writes:
>> Delimeted continuations can be looked upon as a generalization of
>> common lisps tagbody e.g. it's trivial to produce tagbody semantics
>> with the help of prompts.
>
> I haven't yet digested the rest of your email, but I wanted to point out
> that prompts are not needed to produce Common Lisp 'tagbody' semantics.
> All that's needed is a set of mutually-recursive local procedures that
> tail call each other.  Each local procedure corresponds to a label, and
> the tail calls correspond to GOTOs.
>
> In fact, one of the earliest papers on Scheme, "LAMBDA, The Ultimate
> Imperative" published in 1976, showed how to convert arbitrary Lisp
> 'PROG' forms into a very early version of Scheme.  Note that Lisp 'PROG'
> was a combined 'let', 'block', and 'tagbody', and can do everything that
> Common Lisp's 'tagbody' can do.

Ugh.  I just realized that this is not true, because of the fact that
Common Lisp added lexical scoping and the ability to use 'go' to escape
from procedures nested within the 'tagbody'.  Indeed, Common Lisp's
'tagbody' is more powerful than old Lisp's PROG, and apparently needs
escape-only continuations in the general case.

Sorry for the wasted bandwidth :-(

     Mark



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: a rehash of the question of optimizing some prompt ideoms
  2013-08-30 18:54 a rehash of the question of optimizing some prompt ideoms Stefan Israelsson Tampe
  2013-08-31  4:35 ` Mark H Weaver
@ 2013-09-01 20:34 ` Stefan Israelsson Tampe
  1 sibling, 0 replies; 4+ messages in thread
From: Stefan Israelsson Tampe @ 2013-09-01 20:34 UTC (permalink / raw)
  To: guile-devel

[-- Attachment #1: Type: text/plain, Size: 3255 bytes --]

Hi,

To note in e.g. logic programming one can inline a lot of code and
the final result of peval is that it will and should not expand the lambdas
at site
due to code explosion. What happens now, as I understand, is that closures
are created at a resulting quite hefty overhead. In stead if one employed
local functions inside the stack and issued a goto to these functions and a
corresponding return to the call site with return value in appropriate slot
we
would be much better off because we would simply not need to create closures
on the heap and have very low overhead in the argument handling and function
dispatch. To make this work we would only need to have named gotos, the rest
should be handled by the scheme in scheme compiler.

So there are good arguments to have
1. Named goto operations in the VM
2. A notion of local execution unit that are of two kinds
   i)  Stateless aka functions, can reuse register space
   ii) Statefull  aka need to allocate a fixed register space to the local
funciton

WDYT?




On Fri, Aug 30, 2013 at 8:54 PM, Stefan Israelsson Tampe <
stefan.itampe@gmail.com> wrote:

> Hi all,
>
> In the wake of the wowely code Andy Mark and Noah have been producing
> I want to lift the question of what we can do to compile some
> delimeted continuation code effeciently.
>
> Delimeted continuations can be looked upon as a generalization of
> common lisps tagbody e.g. it's trivial to produce tagbody semantics
> with the help of prompts. Now a quesiton is how we should make sure
> that most sane code that can be compiled to goto's in the rtl backend
> really get that far. As I understand the cps compiler is well suited
> to take on this task. But we should not aim towards atgbody, but also
> generators and similar constructs. To see what kind of semantics to
> support maybe the code in
>
>   https://gitorious.org/guile-coroutines/guile-
>
> coroutines/source/fc49d41dfa0cc0647aaeeddf8fb15d55dc2fb6ef:stis/coroutine.scm
>
> Can help as well as the example in the same repo,
>
> https://gitorious.org/guile-coroutines/guile-
>
> coroutines/source/fc49d41dfa0cc0647aaeeddf8fb15d55dc2fb6ef:stis/coroutine/test.scm
>
> So what can we do in rtl that we cannot do before? To note here is
> that in rtl we can basically allocate a region of the register space
> for e.g. a generator. The nice thing with rtl is that all functions
> are executed at the end of the register space and therefore we could
> basically use named gotos to jump between the different
> generators located at different stack areas. This is not possible in a
> stack based VM. So not only do we skip expensive function call's but
> tear down and setup of the stack is not needed. Of cause to be
> able to take advantage of this not all generators can be used in such
> a scheme. (It would be nice to get Academic references for this) but
> it should be doable.
>
> We would need some more one more instruction from RTL, namely named
> gotos.
>
> It's also perhaps possible to enlarge the ideas to separate where
> functions are evaluated and where the "local rigister area" of the
> generator is
> situated. E.g. An area allocated from the heap. But this lead to a
> complete redesign of RTL but it would could be a cool concept.
>
> WDYT?
>
>

[-- Attachment #2: Type: text/html, Size: 4234 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-09-01 20:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-08-30 18:54 a rehash of the question of optimizing some prompt ideoms Stefan Israelsson Tampe
2013-08-31  4:35 ` Mark H Weaver
2013-08-31  4:56   ` Mark H Weaver
2013-09-01 20:34 ` Stefan Israelsson Tampe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).