Debian Codegraph @

scheme/ikarus.guardians.ss

raw
1 ;;; Ikarus Scheme -- A compiler for R6RS Scheme.
2 ;;; Copyright (C) 2006,2007,2008 Abdulaziz Ghuloum
3 ;;;
4 ;;; This program is free software: you can redistribute it and/or modify
5 ;;; it under the terms of the GNU General Public License version 3 as
6 ;;; published by the Free Software Foundation.
7 ;;;
8 ;;; This program is distributed in the hope that it will be useful, but
9 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
10 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 ;;; General Public License for more details.
12 ;;;
13 ;;; You should have received a copy of the GNU General Public License
14 ;;; along with this program. If not, see <http://www.gnu.org/licenses/>.
15
16
17 ;;; The procedure make-guardian is coped en verbatim
18 ;;; from Dybvig et al. Guardians paper.
19
20 (library (ikarus guardians)
21 (export make-guardian)
22 (import (except (ikarus) make-guardian))
23 (define make-guardian
24 (lambda ()
25 (let ([tc
26 (let ([x (cons #f #f)])
27 (cons x x))])
28 (case-lambda
29 [()
30 (and (not (eq? (car tc) (cdr tc)))
31 (let ([x (car tc)])
32 (let ([y (car x)])
33 (set-car! tc (cdr x))
34 (set-car! x #f)
35 (set-cdr! x #f)
36 y)))]
37 [(obj)
38 (foreign-call "ikrt_register_guardian_pair" (cons tc obj))
39 (void)])))))