aboutsummaryrefslogblamecommitdiff
path: root/snug-clean/src/Snug/Compile/Simulate.dcl
blob: b131f3459e471c2d17193c6818fb64adf0947683 (plain) (tree)
1
2
3
4
5
6
7
8
9







                                                                              
                                    
                                      
                                                                          
                                     
                                                               

                  





                                                                       
                                                                           
                          
 
                                                                         
                                        
                                                                   
                                         
 
                                    
                                             
   





                                                                            

                                                                           
                               
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 ()