This is the mail archive of the guile@sources.redhat.com mailing list for the Guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: How often are continuations created?


Marius Vollmer <mvo@zagadka.ping.de> writes:

> So, it looks like you need to allocate bindings that might get mutated
> in external frames, on the heap.
> 
> Is that right?

Right.  And I think I have done this already:

  (lambda (a)                           ;; closure 1
    (lambda (b c)                       ;; closure 2
      (call-with-current-continuation
        (lambda (cont) cont))           ;; closure 3
      (set! b 1)
      c)
    (set! a 2))

becomes

  .program1                   ;; top-level
    %make-program .program2
    %return

  .program2                   ;; closure 1
    %make-program .program3
    %loadi 2
    %savee:0:0                ;; (set! a 2) `a' is external
    %loadi #<unspecified>
    %return

  .program3                   ;; closure 2
    %make-program .program4
    %call/cc 1
    %loadi 1
    %savee:0:0                ;; (set! b 1) `b' is external
    %loadi #<unspecified>     ;; this is redundant and can be optimized
    %loadl:0                  ;; `c' is local
    %return

  .program4                   ;; closure 3
    %loadl:0                  ;; `cont' is local
    %return

Hopefully I'll release the next snapshot with continuations in a day.

> As a general guideline, I would strive to make executation fast when
> no continuations are captured and or activated, and tolerate it that
> continuations are significantly more expansive than function calls.  I
> think that for each performance critical application of continuations,
> there is a special purpose solution that can be cheap.  For example,
> break/continue can be done by locally analyzable escaping
> continuations that the compiler can turn into efficient code.
> Multithreading is done without continuations anyway.  Backtracking
> algorithms might have to suffer, tho...

BTW, my VM has a %jump instruction, and the intermediate code of the
compiler has #:label and #:goto keywords.  I think writing a compiler
could be easier than writing a translator when we have a VM.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]