1
0
forked from GitHub/gf-core

bugfix in the pattern matching compiler and a number of other fixes that I somehow did not push before

This commit is contained in:
kr.angelov
2014-09-29 15:00:04 +00:00
parent 0d08417efe
commit 698329f469
5 changed files with 275 additions and 187 deletions

View File

@@ -15,31 +15,31 @@ data Literal =
type CodeLabel = Int
data Instr
= ENTER
| CASE CId {-# UNPACK #-} !CodeLabel
= CHECK_ARGS {-# UNPACK #-} !Int
| CASE CId {-# UNPACK #-} !Int {-# UNPACK #-} !CodeLabel
| CASE_LIT Literal {-# UNPACK #-} !CodeLabel
| ALLOC {-# UNPACK #-} !Int
| PUT_CONSTR CId
| PUT_FUN CId
| PUT_CLOSURE {-# UNPACK #-} !CodeLabel
| PUT_LIT Literal
| SET IVal
| SET_PAD
| PUSH IVal
| EVAL IVal TailInfo
| CALL CId TailInfo
| RET {-# UNPACK #-} !Int TailInfo
| DROP {-# UNPACK #-} !Int {-# UNPACK #-} !CodeLabel
| FAIL
| UPDATE
| RET {-# UNPACK #-} !Int
data IVal
= HEAP {-# UNPACK #-} !Int
| ARG_VAR {-# UNPACK #-} !Int
| FREE_VAR {-# UNPACK #-} !Int
| GLOBAL CId
data TailInfo
= RecCall
| TailCall {-# UNPACK #-} !Int {-# UNPACK #-} !Int
| TailCall {-# UNPACK #-} !Int {-# UNPACK #-} !Int {-# UNPACK #-} !Int
| UpdateCall {-# UNPACK #-} !Int {-# UNPACK #-} !Int
ppLit (LStr s) = text (show s)
ppLit (LInt n) = int n
@@ -49,28 +49,29 @@ ppCode :: Int -> [[Instr]] -> Doc
ppCode l [] = empty
ppCode l (is:iss) = ppLabel l <+> vcat (map ppInstr is) $$ ppCode (l+1) iss
ppInstr (ENTER ) = text "ENTER"
ppInstr (CASE id l ) = text "CASE " <+> ppCId id <+> ppLabel l
ppInstr (CHECK_ARGS n) = text "CHECK_ARGS " <+> int n
ppInstr (CASE id n l ) = text "CASE " <+> ppCId id <+> int n <+> ppLabel l
ppInstr (CASE_LIT lit l ) = text "CASE_LIT " <+> ppLit lit <+> ppLabel l
ppInstr (ALLOC n) = text "ALLOC " <+> int n
ppInstr (PUT_CONSTR id) = text "PUT_CONSTR " <+> ppCId id
ppInstr (PUT_FUN id) = text "PUT_FUN " <+> ppCId id
ppInstr (PUT_CLOSURE l) = text "PUT_CLOSURE" <+> ppLabel l
ppInstr (PUT_LIT lit ) = text "PUT_LIT " <+> ppLit lit
ppInstr (SET v) = text "SET " <+> ppIVal v
ppInstr (SET_PAD ) = text "SET_PAD"
ppInstr (PUSH v) = text "PUSH " <+> ppIVal v
ppInstr (EVAL v ti) = text "EVAL " <+> ppIVal v <+> ppTailInfo ti
ppInstr (CALL v ti) = text "CALL " <+> ppCId v <+> ppTailInfo ti
ppInstr (RET h (TailCall a b c)) = text "RET " <+> ppIVal (HEAP h) <+> text "tail" <> parens (int a <> comma <> int b)
ppInstr (RET h (UpdateCall b c)) = text "RET " <+> ppIVal (HEAP h) <+> text "update" <> parens (int b)
ppInstr (DROP n l ) = text "DROP " <+> int n <+> ppLabel l
ppInstr (FAIL ) = text "FAIL"
ppInstr (UPDATE ) = text "UPDATE"
ppInstr (RET n) = text "RET " <+> int n
ppIVal (HEAP n) = text "hp" <> parens (int n)
ppIVal (ARG_VAR n) = text "stk" <> parens (int n)
ppIVal (FREE_VAR n) = text "env" <> parens (int n)
ppIVal (GLOBAL id) = ppCId id
ppTailInfo RecCall = empty
ppTailInfo (TailCall a b) = text "tail" <> parens (int a <> comma <> int b)
ppTailInfo RecCall = empty
ppTailInfo (TailCall a b c) = text "tail" <> parens (int a <> comma <> int b <> comma <> int c)
ppTailInfo (UpdateCall b c) = text "update" <> parens (int b <> comma <> int c)
ppLabel l = text (let s = show l in replicate (3-length s) '0' ++ s)