OLD | NEW |
1 library; | 1 library; |
2 import self as self; | 2 import self as self; |
3 import "dart:core" as core; | 3 import "dart:core" as core; |
4 | 4 |
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[0][1] = #contextParameter[1]; | |
15 } | |
16 } | |
17 class Closure#main#function#1 extends core::Object implements core::Function { | |
18 field core::String note = "This is temporary. The VM doesn't need closure clas
ses."; | |
19 field Vector context; | |
20 constructor •(final Vector context) → dynamic | |
21 : self::Closure#main#function#1::context = context | |
22 ; | |
23 method call() → dynamic { | |
24 "This is a temporary solution. In the VM, this will become an additional par
ameter."; | |
25 final Vector #contextParameter = this.{self::Closure#main#function#1::contex
t}; | |
26 if(!(#contextParameter[0][1]).==(self::max.-(1))) | |
27 throw "last: ${#contextParameter[0][1]} != ${self::max.-(1)}"; | |
28 } | |
29 } | |
30 static const field core::int max = 100; | 5 static const field core::int max = 100; |
31 static method main() → dynamic { | 6 static method main() → dynamic { |
32 dynamic closures = <dynamic>[]; | 7 dynamic closures = <dynamic>[]; |
33 dynamic closures2 = <dynamic>[]; | 8 dynamic closures2 = <dynamic>[]; |
34 final Vector #context = MakeVector(2); | 9 final Vector #context = MakeVector(2); |
35 #context[1] = null; | 10 #context[1] = null; |
36 { | 11 { |
37 Vector #context = MakeVector(2); | 12 Vector #context = MakeVector(2); |
38 #context[0] = #context; | 13 #context[0] = #context; |
39 #context[1] = 0; | 14 #context[1] = 0; |
40 for (; (#context[1]).<(self::max); #context = CopyVector(#context), #context
[1] = (#context[1]).+(1)) { | 15 for (; (#context[1]).<(self::max); #context = CopyVector(#context), #context
[1] = (#context[1]).+(1)) { |
41 closures.add(new self::Closure#main#function::•(#context)); | 16 closures.add(MakeClosure<() → dynamic>(self::closure#main#function, #conte
xt)); |
42 closures2.add(new self::Closure#main#function#1::•(#context)); | 17 closures2.add(MakeClosure<() → dynamic>(self::closure#main#function#1, #co
ntext)); |
43 } | 18 } |
44 } | 19 } |
45 core::int sum = 0; | 20 core::int sum = 0; |
46 for (core::Function f in closures) { | 21 for (core::Function f in closures) { |
47 sum = sum.+(f.call()); | 22 sum = sum.+(f.call()); |
48 } | 23 } |
49 for (core::Function f in closures2) { | 24 for (core::Function f in closures2) { |
50 f.call(); | 25 f.call(); |
51 } | 26 } |
52 core::int expectedSum = self::max.-(1).*(self::max).~/(2); | 27 core::int expectedSum = self::max.-(1).*(self::max).~/(2); |
53 if(!expectedSum.==(sum)) { | 28 if(!expectedSum.==(sum)) { |
54 throw core::Exception::•("Unexpected sum = ${sum} != ${expectedSum}"); | 29 throw core::Exception::•("Unexpected sum = ${sum} != ${expectedSum}"); |
55 } | 30 } |
56 } | 31 } |
| 32 static method closure#main#function(Vector #contextParameter) → dynamic { |
| 33 return #contextParameter[0][1] = #contextParameter[1]; |
| 34 } |
| 35 static method closure#main#function#1(Vector #contextParameter) → dynamic { |
| 36 if(!(#contextParameter[0][1]).==(self::max.-(1))) |
| 37 throw "last: ${#contextParameter[0][1]} != ${self::max.-(1)}"; |
| 38 } |
OLD | NEW |