Skip to content

Commit fe7fdcc

Browse files
committed
[Heavy] Fix valuerefs in error handling
1 parent 5a60504 commit fe7fdcc

File tree

3 files changed

+34
-7
lines changed

3 files changed

+34
-7
lines changed

heavy/lib/OpGen.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ mlir::Value OpGen::GetSingleResult(heavy::Value V) {
143143
mlir::Value Result = Visit(V);
144144

145145
// Take the first continuation arg.
146-
if (isa<HeavyValueRefsTy>(Result.getType()))
146+
if (Result && isa<HeavyValueRefsTy>(Result.getType()))
147147
Result = create<LoadRefOp>(heavy::SourceLocation(), Result, /*Index*/0);
148148

149149
if (CheckError())
@@ -533,12 +533,6 @@ void OpGen::PopContinuationScope() {
533533

534534
bool OpGen::isLocalDefineAllowed() {
535535
return IsLocalDefineAllowed;
536-
#if 0
537-
mlir::Block* Block = Builder.getInsertionBlock();
538-
if (!Block) return false;
539-
return (Block->empty() ||
540-
isa<BindingOp>(Block->back()));
541-
#endif
542536
}
543537

544538
// createSyntaxSpec

heavy/test/Evaluate/define-syntax.scm

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,27 @@
33

44
;; TODO Local let-syntax needs to be tested/supported.
55

6+
(define-syntax capture-late-bind
7+
(syntax-rules ()
8+
((capture-late-bind x)
9+
((lambda ()
10+
(define storage 0)
11+
(lambda ()
12+
(set! storage
13+
(if (symbol? ok)
14+
ok 'oknotyet))
15+
(write storage)))))))
16+
17+
; CHECK: oknotyet
18+
((capture-late-bind 5))
19+
(newline)
20+
621
(define ok 'ok!)
22+
23+
; CHECK-NEXT: ok
24+
((capture-late-bind 5))
25+
26+
(newline)
727
(define-syntax my-lambda
828
(syntax-rules (=>)
929
((my-lambda formals => body)

heavy/test/Evaluate/lambda.scm

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,16 @@
7878
msg)))
7979
(write global)
8080
(newline)
81+
82+
; Test capture of lazy global binding.
83+
(define (fnzzz)
84+
(define temp lazy-binding-fn)
85+
(lambda (x)
86+
(temp x)))
87+
88+
(define (lazy-binding-fn x)
89+
(write x)
90+
(newline))
91+
92+
; CHECK: just-lazy
93+
((fnzzz) 'just-lazy)

0 commit comments

Comments
 (0)