[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 63/99: Implement hashtable built-ins
From: |
Christopher Allan Webber |
Subject: |
[Guile-commits] 63/99: Implement hashtable built-ins |
Date: |
Sun, 10 Oct 2021 21:51:02 -0400 (EDT) |
cwebber pushed a commit to branch compile-to-js-merge
in repository guile.
commit bfaf07091adb55bda4f768ceeeab1d04870a16c6
Author: Ian Price <ianprice90@googlemail.com>
AuthorDate: Wed Aug 2 23:12:58 2017 +0100
Implement hashtable built-ins
* module/language/js-il/runtime.js
(scheme.HashTable): New Constructor.
(make-hash-table, hash-clear!, hashq-remove!, hashq-ref, hashq-set!,
hash-for-each): Implement built-ins.
---
module/language/js-il/runtime.js | 79 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 79 insertions(+)
diff --git a/module/language/js-il/runtime.js b/module/language/js-il/runtime.js
index 35fa218..9d099b5 100644
--- a/module/language/js-il/runtime.js
+++ b/module/language/js-il/runtime.js
@@ -936,3 +936,82 @@ def_guile0("make-struct", function (self, cont, vtable,
tailsize) {
}
});
+// Hashtables
+def_guile0("make-hash-table", function (self, cont, size) {
+ return cont(new scheme.HashTable());
+});
+
+def_guile0("make-weak-key-hash-table", function (self, cont, size) {
+ // FIXME: not weak
+ return cont(new scheme.HashTable());
+});
+
+def_guile0("hash-clear!", function (self, cont, hashtable) {
+ if (hashtable instanceof scheme.HashTable) {
+ hashtable.table = {};
+ return cont(scheme.FALSE);
+ } else {
+ console.log("hash-clear!", arguments);
+ not_implemented_yet();
+ }
+});
+
+def_guile0("hashq-remove!", function (self, cont, htable, key) {
+ if (htable instanceof scheme.HashTable) {
+ delete htable.table[scm_hash(key)];
+ return cont(scheme.FALSE);
+ } else {
+ console.log("hashq-ref", arguments);
+ not_implemented_yet();
+ }
+});
+
+var scm_hash = function (obj) {
+ if (obj instanceof scheme.Symbol) {
+ return obj.name;
+ }
+
+ console.log("Can't hash object", obj);
+ throw "BadHash";
+};
+
+scheme.HashTable = function ( ) {
+ this.table = {};
+ this.lookup = function (obj, dflt) {
+ var hash = scm_hash(obj);
+ if (this.table.hasOwnProperty(hash)) {
+ return this.table[hash];
+ } else {
+ return dflt;
+ }
+ };
+
+ return this;
+}
+
+def_guile0("hashq-ref", function(self, cont, obarray, sym, dflt) {
+
+ if (obarray instanceof scheme.HashTable) {
+ return cont(obarray.lookup(sym, dflt ? dflt : scheme.FALSE));
+ } else {
+ console.log("hashq-ref", arguments);
+ not_implemented_yet();
+ }
+});
+
+
+def_guile0("hashq-set!", function (self, cont, hashtable, key, obj) {
+ if (hashtable instanceof scheme.HashTable) {
+ hashtable.table[scm_hash(key)] = obj;
+ return cont(scheme.FALSE);
+ } else {
+ console.log("hashq-set!", arguments);
+ not_implemented_yet();
+ }
+});
+
+def_guile0("hash-for-each", function (self, cont, module, symbol) {
+ // FIXME:
+ return cont(scheme.FALSE);
+});
+
- [Guile-commits] 81/99: Argument to make-fluid is optional, (continued)
- [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
- [Guile-commits] 63/99: Implement hashtable built-ins,
Christopher Allan Webber <=
- [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, 2021/10/10
- [Guile-commits] 93/99: Fix module/Makefile.am after compile-to-js merge, Christopher Allan Webber, 2021/10/10