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 import "dart:mock" as mock; | 4 import "dart:mock" as mock; |
5 | 5 |
6 class Closure#main#function extends core::Object implements core::Function { | 6 class Closure#main#function extends core::Object implements core::Function { |
7 field core::String note = "This is temporary. The VM doesn't need closure clas
ses."; | 7 field core::String note = "This is temporary. The VM doesn't need closure clas
ses."; |
8 field mock::Context context; | 8 field mock::Context context; |
9 constructor •(final mock::Context context) → dynamic | 9 constructor •(final mock::Context context) → dynamic |
10 : self::Closure#main#function::context = context | 10 : self::Closure#main#function::context = context |
11 ; | 11 ; |
12 method call() → dynamic { | 12 method call() → dynamic { |
13 "This is a temporary solution. In the VM, this will become an additional par
ameter."; | 13 "This is a temporary solution. In the VM, this will become an additional par
ameter."; |
14 final mock::Context #contextParameter = this.{self::Closure#main#function::c
ontext}; | 14 final mock::Context #contextParameter = this.{self::Closure#main#function::c
ontext}; |
15 return #contextParameter.[](0); | 15 return #contextParameter.[](0); |
16 } | 16 } |
17 } | 17 } |
18 static const field dynamic numbers = const <core::int>[0, 1, 2, 3, 4, 5, 6, 7, 8
, 9]; | 18 static const field dynamic numbers = const <core::int>[0, 1, 2, 3, 4, 5, 6, 7, 8
, 9]; |
19 static method main() → dynamic { | 19 static method main() → dynamic { |
20 dynamic closures = <dynamic>[]; | 20 dynamic closures = <dynamic>[]; |
21 for (core::int i in self::numbers) { | 21 for (core::int i in self::numbers) { |
22 final mock::Context #context = new mock::Context::•(1); | 22 final mock::Context #context = new mock::Context::•(1); |
23 #context.parent = null; | |
24 #context.[]=(0, i); | 23 #context.[]=(0, i); |
25 { | 24 { |
26 closures.add(new self::Closure#main#function::•(#context)); | 25 closures.add(new self::Closure#main#function::•(#context)); |
27 } | 26 } |
28 } | 27 } |
29 core::int sum = 0; | 28 core::int sum = 0; |
30 for (core::Function f in closures) { | 29 for (core::Function f in closures) { |
31 sum = sum.+(f.call()); | 30 sum = sum.+(f.call()); |
32 } | 31 } |
33 core::int expectedSum = self::numbers.length.-(1).*(self::numbers.length).~/(2
); | 32 core::int expectedSum = self::numbers.length.-(1).*(self::numbers.length).~/(2
); |
34 if(!expectedSum.==(sum)) { | 33 if(!expectedSum.==(sum)) { |
35 throw core::Exception::•("Unexpected sum = ${sum} != ${expectedSum}"); | 34 throw core::Exception::•("Unexpected sum = ${sum} != ${expectedSum}"); |
36 } | 35 } |
37 } | 36 } |
OLD | NEW |