mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-12 14:50:19 +02:00
some work on syntax.test
* module/language/tree-il.scm (tree-il->scheme): * module/ice-9/psyntax.scm (build-conditional): Attempt to not generate (if #f #f) as the second arm of an if, but it doesn't seem to be successful. * module/ice-9/psyntax-pp.scm (syntax-rules): Regenerate. * test-suite/tests/syntax.test (exception:unexpected-syntax): Change capitalization. ("unquote-splicing"): Update test. ("begin"): Add in second arms on these ifs, to avoid the strange though harmless expansion of `if'. (matches?): New helper macro. ("lambda"): Match on lexically bound symbols, as they will be alpha-renamed.
This commit is contained in:
parent
40b36cfbbe
commit
0260421208
4 changed files with 37 additions and 19 deletions
File diff suppressed because one or more lines are too long
|
@ -368,7 +368,9 @@
|
||||||
(case (fluid-ref *mode*)
|
(case (fluid-ref *mode*)
|
||||||
((c) ((@ (language tree-il) make-conditional)
|
((c) ((@ (language tree-il) make-conditional)
|
||||||
source test-exp then-exp else-exp))
|
source test-exp then-exp else-exp))
|
||||||
(else `(if ,test-exp ,then-exp ,else-exp)))))
|
(else (if (equal? else-exp '(if #f #f))
|
||||||
|
`(if ,test-exp ,then-exp)
|
||||||
|
`(if ,test-exp ,then-exp ,else-exp))))))
|
||||||
|
|
||||||
(define build-lexical-reference
|
(define build-lexical-reference
|
||||||
(lambda (type source name var)
|
(lambda (type source name var)
|
||||||
|
|
|
@ -215,7 +215,9 @@
|
||||||
`(,(tree-il->scheme proc) ,@(map tree-il->scheme args)))
|
`(,(tree-il->scheme proc) ,@(map tree-il->scheme args)))
|
||||||
|
|
||||||
((<conditional> test then else)
|
((<conditional> test then else)
|
||||||
`(if ,(tree-il->scheme test) ,(tree-il->scheme then) ,(tree-il->scheme else)))
|
(if (void? else)
|
||||||
|
`(if ,(tree-il->scheme test) ,(tree-il->scheme then))
|
||||||
|
`(if ,(tree-il->scheme test) ,(tree-il->scheme then) ,(tree-il->scheme else))))
|
||||||
|
|
||||||
((<primitive-ref> name)
|
((<primitive-ref> name)
|
||||||
name)
|
name)
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
|
|
||||||
|
|
||||||
(define exception:generic-syncase-error
|
(define exception:generic-syncase-error
|
||||||
(cons 'syntax-error "Source expression failed to match"))
|
(cons 'syntax-error "source expression failed to match"))
|
||||||
(define exception:unexpected-syntax
|
(define exception:unexpected-syntax
|
||||||
(cons 'syntax-error "unexpected syntax"))
|
(cons 'syntax-error "unexpected syntax"))
|
||||||
|
|
||||||
|
@ -111,8 +111,9 @@
|
||||||
(with-test-prefix "unquote-splicing"
|
(with-test-prefix "unquote-splicing"
|
||||||
|
|
||||||
(pass-if-exception "extra arguments"
|
(pass-if-exception "extra arguments"
|
||||||
exception:missing/extra-expr
|
'(syntax-error . "unquote-splicing takes exactly one argument")
|
||||||
(quasiquote ((unquote-splicing (list 1 2) (list 3 4)))))))
|
(eval '(quasiquote ((unquote-splicing (list 1 2) (list 3 4))))
|
||||||
|
(interaction-environment)))))
|
||||||
|
|
||||||
(with-test-prefix "begin"
|
(with-test-prefix "begin"
|
||||||
|
|
||||||
|
@ -121,17 +122,21 @@
|
||||||
|
|
||||||
(with-test-prefix "unmemoization"
|
(with-test-prefix "unmemoization"
|
||||||
|
|
||||||
|
;; FIXME. I have no idea why, but the expander is filling in (if #f
|
||||||
|
;; #f) as the second arm of the if, if the second arm is missing. I
|
||||||
|
;; thought I made it not do that. But in the meantime, let's adapt,
|
||||||
|
;; since that's not what we're testing.
|
||||||
|
|
||||||
(pass-if "normal begin"
|
(pass-if "normal begin"
|
||||||
(let ((foo (lambda () (if (= 1 1) (begin (+ 1) (+ 2))))))
|
(let ((foo (lambda () (if (= 1 1) (begin (+ 1) (+ 2)) #f))))
|
||||||
(foo) ; make sure, memoization has been performed
|
|
||||||
(equal? (procedure-source foo)
|
(equal? (procedure-source foo)
|
||||||
'(lambda () (if (= 1 1) (begin (+ 1) (+ 2)))))))
|
'(lambda () (if (= 1 1) (begin (+ 1) (+ 2)) #f)))))
|
||||||
|
|
||||||
(pass-if "redundant nested begin"
|
(pass-if "redundant nested begin"
|
||||||
(let ((foo (lambda () (if (= 1 1) (begin (+ 1) (begin (+ 2) (+ 3)))))))
|
(let ((foo (lambda () (if (= 1 1) (begin (+ 1) (begin (+ 2) (+ 3))) #f))))
|
||||||
(foo) ; make sure, memoization has been performed
|
(foo) ; make sure, memoization has been performed
|
||||||
(equal? (procedure-source foo)
|
(equal? (procedure-source foo)
|
||||||
'(lambda () (if (= 1 1) (begin (+ 1) (begin (+ 2) (+ 3))))))))
|
'(lambda () (if (= 1 1) (begin (+ 1) (begin (+ 2) (+ 3))) #f)))))
|
||||||
|
|
||||||
(pass-if "redundant begin at start of body"
|
(pass-if "redundant begin at start of body"
|
||||||
(let ((foo (lambda () (begin (+ 1) (+ 2))))) ; should be optimized
|
(let ((foo (lambda () (begin (+ 1) (+ 2))))) ; should be optimized
|
||||||
|
@ -139,25 +144,34 @@
|
||||||
(equal? (procedure-source foo)
|
(equal? (procedure-source foo)
|
||||||
'(lambda () (begin (+ 1) (+ 2)))))))
|
'(lambda () (begin (+ 1) (+ 2)))))))
|
||||||
|
|
||||||
(expect-fail-exception "illegal (begin)"
|
(pass-if-exception "illegal (begin)"
|
||||||
exception:bad-body
|
exception:generic-syncase-error
|
||||||
(eval '(begin (if #t (begin)) #t) (interaction-environment))))
|
(eval '(begin (if #t (begin)) #t) (interaction-environment))))
|
||||||
|
|
||||||
|
(define-syntax matches?
|
||||||
|
(syntax-rules (_)
|
||||||
|
((_ (op arg ...) pat) (let ((x (op arg ...)))
|
||||||
|
(matches? x pat)))
|
||||||
|
((_ x ()) (null? x))
|
||||||
|
((_ x (a . b)) (and (pair? x)
|
||||||
|
(matches? (car x) a)
|
||||||
|
(matches? (cdr x) b)))
|
||||||
|
((_ x _) #t)
|
||||||
|
((_ x pat) (equal? x 'pat))))
|
||||||
|
|
||||||
(with-test-prefix "lambda"
|
(with-test-prefix "lambda"
|
||||||
|
|
||||||
(with-test-prefix "unmemoization"
|
(with-test-prefix "unmemoization"
|
||||||
|
|
||||||
(pass-if "normal lambda"
|
(pass-if "normal lambda"
|
||||||
(let ((foo (lambda () (lambda (x y) (+ x y)))))
|
(let ((foo (lambda () (lambda (x y) (+ x y)))))
|
||||||
((foo) 1 2) ; make sure, memoization has been performed
|
(matches? (procedure-source foo)
|
||||||
(equal? (procedure-source foo)
|
(lambda () (lambda (_ _) (+ _ _))))))
|
||||||
'(lambda () (lambda (x y) (+ x y))))))
|
|
||||||
|
|
||||||
(pass-if "lambda with documentation"
|
(pass-if "lambda with documentation"
|
||||||
(let ((foo (lambda () (lambda (x y) "docstring" (+ x y)))))
|
(let ((foo (lambda () (lambda (x y) "docstring" (+ x y)))))
|
||||||
((foo) 1 2) ; make sure, memoization has been performed
|
(matches? (procedure-source foo)
|
||||||
(equal? (procedure-source foo)
|
(lambda () (lambda (_ _) "docstring" (+ _ _)))))))
|
||||||
'(lambda () (lambda (x y) "docstring" (+ x y)))))))
|
|
||||||
|
|
||||||
(with-test-prefix "bad formals"
|
(with-test-prefix "bad formals"
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue