From c5e20f196c585faed80c3752eff020f00645370c Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Sun, 23 Oct 2016 12:32:40 +0200 Subject: [PATCH] Guile gc experiment. guile/gc.scm: New file. --- guile/gc.scm | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 guile/gc.scm diff --git a/guile/gc.scm b/guile/gc.scm new file mode 100644 index 00000000..01116994 --- /dev/null +++ b/guile/gc.scm @@ -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)