feat: allow yielding main fiber and expose current fiber reference

- Change Fiber.yield() to exit interpreter when no parent fiber exists instead of raising runtime error
- Add Fiber.current primitive to return the currently executing fiber object
- Update interpreter loop to stop execution when PRIM_RUN_FIBER receives null value
- Modify test expectations to reflect new yielding behavior from main fiber
This commit is contained in:
Bob Nystrom
2015-03-07 20:32:11 +00:00
parent 7dcd39f512
commit f1fd125385
7 changed files with 73 additions and 27 deletions
+3 -1
View File
@@ -1 +1,3 @@
Fiber.yield() // expect runtime error: No fiber to yield to.
IO.print("before") // expect: before
Fiber.yield()
IO.print("not reached")
+3 -1
View File
@@ -1,5 +1,6 @@
var a = new Fiber {
Fiber.yield() // expect runtime error: No fiber to yield to.
IO.print("before") // expect: before
Fiber.yield()
}
// Run a chain of fibers. Since none of them are called, they all get discarded
@@ -7,3 +8,4 @@ var a = new Fiber {
var b = new Fiber { a.run() }
var c = new Fiber { b.run() }
c.run()
IO.print("not reached")
+3 -1
View File
@@ -1 +1,3 @@
Fiber.yield(1) // expect runtime error: No fiber to yield to.
IO.print("before") // expect: before
Fiber.yield(1)
IO.print("not reached")
@@ -1,5 +1,6 @@
var a = new Fiber {
Fiber.yield(1) // expect runtime error: No fiber to yield to.
IO.print("before") // expect: before
Fiber.yield(1)
}
// Run a chain of fibers. Since none of them are called, they all get discarded
@@ -7,3 +8,4 @@ var a = new Fiber {
var b = new Fiber { a.run() }
var c = new Fiber { b.run() }
c.run()
IO.print("not reached")