module HJS.Interpreter.InterpMDecl where
import Control.Monad.Identity
import Control.Monad.Error
import Control.Monad.State
import Data.Map as M
import HJS.Parser.JavaScript hiding (Object)
data Ref = Ref String | RefObj ObjId String deriving (Eq,Show,Ord)
data ObjId = ObjId Int | ObjIdNull deriving (Eq,Show,Ord)
data Undefined = Undefined deriving (Eq,Show,Ord)
data Null = Null deriving (Eq,Show,Ord)
data RunFlag = Debug | Trace | ShowHeap deriving (Show,Eq)
data CallValue = CallJS [SourceElement] | CallBuiltIn (InterpM Value)
data BreakContinue = Break | Continue deriving (Show,Eq,Ord)
data ArgList = ArgList [String] | VarArgList
type Value = Either Int
( Either String
( Either Bool
( Either Undefined
( Either Null
( Either ObjId
( Either Ref
( Either [ObjId]
( Either CallValue
( Either [String]
( Either BreakContinue
()))))))))))
type InterpM = ErrorT Throwable (StateT JSState IO)
type Ctx = ([ObjId],ObjId,ObjId,ObjId)
data JSState = JSS {
ctx :: [Ctx],
oheap :: Map ObjId Object,
pos :: (Int,Int),
flags :: [ RunFlag ],
debug :: [DebugAction]
} deriving Show
data Throwable = ThrowReturn Value
| ThrowBreak (Maybe String)
| ThrowContinue (Maybe String)
| ThrowException Value
| ThrowTypeError String
| ThrowInternalError String
deriving Show
data Object = Object {
idd :: ObjId,
prototype :: Maybe ObjId,
klass :: String,
value :: Maybe Value,
properties :: M.Map String (Value,[Attribute])
} deriving Show
data Attribute = ReadOnly | DontEnum | DontDelete | Internal deriving (Eq,Show)
instance Show CallValue where
show (CallJS x) = show x
show (CallBuiltIn _) = show "<builtin>"
instance Ord CallValue where
compare _ _ = EQ
instance Eq CallValue where
(==) _ _ = True
data DebugAction = DBBreak Int
| DBContinue
| StepOver
| StepInto
| PrintObj Int
| PrintHeap
| PrintVar String
| PrintLine
| PrintStack
| Eval String
deriving (Show,Eq)