packages feed

lua-bc 0.1.0.1 → 0.1.0.2

raw patch · 5 files changed

+35/−10 lines, 5 filesPVP: minor bump suggested

API additions: PVP suggests at least a minor version bump

API changes (from Hackage documentation)

+ Language.Lua.Bytecode.Debug: getRegistersAt :: Function -> Int -> Vector VarInfo
+ Language.Lua.Bytecode.Pretty: showLuaString :: ByteString -> String

Files

CHANGELOG.md view
@@ -1,3 +1,8 @@+0.1.0.2+---++* Fix bug in rendering SETUPVAL opcode+ 0.1.0.1 --- 
lua-bc.cabal view
@@ -1,5 +1,5 @@ name:                lua-bc-version:             0.1.0.1+version:             0.1.0.2 synopsis:            Lua bytecode parser description:         Lua bytecode parser license:             MIT
src/Language/Lua/Bytecode.hs view
@@ -11,6 +11,7 @@   toEnum = Reg   fromEnum (Reg r) = r +-- | Zero-based index into upvalues newtype UpIx = UpIx Int  deriving (Read,Show,Eq,Ord) 
src/Language/Lua/Bytecode/Debug.hs view
@@ -3,6 +3,7 @@  import Data.ByteString (ByteString,append) import qualified Data.ByteString.Char8 as BS+import           Data.Vector (Vector) import qualified Data.Vector as Vector import           Data.String(fromString) import           Data.Map ( Map )@@ -18,6 +19,9 @@ -- Debugging functions ------------------------------------------------------------------------ +++ lookupLineNumber ::   Function ->   Int {- ^ program counter -} ->@@ -63,10 +67,17 @@                                          vs Vector.!? x   where   memo      = Vector.generate (Vector.length (funcCode func)) locals-  locals pc = Vector.map varInfoName-            $ Vector.filter (\x -> pc < varInfoEnd x)-            $ Vector.takeWhile (\x -> varInfoStart x <= pc)-            $ debugInfoVars (funcDebug func)+  locals pc = Vector.map varInfoName $ getRegistersAt func pc++-- | Get what registers are in scope at a particular op-code.+-- R1 is at entry 0, R2 is entry 1, etc.+-- NOTE that there might be multiple registers with the same named thing.+-- The one currently in scope is the last one.+getRegistersAt :: Function -> Int {-^PC-} -> Vector VarInfo+getRegistersAt func pc = Vector.filter (\x -> pc < varInfoEnd x)+                       $ Vector.takeWhile (\x -> varInfoStart x <= pc)+                       $ debugInfoVars (funcDebug func)+   
src/Language/Lua/Bytecode/Pretty.hs view
@@ -11,6 +11,7 @@ import Data.Text.Encoding.Error(lenientDecode) import qualified Data.ByteString.Char8 as BS import qualified Data.Vector as Vector+import Numeric (showHex)  data PPInfo = PPInfo   { ppVarAt    :: Int -> Reg  -> Maybe Doc@@ -87,9 +88,19 @@       KString bs    -> str bs       KLongString b -> str b -    where str = text . show . decodeUtf8With lenientDecode+    where str = text . showLuaString +showLuaString :: BS.ByteString -> String+showLuaString bs = '"' : BS.foldr show1 "\"" bs+  where+    show1 x+      | x == '"'                = showString "\\\""+      | x == '\\'               = showString "\\\\"+      | '\x20' <= x, x < '\x7f' = showChar x+      | '\x10' <= x             = showString "\\x"  . showHex (fromEnum x)+      | otherwise               = showString "\\x0" . showHex (fromEnum x) + class PP a where   pp :: PPInfo -> a -> Doc @@ -193,7 +204,7 @@       OP_GETTABLE a b c -> a =: lkp b c        OP_SETTABUP a b c -> lkp a b =: c-      OP_SETUPVAL a b   -> a       =: b+      OP_SETUPVAL a b   -> b       =: a       OP_SETTABLE a b c -> lkp a b =: c        OP_NEWTABLE a b c -> a =: (text "{}" <+> parens (text "array size =" <+>@@ -265,6 +276,3 @@         case ppExtraArg i of           Just _  -> empty           Nothing -> nest 2 (text "where extra =" <+> int n)---