Skip to content

Commit

Permalink
[#32] Added a check for empty and unused ctrl operators
Browse files Browse the repository at this point in the history
  • Loading branch information
JustusAdam committed Feb 21, 2019
1 parent 4faf6a2 commit 3a432fa
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions core/src/Ohua/ALang/Passes/Control.hs
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,20 @@ liftIntoCtrlCtxt ::
(Monad m, MonadGenBnd m) => Binding -> Expression -> m Expression
liftIntoCtrlCtxt ctrlIn e = do
(lam', actuals) <- lambdaLifting e
let (originalFormals, _) = lambdaArgsAndBody e
let (allFormals, e) = lambdaArgsAndBody lam'
ctrlOut <- generateBindingWith "ctrl"
let formals = reverse $ take (length actuals) $ reverse allFormals
let actuals' = [Var ctrlIn] ++ actuals
let ie = mkDestructured formals ctrlOut e
return $
mkLambda originalFormals $
Let
ctrlOut
(fromListToApply (FunRef "ohua.lang/ctrl" Nothing) actuals')
ie
if null actuals
then do
dAssertM $ lam' == e
pure lam'
else do
let (originalFormals, _) = lambdaArgsAndBody e
let (allFormals, e) = lambdaArgsAndBody lam'
ctrlOut <- generateBindingWith "ctrl"
let formals = reverse $ take (length actuals) $ reverse allFormals
let actuals' = [Var ctrlIn] ++ actuals
let ie = mkDestructured formals ctrlOut e
return $
mkLambda originalFormals $
Let
ctrlOut
(fromListToApply (FunRef "ohua.lang/ctrl" Nothing) actuals')
ie

0 comments on commit 3a432fa

Please sign in to comment.