1
Fork 0
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:
Ian Price 2015-06-12 18:30:39 +01:00
parent 941f8fac01
commit e9d0f97410
2 changed files with 49 additions and 0 deletions

View file

@ -235,5 +235,28 @@
(make-call (make-call
(make-refine *scheme* (make-const "String")) (make-refine *scheme* (make-const "String"))
(list (make-const c))))) (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 (else
(throw 'uncompilable-const c)))) (throw 'uncompilable-const c))))

View file

@ -111,13 +111,39 @@ scheme.Symbol = function(s) {
}; };
}; };
// Keywords
scheme.Keyword = function(s) {
this.name = s;
return this;
};
// Vectors // 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 // Bytevectors
// Booleans // Booleans
// Chars // Chars
scheme.Char = function(c) {
this.c = c;
return this;
};
// Strings // Strings
scheme.String = function(s) { scheme.String = function(s) {