mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-19 02:00:26 +02:00
Merge branch 'master' of git://git.savannah.gnu.org/guile into elisp
This commit is contained in:
commit
a43df0ae47
42 changed files with 1767 additions and 1099 deletions
|
@ -20,16 +20,28 @@
|
|||
#:use-module (system vm instruction)
|
||||
#:use-module (language assembly compile-bytecode))
|
||||
|
||||
(define (->u8-list sym val)
|
||||
(let ((entry (assq-ref `((uint16 2 ,bytevector-u16-native-set!)
|
||||
(uint32 4 ,bytevector-u32-native-set!))
|
||||
sym)))
|
||||
(or entry (error "unknown sym" sym))
|
||||
(let ((bv (make-bytevector (car entry))))
|
||||
((cadr entry) bv 0 val)
|
||||
(bytevector->u8-list bv))))
|
||||
|
||||
(define (munge-bytecode v)
|
||||
(let ((newv (make-u8vector (vector-length v))))
|
||||
(let lp ((i 0))
|
||||
(if (= i (vector-length v))
|
||||
newv
|
||||
(let ((x (vector-ref v i)))
|
||||
(u8vector-set! newv i (if (symbol? x)
|
||||
(instruction->opcode x)
|
||||
x))
|
||||
(lp (1+ i)))))))
|
||||
(let lp ((i 0) (out '()))
|
||||
(if (= i (vector-length v))
|
||||
(list->u8vector (reverse out))
|
||||
(let ((x (vector-ref v i)))
|
||||
(cond
|
||||
((symbol? x)
|
||||
(lp (1+ i) (cons (instruction->opcode x) out)))
|
||||
((integer? x)
|
||||
(lp (1+ i) (cons x out)))
|
||||
((pair? x)
|
||||
(lp (1+ i) (append (reverse (apply ->u8-list x)) out)))
|
||||
(else (error "bad test bytecode" x)))))))
|
||||
|
||||
(define (comp-test x y)
|
||||
(let* ((y (munge-bytecode y))
|
||||
|
@ -46,13 +58,6 @@
|
|||
(lambda ()
|
||||
(equal? v y)))))
|
||||
|
||||
(define (u32->u8-list x)
|
||||
;; Return a 4 uint8 list corresponding to the host's native representation
|
||||
;; of X, a uint32.
|
||||
(let ((bv (make-bytevector 4)))
|
||||
(bytevector-u32-native-set! bv 0 x)
|
||||
(bytevector->u8-list bv)))
|
||||
|
||||
|
||||
(with-test-prefix "compiler"
|
||||
(with-test-prefix "asm-to-bytecode"
|
||||
|
@ -85,29 +90,34 @@
|
|||
(vector 'load-keyword 0 0 3 (char->integer #\q) (char->integer #\u)
|
||||
(char->integer #\x)))
|
||||
|
||||
(comp-test '(load-program 3 2 1 0 () 3 #f (make-int8 3) (return))
|
||||
(list->vector
|
||||
`(load-program
|
||||
3 2 1 0 ;; nargs, nrest, nlocs, nexts
|
||||
,@(u32->u8-list 3) ;; len
|
||||
,@(u32->u8-list 0) ;; metalen
|
||||
make-int8 3
|
||||
return)))
|
||||
(comp-test '(load-program 3 2 1 () 3 #f (make-int8 3) (return))
|
||||
#(load-program
|
||||
3 2 (uint16 1) ;; nargs, nrest, nlocs
|
||||
(uint32 3) ;; len
|
||||
(uint32 0) ;; metalen
|
||||
(uint32 0) ;; padding
|
||||
make-int8 3
|
||||
return))
|
||||
|
||||
(comp-test '(load-program 3 2 1 0 () 3
|
||||
(load-program 3 2 1 0 () 3
|
||||
;; the nops are to pad meta to an 8-byte alignment. not strictly
|
||||
;; necessary for this test, but representative of the common case.
|
||||
(comp-test '(load-program 3 2 1 () 8
|
||||
(load-program 3 2 1 () 3
|
||||
#f
|
||||
(make-int8 3) (return))
|
||||
(make-int8 3) (return))
|
||||
(list->vector
|
||||
`(load-program
|
||||
3 2 1 0 ;; nargs, nrest, nlocs, nexts
|
||||
,@(u32->u8-list 3) ;; len
|
||||
,@(u32->u8-list (+ 3 12)) ;; metalen
|
||||
make-int8 3
|
||||
return
|
||||
3 2 1 0 ;; nargs, nrest, nlocs, nexts
|
||||
,@(u32->u8-list 3) ;; len
|
||||
,@(u32->u8-list 0) ;; metalen
|
||||
make-int8 3
|
||||
return)))))
|
||||
(make-int8 3) (return)
|
||||
(nop) (nop) (nop) (nop) (nop))
|
||||
#(load-program
|
||||
3 2 (uint16 1) ;; nargs, nrest, nlocs
|
||||
(uint32 8) ;; len
|
||||
(uint32 19) ;; metalen
|
||||
(uint32 0) ;; padding
|
||||
make-int8 3
|
||||
return
|
||||
nop nop nop nop nop
|
||||
3 2 (uint16 1) ;; nargs, nrest, nlocs
|
||||
(uint32 3) ;; len
|
||||
(uint32 0) ;; metalen
|
||||
(uint32 0) ;; padding
|
||||
make-int8 3
|
||||
return))))
|
||||
|
|
|
@ -21,8 +21,10 @@
|
|||
#:use-module (test-suite lib)
|
||||
#:use-module (system base compile)
|
||||
#:use-module (system base pmatch)
|
||||
#:use-module (system base message)
|
||||
#:use-module (language tree-il)
|
||||
#:use-module (language glil))
|
||||
#:use-module (language glil)
|
||||
#:use-module (srfi srfi-13))
|
||||
|
||||
;; Of course, the GLIL that is emitted depends on the source info of the
|
||||
;; input. Here we're not concerned about that, so we strip source
|
||||
|
@ -64,21 +66,21 @@
|
|||
(with-test-prefix "void"
|
||||
(assert-tree-il->glil
|
||||
(void)
|
||||
(program 0 0 0 0 () (void) (call return 1)))
|
||||
(program 0 0 0 () (void) (call return 1)))
|
||||
(assert-tree-il->glil
|
||||
(begin (void) (const 1))
|
||||
(program 0 0 0 0 () (const 1) (call return 1)))
|
||||
(program 0 0 0 () (const 1) (call return 1)))
|
||||
(assert-tree-il->glil
|
||||
(apply (primitive +) (void) (const 1))
|
||||
(program 0 0 0 0 () (void) (const 1) (call add 2) (call return 1))))
|
||||
(program 0 0 0 () (void) (const 1) (call add 2) (call return 1))))
|
||||
|
||||
(with-test-prefix "application"
|
||||
(assert-tree-il->glil
|
||||
(apply (toplevel foo) (const 1))
|
||||
(program 0 0 0 0 () (toplevel ref foo) (const 1) (call goto/args 1)))
|
||||
(program 0 0 0 () (toplevel ref foo) (const 1) (call goto/args 1)))
|
||||
(assert-tree-il->glil/pmatch
|
||||
(begin (apply (toplevel foo) (const 1)) (void))
|
||||
(program 0 0 0 0 () (toplevel ref foo) (const 1) (mv-call 1 ,l1)
|
||||
(program 0 0 0 () (toplevel ref foo) (const 1) (mv-call 1 ,l1)
|
||||
(call drop 1) (branch br ,l2)
|
||||
(label ,l3) (mv-bind () #f) (unbind)
|
||||
(label ,l4)
|
||||
|
@ -86,26 +88,26 @@
|
|||
(and (eq? l1 l3) (eq? l2 l4)))
|
||||
(assert-tree-il->glil
|
||||
(apply (toplevel foo) (apply (toplevel bar)))
|
||||
(program 0 0 0 0 () (toplevel ref foo) (toplevel ref bar) (call call 0)
|
||||
(program 0 0 0 () (toplevel ref foo) (toplevel ref bar) (call call 0)
|
||||
(call goto/args 1))))
|
||||
|
||||
(with-test-prefix "conditional"
|
||||
(assert-tree-il->glil/pmatch
|
||||
(if (const #t) (const 1) (const 2))
|
||||
(program 0 0 0 0 () (const #t) (branch br-if-not ,l1)
|
||||
(program 0 0 0 () (const #t) (branch br-if-not ,l1)
|
||||
(const 1) (call return 1)
|
||||
(label ,l2) (const 2) (call return 1))
|
||||
(eq? l1 l2))
|
||||
|
||||
(assert-tree-il->glil/pmatch
|
||||
(begin (if (const #t) (const 1) (const 2)) (const #f))
|
||||
(program 0 0 0 0 () (const #t) (branch br-if-not ,l1) (branch br ,l2)
|
||||
(program 0 0 0 () (const #t) (branch br-if-not ,l1) (branch br ,l2)
|
||||
(label ,l3) (label ,l4) (const #f) (call return 1))
|
||||
(eq? l1 l3) (eq? l2 l4))
|
||||
|
||||
(assert-tree-il->glil/pmatch
|
||||
(apply (primitive null?) (if (const #t) (const 1) (const 2)))
|
||||
(program 0 0 0 0 () (const #t) (branch br-if-not ,l1)
|
||||
(program 0 0 0 () (const #t) (branch br-if-not ,l1)
|
||||
(const 1) (branch br ,l2)
|
||||
(label ,l3) (const 2) (label ,l4)
|
||||
(call null? 1) (call return 1))
|
||||
|
@ -114,279 +116,281 @@
|
|||
(with-test-prefix "primitive-ref"
|
||||
(assert-tree-il->glil
|
||||
(primitive +)
|
||||
(program 0 0 0 0 () (toplevel ref +) (call return 1)))
|
||||
(program 0 0 0 () (toplevel ref +) (call return 1)))
|
||||
|
||||
(assert-tree-il->glil
|
||||
(begin (primitive +) (const #f))
|
||||
(program 0 0 0 0 () (const #f) (call return 1)))
|
||||
(program 0 0 0 () (const #f) (call return 1)))
|
||||
|
||||
(assert-tree-il->glil
|
||||
(apply (primitive null?) (primitive +))
|
||||
(program 0 0 0 0 () (toplevel ref +) (call null? 1)
|
||||
(program 0 0 0 () (toplevel ref +) (call null? 1)
|
||||
(call return 1))))
|
||||
|
||||
(with-test-prefix "lexical refs"
|
||||
(assert-tree-il->glil
|
||||
(let (x) (y) ((const 1)) (lexical x y))
|
||||
(program 0 0 1 0 ()
|
||||
(const 1) (bind (x local 0)) (local set 0)
|
||||
(local ref 0) (call return 1)
|
||||
(program 0 0 1 ()
|
||||
(const 1) (bind (x #f 0)) (lexical #t #f set 0)
|
||||
(lexical #t #f ref 0) (call return 1)
|
||||
(unbind)))
|
||||
|
||||
(assert-tree-il->glil
|
||||
(let (x) (y) ((const 1)) (begin (lexical x y) (const #f)))
|
||||
(program 0 0 1 0 ()
|
||||
(const 1) (bind (x local 0)) (local set 0)
|
||||
(program 0 0 1 ()
|
||||
(const 1) (bind (x #f 0)) (lexical #t #f set 0)
|
||||
(const #f) (call return 1)
|
||||
(unbind)))
|
||||
|
||||
(assert-tree-il->glil
|
||||
(let (x) (y) ((const 1)) (apply (primitive null?) (lexical x y)))
|
||||
(program 0 0 1 0 ()
|
||||
(const 1) (bind (x local 0)) (local set 0)
|
||||
(local ref 0) (call null? 1) (call return 1)
|
||||
(program 0 0 1 ()
|
||||
(const 1) (bind (x #f 0)) (lexical #t #f set 0)
|
||||
(lexical #t #f ref 0) (call null? 1) (call return 1)
|
||||
(unbind))))
|
||||
|
||||
(with-test-prefix "lexical sets"
|
||||
(assert-tree-il->glil
|
||||
(let (x) (y) ((const 1)) (set! (lexical x y) (const 2)))
|
||||
(program 0 0 0 1 ()
|
||||
(const 1) (bind (x external 0)) (external set 0 0)
|
||||
(const 2) (external set 0 0) (void) (call return 1)
|
||||
(program 0 0 1 ()
|
||||
(const 1) (bind (x #t 0)) (lexical #t #t box 0)
|
||||
(const 2) (lexical #t #t set 0) (void) (call return 1)
|
||||
(unbind)))
|
||||
|
||||
(assert-tree-il->glil
|
||||
(let (x) (y) ((const 1)) (begin (set! (lexical x y) (const 2)) (const #f)))
|
||||
(program 0 0 0 1 ()
|
||||
(const 1) (bind (x external 0)) (external set 0 0)
|
||||
(const 2) (external set 0 0) (const #f) (call return 1)
|
||||
(program 0 0 1 ()
|
||||
(const 1) (bind (x #t 0)) (lexical #t #t box 0)
|
||||
(const 2) (lexical #t #t set 0) (const #f) (call return 1)
|
||||
(unbind)))
|
||||
|
||||
(assert-tree-il->glil
|
||||
(let (x) (y) ((const 1))
|
||||
(apply (primitive null?) (set! (lexical x y) (const 2))))
|
||||
(program 0 0 0 1 ()
|
||||
(const 1) (bind (x external 0)) (external set 0 0)
|
||||
(const 2) (external set 0 0) (void) (call null? 1) (call return 1)
|
||||
(program 0 0 1 ()
|
||||
(const 1) (bind (x #t 0)) (lexical #t #t box 0)
|
||||
(const 2) (lexical #t #t set 0) (void) (call null? 1) (call return 1)
|
||||
(unbind))))
|
||||
|
||||
(with-test-prefix "module refs"
|
||||
(assert-tree-il->glil
|
||||
(@ (foo) bar)
|
||||
(program 0 0 0 0 ()
|
||||
(program 0 0 0 ()
|
||||
(module public ref (foo) bar)
|
||||
(call return 1)))
|
||||
|
||||
(assert-tree-il->glil
|
||||
(begin (@ (foo) bar) (const #f))
|
||||
(program 0 0 0 0 ()
|
||||
(program 0 0 0 ()
|
||||
(module public ref (foo) bar) (call drop 1)
|
||||
(const #f) (call return 1)))
|
||||
|
||||
(assert-tree-il->glil
|
||||
(apply (primitive null?) (@ (foo) bar))
|
||||
(program 0 0 0 0 ()
|
||||
(program 0 0 0 ()
|
||||
(module public ref (foo) bar)
|
||||
(call null? 1) (call return 1)))
|
||||
|
||||
(assert-tree-il->glil
|
||||
(@@ (foo) bar)
|
||||
(program 0 0 0 0 ()
|
||||
(program 0 0 0 ()
|
||||
(module private ref (foo) bar)
|
||||
(call return 1)))
|
||||
|
||||
(assert-tree-il->glil
|
||||
(begin (@@ (foo) bar) (const #f))
|
||||
(program 0 0 0 0 ()
|
||||
(program 0 0 0 ()
|
||||
(module private ref (foo) bar) (call drop 1)
|
||||
(const #f) (call return 1)))
|
||||
|
||||
(assert-tree-il->glil
|
||||
(apply (primitive null?) (@@ (foo) bar))
|
||||
(program 0 0 0 0 ()
|
||||
(program 0 0 0 ()
|
||||
(module private ref (foo) bar)
|
||||
(call null? 1) (call return 1))))
|
||||
|
||||
(with-test-prefix "module sets"
|
||||
(assert-tree-il->glil
|
||||
(set! (@ (foo) bar) (const 2))
|
||||
(program 0 0 0 0 ()
|
||||
(program 0 0 0 ()
|
||||
(const 2) (module public set (foo) bar)
|
||||
(void) (call return 1)))
|
||||
|
||||
(assert-tree-il->glil
|
||||
(begin (set! (@ (foo) bar) (const 2)) (const #f))
|
||||
(program 0 0 0 0 ()
|
||||
(program 0 0 0 ()
|
||||
(const 2) (module public set (foo) bar)
|
||||
(const #f) (call return 1)))
|
||||
|
||||
(assert-tree-il->glil
|
||||
(apply (primitive null?) (set! (@ (foo) bar) (const 2)))
|
||||
(program 0 0 0 0 ()
|
||||
(program 0 0 0 ()
|
||||
(const 2) (module public set (foo) bar)
|
||||
(void) (call null? 1) (call return 1)))
|
||||
|
||||
(assert-tree-il->glil
|
||||
(set! (@@ (foo) bar) (const 2))
|
||||
(program 0 0 0 0 ()
|
||||
(program 0 0 0 ()
|
||||
(const 2) (module private set (foo) bar)
|
||||
(void) (call return 1)))
|
||||
|
||||
(assert-tree-il->glil
|
||||
(begin (set! (@@ (foo) bar) (const 2)) (const #f))
|
||||
(program 0 0 0 0 ()
|
||||
(program 0 0 0 ()
|
||||
(const 2) (module private set (foo) bar)
|
||||
(const #f) (call return 1)))
|
||||
|
||||
(assert-tree-il->glil
|
||||
(apply (primitive null?) (set! (@@ (foo) bar) (const 2)))
|
||||
(program 0 0 0 0 ()
|
||||
(program 0 0 0 ()
|
||||
(const 2) (module private set (foo) bar)
|
||||
(void) (call null? 1) (call return 1))))
|
||||
|
||||
(with-test-prefix "toplevel refs"
|
||||
(assert-tree-il->glil
|
||||
(toplevel bar)
|
||||
(program 0 0 0 0 ()
|
||||
(program 0 0 0 ()
|
||||
(toplevel ref bar)
|
||||
(call return 1)))
|
||||
|
||||
(assert-tree-il->glil
|
||||
(begin (toplevel bar) (const #f))
|
||||
(program 0 0 0 0 ()
|
||||
(program 0 0 0 ()
|
||||
(toplevel ref bar) (call drop 1)
|
||||
(const #f) (call return 1)))
|
||||
|
||||
(assert-tree-il->glil
|
||||
(apply (primitive null?) (toplevel bar))
|
||||
(program 0 0 0 0 ()
|
||||
(program 0 0 0 ()
|
||||
(toplevel ref bar)
|
||||
(call null? 1) (call return 1))))
|
||||
|
||||
(with-test-prefix "toplevel sets"
|
||||
(assert-tree-il->glil
|
||||
(set! (toplevel bar) (const 2))
|
||||
(program 0 0 0 0 ()
|
||||
(program 0 0 0 ()
|
||||
(const 2) (toplevel set bar)
|
||||
(void) (call return 1)))
|
||||
|
||||
(assert-tree-il->glil
|
||||
(begin (set! (toplevel bar) (const 2)) (const #f))
|
||||
(program 0 0 0 0 ()
|
||||
(program 0 0 0 ()
|
||||
(const 2) (toplevel set bar)
|
||||
(const #f) (call return 1)))
|
||||
|
||||
(assert-tree-il->glil
|
||||
(apply (primitive null?) (set! (toplevel bar) (const 2)))
|
||||
(program 0 0 0 0 ()
|
||||
(program 0 0 0 ()
|
||||
(const 2) (toplevel set bar)
|
||||
(void) (call null? 1) (call return 1))))
|
||||
|
||||
(with-test-prefix "toplevel defines"
|
||||
(assert-tree-il->glil
|
||||
(define bar (const 2))
|
||||
(program 0 0 0 0 ()
|
||||
(program 0 0 0 ()
|
||||
(const 2) (toplevel define bar)
|
||||
(void) (call return 1)))
|
||||
|
||||
(assert-tree-il->glil
|
||||
(begin (define bar (const 2)) (const #f))
|
||||
(program 0 0 0 0 ()
|
||||
(program 0 0 0 ()
|
||||
(const 2) (toplevel define bar)
|
||||
(const #f) (call return 1)))
|
||||
|
||||
(assert-tree-il->glil
|
||||
(apply (primitive null?) (define bar (const 2)))
|
||||
(program 0 0 0 0 ()
|
||||
(program 0 0 0 ()
|
||||
(const 2) (toplevel define bar)
|
||||
(void) (call null? 1) (call return 1))))
|
||||
|
||||
(with-test-prefix "constants"
|
||||
(assert-tree-il->glil
|
||||
(const 2)
|
||||
(program 0 0 0 0 ()
|
||||
(program 0 0 0 ()
|
||||
(const 2) (call return 1)))
|
||||
|
||||
(assert-tree-il->glil
|
||||
(begin (const 2) (const #f))
|
||||
(program 0 0 0 0 ()
|
||||
(program 0 0 0 ()
|
||||
(const #f) (call return 1)))
|
||||
|
||||
(assert-tree-il->glil
|
||||
(apply (primitive null?) (const 2))
|
||||
(program 0 0 0 0 ()
|
||||
(program 0 0 0 ()
|
||||
(const 2) (call null? 1) (call return 1))))
|
||||
|
||||
(with-test-prefix "lambda"
|
||||
(assert-tree-il->glil
|
||||
(lambda (x) (y) () (const 2))
|
||||
(program 0 0 0 0 ()
|
||||
(program 1 0 0 0 ()
|
||||
(bind (x local 0))
|
||||
(program 0 0 0 ()
|
||||
(program 1 0 0 ()
|
||||
(bind (x #f 0))
|
||||
(const 2) (call return 1))
|
||||
(call return 1)))
|
||||
|
||||
(assert-tree-il->glil
|
||||
(lambda (x x1) (y y1) () (const 2))
|
||||
(program 0 0 0 0 ()
|
||||
(program 2 0 0 0 ()
|
||||
(bind (x local 0) (x1 local 1))
|
||||
(program 0 0 0 ()
|
||||
(program 2 0 0 ()
|
||||
(bind (x #f 0) (x1 #f 1))
|
||||
(const 2) (call return 1))
|
||||
(call return 1)))
|
||||
|
||||
(assert-tree-il->glil
|
||||
(lambda x y () (const 2))
|
||||
(program 0 0 0 0 ()
|
||||
(program 1 1 0 0 ()
|
||||
(bind (x local 0))
|
||||
(program 0 0 0 ()
|
||||
(program 1 1 0 ()
|
||||
(bind (x #f 0))
|
||||
(const 2) (call return 1))
|
||||
(call return 1)))
|
||||
|
||||
(assert-tree-il->glil
|
||||
(lambda (x . x1) (y . y1) () (const 2))
|
||||
(program 0 0 0 0 ()
|
||||
(program 2 1 0 0 ()
|
||||
(bind (x local 0) (x1 local 1))
|
||||
(program 0 0 0 ()
|
||||
(program 2 1 0 ()
|
||||
(bind (x #f 0) (x1 #f 1))
|
||||
(const 2) (call return 1))
|
||||
(call return 1)))
|
||||
|
||||
(assert-tree-il->glil
|
||||
(lambda (x . x1) (y . y1) () (lexical x y))
|
||||
(program 0 0 0 0 ()
|
||||
(program 2 1 0 0 ()
|
||||
(bind (x local 0) (x1 local 1))
|
||||
(local ref 0) (call return 1))
|
||||
(program 0 0 0 ()
|
||||
(program 2 1 0 ()
|
||||
(bind (x #f 0) (x1 #f 1))
|
||||
(lexical #t #f ref 0) (call return 1))
|
||||
(call return 1)))
|
||||
|
||||
(assert-tree-il->glil
|
||||
(lambda (x . x1) (y . y1) () (lexical x1 y1))
|
||||
(program 0 0 0 0 ()
|
||||
(program 2 1 0 0 ()
|
||||
(bind (x local 0) (x1 local 1))
|
||||
(local ref 1) (call return 1))
|
||||
(program 0 0 0 ()
|
||||
(program 2 1 0 ()
|
||||
(bind (x #f 0) (x1 #f 1))
|
||||
(lexical #t #f ref 1) (call return 1))
|
||||
(call return 1)))
|
||||
|
||||
(assert-tree-il->glil
|
||||
(lambda (x) (x1) () (lambda (y) (y1) () (lexical x x1)))
|
||||
(program 0 0 0 0 ()
|
||||
(program 1 0 0 1 ()
|
||||
(bind (x external 0))
|
||||
(local ref 0) (external set 0 0)
|
||||
(program 1 0 0 0 ()
|
||||
(bind (y local 0))
|
||||
(external ref 1 0) (call return 1))
|
||||
(program 0 0 0 ()
|
||||
(program 1 0 0 ()
|
||||
(bind (x #f 0))
|
||||
(program 1 0 0 ()
|
||||
(bind (y #f 0))
|
||||
(lexical #f #f ref 0) (call return 1))
|
||||
(lexical #t #f ref 0)
|
||||
(call vector 1)
|
||||
(call make-closure 2)
|
||||
(call return 1))
|
||||
(call return 1))))
|
||||
|
||||
(with-test-prefix "sequence"
|
||||
(assert-tree-il->glil
|
||||
(begin (begin (const 2) (const #f)) (const #t))
|
||||
(program 0 0 0 0 ()
|
||||
(program 0 0 0 ()
|
||||
(const #t) (call return 1)))
|
||||
|
||||
(assert-tree-il->glil
|
||||
(apply (primitive null?) (begin (const #f) (const 2)))
|
||||
(program 0 0 0 0 ()
|
||||
(program 0 0 0 ()
|
||||
(const 2) (call null? 1) (call return 1))))
|
||||
|
||||
;; FIXME: binding info for or-hacked locals might bork the disassembler,
|
||||
|
@ -398,13 +402,13 @@
|
|||
(lexical x y)
|
||||
(let (a) (b) ((const 2))
|
||||
(lexical a b))))
|
||||
(program 0 0 1 0 ()
|
||||
(const 1) (bind (x local 0)) (local set 0)
|
||||
(local ref 0) (branch br-if-not ,l1)
|
||||
(local ref 0) (call return 1)
|
||||
(program 0 0 1 ()
|
||||
(const 1) (bind (x #f 0)) (lexical #t #f set 0)
|
||||
(lexical #t #f ref 0) (branch br-if-not ,l1)
|
||||
(lexical #t #f ref 0) (call return 1)
|
||||
(label ,l2)
|
||||
(const 2) (bind (a local 0)) (local set 0)
|
||||
(local ref 0) (call return 1)
|
||||
(const 2) (bind (a #f 0)) (lexical #t #f set 0)
|
||||
(lexical #t #f ref 0) (call return 1)
|
||||
(unbind)
|
||||
(unbind))
|
||||
(eq? l1 l2))
|
||||
|
@ -415,13 +419,13 @@
|
|||
(lexical x y)
|
||||
(let (a) (b) ((const 2))
|
||||
(lexical x y))))
|
||||
(program 0 0 2 0 ()
|
||||
(const 1) (bind (x local 0)) (local set 0)
|
||||
(local ref 0) (branch br-if-not ,l1)
|
||||
(local ref 0) (call return 1)
|
||||
(program 0 0 2 ()
|
||||
(const 1) (bind (x #f 0)) (lexical #t #f set 0)
|
||||
(lexical #t #f ref 0) (branch br-if-not ,l1)
|
||||
(lexical #t #f ref 0) (call return 1)
|
||||
(label ,l2)
|
||||
(const 2) (bind (a local 1)) (local set 1)
|
||||
(local ref 0) (call return 1)
|
||||
(const 2) (bind (a #f 1)) (lexical #t #f set 1)
|
||||
(lexical #t #f ref 0) (call return 1)
|
||||
(unbind)
|
||||
(unbind))
|
||||
(eq? l1 l2)))
|
||||
|
@ -429,10 +433,10 @@
|
|||
(with-test-prefix "apply"
|
||||
(assert-tree-il->glil
|
||||
(apply (primitive @apply) (toplevel foo) (toplevel bar))
|
||||
(program 0 0 0 0 () (toplevel ref foo) (toplevel ref bar) (call goto/apply 2)))
|
||||
(program 0 0 0 () (toplevel ref foo) (toplevel ref bar) (call goto/apply 2)))
|
||||
(assert-tree-il->glil/pmatch
|
||||
(begin (apply (primitive @apply) (toplevel foo) (toplevel bar)) (void))
|
||||
(program 0 0 0 0 ()
|
||||
(program 0 0 0 ()
|
||||
(toplevel ref apply) (toplevel ref foo) (toplevel ref bar) (mv-call 2 ,l1)
|
||||
(call drop 1) (branch br ,l2) (label ,l3) (mv-bind () #f) (unbind)
|
||||
(label ,l4)
|
||||
|
@ -440,7 +444,7 @@
|
|||
(and (eq? l1 l3) (eq? l2 l4)))
|
||||
(assert-tree-il->glil
|
||||
(apply (toplevel foo) (apply (toplevel @apply) (toplevel bar) (toplevel baz)))
|
||||
(program 0 0 0 0 ()
|
||||
(program 0 0 0 ()
|
||||
(toplevel ref foo)
|
||||
(toplevel ref bar) (toplevel ref baz) (call apply 2)
|
||||
(call goto/args 1))))
|
||||
|
@ -448,10 +452,10 @@
|
|||
(with-test-prefix "call/cc"
|
||||
(assert-tree-il->glil
|
||||
(apply (primitive @call-with-current-continuation) (toplevel foo))
|
||||
(program 0 0 0 0 () (toplevel ref foo) (call goto/cc 1)))
|
||||
(program 0 0 0 () (toplevel ref foo) (call goto/cc 1)))
|
||||
(assert-tree-il->glil/pmatch
|
||||
(begin (apply (primitive @call-with-current-continuation) (toplevel foo)) (void))
|
||||
(program 0 0 0 0 ()
|
||||
(program 0 0 0 ()
|
||||
(toplevel ref call-with-current-continuation) (toplevel ref foo) (mv-call 1 ,l1)
|
||||
(call drop 1) (branch br ,l2) (label ,l3) (mv-bind () #f) (unbind)
|
||||
(label ,l4)
|
||||
|
@ -460,8 +464,121 @@
|
|||
(assert-tree-il->glil
|
||||
(apply (toplevel foo)
|
||||
(apply (toplevel @call-with-current-continuation) (toplevel bar)))
|
||||
(program 0 0 0 0 ()
|
||||
(program 0 0 0 ()
|
||||
(toplevel ref foo)
|
||||
(toplevel ref bar) (call call/cc 1)
|
||||
(call goto/args 1))))
|
||||
|
||||
|
||||
(with-test-prefix "tree-il-fold"
|
||||
|
||||
(pass-if "empty tree"
|
||||
(let ((leaf? #f) (up? #f) (down? #f) (mark (list 'mark)))
|
||||
(and (eq? mark
|
||||
(tree-il-fold (lambda (x y) (set! leaf? #t) y)
|
||||
(lambda (x y) (set! down? #t) y)
|
||||
(lambda (x y) (set! up? #t) y)
|
||||
mark
|
||||
'()))
|
||||
(not leaf?)
|
||||
(not up?)
|
||||
(not down?))))
|
||||
|
||||
(pass-if "lambda and application"
|
||||
(let* ((leaves '()) (ups '()) (downs '())
|
||||
(result (tree-il-fold (lambda (x y)
|
||||
(set! leaves (cons x leaves))
|
||||
(1+ y))
|
||||
(lambda (x y)
|
||||
(set! downs (cons x downs))
|
||||
(1+ y))
|
||||
(lambda (x y)
|
||||
(set! ups (cons x ups))
|
||||
(1+ y))
|
||||
0
|
||||
(parse-tree-il
|
||||
'(lambda (x y) (x1 y1)
|
||||
(apply (toplevel +)
|
||||
(lexical x x1)
|
||||
(lexical y y1)))))))
|
||||
(and (equal? (map strip-source leaves)
|
||||
(list (make-lexical-ref #f 'y 'y1)
|
||||
(make-lexical-ref #f 'x 'x1)
|
||||
(make-toplevel-ref #f '+)))
|
||||
(= (length downs) 2)
|
||||
(equal? (reverse (map strip-source ups))
|
||||
(map strip-source downs))))))
|
||||
|
||||
|
||||
;;;
|
||||
;;; Warnings.
|
||||
;;;
|
||||
|
||||
;; Make sure we get English messages.
|
||||
(setlocale LC_ALL "C")
|
||||
|
||||
(define (call-with-warnings thunk)
|
||||
(let ((port (open-output-string)))
|
||||
(with-fluid* *current-warning-port* port
|
||||
thunk)
|
||||
(let ((warnings (get-output-string port)))
|
||||
(string-tokenize warnings
|
||||
(char-set-complement (char-set #\newline))))))
|
||||
|
||||
(define %opts-w-unused
|
||||
'(#:warnings (unused-variable)))
|
||||
|
||||
|
||||
(with-test-prefix "warnings"
|
||||
|
||||
(pass-if "unknown warning type"
|
||||
(let ((w (call-with-warnings
|
||||
(lambda ()
|
||||
(compile #t #:opts '(#:warnings (does-not-exist)))))))
|
||||
(and (= (length w) 1)
|
||||
(number? (string-contains (car w) "unknown warning")))))
|
||||
|
||||
(with-test-prefix "unused-variable"
|
||||
|
||||
(pass-if "quiet"
|
||||
(null? (call-with-warnings
|
||||
(lambda ()
|
||||
(compile '(lambda (x y) (+ x y))
|
||||
#:opts %opts-w-unused)))))
|
||||
|
||||
(pass-if "let/unused"
|
||||
(let ((w (call-with-warnings
|
||||
(lambda ()
|
||||
(compile '(lambda (x)
|
||||
(let ((y (+ x 2)))
|
||||
x))
|
||||
#:opts %opts-w-unused)))))
|
||||
(and (= (length w) 1)
|
||||
(number? (string-contains (car w) "unused variable `y'")))))
|
||||
|
||||
(pass-if "shadowed variable"
|
||||
(let ((w (call-with-warnings
|
||||
(lambda ()
|
||||
(compile '(lambda (x)
|
||||
(let ((y x))
|
||||
(let ((y (+ x 2)))
|
||||
(+ x y))))
|
||||
#:opts %opts-w-unused)))))
|
||||
(and (= (length w) 1)
|
||||
(number? (string-contains (car w) "unused variable `y'")))))
|
||||
|
||||
(pass-if "letrec"
|
||||
(null? (call-with-warnings
|
||||
(lambda ()
|
||||
(compile '(lambda ()
|
||||
(letrec ((x (lambda () (y)))
|
||||
(y (lambda () (x))))
|
||||
y))
|
||||
#:opts %opts-w-unused)))))
|
||||
|
||||
(pass-if "unused argument"
|
||||
;; Unused arguments should not be reported.
|
||||
(null? (call-with-warnings
|
||||
(lambda ()
|
||||
(compile '(lambda (x y z) #t)
|
||||
#:opts %opts-w-unused)))))))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue