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:
@@ -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.
|
||||
Reference in New Issue
Block a user