mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-10 05:50:26 +02:00
remove lambda wrap hack of brainfuck tree-il compiler
* module/language/brainfuck/compile-tree-il.scm (compile-tree-il): Remove the hack where we wrapped the compiled code in a `lambda', because not only should the tree-il compiler optimize that away, it was really papering around other inefficiencies, and obtuse to boot.
This commit is contained in:
parent
0ebbcf43c4
commit
a84673a68b
1 changed files with 5 additions and 18 deletions
|
@ -49,12 +49,11 @@
|
||||||
;; This compiles a whole brainfuck program. This constructs a Tree-IL
|
;; This compiles a whole brainfuck program. This constructs a Tree-IL
|
||||||
;; code equivalent to Scheme code like this:
|
;; code equivalent to Scheme code like this:
|
||||||
;;
|
;;
|
||||||
;; ((lambda ()
|
|
||||||
;; (let ((pointer 0)
|
;; (let ((pointer 0)
|
||||||
;; (tape (make-vector tape-size 0)))
|
;; (tape (make-vector tape-size 0)))
|
||||||
;; (begin
|
;; (begin
|
||||||
;; <body>
|
;; <body>
|
||||||
;; (write-char #\newline)))))
|
;; (write-char #\newline)))
|
||||||
;;
|
;;
|
||||||
;; So first the pointer and tape variables are set up correctly, then the
|
;; So first the pointer and tape variables are set up correctly, then the
|
||||||
;; program's body is executed in this context, and finally we output an
|
;; program's body is executed in this context, and finally we output an
|
||||||
|
@ -69,17 +68,6 @@
|
||||||
;; throw an error, whereas a number of Brainfuck compilers do not detect
|
;; throw an error, whereas a number of Brainfuck compilers do not detect
|
||||||
;; this.
|
;; this.
|
||||||
;;
|
;;
|
||||||
;; We wrap the code in a lambda so that the body has a place to cache
|
|
||||||
;; the looked-up locations of the primitive functions: vector-ref et al.
|
|
||||||
;; This way we can use toplevel-ref instead of link-now + variable-ref.
|
|
||||||
;; See the VM documentation for more info on those instructions.
|
|
||||||
;;
|
|
||||||
;; Normally when compiling you don't have to think about this at all,
|
|
||||||
;; because the usual pattern is a bunch of definitions, then you call
|
|
||||||
;; those definitions -- so the real work is in the functions anyway,
|
|
||||||
;; which can use toplevel-ref. Here we just force that pattern into
|
|
||||||
;; effect.
|
|
||||||
;;
|
|
||||||
;; Note that we're generating the S-expression representation of
|
;; Note that we're generating the S-expression representation of
|
||||||
;; Tree-IL, then using parse-tree-il to turn it into the actual Tree-IL
|
;; Tree-IL, then using parse-tree-il to turn it into the actual Tree-IL
|
||||||
;; data structures. This makes the compiler more pleasant to look at,
|
;; data structures. This makes the compiler more pleasant to look at,
|
||||||
|
@ -104,11 +92,10 @@
|
||||||
(define (compile-tree-il exp env opts)
|
(define (compile-tree-il exp env opts)
|
||||||
(values
|
(values
|
||||||
(parse-tree-il
|
(parse-tree-il
|
||||||
`(apply (lambda () ()
|
`(let (pointer tape) (pointer tape)
|
||||||
(let (pointer tape) (pointer tape)
|
((const 0)
|
||||||
((const 0)
|
(apply (primitive make-vector) (const ,tape-size) (const 0)))
|
||||||
(apply (primitive make-vector) (const ,tape-size) (const 0)))
|
,(compile-body exp)))
|
||||||
,(compile-body exp)))))
|
|
||||||
env
|
env
|
||||||
env))
|
env))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue