From 5d2f367ea59f5813b95800fcaab1e4d5e16d4a88 Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Wed, 1 Feb 2023 21:24:05 +0100 Subject: Implement basic uses of locals --- snug-clean/src/Snug/Compile/Simulate.dcl | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'snug-clean/src/Snug/Compile/Simulate.dcl') diff --git a/snug-clean/src/Snug/Compile/Simulate.dcl b/snug-clean/src/Snug/Compile/Simulate.dcl index a36dc0d..bf01675 100644 --- a/snug-clean/src/Snug/Compile/Simulate.dcl +++ b/snug-clean/src/Snug/Compile/Simulate.dcl @@ -9,14 +9,24 @@ from Control.Monad.State import :: State, :: StateT, instance pure (StateT s m), instance <*> (StateT s m) from Data.Functor import class Functor -from MIPS.MIPS32 import :: Instruction, :: Label +from MIPS.MIPS32 import :: Immediate, :: Instruction, :: Label, :: Offset, + :: Register from Snug.Syntax import :: BasicValue :: Simulator a :== State SimulationState a :: SimulationState -simulate :: !(Simulator a) -> [Instruction] +:: 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 () @@ -26,6 +36,13 @@ 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. -- cgit v1.2.3