[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 78/99: Implement Hook Builtins
From: |
Christopher Allan Webber |
Subject: |
[Guile-commits] 78/99: Implement Hook Builtins |
Date: |
Sun, 10 Oct 2021 21:51:08 -0400 (EDT) |
cwebber pushed a commit to branch compile-to-js-merge
in repository guile.
commit 7ee8973df5438b9f64b14016e77238df5fc22998
Author: Ian Price <ianprice90@googlemail.com>
AuthorDate: Wed Aug 16 21:37:26 2017 +0100
Implement Hook Builtins
* module/language/js-il/runtime.js:
(scheme.Hook): new constructor
(make-hook, run-hook): Implement builtins.
---
module/language/js-il/runtime.js | 29 ++++++++++++++++++++++++++++-
1 file changed, 28 insertions(+), 1 deletion(-)
diff --git a/module/language/js-il/runtime.js b/module/language/js-il/runtime.js
index cfc1faa..c337fc4 100644
--- a/module/language/js-il/runtime.js
+++ b/module/language/js-il/runtime.js
@@ -1418,8 +1418,35 @@ def_guile0("read-hash-extend", function (self, cont,
char, fun) {
return cont(scheme.FALSE);
});
+scheme.Hook = function (arity) {
+ this.arity = arity;
+ this.procs = [];
+};
+
def_guile0("make-hook", function (self, cont, nargs) {
- return cont(scheme.FALSE);
+ var arity = (nargs === undefined) ? 0 : nargs;
+ return cont(new scheme.Hook(arity));
+});
+
+def_guile0("run-hook", function (self, cont, hook) {
+ var procs = hook.procs;
+ var args = Array.prototype.slice.call(arguments, 3);
+ // FIXME: validate hook
+ // FIXME: check num args = arity or error
+
+ var loop = function (i) {
+ if (i === procs.length) {
+ return cont(scheme.UNSPECIFIED);
+ } else {
+ var newk = function() {
+ return loop(i+1);
+ };
+
+ var proc = procs[i];
+ return proc.fun.apply(proc.fun, [proc, newk].concat(args));
+ }
+ };
+ return loop(0);
});
function scm_simple_format (self, cont) {
- [Guile-commits] 97/99: Switch use of $closure to $const-fun, (continued)
- [Guile-commits] 97/99: Switch use of $closure to $const-fun, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 22/99: Add more Scheme Primitives to runtime.js, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 32/99: Rewrite js-il inliner, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 82/99: pop-fluid uses field of frame not fluid, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 85/99: Handle more JavaScript binary operators, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 86/99: Keywords cannot be both keyword and optional, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 91/99: Update Copyright Headers, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 94/99: Add compiler-chooser for CPS spec, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 96/99: Fix cps's choose-compiler to be able to compile javascript, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 98/99: Merge branch 'main' into compile-to-js-merge, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 78/99: Implement Hook Builtins,
Christopher Allan Webber <=
- [Guile-commits] 81/99: Argument to make-fluid is optional, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 83/99: Implement variable-bound? builtin, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 88/99: read argument to --depends switch, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 89/99: extra-dependencies go before boot-dependencies, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 90/99: Mention all arguments to guild jslink in --help, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 92/99: Merge branch 'compile-to-js-2017' into compile-to-js-rebase, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 99/99: Compile cps to bytecode by default, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 24/99: Primitives create multiple argument continuations., Christopher Allan Webber, 2021/10/10
- [Guile-commits] 14/99: Add binop type, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 53/99: Implement Winding & Unwinding, Christopher Allan Webber, 2021/10/10