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.
20 lines
304 B
Plaintext
20 lines
304 B
Plaintext
var b = Fiber.create(fn {
|
|
IO.print("fiber b")
|
|
})
|
|
|
|
var a = Fiber.create(fn {
|
|
IO.print("begin fiber a")
|
|
b.run
|
|
IO.print("end fiber a")
|
|
})
|
|
|
|
IO.print("begin main")
|
|
a.run
|
|
IO.print("end main")
|
|
|
|
// expect: begin main
|
|
// expect: begin fiber a
|
|
// expect: fiber b
|
|
// expect: end fiber a
|
|
// expect: end main
|