diff options
author | Eduardo Julian | 2019-02-05 19:09:31 -0400 |
---|---|---|
committer | Eduardo Julian | 2019-02-05 19:09:31 -0400 |
commit | 47b97c128bde837fa803a605f3e011a3e9ddd71c (patch) | |
tree | 5e8a84d1b1812ec4a157d4049c778ec2e4e434c4 /stdlib/source/test/lux/compiler/default/phase/synthesis/case.lux | |
parent | be5710d104e6ee085dcb9d871be0b80305e48f8b (diff) |
Integrated tests into normal source code.
Diffstat (limited to 'stdlib/source/test/lux/compiler/default/phase/synthesis/case.lux')
-rw-r--r-- | stdlib/source/test/lux/compiler/default/phase/synthesis/case.lux | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/stdlib/source/test/lux/compiler/default/phase/synthesis/case.lux b/stdlib/source/test/lux/compiler/default/phase/synthesis/case.lux new file mode 100644 index 000000000..319d4ab57 --- /dev/null +++ b/stdlib/source/test/lux/compiler/default/phase/synthesis/case.lux @@ -0,0 +1,88 @@ +(.module: + [lux #* + [control + [monad (#+ do)] + pipe] + [data + ["." error ("error/." functor)]] + [compiler + [default + ["." reference] + ["." phase + ["." analysis (#+ Branch Analysis)] + ["//" synthesis (#+ Synthesis) + ["." expression]] + [extension + ["." bundle]]]]] + [math + ["r" random]] + test] + ["." //primitive]) + +(context: "Dummy variables." + (<| (times 100) + (do @ + [maskedA //primitive.primitive + temp (|> r.nat (:: @ map (n/% 100))) + #let [maskA (analysis.control/case + [maskedA + [[(#analysis.Bind temp) + (#analysis.Reference (reference.local temp))] + (list)]])]] + (test "Dummy variables created to mask expressions get eliminated during synthesis." + (|> maskA + expression.phase + (phase.run [bundle.empty //.init]) + (error/map (//primitive.corresponds? maskedA)) + (error.default #0)))))) + +(context: "Let expressions." + (<| (times 100) + (do @ + [registerA r.nat + inputA //primitive.primitive + outputA //primitive.primitive + #let [letA (analysis.control/case + [inputA + [[(#analysis.Bind registerA) + outputA] + (list)]])]] + (test "Can detect and reify simple 'let' expressions." + (|> letA + expression.phase + (phase.run [bundle.empty //.init]) + (case> (^ (#error.Success (//.branch/let [inputS registerS outputS]))) + (and (n/= registerA registerS) + (//primitive.corresponds? inputA inputS) + (//primitive.corresponds? outputA outputS)) + + _ + #0)))))) + +(context: "If expressions." + (<| (times 100) + (do @ + [then|else r.bit + inputA //primitive.primitive + thenA //primitive.primitive + elseA //primitive.primitive + #let [thenB (: Branch + [(#analysis.Simple (#analysis.Bit #1)) + thenA]) + elseB (: Branch + [(#analysis.Simple (#analysis.Bit #0)) + elseA]) + ifA (if then|else + (analysis.control/case [inputA [thenB (list elseB)]]) + (analysis.control/case [inputA [elseB (list thenB)]]))]] + (test "Can detect and reify simple 'if' expressions." + (|> ifA + expression.phase + (phase.run [bundle.empty //.init]) + (case> (^ (#error.Success (//.branch/if [inputS thenS elseS]))) + (and (//primitive.corresponds? inputA inputS) + (//primitive.corresponds? thenA thenS) + (//primitive.corresponds? elseA elseS)) + + _ + #0)))))) |