| library; |
| import self as self; |
| import "dart:core" as core; |
| |
| class Closure#main#function extends core::Object implements core::Function { |
| field core::String note = "This is temporary. The VM doesn't need closure classes."; |
| field Vector context; |
| constructor •(final Vector context) → dynamic |
| : self::Closure#main#function::context = context |
| ; |
| method call() → dynamic { |
| "This is a temporary solution. In the VM, this will become an additional parameter."; |
| final Vector #contextParameter = this.{self::Closure#main#function::context}; |
| return #contextParameter[1]; |
| } |
| } |
| static const field dynamic numbers = const <core::int>[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; |
| static method main() → dynamic { |
| dynamic closures = <dynamic>[]; |
| for (core::int i in self::numbers) { |
| final Vector #context = MakeVector(2); |
| #context[1] = i; |
| closures.add(new self::Closure#main#function::•(#context)); |
| } |
| core::int sum = 0; |
| for (core::Function f in closures) { |
| sum = sum.+(f.call()); |
| } |
| core::int expectedSum = self::numbers.length.-(1).*(self::numbers.length).~/(2); |
| if(!expectedSum.==(sum)) { |
| throw core::Exception::•("Unexpected sum = ${sum} != ${expectedSum}"); |
| } |
| } |