module Swf.Assembly where
import Text.PrettyPrint.HughesPJ
import Data.Maybe
import Data.Word
import Data.Int
data PreSup = None | Preload | Suppress
data SwfAssembly =
ActionGotoFrame Word16
| ActionGetURL String String
| ActionNextFrame
| ActionPreviousFrame
| ActionPlay
| ActionStop
| ActionToggleQuality
| ActionStopSounds
| ActionWaitForFrame Word16 Word8
| ActionSetTarget String
| ActionGotoLabel String
| ActionAdd
| ActionAdd2
| ActionSubtract
| ActionModulo
| ActionMultiply
| ActionDivide
| ActionIf String
| ActionJump String
| ActionCall
| ActionAnd
| ActionOr
| ActionNot
| ActionGetURL2 Word8
| ActionGotoFrame2 Bool
| ActionSetTarget2
| ActionGetProperty
| ActionSetProperty
| ActionCloneSprite
| ActionRemoveSprite
| ActionStartDrag
| ActionEndDrag
| ActionWaitForFrame2 Word8
| ActionEquals
| ActionGreater
| ActionLess
| ActionLess2
| ActionStrictEquals
| ActionCallFunction
| ActionCallMethod
| ActionConstantPool [String]
| ActionDefineFunction (Maybe String) [String] [SwfAssembly]
| ActionDefineLocal
| ActionDefineLocal2
| ActionDelete
| ActionDelete2
| ActionEnumerate
| ActionEnumerate2
| ActionEquals2
| ActionGetMember
| ActionInitArray
| ActionInitObject
| ActioninstanceOf
| ActionNewMethod
| ActionNewObject
| ActionSetMember
| ActionTargetPath
| ActionWith Int String
| ActionInstanceOf
| ActionDefineFunction2 String [(String,Word8)] Word8 Bool Bool PreSup PreSup PreSup Bool
| ActionExtends
| ActionImplementsOp
| ActionTry (Either String Word8) (Maybe [SwfAssembly]) (Maybe [SwfAssembly])
| ActionThrow
| ActionPushString String
| ActionPushFloat Float
| ActionPushNull
| ActionPushUndefined
| ActionPushRegister Word8
| ActionPushBool Bool
| ActionPushDouble Double
| ActionPushInt Word32
| ActionPop
| ActionBitAnd
| ActionBitLShift
| ActionBitOr
| ActionBitRShift
| ActionBitURShift
| ActionBitXor
| ActionDecrement
| ActionIncrement
| ActionPushDuplicate
| ActionReturn
| ActionStackSwap
| ActionStoreRegister Word8
| ActionStringEquals
| ActionStringLength
| ActionStringAdd
| ActionStringExtract
| ActionStringLess
| ActionStringGreater
| ActionMBStringLength
| ActionMBStringExtract
| ActionToNumber
| ActionToString
| ActionTypeOf
| ActionToInteger
| ActionCharToAscii
| ActionAsciiToChar
| ActionMBCharToAscii
| ActionMBAsciiToChar
| ActionCastOp
| ActionTrace
| ActionGetTime
| ActionRandomNumber
| ActionGetVariable
| ActionSetVariable
| Frame Integer [SwfAssembly]
| Movie String [SwfAssembly]
| Label String
| Comment String
instance Show SwfAssembly where
show o = show (ppSwfAssembly o)
ppSwfAssembly o =
case o of
ActionAdd -> (nest 4 (text "add"))
ActionSubtract -> (nest 4 (text "subtract"))
ActionMultiply -> (nest 4 (text "multiply"))
ActionDivide -> (nest 4 (text "divide"))
ActionEquals -> (nest 4 (text "equals"))
ActionLess -> (nest 4 (text "less"))
ActionLess2 -> (nest 4 (text "less2"))
ActionGreater -> (nest 4 (text "greater"))
ActionStrictEquals -> (nest 4 (text "actionStrictEquals"))
ActionIf label -> (nest 4 (text ("branchiftrue " ++ label)))
ActionJump label -> (nest 4 (text ("branch " ++ label)))
ActionAnd -> (nest 4 (text "and"))
ActionOr -> (nest 4 (text "or"))
ActionNot -> (nest 4 (text "not"))
ActionCallMethod -> (nest 4 (text "callMethod"))
ActionCallFunction -> (nest 4 (text "callFunction"))
ActionDefineFunction name formals body ->
(nest 4 ((text "function") <+> (maybe empty text name) <+> (parens (hsep (punctuate comma (map (text .show) formals))))
$$ (vcat (map ppSwfAssembly body))
$$ (text "end")))
ActionDefineLocal -> (nest 4 (text "definelocal"))
ActionDelete -> (nest 4 (text "delete"))
ActionDelete2 -> (nest 4 (text "delete2"))
ActionEnumerate -> (nest 4 (text "enumerate"))
ActionEnumerate2 -> (nest 4 (text "enumerate2"))
ActionEquals2 -> (nest 4 (text "equals2"))
ActionGetMember -> (nest 4 (text "getMember"))
ActionSetMember -> (nest 4 (text "setMember"))
ActionInitArray -> (nest 4 (text "initArray"))
ActionInitObject -> (nest 4 (text "initObject"))
ActionPushString s -> (nest 4 ((text "push") <+> (text (show s))))
ActionPushFloat f -> (nest 4 ((text "push") <+> (text (show f))))
ActionPushRegister r -> (nest 4 ((text "push") <+> (text ('r' : show r))))
ActionPushDouble d -> (nest 4 ((text "push") <+> (text (show d))))
ActionPushNull -> (nest 4 ((text "push") <+> (text "null")))
ActionPushUndefined -> (nest 4 ((text "push") <+> (text "undefined")))
ActionPushBool b -> (nest 4 ((text "push") <+> (text (show b))))
ActionPushInt i -> (nest 4 ((text "push") <+> (text (show i))))
ActionPop -> (nest 4 (text "pop"))
ActionDecrement -> (nest 4 (text "decrement"))
ActionIncrement -> (nest 4 (text "increment"))
ActionReturn -> (nest 4 (text "return"))
ActionStackSwap -> (nest 4 (text "swap"))
ActionPushDuplicate -> (nest 4 (text "pushDuplicate"))
ActionStoreRegister r -> (nest 4 ((text "storeRegister") <+> (text ('r' : show r))))
ActionStringEquals -> (nest 4 (text "stringEquals"))
ActionStringLength -> (nest 4 (text "stringLength"))
ActionStringAdd -> (nest 4 (text "stringAdd"))
ActionStringExtract -> (nest 4 (text "stringExtract"))
ActionStringLess -> (nest 4 (text "stringLess"))
ActionStringGreater -> (nest 4 (text "stringGreater"))
ActionMBStringLength -> (nest 4 (text "mbStringLength"))
ActionMBStringExtract -> (nest 4 (text "mbStringExtract"))
ActionToNumber -> (nest 4 (text "toNumber"))
ActionToString -> (nest 4 (text "toString"))
ActionTypeOf -> (nest 4 (text "typeOf"))
ActionToInteger -> (nest 4 (text "toInteger"))
ActionCastOp -> (nest 4 (text "castOp"))
ActionTrace -> (nest 4 (text "trace"))
ActionGetVariable -> (nest 4 (text "getVariable"))
ActionSetVariable -> (nest 4 (text "setVariable"))
Frame i opcodes -> nest 4 (text "frame" <+> text (show i) $$
(vcat (map ppSwfAssembly opcodes)) $$
text "end")
Movie file opcodes -> text ("movie '" ++ file ++ "'") $$
(vcat (map ppSwfAssembly opcodes)) $$
text "end"
Label name -> text (name ++ ":")
Comment str -> text (';':' ':str)
ppSwfAssemblies :: [SwfAssembly] -> Doc
ppSwfAssemblies assemblies =
vcat (map ppSwfAssembly assemblies)