mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-23 20:15:05 +02:00
Integrated immutable functions
This commit is contained in:
parent
0647ae6166
commit
e85a04fd81
1 changed files with 39 additions and 1 deletions
|
@ -76,6 +76,9 @@
|
||||||
;; Inlines (TBD, this may move)
|
;; Inlines (TBD, this may move)
|
||||||
define-c-inline?
|
define-c-inline?
|
||||||
define-c->inline-var
|
define-c->inline-var
|
||||||
|
;; Immutable objects
|
||||||
|
immutable?
|
||||||
|
Cyc-set-immutable!
|
||||||
;; String functions
|
;; String functions
|
||||||
string-join
|
string-join
|
||||||
string-split
|
string-split
|
||||||
|
@ -750,4 +753,39 @@
|
||||||
(loop input (add current output) '()))
|
(loop input (add current output) '()))
|
||||||
(loop input output (cons char current))))))))
|
(loop input output (cons char current))))))))
|
||||||
|
|
||||||
))
|
;; Immutable Object section
|
||||||
|
|
||||||
|
;; Predicate - is the given object immutable?
|
||||||
|
(define-c immutable?
|
||||||
|
"(void *data, int argc, closure _, object k, object obj)"
|
||||||
|
"object result = boolean_t;
|
||||||
|
if (is_object_type(obj) &&
|
||||||
|
(type_of(obj) == pair_tag ||
|
||||||
|
type_of(obj) == vector_tag ||
|
||||||
|
type_of(obj) == bytevector_tag ||
|
||||||
|
type_of(obj) == string_tag
|
||||||
|
) &&
|
||||||
|
!immutable(obj) ) {
|
||||||
|
result = boolean_f;
|
||||||
|
}
|
||||||
|
return_closcall1(data, k, result); ")
|
||||||
|
|
||||||
|
;; Internal helper function - set immutable field on a single obj
|
||||||
|
(define-c _Cyc-set-immutable!
|
||||||
|
"(void *data, int argc, closure _, object k, object obj, object val)"
|
||||||
|
"object result = boolean_f;
|
||||||
|
if (is_object_type(obj)) {
|
||||||
|
immutable(obj) = (val == boolean_f) ? 0 : 1;
|
||||||
|
result = boolean_t;
|
||||||
|
}
|
||||||
|
return_closcall1(data, k, result); ")
|
||||||
|
|
||||||
|
;; Recursively update the immutable field for the given object
|
||||||
|
(define (Cyc-set-immutable! obj val)
|
||||||
|
(_Cyc-set-immutable! obj val)
|
||||||
|
(cond
|
||||||
|
((pair? obj) (for-each (lambda (o) (_Cyc-set-immutable! o val)) obj))
|
||||||
|
((vector? obj) (vector-for-each (lambda (o) (_Cyc-set-immutable! o val)) obj))))
|
||||||
|
;; END immutables
|
||||||
|
|
||||||
|
))
|
||||||
|
|
Loading…
Add table
Reference in a new issue