[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 56/99: Implement builtin list procedures.
From: |
Christopher Allan Webber |
Subject: |
[Guile-commits] 56/99: Implement builtin list procedures. |
Date: |
Sun, 10 Oct 2021 21:51:00 -0400 (EDT) |
cwebber pushed a commit to branch compile-to-js-merge
in repository guile.
commit 2a3c43a5a9594be20993467456ad906ce32c6fd0
Author: Ian Price <ianprice90@googlemail.com>
AuthorDate: Wed Aug 2 21:11:02 2017 +0100
Implement builtin list procedures.
* module/language/js-il/runtime.js
(make-list, length, list?, reverse, append, memq, member, delete!):
New procedures
---
module/language/js-il/runtime.js | 90 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 90 insertions(+)
diff --git a/module/language/js-il/runtime.js b/module/language/js-il/runtime.js
index a140147..5011f2e 100644
--- a/module/language/js-il/runtime.js
+++ b/module/language/js-il/runtime.js
@@ -651,6 +651,96 @@ function scm_mul(self, cont) {
};
def_guile0("*", scm_mul);
+// Lists
+def_guile0("make-list", function (self, cont, n, obj) {
+ var list = scheme.EMPTY;
+
+ for (var i = 0; i <= n; i++) {
+ list = new scheme.Pair(obj, list);
+ }
+
+ return cont(list);
+});
+
+def_guile0("length", function (self, cont, list) {
+ var len = 0;
+
+ while (!scheme.is_true(scheme.primitives["null?"](list))) {
+ if (scheme.is_true(scheme.primitives["pair?"](list))) {
+ list = list.cdr;
+ len += 1;
+ } else {
+ console.log("length bad");
+ not_implemented_yet();
+ }
+ }
+
+ return cont(len);
+});
+
+def_guile0("list?", function (self, cont, list) {
+
+ while (!scheme.is_true(scheme.primitives["null?"](list))) {
+ if (scheme.is_true(scheme.primitives["pair?"](list))) {
+ list = list.cdr;
+ } else {
+ return cont(scheme.FALSE);
+ }
+ }
+
+ return cont(scheme.TRUE);
+});
+
+def_guile0("reverse", function (self, cont, lst) {
+ var l = scheme.EMPTY;
+ while (lst != scheme.EMPTY) {
+ l = scheme.primitives.cons(lst.car, l);
+ lst = lst.cdr;
+ }
+ return cont(l);
+});
+
+def_guile0("append", function (self, cont, l1, l2) {
+ if (arguments.length != 4) {
+ console.log("FIXAPPEND", arguments.length);
+ throw "fail";
+ }
+
+
+ if (l1 === scheme.EMPTY) {
+ return cont(l2);
+ }
+
+ var l = new scheme.Pair(l1.car, l2);
+
+ var lp = l;
+ while (scheme.is_true(scheme.primitives["pair?"](l1.cdr))) {
+
+ var lo = new scheme.Pair(l1.cdr.car, l2);
+ lp.cdr = l2;
+
+ lp = lp.cdr;
+ l1 = l1.cdr;
+ }
+
+ return cont(l);
+});
+
+def_guile0("memq", function (self, cont, val, args) {
+ return cont(scheme.FALSE);
+});
+
+def_guile0("member", function (self, cont, elt, list) {
+ // FIXME: needs equal? console.log("member", arguments);
+ // throw "";
+ return cont(scheme.FALSE);
+});
+
+def_guile0("delete!", function (self, cont, elt, list) {
+ // FIXME:
+ return cont(list);
+});
+
// Macros
scheme.Macro = function (name, type, binding) {
// TODO: prim field?
- [Guile-commits] 44/99: Update primitives in no-values-primitives, (continued)
- [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
- [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 <=
- [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, 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