[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 65/99: Implement module built-ins.
From: |
Christopher Allan Webber |
Subject: |
[Guile-commits] 65/99: Implement module built-ins. |
Date: |
Sun, 10 Oct 2021 21:51:03 -0400 (EDT) |
cwebber pushed a commit to branch compile-to-js-merge
in repository guile.
commit 3c62ab81853eda1ff11b97abb545c39cce0a2f42
Author: Ian Price <ianprice90@googlemail.com>
AuthorDate: Wed Aug 2 23:24:20 2017 +0100
Implement module built-ins.
* module/language/js-il/runtime.js
(variable?): New Primitive.
(primitive-load-path, module-local-variable, module-variable,
%get-pre-modules-obarray, set-current-module): Implement built-ins.
---
module/language/js-il/runtime.js | 75 ++++++++++++++++++++++++++++++++++++++--
1 file changed, 72 insertions(+), 3 deletions(-)
diff --git a/module/language/js-il/runtime.js b/module/language/js-il/runtime.js
index feda26a..1ff5ae1 100644
--- a/module/language/js-il/runtime.js
+++ b/module/language/js-il/runtime.js
@@ -507,7 +507,10 @@ scheme.primitives["fluid-ref"] = function (fluid) {
};
// Variables
-scheme.primitives["variable?"] = not_implemented_yet;
+scheme.primitives["variable?"] = function (obj) {
+ // FIXME: should variables be distinct from boxes?
+ return coerce_bool(obj instanceof scheme.Box);
+};
// Dynamic Wind
scheme.primitives["wind"] = function(enter, leave) {
@@ -827,8 +830,6 @@ def_guile0("string-join", function (self, cont, strings) {
return cont(new scheme.String(s));
});
-});
-
// Structs
var vtable_base_layout = new scheme.String("pruhsruhpwphuhuh");
def_guile_val("standard-vtable-fields", vtable_base_layout);
@@ -1028,3 +1029,71 @@ def_guile0("hash-for-each", function (self, cont,
module, symbol) {
return cont(scheme.FALSE);
});
+// Modules
+def_guile0("make-variable", function (self, cont, val) {
+ return cont(new scheme.Box(val));
+});
+
+def_guile0("define!", function (self, cont, symbol, value) {
+ // FIXME: reuse module-define!
+ if (symbol.name in scheme.env) {
+ scheme.env[symbol.name].x = value;
+ } else {
+ scheme.env[symbol.name] = new scheme.Box(value);
+ }
+ return cont();
+});
+
+var boot_modules = {};
+
+function scm_primitive_load_path (self, cont, path) {
+ if (path.s in boot_modules) {
+ boot_modules[path.s](); // FIXME: note modules should share cont?
+ return cont(scheme.UNDEFINED);
+ } else {
+ console.log("primitive load path", arguments);
+ not_implemented_yet();
+ }
+};
+def_guile0("primitive-load-path", scm_primitive_load_path);
+
+boot_modules["ice-9/deprecated"] = function () {};
+boot_modules["ice-9/ports"] = function () {};
+boot_modules["ice-9/posix"] = function () {};
+boot_modules["ice-9/threads"] = function () {};
+boot_modules["srfi/srfi-4"] = function () {};
+
+def_guile0("module-local-variable", function (self, cont, module, symbol) {
+ if (module instanceof scheme.Struct) {
+ // Assumes we get a module with a hashtable
+ var obarray = scheme.primitives["struct-ref"](module, 0);
+ return cont(obarray.lookup(symbol, scheme.FALSE)); // hashq-ref
+ } else {
+ // FIXME: could be #f, then should use the pre-mod obarray
+ console.log("module-local-variable needs real modules");
+ throw "fail";
+ }
+});
+
+def_guile0("module-variable", function (self, cont, module, symbol) {
+ if (module instanceof scheme.Struct) {
+ console.log("FIXME: should only be called pre-bootstrap");
+ throw "fail";
+ }
+ if (module instanceof scheme.HashTable) {
+ console.log("modvar htable");
+ throw "fail";
+ }
+ return cont(module[symbol.name]);
+});
+
+def_guile0("%get-pre-modules-obarray", function (self, cont) {
+ var obarray = new scheme.HashTable();
+ obarray.table = scheme.env;
+ return cont(obarray);
+});
+
+def_guile0("set-current-module", function (self, cont, module) {
+ return cont(scheme.FALSE);
+});
+
- [Guile-commits] 43/99: Handle multiple conts in a function body, (continued)
- [Guile-commits] 43/99: Handle multiple conts in a function body, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 46/99: JS-IL inliner has different count-calls for different clauses, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 40/99: Merge branch 'stable-2.2' into compile-to-js-2017, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 49/99: Compile Syntax Objects to Javascript, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 39/99: Add missing simplify.scm to Makefile, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 37/99: Fixup binop unparsing, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 57/99: Implement built-in syntax procedures., Christopher Allan Webber, 2021/10/10
- [Guile-commits] 56/99: Implement builtin list procedures., Christopher Allan Webber, 2021/10/10
- [Guile-commits] 58/99: Implement built-in symbol procedures., Christopher Allan Webber, 2021/10/10
- [Guile-commits] 64/99: Implement procedure built-ins., Christopher Allan Webber, 2021/10/10
- [Guile-commits] 65/99: Implement module built-ins.,
Christopher Allan Webber <=
- [Guile-commits] 72/99: Implement basic `equal?' implementation, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 68/99: struct-set! primitive returns no values, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 71/99: modules should be passed current continuation, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 79/99: Implement list builtins, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 80/99: *features* is an empty list, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 84/99: Add assignment js-type to (language javascript), Christopher Allan Webber, 2021/10/10
- [Guile-commits] 87/99: Create stub module forms for dependecies, Christopher Allan Webber, 2021/10/10
- [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