[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 51/99: Implement cached-module-box
From: |
Christopher Allan Webber |
Subject: |
[Guile-commits] 51/99: Implement cached-module-box |
Date: |
Sun, 10 Oct 2021 21:50:58 -0400 (EDT) |
cwebber pushed a commit to branch compile-to-js-merge
in repository guile.
commit b3c0fcdb25b4217a526661f1e9989f1a1f533da2
Author: Ian Price <ianprice90@googlemail.com>
AuthorDate: Thu Jun 22 14:55:07 2017 +0100
Implement cached-module-box
* module/language/js-il/runtime.js (scheme): Add module_cache field.
(scheme.primitives) Add cached-module-box primitive.
(def_guile0) Convenience for adding to (guile) module cache.
---
module/language/js-il/runtime.js | 59 +++++++++++++++++++++++++++++++++++++++-
1 file changed, 58 insertions(+), 1 deletion(-)
diff --git a/module/language/js-il/runtime.js b/module/language/js-il/runtime.js
index 85669da..cccccc6 100644
--- a/module/language/js-il/runtime.js
+++ b/module/language/js-il/runtime.js
@@ -4,6 +4,7 @@ var scheme = {
utils : {},
env : {},
cache: [],
+ module_cache: {},
builtins: [],
dynstack : [],
// TODO: placeholders
@@ -314,7 +315,21 @@ scheme.primitives["cached-toplevel-box"] = function
(scope, sym, is_bound) {
return scheme.cache[scope][sym.name];
};
-scheme.primitives["cached-module-box"] = not_implemented_yet;
+scheme.primitives["cached-module-box"] = function (module_name, sym,
is_public, is_bound) {
+ var cache = scheme.module_cache;
+
+ while (scheme.EMPTY != module_name.cdr) {
+ cache = cache[module_name.car.name];
+ }
+
+ cache = cache[module_name.car.name];
+ var r = cache[sym.name];
+ if (typeof r === 'undefined') {
+ throw {r : "cached-module-box", s : sym, m : module_name};
+ } else {
+ return r;
+ }
+};
scheme.primitives["current-module"] = function () {
return scheme.env;
@@ -493,3 +508,45 @@ scheme.frame.Fluid = function(fluid, old_value) {
this.fluid = fluid;
this.old_value = old_value;
};
+
+// Module Cache
+scheme.module_cache["guile"] = scheme.env;
+
+function def_guile0 (name, fn) {
+ var sym = new scheme.Symbol(name); // put in obarray
+ var clos = new scheme.Closure(fn, 0);
+ var box = new scheme.Box(clos);
+ scheme.module_cache["guile"][name] = box;
+};
+
+function scm_list (self, cont) {
+ var l = scheme.EMPTY;
+ for (var i = arguments.length - 1; i >= 2; i--){
+ l = scheme.primitives.cons(arguments[i],l);
+ };
+ return cont(l);
+};
+def_guile0("list", scm_list);
+
+function scm_add(self, cont) {
+
+ var total = 0;
+ for (var i = arguments.length - 1; i >= 2; i--){
+ total += arguments[i];
+ };
+ return cont(total);
+
+};
+def_guile0("+", scm_add);
+
+function scm_mul(self, cont) {
+
+ var total = 1;
+ for (var i = arguments.length - 1; i >= 2; i--){
+ total *= arguments[i];
+ };
+ return cont(total);
+
+};
+def_guile0("*", scm_mul);
+
- [Guile-commits] 62/99: scm_struct_init skips hidden fields., (continued)
- [Guile-commits] 62/99: scm_struct_init skips hidden fields., Christopher Allan Webber, 2021/10/10
- [Guile-commits] 59/99: Implement built-in string procedures., Christopher Allan Webber, 2021/10/10
- [Guile-commits] 60/99: Implement struct built-ins., Christopher Allan Webber, 2021/10/10
- [Guile-commits] 70/99: Add `guild jslink' to bundle JS programs, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 75/99: scheme.HashTable uses ES6 Map objects, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 41/99: Fix build of (language cps compile-js), Christopher Allan Webber, 2021/10/10
- [Guile-commits] 45/99: Add #:js-inline? and #:js-flatten? debugging options, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 54/99: Implement structs in runtime.js, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 25/99: Implement call-with-values, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 52/99: Add macro type in runtime.js, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 51/99: Implement cached-module-box,
Christopher Allan Webber <=
- [Guile-commits] 48/99: Rebuild nested scopes for js continuations, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 18/99: Add more types of constants, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 17/99: Implement Optional arguments, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 27/99: values takes multiple arguments, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 28/99: Implement apply correctly, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 38/99: Explicitly test for undefined arguments to handle false values like 0, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 44/99: Update primitives in no-values-primitives, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 35/99: Change local type representation and remove var type, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 42/99: compile-js uses the new cps representation, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 43/99: Handle multiple conts in a function body, Christopher Allan Webber, 2021/10/10