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:
parent
de45d8eef9
commit
0a715b9adc
2 changed files with 27 additions and 37 deletions
|
@ -709,33 +709,28 @@ to play around with it at the REPL, as can be seen in this annotated
|
||||||
example:
|
example:
|
||||||
|
|
||||||
@example
|
@example
|
||||||
scheme@@(guile-user)> (compile '(+ 32 10) #:to 'assembly)
|
scheme@@(guile-user)> (pp (compile '(+ 32 10) #:to 'assembly))
|
||||||
(load-program
|
(load-program
|
||||||
((:LCASE104 . 6)) ; Labels, unused in this case.
|
((:LCASE16 . 2)) ; Labels, unused in this case.
|
||||||
16 ; Length of the thunk that was compiled.
|
8 ; Length of the thunk that was compiled.
|
||||||
(load-program ; Metadata thunk.
|
(load-program ; Metadata thunk.
|
||||||
()
|
()
|
||||||
17
|
17
|
||||||
#f ; No metadata thunk for the metadata thunk.
|
#f ; No metadata thunk for the metadata thunk.
|
||||||
(make-eol)
|
(make-eol)
|
||||||
(make-eol)
|
(make-eol)
|
||||||
(make-int8 6)
|
(make-int8 2) ; Liveness extents, source info, and arities,
|
||||||
(make-int8 12) ; Liveness extents, source info, and arities,
|
(make-int8 8) ; in a format that Guile knows how to parse.
|
||||||
(make-int8:0) ; in a format that Guile knows how to parse.
|
(make-int8:0)
|
||||||
(list 0 3)
|
(list 0 3)
|
||||||
(list 0 1)
|
(list 0 1)
|
||||||
(list 0 3)
|
(list 0 3)
|
||||||
(return))
|
(return))
|
||||||
(assert-nargs-ee 0 0) ; Prologue.
|
(assert-nargs-ee/locals 0) ; Prologue.
|
||||||
(reserve-locals 0 0)
|
|
||||||
(make-int8 32) ; Actual code starts here.
|
(make-int8 32) ; Actual code starts here.
|
||||||
(make-int8 10)
|
(make-int8 10)
|
||||||
(add)
|
(add)
|
||||||
(return)
|
(return))
|
||||||
(nop)
|
|
||||||
(nop) ; Padding; the metadata thunk is actually
|
|
||||||
(nop) ; written after the main text.
|
|
||||||
(nop))
|
|
||||||
@end example
|
@end example
|
||||||
|
|
||||||
Of course you can switch the REPL to assembly and enter in assembly
|
Of course you can switch the REPL to assembly and enter in assembly
|
||||||
|
@ -754,12 +749,11 @@ the next step down from assembly:
|
||||||
|
|
||||||
@example
|
@example
|
||||||
scheme@@(guile-user)> (compile '(+ 32 10) #:to 'bytecode)
|
scheme@@(guile-user)> (compile '(+ 32 10) #:to 'bytecode)
|
||||||
@result{} #vu8(16 0 0 0 25 0 0 0 ; Header.
|
@result{} #vu8(8 0 0 0 25 0 0 0 ; Header.
|
||||||
45 0 0 52 0 0 ; Prologue.
|
95 0 ; Prologue.
|
||||||
10 32 10 10 148 66 ; Actual code.
|
10 32 10 10 148 66 17 ; Actual code.
|
||||||
0 0 0 0 ; Padding.
|
0 0 0 0 0 0 0 9 ; Metadata thunk.
|
||||||
17 0 0 0 0 0 0 0 9 9 10 6 10 ; Metadata thunk.
|
9 10 2 10 8 11 18 0 3 18 0 1 18 0 3 66)
|
||||||
12 11 18 0 3 18 0 1 18 0 3 66)
|
|
||||||
@end example
|
@end example
|
||||||
|
|
||||||
``Objcode'' is bytecode, but mapped directly to a C structure,
|
``Objcode'' is bytecode, but mapped directly to a C structure,
|
||||||
|
|
|
@ -309,31 +309,27 @@ We can see how these concepts tie together by disassembling the
|
||||||
@smallexample
|
@smallexample
|
||||||
scheme@@(guile-user)> (define (foo a) (lambda (b) (list foo a b)))
|
scheme@@(guile-user)> (define (foo a) (lambda (b) (list foo a b)))
|
||||||
scheme@@(guile-user)> ,x foo
|
scheme@@(guile-user)> ,x foo
|
||||||
Disassembly of #<procedure foo (a)>:
|
0 (assert-nargs-ee/locals 1)
|
||||||
|
2 (object-ref 1) ;; #<procedure 8ebec20 at <current input>:0:17 (b)>
|
||||||
0 (assert-nargs-ee 0 1)
|
4 (local-ref 0) ;; `a'
|
||||||
3 (reserve-locals 0 1)
|
6 (make-closure 0 1)
|
||||||
6 (object-ref 1) ;; #<procedure 85bfec0 at <current input>:0:16 (b)>
|
9 (return)
|
||||||
8 (local-ref 0) ;; `a'
|
|
||||||
10 (make-closure 0 1)
|
|
||||||
13 (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)
|
0 (assert-nargs-ee/locals 1)
|
||||||
3 (reserve-locals 0 1)
|
2 (toplevel-ref 1) ;; `foo'
|
||||||
6 (toplevel-ref 1) ;; `foo'
|
4 (free-ref 0) ;; (closure variable)
|
||||||
8 (free-ref 0) ;; (closure variable)
|
6 (local-ref 0) ;; `b'
|
||||||
10 (local-ref 0) ;; `b'
|
8 (list 0 3) ;; 3 elements at (unknown file):0:29
|
||||||
12 (list 0 3) ;; 3 elements at (unknown file):0:28
|
11 (return)
|
||||||
15 (return)
|
|
||||||
@end smallexample
|
@end smallexample
|
||||||
|
|
||||||
First there's some prelude, where @code{foo} checks that it was called with only
|
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}
|
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.
|
vector). Finally we return the closure.
|
||||||
|
|
||||||
The second stanza disassembles the compiled lambda. After the prelude, we note
|
The second stanza disassembles the compiled lambda. After the prelude, we note
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue