mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-01 04:10:18 +02:00
Add more types of constants
This commit is contained in:
parent
941f8fac01
commit
e9d0f97410
2 changed files with 49 additions and 0 deletions
|
@ -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))))
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue