never executed always true always false
1 module HelVM.HelMA.Automaton.Automaton (
2 start,
3 runAndDumpLogs,
4 run,
5 ) where
6
7 import HelVM.HelMA.Automaton.API.AutomatonOptions
8 import HelVM.HelMA.Automaton.API.AutoOptions
9
10 import HelVM.HelMA.Automaton.Instruction
11
12 import HelVM.HelMA.Automaton.IO.AutomatonIO
13 import HelVM.HelMA.Automaton.IO.BusinessIO
14
15 import HelVM.HelMA.Automaton.Optimizer
16 import HelVM.HelMA.Automaton.Symbol
17 import HelVM.HelMA.Automaton.Trampoline as Trampoline
18
19 import HelVM.HelMA.Automaton.Types.DumpType
20 import HelVM.HelMA.Automaton.Types.RAMType
21 import HelVM.HelMA.Automaton.Types.StackType
22
23 import HelVM.HelMA.Automaton.Combiner
24 import HelVM.HelMA.Automaton.Combiner.CPU as CPU
25
26 import qualified HelVM.HelIO.Collections.MapList as MapList
27 import qualified HelVM.HelIO.Collections.SList as SList
28
29 import HelVM.HelIO.Control.Safe
30
31 import HelVM.HelIO.Extra
32
33 import Control.Monad.Extra
34
35 import qualified Data.Sequence as Seq
36
37 import Prelude hiding (swap)
38
39 start :: BIO m => InstructionList -> AutomatonOptions -> m ()
40 start il ao = start' (flip optimize il $ optLevelAutoOptions ao) (stackType ao) (ramType ao) (autoOptions ao)
41
42 start' :: BIO m => InstructionList -> StackType -> RAMType -> AutoOptions -> m ()
43 start' il s ListRAMType = start'' il s []
44 start' il s SeqRAMType = start'' il s Seq.empty
45 start' il s SListRAMType = start'' il s SList.sListEmpty
46 start' il s MapListRAMType = start'' il s MapList.mapListEmpty
47
48 start'' :: (RAutomatonIO Symbol r m) => InstructionList -> StackType -> r -> AutoOptions -> m ()
49 start'' il ListStackType = start''' il []
50 start'' il SeqStackType = start''' il Seq.empty
51 start'' il SListStackType = start''' il SList.sListEmpty
52
53 start''' :: (SRAutomatonIO Symbol s r m) => InstructionList -> s -> r -> AutoOptions -> m ()
54 start''' il s r p = runAndDumpLogs p (newMemory il s r)
55
56 runAndDumpLogs :: (SRAutomatonIO Symbol s r m) => AutoOptions -> Memory s r -> m ()
57 runAndDumpLogs p = logDump (dumpType p) <=< run (limit p)
58
59 run :: (SRAutomatonIO Symbol s r m) => LimitMaybe -> F s r m
60 run = trampolineMWithLimit nextState
61
62 nextState :: (SRAutomatonIO Symbol s r m) => SF s r m
63 nextState a = nextStateForInstruction =<< currentInstruction (memoryCM a) where
64 nextStateForInstruction i = appendErrorTuple ("Automaton.nextState" , showP a) $ appendErrorTuple ("program:" , printIndexedIL $ toList program) $ appendErrorTuple ("i:" , show i) $ runInstruction i $ incrementIC a where
65 program = memoryProgram a