mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-07-03 11:16:36 +02:00
Binding finalizers. Handling multiple implicit or explicit calls to finalizers.
This commit is contained in:
parent
7dfad8a293
commit
fa44ad7cf8
1 changed files with 19 additions and 7 deletions
|
@ -1399,7 +1399,10 @@
|
|||
" " (type-id-name name)
|
||||
" = sexp_register_c_type(ctx, name, "
|
||||
(cond ((memq 'finalizer: type)
|
||||
=> (lambda (x) (generate-stub-name (cadr x))))
|
||||
=> (lambda (x)
|
||||
(let ((name (cadr x)))
|
||||
(generate-stub-name
|
||||
(if (pair? name) (car name) name)))))
|
||||
(else "sexp_finalize_c_type"))
|
||||
");\n")
|
||||
(cond
|
||||
|
@ -1484,12 +1487,21 @@
|
|||
(cond
|
||||
((memq 'finalizer: type)
|
||||
=> (lambda (x)
|
||||
(cat "static sexp " (generate-stub-name (cadr x))
|
||||
" (sexp ctx, sexp self, sexp_sint_t n, sexp x) {\n"
|
||||
" if (sexp_cpointer_freep(x))\n"
|
||||
" " (cadr x) "(sexp_cpointer_value(x));\n"
|
||||
" return SEXP_VOID;\n"
|
||||
"}\n\n"))))
|
||||
(let* ((y (cadr x))
|
||||
(scheme-name (if (pair? y) (car y) y))
|
||||
(cname (if (pair? y) (cadr y) y)))
|
||||
(cat "static sexp " (generate-stub-name scheme-name)
|
||||
" (sexp ctx, sexp self, sexp_sint_t n, sexp x) {\n"
|
||||
" if (sexp_cpointer_freep(x)) {\n"
|
||||
" " cname "(sexp_cpointer_value(x));\n"
|
||||
;; TODO: keep track of open/close separately from ownership
|
||||
" sexp_cpointer_freep(x) = 0;\n"
|
||||
" }\n"
|
||||
" return SEXP_VOID;\n"
|
||||
"}\n\n")
|
||||
;; make the finalizer available
|
||||
(set! *funcs*
|
||||
(cons (parse-func `(void ,(cadr x) (,name))) *funcs*))))))
|
||||
;; maybe write constructor
|
||||
(cond
|
||||
((memq 'constructor: type)
|
||||
|
|
Loading…
Add table
Reference in a new issue