Skip to content

Commit

Permalink
ES Alt: EffectTracking now handles named alternatives
Browse files Browse the repository at this point in the history
  • Loading branch information
Anabra committed Nov 30, 2019
1 parent 2c4dece commit 75c8ff3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,22 @@ codeGenM = cata folder where
ECaseF val alts_ -> do
caseResultReg <- newReg
altRegs <- sequence alts_
forM altRegs $ \(R altReg) ->
emit IR.Move { srcReg = altReg, dstReg = caseResultReg }
forM altRegs $ \(A _ altNameReg altM) -> do
altResult <- altM
case altResult of
R altResultReg -> do
-- NOTE: Propagate the effect info back to both the case result register and the alternative's register as well
emit IR.Move { srcReg = altResultReg, dstReg = caseResultReg }
emit IR.Move { srcReg = altResultReg, dstReg = altNameReg }
-- TODO: maybe put altName into "A" as well?
_ -> error $ "Effect tracking: a case alternative did not return a register. Scrutinee was: " ++ show (PP val)
pure $ R caseResultReg

-- NOTE: Currently, the names of the alternatives are ignored by the analysis.
AltF _ n exp -> do
AltF cpat n exp -> do
altNameReg <- newReg
addReg n altNameReg
exp
pure $ A cpat altNameReg exp

SAppF name args -> getExternal name >>= \case
Just ext -> do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ type CG = State CGState
data Result
= R IR.Reg
| Z
| A CPat (CG Result)
| A CPat IR.Reg (CG Result)

emit :: IR.Instruction -> CG ()
emit inst = modify' $ \s@CGState{..} -> s {_sInstructions = inst : _sInstructions}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ spec = describe "Effect Tracking Analysis" $ do
, ("y", Effects ["_prim_int_print", "_prim_string_print"])
, ("n", Effects [])

, ("_1", Effects [])
, ("_2", Effects [])
, ("_1", Effects ["_prim_int_print"])
, ("_2", Effects ["_prim_string_print"])
, ("_3", Effects [])
]
, _function = [ ("grinMain", Effects ["_prim_int_print", "_prim_string_print"]) ]
Expand Down Expand Up @@ -177,8 +177,8 @@ spec = describe "Effect Tracking Analysis" $ do
, ("y", Effects ["_prim_int_print", "_prim_string_print"])
, ("n", Effects [])

, ("_1", Effects [])
, ("_2", Effects [])
, ("_1", Effects ["_prim_int_print"])
, ("_2", Effects ["_prim_string_print"])
, ("_3", Effects [])
]
, _function = [ ("f", Effects ["_prim_int_print"])
Expand Down Expand Up @@ -218,10 +218,10 @@ spec = describe "Effect Tracking Analysis" $ do
, ("z", Effects ["_prim_int_print", "_prim_error"])
, ("n", Effects [])

, ("_1", Effects [])
, ("_11", Effects [])
, ("_12", Effects [])
, ("_2", Effects [])
, ("_1", Effects ["_prim_int_print", "_prim_error"])
, ("_11", Effects ["_prim_int_print"])
, ("_12", Effects ["_prim_error"])
, ("_2", Effects ["_prim_string_print"])
, ("_3", Effects [])
]
, _function = [ ("grinMain", Effects ["_prim_int_print", "_prim_string_print", "_prim_error"]) ]
Expand Down

0 comments on commit 75c8ff3

Please sign in to comment.