From 8493e289d1d7ef7143e892185ee3352ac33af0ac Mon Sep 17 00:00:00 2001 From: Martin Gasbichler Date: Sat, 27 Mar 2004 06:23:46 +0000 Subject: [PATCH] Added structure GC Clean up doc --- scsh/interaction/README | 30 +++++++++++++++++++++++++++++- scsh/interaction/gc.scm | 15 +++++++++++++++ scsh/interaction/packages.scm | 13 +++++++++++++ 3 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 scsh/interaction/gc.scm diff --git a/scsh/interaction/README b/scsh/interaction/README index e08d2f6..0c55dea 100644 --- a/scsh/interaction/README +++ b/scsh/interaction/README @@ -1,3 +1,14 @@ +The interaction library currently offers three structures that provide +a programmatic interface to Scheme 48's debugging facilities: + +* REPLS starts the read-eval-print-loop with arbitrary input and + output ports. + +* INSPECT-EXCEPTION provides exception handlers that allow interactive + inspection of exceptions and their backtrace. + +* GC provides a small run-time interface to the garbage collector. + The structure REPLS offers procedures to start up the read-eval-print-loop (REPL) from a script. @@ -28,6 +39,9 @@ from the socket's output port and prints it to (current-output-port). +The structure INSPECT-EXCEPTION makes some of the functionality of the +,debug and ,preview commands available. + (with-inspecting-handler port prepare thunk) This procedure installs a exception handler which captures all @@ -106,4 +120,18 @@ WITH-FATAL-AND-CAPTURING-ERROR-HANDLER. The procedural analogy to the ,proceed command. Continuation must be a continuation object as captured by WITH-FATAL-AND-CAPTURING-ERROR-HANDLER, not a procedure as captured by -CALL-WITH-CURRENT-CONTINUATION. \ No newline at end of file +CALL-WITH-CURRENT-CONTINUATION. + + +The structure GC provides a procedure equivalent to the ,collect +command and offers some statistics about the garbage collector. + +(collect outport) -> unspecified + +Invokes the GC and prints the number of free words before and after +the collection to OUTPORT. + +(gc-count) -> number + +Returns the number of times the garbage collector has been invoked +since the start of the system. diff --git a/scsh/interaction/gc.scm b/scsh/interaction/gc.scm new file mode 100644 index 0000000..571ba13 --- /dev/null +++ b/scsh/interaction/gc.scm @@ -0,0 +1,15 @@ +(define (collect port) + (let ((before (memory-status (enum memory-status-option available) #f))) + (primitive-collect) + (let ((after (memory-status (enum memory-status-option available) #f))) + (display "Before: " port) + (write before port) + (display " words free in semispace" port) + (newline port) + (display "After: " port) + (write after port) + (display " words free in semispace" port) + (newline port)))) + +(define (gc-count) + (memory-status (enum memory-status-option gc-count) #f)) diff --git a/scsh/interaction/packages.scm b/scsh/interaction/packages.scm index 095195c..b7d1bde 100644 --- a/scsh/interaction/packages.scm +++ b/scsh/interaction/packages.scm @@ -10,6 +10,10 @@ (define-interface socket2stdports-interface (export socket<->stdports)) +(define-interface gc-interface + (export collect + gc-count)) + (define-structure repls repls-interface (open scheme-with-scsh command-levels @@ -35,3 +39,12 @@ handle threads) (files socket2stdport)) + +(define-structure gc gc-interface + (open scheme + enumerated + (subset architecture (memory-status-option)) + (modify primitives (rename (collect primitive-collect)) + (expose collect memory-status)) + threads) + (files gc))