1
0
forked from Mirror/wren

Revamp how runtime errors and fiber switching is handled.

- Add Fiber.transferError(_).
- Primitives place runtime errors directly in the fiber instead of on
  the stack.
- Primitives that change fibers set it directly in the VM.
- Allow a fiber's error to be any object (except null).
This commit is contained in:
Bob Nystrom
2015-09-29 22:57:03 -07:00
parent 79354f5a97
commit b05a74da19
14 changed files with 285 additions and 269 deletions

View File

@ -0,0 +1,7 @@
var fiber = Fiber.new {
Fiber.abort(123)
}
System.print(fiber.try()) // expect: 123
System.print(fiber.isDone) // expect: true
System.print(fiber.error) // expect: 123

View File

@ -0,0 +1,9 @@
var fiber = Fiber.new {
Fiber.abort(null)
System.print("get here") // expect: get here
Fiber.yield("value")
}
System.print(fiber.try()) // expect: value
System.print(fiber.isDone) // expect: false
System.print(fiber.error) // expect: null

View File

@ -1 +0,0 @@
Fiber.abort(123) // expect runtime error: Error message must be a string.

View File

@ -0,0 +1,15 @@
var A = Fiber.new {
System.print("transferred to A")
B.transferError("error!")
}
var B = Fiber.new {
System.print("started B")
A.transfer()
System.print("should not get here")
}
B.try()
// expect: started B
// expect: transferred to A
System.print(B.error) // expect: error!

View File

@ -0,0 +1,10 @@
var A = Fiber.new {
B.transferError(123)
}
var B = Fiber.new {
A.transfer()
}
B.try()
System.print(B.error) // expect: 123