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.Functor import class Functor from MIPS.MIPS32 import :: Immediate, :: Instruction, :: Label, :: Offset, :: Register from Snug.Syntax import :: BasicValue :: Simulator a :== State SimulationState 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) -> [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 ()