aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob L. Kreuze2023-05-04 17:41:39 -0400
committerJakob L. Kreuze2023-05-04 17:41:39 -0400
commitfc67a3d0ec16d45b10d2962b2798a1f6148b1c1a (patch)
tree706fc1a3eda1a94ee53870abcc02b4be07f9ed65
parent96b7392b791581465fa806dc8c381f0f043f6cc1 (diff)
Implement with-new-identifiers macro
-rw-r--r--compiler/passes/compile-reference.scm8
-rw-r--r--compiler/types.scm15
2 files changed, 16 insertions, 7 deletions
diff --git a/compiler/passes/compile-reference.scm b/compiler/passes/compile-reference.scm
index ca48d84..0d28206 100644
--- a/compiler/passes/compile-reference.scm
+++ b/compiler/passes/compile-reference.scm
@@ -30,13 +30,7 @@
(define (recur input-identifier form new-identifiers)
(match form
((target rest ...)
- (let* ((target-cast-id (fresh-identifier new-identifiers))
- (new-identifiers (cons target-cast-id new-identifiers))
- (target-cast-id (make <variable-ref> #:name target-cast-id))
-
- (deref-id (fresh-identifier new-identifiers))
- (new-identifiers (cons deref-id new-identifiers))
- (deref-id (make <variable-ref> #:name deref-id)))
+ (with-anonymous-identifiers (new-identifiers target-cast-id deref-id)
(cond ((and (infer-is-a? input-identifier 'array breadcrumb scope)
(infer-is-a? input-identifier 'number breadcrumb scope))
`((,target-cast-id ,(make <lean-funcall>
diff --git a/compiler/types.scm b/compiler/types.scm
index 9b8447f..b5e2862 100644
--- a/compiler/types.scm
+++ b/compiler/types.scm
@@ -35,6 +35,7 @@
<scope>
identifiers
+ with-anonymous-identifiers
add-to-scope
originating-breadcrumb
canonicalize
@@ -157,6 +158,20 @@
(identifiers #:init-keyword #:identifiers
#:accessor inner))
+(define-syntax with-anonymous-identifiers
+ (lambda (stx)
+ (syntax-case stx ()
+ ((_ (new-identifiers ids ...) body ...)
+ (let ((let-clauses
+ (flat-map (lambda (id)
+ #`((#,(datum->syntax stx id) (fresh-identifier new-identifiers))
+ (new-identifiers (cons #,(datum->syntax stx id) new-identifiers))
+ (#,(datum->syntax stx id) (make <variable-ref>
+ #:name #,(datum->syntax stx id)))))
+ (syntax->datum #'(ids ...)))))
+ #`(let* (#,@let-clauses)
+ body ...))))))
+
(define (add-to-scope scope breadcrumb identifier constraint)
"Add a new IDENTIFIER with TYPE to BREADCRUMB in SCOPE"
(define looking-at (hash-table-ref/default (inner scope) breadcrumb '()))

© 2015 - 2026 Jakob L. Kreuze