4 ms·
> It looks a bit like Dart (AFAICT), which is probably no coincidence? Probably more convergent evolution than anything, but there are certainly similarities.
by munificent 12y ago
> It looks a bit like Dart (AFAICT), which is probably no coincidence?
Probably more convergent evolution than anything, but there are certainly similarities. :)
> Are you going to model it after Lua as you did the parser?
Yes, absolutely. My mantra is "when in doubt, do what Lua does", which works surprisingly well. I have so much respect for Ierusalimschy and company.
You can see the in-progress API here: https://github.com/munificent/wren/blob/master/include/wren.h https://github.com/munificent/wren/blob/master/include/wren....
> They did a great job with this comparison paper: http://www.jucs.org/jucs_13_6/c_apis_in_extension http://www.jucs.org/jucs_13_6/c_apis_in_extension
Oh, man. This is perfect!
> I always wanted channels between C/C++ and a scripting language.
Wren is deeply built around fibers. It doesn't use the native C stack, so my hope is that it will be pretty easy to be able to suspend the interpreter to switch back to C and then resume it when you go back. All of the mechanism is there, I just have to see how it feels in practice.
You can build channels on top of fibers, so I'm really keen to play around with some different concurrency and communication models here and see what they feel like.
> I think both C and C++ are important use cases.
Me too.
- marktangotango 12y agoSeems like fibers/coroutines are a curiosity here, how useful are they supposed to be from a performance perspective? Example, say I have a thread with a wren vm instance running with a bunch of fibers inside, and a fiber calls back to a C function that's blocking (on io say) then this still blocks the entire thread. Seems like there'd have to be a way to integrate with an event loop, and register a fiber with an event (edit or file descriptor/socket). Contemplating this makes me sleepy and grouchy ie it's very abstract, have you given any thought to this use case?
- munificent 12y ago> Seems like fibers/coroutines are a curiosity here, how useful are they supposed to be from a performance perspective? Think of them as a way to organize your program, not a way to optimize it. Fibers let you have multiple independent imperative flows of behavior that you can bounce between without having to return from one in order to get to the other. Instead of always having to organize your behavior in a single rigid stack of "can't do X until done doing Y", you can have as many separate stacks as you want. You can also hook them up to something like asynchronous IO where an IO operation will implicitly park a fiber and let others run. I did that using libuv in my other language Magpie [1]. That's also really nice, but it naturally requires more low level support and has some implications on how fibers are scheduled. In Wren, fibers are explicitly cooperative—you specifically choose which fiber to resume when you suspend one. If you're parking on IO, you need some more implicit logic so the scheduler can automatically pick a fiber to resume. In practice, I think that just means that if all fibers are parked waiting on IO, the scheduler resumes whichever one's IO operation completes first. [1]: http://magpie-lang.org/ http://magpie-lang.org/
- marktangotango 12y agoGreat insight, thanks. I'll take a look at magpie.