guile-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Guile-commits] 18/99: Add more types of constants


From: Christopher Allan Webber
Subject: [Guile-commits] 18/99: Add more types of constants
Date: Sun, 10 Oct 2021 21:50:45 -0400 (EDT)

cwebber pushed a commit to branch compile-to-js-merge
in repository guile.

commit e9d0f97410d3549caab95acea1b706e544e44f8b
Author: Ian Price <ianprice90@googlemail.com>
AuthorDate: Fri Jun 12 18:30:39 2015 +0100

    Add more types of constants
---
 module/language/js-il/compile-javascript.scm | 23 +++++++++++++++++++++++
 module/language/js-il/runtime.js             | 26 ++++++++++++++++++++++++++
 2 files changed, 49 insertions(+)

diff --git a/module/language/js-il/compile-javascript.scm 
b/module/language/js-il/compile-javascript.scm
index 7f814ff..3b13e08 100644
--- a/module/language/js-il/compile-javascript.scm
+++ b/module/language/js-il/compile-javascript.scm
@@ -235,5 +235,28 @@
           (make-call
            (make-refine *scheme* (make-const "String"))
            (list (make-const c)))))
+        ((pair? c)
+         (make-new
+          (make-call
+           (make-refine *scheme* (make-const "Pair"))
+           (list (compile-const (car c))
+                 (compile-const (cdr c))))))
+        ((vector? c)
+         (make-new
+          (make-call
+           (make-refine *scheme* (make-const "Vector"))
+           (map compile-const (vector->list c)))))
+        ((char? c)
+         (make-new
+          (make-call
+           (make-refine *scheme* (make-const "Char"))
+           (list (make-const (string c))))))
+        ((keyword? c)
+         (make-new
+          (make-call
+           (make-refine *scheme* (make-const "Keyword"))
+           (list (make-const (symbol->string (keyword->symbol c)))))))
+        ((undefined? c)
+         (make-refine *scheme* (make-const "UNDEFINED")))
         (else
          (throw 'uncompilable-const c))))
diff --git a/module/language/js-il/runtime.js b/module/language/js-il/runtime.js
index 1e51c6b..6569cbe 100644
--- a/module/language/js-il/runtime.js
+++ b/module/language/js-il/runtime.js
@@ -111,13 +111,39 @@ scheme.Symbol = function(s) {
     };
 };
 
+// Keywords
+scheme.Keyword = function(s) {
+    this.name = s;
+    return this;
+};
+
 // Vectors
+scheme.Vector = function () {
+    this.array = Array.prototype.slice.call(arguments);
+    return this;
+};
+
+scheme.primitives["vector-ref"] = function (vec, idx) {
+    return vec.array[idx];
+};
+
+scheme.primitives["vector-set!"] = function (vec, idx, obj) {
+    return vec.array[idx] = obj;
+};
+
+scheme.primitives["vector-length"] = function (vec) {
+    return vec.array.length;
+};
 
 // Bytevectors
 
 // Booleans
 
 // Chars
+scheme.Char = function(c) {
+    this.c = c;
+    return this;
+};
 
 // Strings
 scheme.String = function(s) {



reply via email to

[Prev in Thread] Current Thread [Next in Thread]