1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
definition module Snug.Compile.Simulate
from Control.Applicative import class Applicative, class pure, class <*>
from Control.Monad import class Monad
from Control.Monad.Identity import :: Identity, instance Functor Identity,
instance Monad Identity, instance pure Identity, instance <*> Identity
from Control.Monad.State import :: State, :: StateT,
instance Functor (StateT s m), instance Monad (StateT s m),
instance pure (StateT s m), instance <*> (StateT s m)
from Data.Error import :: MaybeError
from Data.Functor import class Functor
from MIPS.MIPS32 import :: Immediate, :: Instruction, :: Label, :: Offset,
:: Register
from Snug.Syntax import :: BasicValue
:: Simulator a :== StateT SimulationState (MaybeError String) a
:: SimulationState
:: StackValue
= SVIndirect !Offset !Register //* value stored in reg + offset
| SVRegOffset !Register !Offset //* value is reg + offset
/* for internal use only: */
| SVImmediate !Immediate
simulate :: ![StackValue] !(Simulator a) -> MaybeError String [Instruction]
stackSize :: Simulator Int
//* Build a constructor node with *n* arguments and push it to the stack.
buildCons :: !Label !Int -> Simulator ()
//* Build a thunk node with *n* arguments and push it to the stack.
buildThunk :: !Label !Int -> Simulator ()
//* Push a basic value to the stack.
pushBasicValue :: !BasicValue -> Simulator ()
/**
* Push the *j*th argument of the *i*th element on the stack onto the stack.
* @param *i*
* @param *j*
*/
pushArg :: !Int !Int -> Simulator ()
/**
* Overwrite the node currently under evaluation with an indirection to the
* node on top of the stack, and continue evaluating that node instead.
*/
indirectAndEval :: Simulator ()
|