[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 79/99: Implement list builtins
From: |
Christopher Allan Webber |
Subject: |
[Guile-commits] 79/99: Implement list builtins |
Date: |
Sun, 10 Oct 2021 21:51:09 -0400 (EDT) |
cwebber pushed a commit to branch compile-to-js-merge
in repository guile.
commit 8321baee15cf65c45a608458792a0e028cbded5e
Author: Ian Price <ianprice90@googlemail.com>
AuthorDate: Wed Aug 16 21:40:39 2017 +0100
Implement list builtins
* module/language/js-il/runtime.js
(cons, memq, member, delete!): Implement builtins
---
module/language/js-il/runtime.js | 40 ++++++++++++++++++++++++++++++++++++----
1 file changed, 36 insertions(+), 4 deletions(-)
diff --git a/module/language/js-il/runtime.js b/module/language/js-il/runtime.js
index c337fc4..5398868 100644
--- a/module/language/js-il/runtime.js
+++ b/module/language/js-il/runtime.js
@@ -945,6 +945,10 @@ def_guile0("make-list", function (self, cont, n, obj) {
return cont(list);
});
+def_guile0("cons", function (self, cont, car, cdr) {
+ return cont(scheme.primitives.cons(car, cdr));
+});
+
def_guile0("length", function (self, cont, list) {
var len = 0;
@@ -1027,18 +1031,46 @@ def_guile0("equal?", function (self, cont, x, y) {
return cont(coerce_bool(scm_equal(x,y)));
});
-def_guile0("memq", function (self, cont, val, args) {
+def_guile0("memq", function (self, cont, elt, list) {
+ // FIXME: validate list
+ for (; list != scheme.EMPTY && list != scheme.NIL; list = list.cdr) {
+ if (elt === list.car) { // FIXME: eqv
+ return cont(list);
+ }
+ }
return cont(scheme.FALSE);
});
def_guile0("member", function (self, cont, elt, list) {
- // FIXME: needs equal? console.log("member", arguments);
- // throw "";
+ // FIXME: validate list
+ for (; list != scheme.EMPTY && list != scheme.NIL; list = list.cdr) {
+ if (scm_equal(elt, list.car)) {
+ return cont(list);
+ }
+ }
return cont(scheme.FALSE);
});
def_guile0("delete!", function (self, cont, elt, list) {
- // FIXME:
+ // FIXME: validate list
+ if (list instanceof scheme.Pair) {
+ // initially skip car;
+ for (var prev = list, walk = list.cdr;
+ walk instanceof scheme.Pair;
+ walk = walk.cdr) {
+
+ if (scm_equal(walk.car, elt)) {
+ prev.cdr = walk.cdr;
+ } else {
+ prev = prev.cdr;
+ }
+ }
+ // fixup car in return value, but can't delete
+ if (scm_equal(list.car, elt)) {
+ return cont(list.cdr);
+ }
+ }
+
return cont(list);
});
- [Guile-commits] 39/99: Add missing simplify.scm to Makefile, (continued)
- [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, 2021/10/10
- [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 <=
- [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
- [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