mfichman / jogo

High(er) performance compiled programming language with clean, powerful syntax
MIT License
6 stars 1 forks source link

Continuations (equivalent) #67

Open mfichman opened 11 years ago

mfichman commented 11 years ago

The coroutine implementation is equivalent to 1-shot continuations. By adding the ability to deep-copy coroutines, Jogo would have full continuation support. The question is: How could this be done efficiently? The naïve solution would simply copy the whole coroutine stack. A more efficient implementation would use copy-on-write, perhaps doing something tricky with SIGSEGV and copy-on-write memory pages to detect writes. The deep-copy would be started by the fork function:

coro = Coroutine(function() {
    Io::println('hello')
    yield
    Io::println('goodbye')
}
coro()
forked = coro.fork()
coro()
forked()

This would output:

'hello'
'goodbye'
'goodbye'