1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-20 11:40:18 +02:00

Update example disassemblies

* doc/ref/compiler.texi:
* doc/ref/vm.texi: Update example disassemblies for current compiler,
  which uses assert-nargs-ee/locals.
This commit is contained in:
Andy Wingo 2010-05-02 14:18:58 +02:00
parent de45d8eef9
commit 0a715b9adc
2 changed files with 27 additions and 37 deletions

View file

@ -709,33 +709,28 @@ to play around with it at the REPL, as can be seen in this annotated
example:
@example
scheme@@(guile-user)> (compile '(+ 32 10) #:to 'assembly)
scheme@@(guile-user)> (pp (compile '(+ 32 10) #:to 'assembly))
(load-program
((:LCASE104 . 6)) ; Labels, unused in this case.
16 ; Length of the thunk that was compiled.
((:LCASE16 . 2)) ; Labels, unused in this case.
8 ; Length of the thunk that was compiled.
(load-program ; Metadata thunk.
()
17
#f ; No metadata thunk for the metadata thunk.
(make-eol)
(make-eol)
(make-int8 6)
(make-int8 12) ; Liveness extents, source info, and arities,
(make-int8:0) ; in a format that Guile knows how to parse.
(make-int8 2) ; Liveness extents, source info, and arities,
(make-int8 8) ; in a format that Guile knows how to parse.
(make-int8:0)
(list 0 3)
(list 0 1)
(list 0 3)
(return))
(assert-nargs-ee 0 0) ; Prologue.
(reserve-locals 0 0)
(assert-nargs-ee/locals 0) ; Prologue.
(make-int8 32) ; Actual code starts here.
(make-int8 10)
(add)
(return)
(nop)
(nop) ; Padding; the metadata thunk is actually
(nop) ; written after the main text.
(nop))
(return))
@end example
Of course you can switch the REPL to assembly and enter in assembly
@ -754,12 +749,11 @@ the next step down from assembly:
@example
scheme@@(guile-user)> (compile '(+ 32 10) #:to 'bytecode)
@result{} #vu8(16 0 0 0 25 0 0 0 ; Header.
45 0 0 52 0 0 ; Prologue.
10 32 10 10 148 66 ; Actual code.
0 0 0 0 ; Padding.
17 0 0 0 0 0 0 0 9 9 10 6 10 ; Metadata thunk.
12 11 18 0 3 18 0 1 18 0 3 66)
@result{} #vu8(8 0 0 0 25 0 0 0 ; Header.
95 0 ; Prologue.
10 32 10 10 148 66 17 ; Actual code.
0 0 0 0 0 0 0 9 ; Metadata thunk.
9 10 2 10 8 11 18 0 3 18 0 1 18 0 3 66)
@end example
``Objcode'' is bytecode, but mapped directly to a C structure,

View file

@ -309,31 +309,27 @@ 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 #<procedure foo (a)>:
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)
0 (assert-nargs-ee/locals 1)
2 (object-ref 1) ;; #<procedure 8ebec20 at <current input>:0:17 (b)>
4 (local-ref 0) ;; `a'
6 (make-closure 0 1)
9 (return)
----------------------------------------
Disassembly of #<procedure 85bfec0 at <current input>:0:16 (b)>:
Disassembly of #<procedure 8ebec20 at <current input>:0:17 (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)
0 (assert-nargs-ee/locals 1)
2 (toplevel-ref 1) ;; `foo'
4 (free-ref 0) ;; (closure variable)
6 (local-ref 0) ;; `b'
8 (list 0 3) ;; 3 elements at (unknown file):0:29
11 (return)
@end smallexample
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
1 argument. Then at @code{ip} 2, we load up the compiled lambda. @code{Ip} 4
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
6---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