diff options
author | Andy Wingo <wingo@pobox.com> | 2010-01-12 00:19:18 +0100 |
---|---|---|
committer | Andy Wingo <wingo@pobox.com> | 2010-01-12 00:19:18 +0100 |
commit | 136b5494d13fdc4a7b3b59d4bd451beb2c075e25 (patch) | |
tree | 8947937624779c7d93d4988b59fbc71509a3d7da | |
parent | 3b12702faf0fa42890e4c857aabda3e6d5eb5c83 (diff) | |
download | guile-136b5494d13fdc4a7b3b59d4bd451beb2c075e25.tar.gz |
programs print as #<procedure ...>
* module/system/vm/program.scm (write-program): Print as #<procedure
...>. Fix stdin printing.
* doc/ref/vm.texi: Update a little bit.
-rw-r--r-- | doc/ref/vm.texi | 65 | ||||
-rw-r--r-- | module/system/vm/program.scm | 5 |
2 files changed, 37 insertions, 33 deletions
diff --git a/doc/ref/vm.texi b/doc/ref/vm.texi index b64c2a675..ffcfbed22 100644 --- a/doc/ref/vm.texi +++ b/doc/ref/vm.texi @@ -306,42 +306,45 @@ We can see how these concepts tie together by disassembling the @smallexample scheme@@(guile-user)> (define (foo a) (lambda (b) (list foo a b))) scheme@@(guile-user)> ,x foo -Disassembly of #<program foo (a)>: +Disassembly of #<procedure foo (a)>: - 0 (object-ref 1) ;; #<program b7e478b0 at <unknown port>:0:16 (b)> - 2 (local-ref 0) ;; `a' (arg) - 4 (vector 0 1) ;; 1 element - 7 (make-closure) - 8 (return) + 0 (assert-nargs-ee 0 1) + 3 (reserve-locals 0 1) + 6 (object-ref 1) ;; #<procedure 85bfec0 at <current input>:0:16 (b)> + 8 (local-ref 0) ;; `a' + 10 (make-closure 0 1) + 13 (return) ---------------------------------------- -Disassembly of #<program b7e478b0 at <unknown port>:0:16 (b)>: - - 0 (toplevel-ref 1) ;; `foo' - 2 (free-ref 0) ;; (closure variable) - 4 (local-ref 0) ;; `b' (arg) - 6 (list 0 3) ;; 3 elements at (unknown file):0:28 - 9 (return) +Disassembly of #<procedure 85bfec0 at <current input>:0:16 (b)>: + + 0 (assert-nargs-ee 0 1) + 3 (reserve-locals 0 1) + 6 (toplevel-ref 1) ;; `foo' + 8 (free-ref 0) ;; (closure variable) + 10 (local-ref 0) ;; `b' + 12 (list 0 3) ;; 3 elements at (unknown file):0:28 + 15 (return) @end smallexample -At @code{ip} 0, we load up the compiled lambda. @code{Ip} 2 and 4 -create the free variables vector, and @code{ip} 7 makes the -closure---binding code (from the compiled lambda) with data (the -free-variable vector). Finally we return the closure. - -The second stanza disassembles the compiled lambda. Toplevel variables -are resolved relative to the module that was current when the -procedure was created. This lookup occurs lazily, at the first time -the variable is actually referenced, and the location of the lookup is -cached so that future references are very cheap. @xref{Environment -Control Instructions}, for more details. - -Then we see a reference to an external variable, corresponding to -@code{a}. The disassembler doesn't have enough information to give a -name to that variable, so it just marks it as being a ``closure -variable''. Finally we see the reference to @code{b}, then the -@code{list} opcode, an inline implementation of the @code{list} scheme -routine. +First there's some prelude, where @code{foo} checks that it was called with only +1 argument. Then at @code{ip} 6, we load up the compiled lambda. @code{Ip} 8 +loads up `a', so that it can be captured into a closure by at @code{ip} +10---binding code (from the compiled lambda) with data (the free-variable +vector). Finally we return the closure. + +The second stanza disassembles the compiled lambda. After the prelude, we note +that toplevel variables are resolved relative to the module that was current +when the procedure was created. This lookup occurs lazily, at the first time the +variable is actually referenced, and the location of the lookup is cached so +that future references are very cheap. @xref{Environment Control Instructions}, +for more details. + +Then we see a reference to a free variable, corresponding to @code{a}. The +disassembler doesn't have enough information to give a name to that variable, so +it just marks it as being a ``closure variable''. Finally we see the reference +to @code{b}, then the @code{list} opcode, an inline implementation of the +@code{list} scheme routine. @node Instruction Set @subsection Instruction Set diff --git a/module/system/vm/program.scm b/module/system/vm/program.scm index ccb9ebfe7..28d453ab9 100644 --- a/module/system/vm/program.scm +++ b/module/system/vm/program.scm @@ -192,13 +192,14 @@ . ,rest))) (define (write-program prog port) - (format port "#<program ~a~a>" + (format port "#<procedure ~a~a>" (or (program-name prog) (and=> (program-source prog 0) (lambda (s) (format #f "~a at ~a:~a:~a" (number->string (object-address prog) 16) - (or (source:file s) "<unknown port>") + (or (source:file s) + (if s "<current input>" "<unknown port>")) (source:line s) (source:column s)))) (number->string (object-address prog) 16)) (let ((arities (program-arities prog))) |