feat: add scheduler module and refactor built-in module loading into shared modules.c

Introduce a new scheduler module with fiber-based cooperative multitasking, including native bindings for resume operations and a Wren class for scheduling callables. Refactor the existing timer module and CLI code to use a centralized built-in module registry in modules.c, replacing direct includes of timer.h and timer.wren.inc. Update Xcode project and Makefile to compile the new scheduler.c, modules.c, and their generated .wren.inc sources.
This commit is contained in:
Bob Nystrom
2015-09-13 18:32:39 +00:00
parent 95626bb136
commit 34bcc6bd2d
18 changed files with 291 additions and 110 deletions
+15
View File
@@ -0,0 +1,15 @@
import "scheduler" for Scheduler
import "timer" for Timer
var run = false
Scheduler.add {
run = true
}
// Does not run immediately.
IO.print(run) // expect: false
Timer.sleep(0)
// Runs when the main fiber suspends on IO.
IO.print(run) // expect: true
+3 -2
View File
@@ -1,11 +1,12 @@
import "scheduler" for Scheduler
import "timer" for Timer
Timer.schedule {
Scheduler.add {
Timer.sleep(2)
IO.print("a")
}
Timer.schedule {
Scheduler.add {
Timer.sleep(1)
IO.print("b")
}
+3 -2
View File
@@ -1,12 +1,13 @@
import "scheduler" for Scheduler
import "timer" for Timer
// These are both rounded to 1, so "a" should complete first.
Timer.schedule {
Scheduler.add {
Timer.sleep(1.5)
IO.print("a")
}
Timer.schedule {
Scheduler.add {
Timer.sleep(1.3)
IO.print("b")
}
+3 -2
View File
@@ -1,12 +1,13 @@
import "scheduler" for Scheduler
import "timer" for Timer
Timer.schedule {
Scheduler.add {
IO.print("a before")
Timer.sleep(0)
IO.print("a after")
}
Timer.schedule {
Scheduler.add {
IO.print("b before")
Timer.sleep(0)
IO.print("b after")