parent
848d2148b0
commit
17aae65664
File diff suppressed because it is too large
Load Diff
|
@ -279,4 +279,6 @@
|
|||
(define l (for/list ([i 100]) 0))
|
||||
(test 0 apply @max l))
|
||||
|
||||
;; ----------------------------------------
|
||||
|
||||
(report-errs)
|
||||
|
|
|
@ -689,6 +689,73 @@
|
|||
(lambda () y)))
|
||||
(test #f object-name (return-a-function-that-returns-y))
|
||||
|
||||
;; ----------------------------------------
|
||||
;; Check 'inferred-name property on `lambda` that supports keywords
|
||||
;; and optional arguments
|
||||
|
||||
(let ([mk
|
||||
(lambda (mod-name proc)
|
||||
(define e
|
||||
`(module ,mod-name racket/base
|
||||
(require (for-syntax racket/base))
|
||||
(provide check-all)
|
||||
|
||||
(define-for-syntax (add-name stx)
|
||||
(syntax-property stx 'inferred-name 'new-name))
|
||||
|
||||
(define-for-syntax fun
|
||||
#',proc)
|
||||
|
||||
(define-syntax (go1 stx)
|
||||
(syntax-case stx ()
|
||||
[(_ id)
|
||||
#`(define id #,fun)]))
|
||||
(define-syntax (go2 stx)
|
||||
(syntax-case stx ()
|
||||
[(_ id)
|
||||
#`(define id #,(add-name fun))]))
|
||||
(define-syntax (go3 stx)
|
||||
(syntax-case stx ()
|
||||
[(_ id)
|
||||
#`(define id (#%expression #,(add-name fun)))]))
|
||||
(define-syntax (go4 stx)
|
||||
(syntax-case stx ()
|
||||
[(_ id)
|
||||
#`(define id (let () #,(add-name fun)))]))
|
||||
|
||||
(go1 f1)
|
||||
(go2 f2)
|
||||
(go3 f3)
|
||||
(go4 f4)
|
||||
|
||||
(define (check-all check)
|
||||
(go1 g1)
|
||||
(go2 g2)
|
||||
(go3 g3)
|
||||
(go4 g4)
|
||||
|
||||
(check f1 'f1)
|
||||
(check f2 'new-name)
|
||||
(check f3 'new-name)
|
||||
(check f4 'new-name)
|
||||
|
||||
(check g1 'g1)
|
||||
(check g2 'new-name)
|
||||
(check g3 'new-name)
|
||||
(check g4 'new-name))))
|
||||
(eval e)
|
||||
((dynamic-require `',mod-name 'check-all)
|
||||
(lambda (proc name)
|
||||
(test name mod-name (object-name proc)))))])
|
||||
(mk 'checks-many-declared-inferred-names
|
||||
'(lambda (x) x))
|
||||
(mk 'checks-many-declared-inferred-names/opt
|
||||
'(lambda (x [y 10]) x))
|
||||
(mk 'checks-many-declared-inferred-names/keyword
|
||||
'(lambda (x #:z z) x))
|
||||
(mk 'checks-many-declared-inferred-names/opt-keyword
|
||||
'(lambda (x #:z [z 11]) x)))
|
||||
|
||||
;; ----------------------------------------
|
||||
|
||||
(report-errs)
|
||||
|
|
|
@ -676,8 +676,19 @@
|
|||
[(null? kws) null]
|
||||
[else
|
||||
(cons (cadar kws) (loop (cdr kws)))])))]
|
||||
[local-name (or local-name
|
||||
(syntax-local-infer-name stx))])
|
||||
[local-name (let ([name (simplify-inferred-name (syntax-property stx 'inferred-name))])
|
||||
(cond
|
||||
[(or (symbol? name) (identifier? name)) name]
|
||||
[else (or local-name
|
||||
(let ([name (syntax-local-infer-name stx)])
|
||||
(and (or (symbol? name) (identifier? name))
|
||||
name)))]))]
|
||||
[add-local-name (lambda (stx)
|
||||
(if local-name
|
||||
;; Expecting always a `[case-]lambda form, so 'inferred-name
|
||||
;; should work and is less invasive than `let`:
|
||||
(syntax-property stx 'inferred-name local-name)
|
||||
stx))])
|
||||
(with-syntax ([(kw-arg ...) kw-args]
|
||||
[kws-sorted sorted-kws]
|
||||
[(opt-arg ...) opt-args]
|
||||
|
@ -761,14 +772,15 @@
|
|||
[mk-no-kws
|
||||
(lambda (kw-core?)
|
||||
;; entry point without keywords:
|
||||
(annotate-method
|
||||
(quasisyntax/loc/always stx
|
||||
(opt-cases #,(if kw-core?
|
||||
#'(unpack null null)
|
||||
#'(core))
|
||||
([opt-id opt-arg opt-not-supplied] ...) (plain-id ...)
|
||||
() ()
|
||||
(rest-empty rest-id . rest) ()))))]
|
||||
(add-local-name
|
||||
(annotate-method
|
||||
(quasisyntax/loc/always stx
|
||||
(opt-cases #,(if kw-core?
|
||||
#'(unpack null null)
|
||||
#'(core))
|
||||
([opt-id opt-arg opt-not-supplied] ...) (plain-id ...)
|
||||
() ()
|
||||
(rest-empty rest-id . rest) ())))))]
|
||||
[mk-with-kws
|
||||
(lambda ()
|
||||
;; entry point with keywords:
|
||||
|
@ -808,11 +820,7 @@
|
|||
(mk-core #t)
|
||||
(mk-unpack)
|
||||
(with-syntax ([kws (map car sorted-kws)]
|
||||
[no-kws (let ([p (mk-no-kws #t)]
|
||||
[n local-name])
|
||||
(if n
|
||||
#`(let ([#,n #,p]) #,n)
|
||||
p))]
|
||||
[no-kws (mk-no-kws #t)]
|
||||
[with-kws (mk-with-kws)])
|
||||
(quasisyntax/loc stx
|
||||
(make-okp
|
||||
|
@ -1110,10 +1118,13 @@
|
|||
(compile-enforce-module-constants))
|
||||
(and (list? ctx)
|
||||
(andmap liberal-define-context? ctx))))))]
|
||||
[opt (lambda (rhs core-wrap plain)
|
||||
[opt (lambda (lam-id rhs core-wrap plain)
|
||||
(parse-lambda rhs
|
||||
id
|
||||
plain
|
||||
(lambda (new-rhs)
|
||||
(plain (syntax-track-origin new-rhs
|
||||
rhs
|
||||
lam-id)))
|
||||
(lambda (impl kwimpl wrap
|
||||
core-id unpack-id
|
||||
n-req opt-not-supplieds rest? req-kws all-kws)
|
||||
|
@ -1133,11 +1144,11 @@
|
|||
#,(quasisyntax/loc stx
|
||||
(define #,unpack-id #,kwimpl))
|
||||
#,(quasisyntax/loc stx
|
||||
(define proc #,wrap)))))))))])
|
||||
(define proc #,(syntax-track-origin wrap rhs lam-id))))))))))])
|
||||
(syntax-case rhs (begin quote)
|
||||
[(lam-id . _)
|
||||
(can-opt? #'lam-id)
|
||||
(opt rhs values plain)]
|
||||
(opt #'lam-id rhs values plain)]
|
||||
[(begin (quote sym) (lam-id . _))
|
||||
;; looks like a compiler hint
|
||||
(and (can-opt? #'lam-id)
|
||||
|
@ -1145,7 +1156,8 @@
|
|||
(syntax-case rhs ()
|
||||
[(_ _ sub-rhs)
|
||||
(let ([wrap (lambda (stx) #`(begin (quote sym) #,stx))])
|
||||
(opt #'sub-rhs
|
||||
(opt #'lam-id
|
||||
#'sub-rhs
|
||||
wrap
|
||||
(lambda (rhs) (plain (wrap rhs)))))])]
|
||||
[_ (plain rhs)]))))
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
|
||||
(module name '#%kernel
|
||||
(#%require "define.rkt" "qq-and-or.rkt" "cond.rkt")
|
||||
(#%provide syntax-local-infer-name)
|
||||
(#%provide syntax-local-infer-name
|
||||
simplify-inferred-name)
|
||||
|
||||
(define syntax-local-infer-name
|
||||
(case-lambda
|
||||
|
|
|
@ -6,8 +6,7 @@
|
|||
(#%provide normalize-definition normalize-definition/mk-rhs)
|
||||
|
||||
(define-values (normalize-definition/mk-rhs)
|
||||
(lambda
|
||||
(stx lambda-stx check-context? allow-key+opt? err-no-body?)
|
||||
(lambda (stx lambda-stx check-context? allow-key+opt? err-no-body?)
|
||||
(when (and check-context?
|
||||
(memq (syntax-local-context) '(expression)))
|
||||
(raise-syntax-error
|
||||
|
|
|
@ -143,7 +143,7 @@
|
|||
[else v]))
|
||||
;; Get either a declared 'inferred-name or one accumulated by the compiler
|
||||
(define name (or (let ([v (simplify-name (syntax-property orig-s 'inferred-name))])
|
||||
(and (or (symbol? v) (syntax? v) (void? v))
|
||||
(and (or (symbol? v) (and (syntax? v) (symbol? (syntax-e v))) (void? v))
|
||||
v))
|
||||
inferred-name))
|
||||
(define named-s (if name
|
||||
|
|
|
@ -31276,7 +31276,8 @@ static const char *startup_source =
|
|||
"(if(let-values(((or-part_0)(symbol? v_0)))"
|
||||
"(if or-part_0"
|
||||
" or-part_0"
|
||||
"(let-values(((or-part_1)(syntax?$1 v_0)))"
|
||||
"(let-values(((or-part_1)"
|
||||
"(if(syntax?$1 v_0)(symbol?(syntax-e$1 v_0)) #f)))"
|
||||
"(if or-part_1 or-part_1(void? v_0)))))"
|
||||
" v_0"
|
||||
" #f))))"
|
||||
|
|
Loading…
Reference in New Issue
Block a user