mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-07-03 19:26: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)
|
" " (type-id-name name)
|
||||||
" = sexp_register_c_type(ctx, name, "
|
" = sexp_register_c_type(ctx, name, "
|
||||||
(cond ((memq 'finalizer: type)
|
(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"))
|
(else "sexp_finalize_c_type"))
|
||||||
");\n")
|
");\n")
|
||||||
(cond
|
(cond
|
||||||
|
@ -1484,12 +1487,21 @@
|
||||||
(cond
|
(cond
|
||||||
((memq 'finalizer: type)
|
((memq 'finalizer: type)
|
||||||
=> (lambda (x)
|
=> (lambda (x)
|
||||||
(cat "static sexp " (generate-stub-name (cadr x))
|
(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"
|
" (sexp ctx, sexp self, sexp_sint_t n, sexp x) {\n"
|
||||||
" if (sexp_cpointer_freep(x))\n"
|
" if (sexp_cpointer_freep(x)) {\n"
|
||||||
" " (cadr x) "(sexp_cpointer_value(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"
|
" return SEXP_VOID;\n"
|
||||||
"}\n\n"))))
|
"}\n\n")
|
||||||
|
;; make the finalizer available
|
||||||
|
(set! *funcs*
|
||||||
|
(cons (parse-func `(void ,(cadr x) (,name))) *funcs*))))))
|
||||||
;; maybe write constructor
|
;; maybe write constructor
|
||||||
(cond
|
(cond
|
||||||
((memq 'constructor: type)
|
((memq 'constructor: type)
|
||||||
|
|
Loading…
Add table
Reference in a new issue