2015-09-13 20:32:39 +02:00
|
|
|
class Scheduler {
|
|
|
|
|
static add(callable) {
|
perf: replace string concatenation with list join and add normalized headers map in html, http, jinja, json, markdown modules
Optimize string building in decodeUtf8_, slugify, parseRaw_, processCode_, and processBold_ by accumulating parts in a list and joining once, avoiding repeated string allocation. In HttpResponse constructor, precompute a normalized headers map for O(1) case-insensitive header lookups instead of linear scan. Simplify Json.stringify indent generation using string repetition operator.
2026-01-26 10:59:07 +01:00
|
|
|
if (__scheduled == null) {
|
|
|
|
|
__scheduled = []
|
|
|
|
|
__scheduleIndex = 0
|
|
|
|
|
}
|
2015-09-13 20:32:39 +02:00
|
|
|
__scheduled.add(Fiber.new {
|
|
|
|
|
callable.call()
|
|
|
|
|
runNextScheduled_()
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static resume_(fiber) { fiber.transfer() }
|
|
|
|
|
static resume_(fiber, arg) { fiber.transfer(arg) }
|
2015-10-01 06:13:36 +02:00
|
|
|
static resumeError_(fiber, error) { fiber.transferError(error) }
|
2015-09-13 20:32:39 +02:00
|
|
|
|
feat: add async/await keywords, Num/String extensions, and Jinja markdown example
Add `async` and `await` token support to the Wren compiler with scheduler resolution logic, extend `Num` with `e` constant, hyperbolic trig, base conversion, and new methods (`isZero`, `gcd`, `lcm`, `digits`, etc.), extend `String` with `lower`, `upper`, `capitalize`, `title`, and regenerate `wren_core.wren.inc`. Include `Makefile` for multi-platform builds, rewrite `README.md` with updated build instructions, and add `example/await_demo.wren` and `example/jinja_markdown.wren` demonstrating new features.
2026-01-25 04:58:39 +01:00
|
|
|
static await_(arg) {
|
|
|
|
|
if (arg is Fn) {
|
|
|
|
|
arg.call()
|
|
|
|
|
return Scheduler.runNextScheduled_()
|
|
|
|
|
}
|
|
|
|
|
if (arg is Future) return arg.await_()
|
|
|
|
|
return arg
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static async_(fn) {
|
|
|
|
|
return Future.new(fn)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static scheduleTransfer_(fiber, value) {
|
perf: replace string concatenation with list join and add normalized headers map in html, http, jinja, json, markdown modules
Optimize string building in decodeUtf8_, slugify, parseRaw_, processCode_, and processBold_ by accumulating parts in a list and joining once, avoiding repeated string allocation. In HttpResponse constructor, precompute a normalized headers map for O(1) case-insensitive header lookups instead of linear scan. Simplify Json.stringify indent generation using string repetition operator.
2026-01-26 10:59:07 +01:00
|
|
|
if (__scheduled == null) {
|
|
|
|
|
__scheduled = []
|
|
|
|
|
__scheduleIndex = 0
|
|
|
|
|
}
|
feat: add async/await keywords, Num/String extensions, and Jinja markdown example
Add `async` and `await` token support to the Wren compiler with scheduler resolution logic, extend `Num` with `e` constant, hyperbolic trig, base conversion, and new methods (`isZero`, `gcd`, `lcm`, `digits`, etc.), extend `String` with `lower`, `upper`, `capitalize`, `title`, and regenerate `wren_core.wren.inc`. Include `Makefile` for multi-platform builds, rewrite `README.md` with updated build instructions, and add `example/await_demo.wren` and `example/jinja_markdown.wren` demonstrating new features.
2026-01-25 04:58:39 +01:00
|
|
|
__scheduled.add(Fiber.new {
|
|
|
|
|
fiber.transfer(value)
|
|
|
|
|
})
|
2021-05-02 00:58:17 +02:00
|
|
|
}
|
|
|
|
|
|
2015-09-13 20:32:39 +02:00
|
|
|
static runNextScheduled_() {
|
perf: replace string concatenation with list join and add normalized headers map in html, http, jinja, json, markdown modules
Optimize string building in decodeUtf8_, slugify, parseRaw_, processCode_, and processBold_ by accumulating parts in a list and joining once, avoiding repeated string allocation. In HttpResponse constructor, precompute a normalized headers map for O(1) case-insensitive header lookups instead of linear scan. Simplify Json.stringify indent generation using string repetition operator.
2026-01-26 10:59:07 +01:00
|
|
|
if (__scheduled == null || __scheduleIndex >= __scheduled.count) {
|
|
|
|
|
__scheduled = null
|
|
|
|
|
__scheduleIndex = 0
|
2015-09-13 20:32:39 +02:00
|
|
|
return Fiber.suspend()
|
|
|
|
|
}
|
perf: replace string concatenation with list join and add normalized headers map in html, http, jinja, json, markdown modules
Optimize string building in decodeUtf8_, slugify, parseRaw_, processCode_, and processBold_ by accumulating parts in a list and joining once, avoiding repeated string allocation. In HttpResponse constructor, precompute a normalized headers map for O(1) case-insensitive header lookups instead of linear scan. Simplify Json.stringify indent generation using string repetition operator.
2026-01-26 10:59:07 +01:00
|
|
|
var fiber = __scheduled[__scheduleIndex]
|
|
|
|
|
__scheduleIndex = __scheduleIndex + 1
|
|
|
|
|
if (__scheduleIndex > 64 && __scheduleIndex > __scheduled.count / 2) {
|
|
|
|
|
__scheduled = __scheduled[__scheduleIndex..-1]
|
|
|
|
|
__scheduleIndex = 0
|
|
|
|
|
}
|
|
|
|
|
return fiber.transfer()
|
2015-09-13 20:32:39 +02:00
|
|
|
}
|
|
|
|
|
|
2026-01-25 10:50:20 +01:00
|
|
|
static hasScheduled_ {
|
perf: replace string concatenation with list join and add normalized headers map in html, http, jinja, json, markdown modules
Optimize string building in decodeUtf8_, slugify, parseRaw_, processCode_, and processBold_ by accumulating parts in a list and joining once, avoiding repeated string allocation. In HttpResponse constructor, precompute a normalized headers map for O(1) case-insensitive header lookups instead of linear scan. Simplify Json.stringify indent generation using string repetition operator.
2026-01-26 10:59:07 +01:00
|
|
|
return __scheduled != null && __scheduleIndex < __scheduled.count
|
2026-01-25 10:50:20 +01:00
|
|
|
}
|
|
|
|
|
|
2015-09-13 20:32:39 +02:00
|
|
|
foreign static captureMethods_()
|
|
|
|
|
}
|
|
|
|
|
|
feat: add async/await keywords, Num/String extensions, and Jinja markdown example
Add `async` and `await` token support to the Wren compiler with scheduler resolution logic, extend `Num` with `e` constant, hyperbolic trig, base conversion, and new methods (`isZero`, `gcd`, `lcm`, `digits`, etc.), extend `String` with `lower`, `upper`, `capitalize`, `title`, and regenerate `wren_core.wren.inc`. Include `Makefile` for multi-platform builds, rewrite `README.md` with updated build instructions, and add `example/await_demo.wren` and `example/jinja_markdown.wren` demonstrating new features.
2026-01-25 04:58:39 +01:00
|
|
|
class Future {
|
|
|
|
|
construct new(fn) {
|
|
|
|
|
_resolved = false
|
|
|
|
|
_result = null
|
|
|
|
|
_waiters = []
|
|
|
|
|
var self = this
|
|
|
|
|
Scheduler.add {
|
|
|
|
|
self.resolve_(fn.call())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resolve_(value) {
|
|
|
|
|
_resolved = true
|
|
|
|
|
_result = value
|
|
|
|
|
for (w in _waiters) {
|
|
|
|
|
Scheduler.scheduleTransfer_(w, value)
|
|
|
|
|
}
|
|
|
|
|
_waiters = []
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await_() {
|
|
|
|
|
if (_resolved) return _result
|
|
|
|
|
_waiters.add(Fiber.current)
|
|
|
|
|
return Scheduler.runNextScheduled_()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
isDone { _resolved }
|
|
|
|
|
result { _result }
|
2026-01-25 10:50:20 +01:00
|
|
|
|
|
|
|
|
call() { this }
|
feat: add async/await keywords, Num/String extensions, and Jinja markdown example
Add `async` and `await` token support to the Wren compiler with scheduler resolution logic, extend `Num` with `e` constant, hyperbolic trig, base conversion, and new methods (`isZero`, `gcd`, `lcm`, `digits`, etc.), extend `String` with `lower`, `upper`, `capitalize`, `title`, and regenerate `wren_core.wren.inc`. Include `Makefile` for multi-platform builds, rewrite `README.md` with updated build instructions, and add `example/await_demo.wren` and `example/jinja_markdown.wren` demonstrating new features.
2026-01-25 04:58:39 +01:00
|
|
|
}
|
|
|
|
|
|
2015-09-13 20:32:39 +02:00
|
|
|
Scheduler.captureMethods_()
|