diff options
| author | kr.angelov <kr.angelov@gmail.com> | 2014-10-30 13:09:50 +0000 |
|---|---|---|
| committer | kr.angelov <kr.angelov@gmail.com> | 2014-10-30 13:09:50 +0000 |
| commit | 9b0f354c7cef175c172edae582dcfa48817db7ba (patch) | |
| tree | 99bee2d13ee471423999b57f2dc3a5aa8164d9b3 /src/runtime/haskell/PGF/ByteCode.hs | |
| parent | 0519493ca936c8e555cfdf9178195418e342ff05 (diff) | |
a more efficient tail call by using the new TUCK instruction
Diffstat (limited to 'src/runtime/haskell/PGF/ByteCode.hs')
| -rw-r--r-- | src/runtime/haskell/PGF/ByteCode.hs | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/runtime/haskell/PGF/ByteCode.hs b/src/runtime/haskell/PGF/ByteCode.hs index 6cf7daffd..9ac072378 100644 --- a/src/runtime/haskell/PGF/ByteCode.hs +++ b/src/runtime/haskell/PGF/ByteCode.hs @@ -27,6 +27,7 @@ data Instr | SET_PAD | PUSH_FRAME | PUSH IVal + | TUCK IVal {-# UNPACK #-} !Int | EVAL IVal TailInfo | DROP {-# UNPACK #-} !Int | JUMP {-# UNPACK #-} !CodeLabel @@ -38,11 +39,12 @@ data IVal | ARG_VAR {-# UNPACK #-} !Int | FREE_VAR {-# UNPACK #-} !Int | GLOBAL CId + deriving Eq data TailInfo = RecCall - | TailCall {-# UNPACK #-} !Int {-# UNPACK #-} !Int {-# UNPACK #-} !Int - | UpdateCall {-# UNPACK #-} !Int {-# UNPACK #-} !Int + | TailCall {-# UNPACK #-} !Int + | UpdateCall ppLit (LStr s) = text (show s) ppLit (LInt n) = int n @@ -65,6 +67,7 @@ ppInstr (SET_PAD ) = text "SET_PAD" ppInstr (PUSH_FRAME ) = text "PUSH_FRAME" ppInstr (PUSH v) = text "PUSH " <+> ppIVal v ppInstr (EVAL v ti) = text "EVAL " <+> ppIVal v <+> ppTailInfo ti +ppInstr (TUCK v n ) = text "TUCK " <+> ppIVal v <+> int n ppInstr (DROP n ) = text "DROP " <+> int n ppInstr (JUMP l ) = text "JUMP " <+> ppLabel l ppInstr (FAIL ) = text "FAIL" @@ -75,8 +78,8 @@ 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 c) = text "tail" <> parens (int a <> comma <> int b <> comma <> int c) -ppTailInfo (UpdateCall b c) = text "update" <> parens (int b <> comma <> int c) +ppTailInfo RecCall = empty +ppTailInfo (TailCall n) = text "tail" <> parens (int n) +ppTailInfo UpdateCall = text "update" ppLabel l = text (let s = show l in replicate (3-length s) '0' ++ s) |
