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