Guile gc experiment.

guile/gc.scm: New file.
This commit is contained in:
Jan Nieuwenhuizen 2016-10-23 12:32:40 +02:00
parent a00e69863e
commit c5e20f196c
1 changed files with 33 additions and 0 deletions

33
guile/gc.scm Normal file
View File

@ -0,0 +1,33 @@
(define-module (guile gc))
(define (R) (reload-module (current-module)))
(define gc-size 20)
(define the-cars (make-vector gc-size))
(define the-cdrs (make-vector gc-size))
(define gc-free 0)
(define (show-gc)
(display "free:") (display gc-free) (newline)
(display "cars:") (display the-cars) (newline))
(show-gc)
(define (make-cell type . x)
(cons type (if (pair? x) (car x))))
(define (gc-alloc)
((lambda (index)
(set! gc-free (+ gc-free 1))
;;(cons 'cell index)
(make-cell *unspecified* index)
)
gc-free))
(define (gc-make-number x)
((lambda (cell)
(vector-set! the-cars (cdr cell) (make-cell 'number x))
cell)
(gc-alloc)))
(display (gc-make-number 3)) (newline)
(show-gc)