This commit is contained in:
Justin Ethier 2019-05-21 13:02:35 -04:00
parent bbd24a8972
commit 0647ae6166

View file

@ -2,17 +2,18 @@
(import (scheme base) (scheme write)) (import (scheme base) (scheme write))
;; TODO: make #t respect object type
(define-c immutable? (define-c immutable?
"(void *data, int argc, closure _, object k, object obj)" "(void *data, int argc, closure _, object k, object obj)"
"object result = boolean_f; "object result = boolean_t;
if (is_object_type(obj) && if (is_object_type(obj) &&
(type_of(obj) == pair_tag || (type_of(obj) == pair_tag ||
type_of(obj) == vector_tag || type_of(obj) == vector_tag ||
type_of(obj) == bytevector_tag || type_of(obj) == bytevector_tag ||
type_of(obj) == string_tag type_of(obj) == string_tag
) && ) &&
immutable(obj) ) { !immutable(obj) ) {
result = boolean_t; result = boolean_f;
} }
return_closcall1(data, k, result); ") return_closcall1(data, k, result); ")
@ -28,10 +29,11 @@
(define (Cyc-set-immutable! obj val) (define (Cyc-set-immutable! obj val)
(_Cyc-set-immutable! obj val) (_Cyc-set-immutable! obj val)
(cond (cond
((pair? obj) (map (lambda (o) (_Cyc-set-immutable! o val)) obj)) ((pair? obj) (for-each (lambda (o) (_Cyc-set-immutable! o val)) obj))
((vector? obj) (vector-map (lambda (o) (_Cyc-set-immutable! o val)) obj)))) ((vector? obj) (vector-for-each (lambda (o) (_Cyc-set-immutable! o val)) obj))))
(define lis '(1 2 3)) (define lis '(1 2 3))
(define vec '#((1) 2 3))
(write (write
(list (list
@ -42,5 +44,16 @@
(immutable? (car lis)) (immutable? (car lis))
(set-car! lis 'a) (set-car! lis 'a)
lis lis
))
(newline)
(write
(list
(immutable? vec)
(immutable? (vector-ref vec 0))
;(Cyc-set-immutable! vec #f)
(immutable? vec)
(immutable? (vector-ref vec 0))
(vector-set! vec 0 'x)
vec
) )
) )