Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {-
- Compiled code for:
- id x = x
- compose f g x = f (g x)
- main = print_int (compose (\x -> x) (\x -> x) 999)
- It doesn't eliminate the id functions.
- But if I compile:
- ...
- main = print_int ((\x -> x) ((\x -> x) 999))
- This program has the calls to id optimised away
- I could 'fix' this by writing my own inliner before going to grin, but
- it feels like grin might be able to do the optimistion for me.
- -}
- eval p.0 =
- v.0 <- fetch p.0
- case v.0 of
- #default ->
- pure v.0
- (Fap1 a.0 a.1) ->
- res.0 <- ap1 $ a.0 a.1
- update p.0 res.0
- pure res.0
- (Fv1 a.2 a.3 a.4) ->
- res.1 <- v1 $ a.2 a.3 a.4
- update p.0 res.1
- pure res.1
- (Fv2 a.5) ->
- res.2 <- v2 $ a.5
- update p.0 res.2
- pure res.2
- (Fv3 a.6) ->
- res.3 <- v3 $ a.6
- update p.0 res.3
- pure res.3
- apply p.1 x.0 =
- case p.1 of
- (P1ap1 a.7) ->
- ap1 $ a.7 x.0
- (P2ap1) ->
- pure (P1ap1 x.0)
- (P1v1 a.8 a.9) ->
- v1 $ a.8 a.9 x.0
- (P2v1 a.10) ->
- pure (P1v1 a.10 x.0)
- (P3v1) ->
- pure (P2v1 x.0)
- (P1v2) ->
- v2 $ x.0
- (P1v3) ->
- v3 $ x.0
- ap1 x0 x1 =
- b1 <- eval $ x0
- apply $ b1 x1
- v1 v4 v5 v6 =
- v7 <- store (Fap1 v5 v6)
- v8 <- ap1 $ v4 v7
- pure v8
- v2 v9 =
- v10 <- eval $ v9
- pure v10
- v3 v11 =
- v12 <- eval $ v11
- pure v12
- grinMain =
- v13 <- store (P1v2)
- v14 <- store (P1v3)
- v15 <- store (CInt 999)
- v16 <- store (Fv1 v13 v14 v15)
- (CInt v17) <- eval $ v16
- v18 <- _prim_int_print $ v17
- pure v18
Add Comment
Please, Sign In to add comment