At 6:42 AM +0900 7/21/02, Phil Tomson wrote:
>In article <a05111b10b95f7847af7a@[63.120.19.221]>,
>Dan Sugalski  <dan / sidhe.org> wrote:
>>At 5:22 AM +0900 7/21/02, Phil Tomson wrote:
>>>In article <a05111b05b95de4b58e30@[63.120.19.221]>,
>>>Dan Sugalski  <dan / sidhe.org> wrote:
>>>>At 10:35 PM +0900 7/19/02, James F.Hranicky wrote:
>>>>>While people are kicking around ideas for new backends for Ruby,
>>>>>does anyone think that a backend could be written for Ruby that
>>>>>uses the Objective C (GnuStep, Cocoa) runtime libraries? Or even
>>>>>just a translator from Ruby to ObjC ?
>>>>>
>>>>>Seems that the languages are simliar in many respects, and it seems
>>>>>like ObjC, being a superset of C, would make a good backend if it's
>>>>>possible (threads, performance, etc).
>>>>
>>>>You'd have a heck of a time with continuations, unfortunately.
>>>   >Otherwise it should  be reasonably doable.
>>>
>>>Well, in the current Ruby implementation continuations are implemented
>>>with C code, why couldn't they be implemented in ObjectiveC?
>>
>>I was looking at the translator aspect, translating Ruby to
>>Objective-C. That was the part that was the real non-starter,
>>courtesy of continuations. (I've got a paper or two kicking around
>>about some of the interesting things that the Scheme folks had to do
>>to get continuations going with what's essentially a C environment.
>>It's... interesting)
>>
>>Certainly the interpreter could be done in Objective C. That part's
>>no big deal since objective C's pretty much a superset of C so ruby
>>right now is more or less an Objective C app.
>
>
>I'm thinking of the translator aspect as well (Ruby => Objective C).  But
>I suppose we'd have to muck around with the Objective C runtime to get
>continuations to work... I dunno how hard that would be, but it seems like
>it might be doable....

Continuations are a massive pain to do in a language that doesn't 
have them. Doing continuations means messing around with the system 
stack, and to do it well you really want to treat the stack as a tree 
of semi-independent frames rather than a single chunk of contiguous 
memory as most C-style languages do.

There are tricks you can play, for example you can translate all 
function calls into a continuation-passing style call and do Evil 
Things with setjmp/longjmp, but generally those tricks are, well, 
evil. Plus they don't Play Well with others. (Though, arguably, 
anytime you mix languages with continuations with languages without 
continuations you can run into trouble, but it's not tough to make 
those bad spots edge cases)
-- 
                                         Dan

--------------------------------------"it's like this"-------------------
Dan Sugalski                          even samurai
dan / sidhe.org                         have teddy bears and even
                                       teddy bears get drunk