feat: implement fiber primitives with create, run, yield and caller tracking

Add core fiber functionality including Fiber.create, Fiber.run, Fiber.yield
primitives with value passing between fibers. Introduce PRIM_RUN_FIBER result
type for interpreter loop, add caller field to ObjFiber struct for yield
resumption, and update GC marking to traverse fiber caller chains. Modify
wrenNewFiber to accept a function/closure argument and initialize the first
call frame. Add debug stack printing with fiber pointer. Include test suite
covering fiber creation, run, yield, value passing, type checking, and
caller resumption.
This commit is contained in:
Bob Nystrom
2014-01-12 19:02:07 +00:00
parent d0d92971d8
commit fc4880774e
15 changed files with 306 additions and 40 deletions
+12
View File
@@ -0,0 +1,12 @@
var fiber = Fiber.create(fn {
IO.print("fiber")
})
IO.print("before") // expect: before
fiber.run // expect: fiber
IO.print("after") // expect: after
// TODO: Test handles error if fiber tries to run itself.
// TODO: Test create is passed right argument type.
// TODO: Test closing over stuff in fiber function.
// TODO: Test running a finished fiber.