OLD | NEW |
1 library; | 1 library; |
2 import self as self; | 2 import self as self; |
3 import "dart:core" as core; | |
4 | 3 |
5 class Closure#main#function extends core::Object implements core::Function { | |
6 field core::String note = "This is temporary. The VM doesn't need closure clas
ses."; | |
7 field Vector context; | |
8 constructor •(final Vector context) → dynamic | |
9 : self::Closure#main#function::context = context | |
10 ; | |
11 method call() → dynamic { | |
12 "This is a temporary solution. In the VM, this will become an additional par
ameter."; | |
13 final Vector #contextParameter = this.{self::Closure#main#function::context}
; | |
14 return #contextParameter[1]; | |
15 } | |
16 } | |
17 static method main() → dynamic { | 4 static method main() → dynamic { |
18 dynamic closure; | 5 dynamic closure; |
19 { | 6 { |
20 Vector #context = MakeVector(2); | 7 Vector #context = MakeVector(2); |
21 #context[1] = 0; | 8 #context[1] = 0; |
22 dynamic fn = new self::Closure#main#function::•(#context); | 9 dynamic fn = MakeClosure<() → dynamic>(self::closure#main#function, #context
); |
23 for (; (#context[1]).<(3); #context = CopyVector(#context), #context[1] = (#
context[1]).+(1)) { | 10 for (; (#context[1]).<(3); #context = CopyVector(#context), #context[1] = (#
context[1]).+(1)) { |
24 #context[1] = (#context[1]).+(1); | 11 #context[1] = (#context[1]).+(1); |
25 closure = fn; | 12 closure = fn; |
26 } | 13 } |
27 } | 14 } |
28 dynamic x = closure.call(); | 15 dynamic x = closure.call(); |
29 if(!x.==(1)) { | 16 if(!x.==(1)) { |
30 throw "Expected 1, but got ${x}."; | 17 throw "Expected 1, but got ${x}."; |
31 } | 18 } |
32 } | 19 } |
| 20 static method closure#main#function(Vector #contextParameter) → dynamic { |
| 21 return #contextParameter[1]; |
| 22 } |
OLD | NEW |