[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 77/99: Search for variables in imports.
From: |
Christopher Allan Webber |
Subject: |
[Guile-commits] 77/99: Search for variables in imports. |
Date: |
Sun, 10 Oct 2021 21:51:08 -0400 (EDT) |
cwebber pushed a commit to branch compile-to-js-merge
in repository guile.
commit 84aa3697cc7f45dd98fcfa7bb8440cb04b935bcc
Author: Ian Price <ianprice90@googlemail.com>
AuthorDate: Wed Aug 16 21:34:10 2017 +0100
Search for variables in imports.
* module/language/js-il/runtime.js:
(scm_module_variable): Look in imports if not in obarray.
(module_imported_variable): New procedure.
(scm_module_index_obarray, scm_module_index_uses,
scm_module_index_import_obarray): New variables.
---
module/language/js-il/runtime.js | 45 +++++++++++++++++++++++++++++++++++++++-
1 file changed, 44 insertions(+), 1 deletion(-)
diff --git a/module/language/js-il/runtime.js b/module/language/js-il/runtime.js
index 299a0d3..cfc1faa 100644
--- a/module/language/js-il/runtime.js
+++ b/module/language/js-il/runtime.js
@@ -531,7 +531,16 @@ function scm_module_variable(module, sym) {
// 1. Check Module Obarray
if (module instanceof scheme.Struct) {
var obarray = module.fields[0];
- return obarray.lookup(sym, scheme.UNDEFINED);
+ var v = obarray.lookup(sym, scheme.UNDEFINED);
+ if (v === scheme.UNDEFINED) { // is_false
+ // 2. Search among the imported variables
+ v = module_imported_variable(module, sym);
+ return v;
+ // can't be imported
+ not_implemented_yet();
+ } else {
+ return v;
+ }
}
// 2. Search among the imported variables
// 3. Query the custom binder
@@ -542,6 +551,40 @@ function scm_module_variable(module, sym) {
return scm_pre_modules_obarray.lookup(sym, scheme.UNDEFINED);
}
+var scm_module_index_obarray = 0;
+var scm_module_index_uses = 1;
+var scm_module_index_import_obarray = 8;
+function module_imported_variable(module, sym) {
+ // search cached imported bindings
+ var imports = module.fields[scm_module_index_import_obarray];
+ var v = imports.lookup(sym, scheme.UNDEFINED);
+ if (!(scheme.UNDEFINED === (v))) {
+ return v;
+ }
+ // search use list
+ var uses = module.fields[scm_module_index_uses];
+ var found_var = scheme.FALSE;
+ var found_iface = scheme.FALSE;
+ for (; uses instanceof scheme.Pair; uses = uses.cdr) {
+ var iface = uses.car;
+ var v = scm_module_variable(iface, sym);
+ if (scheme.is_true(v)) {
+ if (scheme.is_true(found_var)) {
+ console.log("resolve duplicate binding");
+ not_implemented_yet();
+ } else {
+ found_var = v;
+ found_iface = iface;
+ }
+ }
+ }
+ if (scheme.is_true(found_var)) {
+ imports.set(sym, found_var);
+ return found_var;
+ }
+ return scheme.FALSE;
+}
+
function scm_module_define(module, sym, val) {
var v = scm_module_ensure_local_variable(module, sym);
v.x = val;
- [Guile-commits] 53/99: Implement Winding & Unwinding, (continued)
- [Guile-commits] 53/99: Implement Winding & Unwinding, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 63/99: Implement hashtable built-ins, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 66/99: Implement misc built-ins, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 61/99: define! primitive only takes one argument., Christopher Allan Webber, 2021/10/10
- [Guile-commits] 69/99: Unwind prompt frames, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 67/99: Make child structs applicable., Christopher Allan Webber, 2021/10/10
- [Guile-commits] 74/99: Reimplement JS module system primitives., Christopher Allan Webber, 2021/10/10
- [Guile-commits] 95/99: Fix import of lower-cps in compile-js.scm, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 73/99: Implement unboxed integer primitives., Christopher Allan Webber, 2021/10/10
- [Guile-commits] 76/99: Separate public / private module lookups, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 77/99: Search for variables in imports.,
Christopher Allan Webber <=
- [Guile-commits] 93/99: Fix module/Makefile.am after compile-to-js merge, Christopher Allan Webber, 2021/10/10