(;module: lux (lux [io] (control [monad #+ do] pipe) (data [product] [number] text/format (coll [list "L/" Functor Fold] ["D" dict] ["s" set])) ["r" math/random "r/" Monad] test) (luxc (lang ["la" analysis] ["ls" synthesis]) [synthesizer]) (../.. common)) (context: "Dummy variables." (<| (times +100) (do @ [maskedA gen-primitive temp r;nat #let [maskA (#la;Case maskedA (list [(#la;BindP temp) (#la;Variable (#;Local temp))]))]] (test "Dummy variables created to mask expressions get eliminated during synthesis." (|> (synthesizer;synthesize maskA) (corresponds? maskedA)))))) (context: "Let expressions." (<| (times +100) (do @ [registerA r;nat inputA gen-primitive outputA gen-primitive #let [letA (#la;Case inputA (list [(#la;BindP registerA) outputA]))]] (test "Can detect and reify simple 'let' expressions." (|> (synthesizer;synthesize letA) (case> (#ls;Let registerS inputS outputS) (and (n.= registerA registerS) (corresponds? inputA inputS) (corresponds? outputA outputS)) _ false)))))) (context: "If expressions." (<| (times +100) (do @ [then|else r;bool inputA gen-primitive thenA gen-primitive elseA gen-primitive #let [ifA (if then|else (#la;Case inputA (list [(#la;BoolP true) thenA] [(#la;BoolP false) elseA])) (#la;Case inputA (list [(#la;BoolP false) elseA] [(#la;BoolP true) thenA])))]] (test "Can detect and reify simple 'if' expressions." (|> (synthesizer;synthesize ifA) (case> (#ls;If inputS thenS elseS) (and (corresponds? inputA inputS) (corresponds? thenA thenS) (corresponds? elseA elseS)) _ false))))))