| library; | |
| import self as self; | |
| import "dart:core" as core; | |
| static method main() → void { | |
| self::forStatement(); | |
| self::patternForStatement(); | |
| self::forElement(); | |
| self::patternForElement(); | |
| } | |
| static method forStatement() → void { | |
| core::List<() → core::int> capturedInCondition = <() → core::int>[]; | |
| function inCondition(() → core::int f) → core::int { | |
| capturedInCondition.{core::List::add}(f){(() → core::int) → void}; | |
| return f(){() → core::int}; | |
| } | |
| core::List<() → core::int> capturedInUpdate = <() → core::int>[]; | |
| function inUpdate(() → core::int f##1) → core::int { | |
| capturedInUpdate.{core::List::add}(f##1){(() → core::int) → void}; | |
| return f##1(){() → core::int}; | |
| } | |
| core::List<() → core::int> capturedInBody = <() → core::int>[]; | |
| function inBody(() → core::int f##2) → core::int { | |
| capturedInBody.{core::List::add}(f##2){(() → core::int) → void}; | |
| return f##2(){() → core::int}; | |
| } | |
| for (core::int i = 0; inCondition(() → core::int => i){(() → core::int) → core::int}.{core::num::<}(10){(core::num) → core::bool}; inUpdate(() → core::int => let final core::int #t1 = i in let final void #t2 = i = #t1.{core::num::+}(1){(core::num) → core::int} in #t1){(() → core::int) → core::int}) { | |
| inBody(() → core::int => i){(() → core::int) → core::int}; | |
| } | |
| self::check(capturedInCondition, <core::int>[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); | |
| self::check(capturedInUpdate, <core::int>[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); | |
| self::check(capturedInBody, <core::int>[0, 2, 3, 4, 5, 6, 7, 8, 9, 10]); | |
| } | |
| static method patternForStatement() → void { | |
| core::List<() → core::int> capturedInCondition = <() → core::int>[]; | |
| function inCondition(() → core::int f) → core::int { | |
| capturedInCondition.{core::List::add}(f){(() → core::int) → void}; | |
| return f(){() → core::int}; | |
| } | |
| core::List<() → core::int> capturedInUpdate = <() → core::int>[]; | |
| function inUpdate(() → core::int f##1) → core::int { | |
| capturedInUpdate.{core::List::add}(f##1){(() → core::int) → void}; | |
| return f##1(){() → core::int}; | |
| } | |
| core::List<() → core::int> capturedInBody = <() → core::int>[]; | |
| function inBody(() → core::int f##2) → core::int { | |
| capturedInBody.{core::List::add}(f##2){(() → core::int) → void}; | |
| return f##2(){() → core::int}; | |
| } | |
| { | |
| hoisted core::int i; | |
| { | |
| final synthesized(core::int) #0#0 = (0); | |
| synthesized core::int #0#1; | |
| synthesized core::bool #0#1#isSet = false; | |
| if(!((#0#1#isSet ?{core::int} #0#1 : let final dynamic #t3 = #0#1#isSet = true in #0#1 = #0#0.$1{core::int}) is core::int && (let final dynamic #t4 = i = #0#1#isSet ?{core::int} #0#1 : let final dynamic #t5 = #0#1#isSet = true in #0#1 = #0#0.$1{core::int} in true))) | |
| throw{for-error-handling} new core::StateError::•("Pattern matching error"); | |
| } | |
| final core::int #t6 = i; | |
| for (core::int i##1 = #t6; inCondition(() → core::int => i##1){(() → core::int) → core::int}.{core::num::<}(10){(core::num) → core::bool}; inUpdate(() → core::int => let final core::int #t7 = i##1 in let final void #t8 = i##1 = #t7.{core::num::+}(1){(core::num) → core::int} in #t7){(() → core::int) → core::int}) { | |
| inBody(() → core::int => i##1){(() → core::int) → core::int}; | |
| } | |
| } | |
| self::check(capturedInCondition, <core::int>[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); | |
| self::check(capturedInUpdate, <core::int>[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); | |
| self::check(capturedInBody, <core::int>[0, 2, 3, 4, 5, 6, 7, 8, 9, 10]); | |
| } | |
| static method forElement() → void { | |
| core::List<() → core::int> capturedInCondition = <() → core::int>[]; | |
| function inCondition(() → core::int f) → core::int { | |
| capturedInCondition.{core::List::add}(f){(() → core::int) → void}; | |
| return f(){() → core::int}; | |
| } | |
| core::List<() → core::int> capturedInUpdate = <() → core::int>[]; | |
| function inUpdate(() → core::int f##1) → core::int { | |
| capturedInUpdate.{core::List::add}(f##1){(() → core::int) → void}; | |
| return f##1(){() → core::int}; | |
| } | |
| core::List<() → core::int> capturedInBody = <() → core::int>[]; | |
| function inBody(() → core::int f##2) → core::int { | |
| capturedInBody.{core::List::add}(f##2){(() → core::int) → void}; | |
| return f##2(){() → core::int}; | |
| } | |
| core::List<core::int> list = block { | |
| final core::List<core::int> #t9 = <core::int>[]; | |
| for (core::int i = 0; inCondition(() → core::int => i){(() → core::int) → core::int}.{core::num::<}(10){(core::num) → core::bool}; inUpdate(() → core::int => let final core::int #t10 = i in let final void #t11 = i = #t10.{core::num::+}(1){(core::num) → core::int} in #t10){(() → core::int) → core::int}) | |
| #t9.{core::List::add}{Invariant}(inBody(() → core::int => i){(() → core::int) → core::int}){(core::int) → void}; | |
| } =>#t9; | |
| self::check(capturedInCondition, <core::int>[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); | |
| self::check(capturedInUpdate, <core::int>[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); | |
| self::check(capturedInBody, <core::int>[0, 2, 3, 4, 5, 6, 7, 8, 9, 10]); | |
| } | |
| static method patternForElement() → void { | |
| core::List<() → core::int> capturedInCondition = <() → core::int>[]; | |
| function inCondition(() → core::int f) → core::int { | |
| capturedInCondition.{core::List::add}(f){(() → core::int) → void}; | |
| return f(){() → core::int}; | |
| } | |
| core::List<() → core::int> capturedInUpdate = <() → core::int>[]; | |
| function inUpdate(() → core::int f##1) → core::int { | |
| capturedInUpdate.{core::List::add}(f##1){(() → core::int) → void}; | |
| return f##1(){() → core::int}; | |
| } | |
| core::List<() → core::int> capturedInBody = <() → core::int>[]; | |
| function inBody(() → core::int f##2) → core::int { | |
| capturedInBody.{core::List::add}(f##2){(() → core::int) → void}; | |
| return f##2(){() → core::int}; | |
| } | |
| core::List<core::int> list = block { | |
| final core::List<core::int> #t12 = <core::int>[]; | |
| hoisted core::int i; | |
| { | |
| final synthesized(core::int) #0#0 = (0); | |
| synthesized core::int #0#1; | |
| synthesized core::bool #0#1#isSet = false; | |
| if(!((#0#1#isSet ?{core::int} #0#1 : let final dynamic #t13 = #0#1#isSet = true in #0#1 = #0#0.$1{core::int}) is core::int && (let final dynamic #t14 = i = #0#1#isSet ?{core::int} #0#1 : let final dynamic #t15 = #0#1#isSet = true in #0#1 = #0#0.$1{core::int} in true))) | |
| throw{for-error-handling} new core::StateError::•("Pattern matching error"); | |
| } | |
| final core::int #t16 = i; | |
| for (core::int i##1 = #t16; inCondition(() → core::int => i##1){(() → core::int) → core::int}.{core::num::<}(10){(core::num) → core::bool}; inUpdate(() → core::int => let final core::int #t17 = i##1 in let final void #t18 = i##1 = #t17.{core::num::+}(1){(core::num) → core::int} in #t17){(() → core::int) → core::int}) | |
| #t12.{core::List::add}{Invariant}(inBody(() → core::int => i##1){(() → core::int) → core::int}){(core::int) → void}; | |
| } =>#t12; | |
| self::check(capturedInCondition, <core::int>[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); | |
| self::check(capturedInUpdate, <core::int>[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); | |
| self::check(capturedInBody, <core::int>[0, 2, 3, 4, 5, 6, 7, 8, 9, 10]); | |
| } | |
| static method check(core::List<() → core::int> actual, core::List<core::int> expected) → void { | |
| if(!(actual.{core::List::length}{core::int} =={core::num::==}{(core::Object) → core::bool} expected.{core::List::length}{core::int})) { | |
| throw "Expected ${expected.{core::List::length}{core::int}} elements"; | |
| } | |
| for (core::int i = 0; i.{core::num::<}(expected.{core::List::length}{core::int}){(core::num) → core::bool}; i = i.{core::num::+}(1){(core::num) → core::int}) { | |
| core::int value = actual.{core::List::[]}(i){(core::int) → () → core::int}(){() → core::int}; | |
| if(!(value =={core::num::==}{(core::Object) → core::bool} expected.{core::List::[]}(i){(core::int) → core::int})) { | |
| throw "Expected value ${expected.{core::List::[]}(i){(core::int) → core::int}} at index ${i}, found ${value}"; | |
| } | |
| } | |
| } |