programs print as #<procedure ...>
authorAndy Wingo <wingo@pobox.com>
Mon, 11 Jan 2010 23:19:18 +0000 (00:19 +0100)
committerAndy Wingo <wingo@pobox.com>
Mon, 11 Jan 2010 23:19:18 +0000 (00:19 +0100)
* module/system/vm/program.scm (write-program): Print as #<procedure
  ...>. Fix stdin printing.

* doc/ref/vm.texi: Update a little bit.

doc/ref/vm.texi
module/system/vm/program.scm

index b64c2a6..ffcfbed 100644 (file)
@@ -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
index ccb9ebf..28d453a 100644 (file)
       . ,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)))