The content of this module is based on the MSc Thesis Coinductive Formalization of SECD Machine in Agda by Adam Krupička
import public Data.Late
import public Data.List.Quantifiersdata Ty : Typedata Const : Ty -> TypefromInteger : Integer -> Const TyIntStack : TypeEnv : TypeFunDump : Typerecord State : Type.stack : State -> Stackstack : State -> Stack.env : State -> Envenv : State -> Env.dump : State -> FunDumpdump : State -> FunDumpdata Step : State -> State -> TypeLDC : Const ty -> Step (MkState s e f) (MkState (ty :: s) e f)Load a constant of a base type
LDA : Elem ty e -> Step (MkState s e f) (MkState (ty :: s) e f)Load a value from an address in the environment
LDF : Steps (MkState [] (a :: e) ((a, b) :: f)) (MkState [b] (a :: e) ((a, b) :: f)) -> Step (MkState s e f) (MkState (TyFun a b :: s) e f)Load a recursive function
LDR : Elem (a, b) f -> Step (MkState s e f) (MkState (TyFun a b :: s) e f)Load a function for recursive application
APP : Step (MkState (a :: (TyFun a b :: s)) e f) (MkState (b :: s) e f)Apply a function to its argument
TAP : Step (MkState (a :: (TyFun a b :: s)) e f) (MkState (b :: s) e f)Apply a function to its argument, tail call
RTN : Step (MkState (b :: s) e ((a, b) :: f)) (MkState [b] e ((a, b) :: f))Return a value from inside a function
BCH : Steps (MkState s e f) (MkState s' e f) -> Steps (MkState s e f) (MkState s' e f) -> Step (MkState (TyBool :: s) e f) (MkState s' e f)Branch over a boolean
FLP : Step (MkState (a :: (b :: s)) e f) (MkState (b :: (a :: s)) e f)Flip the stack's top values
NIL : Step (MkState s e f) (MkState (TyList a :: s) e f)Nil constructor
CNS : Step (MkState (a :: (TyList a :: s)) e f) (MkState (TyList a :: s) e f)Cons constructor
HED : Step (MkState (TyList a :: s) e f) (MkState (a :: s) e f)Head destructor
TAL : Step (MkState (TyList a :: s) e f) (MkState (TyList a :: s) e f)Tail destructor
MKP : Step (MkState (a :: (b :: s)) e f) (MkState (TyPair a b :: s) e f)Pair constructor
FST : Step (MkState (TyPair a b :: s) e f) (MkState (a :: s) e f)First pair destructor
SND : Step (MkState (TyPair a b :: s) e f) (MkState (b :: s) e f)Second pair destructor
ADD : Step (MkState (TyInt :: (TyInt :: s)) e f) (MkState (TyInt :: s) e f)Addition of ints
SUB : Step (MkState (TyInt :: (TyInt :: s)) e f) (MkState (TyInt :: s) e f)Subtraction of ints
MUL : Step (MkState (TyInt :: (TyInt :: s)) e f) (MkState (TyInt :: s) e f)Multiplication of ints
EQB : Step (MkState (a :: (a :: s)) e f) (MkState (TyBool :: s) e f)Structural equality test
NOT : Step (MkState (TyBool :: s) e f) (MkState (TyBool :: s) e f)Boolean negation
data Steps : State -> State -> Typedata Stepz : State -> State -> Type(<>>) : Stepz s t -> Steps t u -> Steps s u(<><) : Stepz s t -> Steps t u -> Stepz s u(++) : Steps s t -> Steps t u -> Steps s uNUL : Steps (MkState (TyList a :: s) e f) (MkState (TyBool :: s) e f)LDL : List Int -> Steps (MkState s e f) (MkState (TyList TyInt :: s) e f)PLS : Step (MkState s e f) (MkState (TyFun TyInt (TyFun TyInt TyInt) :: s) e f)MAP : Step (MkState [] e f) (MkState [TyFun (TyFun a b) (TyFun (TyList a) (TyList b))] e f)FLD : Step (MkState [] e f) (MkState [TyFun (TyFun b (TyFun a b)) (TyFun b (TyFun (TyList a) b))] e f)SUM : Steps (MkState [] e f) (MkState [TyFun (TyList TyInt) TyInt] e f)Meaning : Ty -> TypefromConst : Const ty -> Meaning tyMeaning : List Ty -> Type0 Meaning : FunDump -> Typetail : Meaning (ab :: f) -> Meaning flookup : Meaning f -> Elem (a, b) f -> Closure a brecord Meaning : State -> TypeMkMeaning : Meaning (st .stack) -> Meaning (st .env) -> Meaning (st .dump) -> Meaning st.dumpVal : Meaning st -> Meaning (st .dump).envVal : Meaning st -> Meaning (st .env).stackVal : Meaning st -> Meaning (st .stack).stackVal : Meaning st -> Meaning (st .stack)stackVal : Meaning st -> Meaning (st .stack).envVal : Meaning st -> Meaning (st .env)envVal : Meaning st -> Meaning (st .env).dumpVal : Meaning st -> Meaning (st .dump)dumpVal : Meaning st -> Meaning (st .dump)record Closure : Ty -> Ty -> TypeMkClosure : Steps (MkState [] (a :: localEnv) ((a, b) :: localFunDump)) (MkState [b] (a :: localEnv) ((a, b) :: localFunDump)) -> Meaning localEnv -> Meaning localFunDump -> Closure a b.code : ({rec:0} : Closure a b) -> Steps (MkState [] (a :: localEnv {rec:0}) ((a, b) :: localFunDump {rec:0})) (MkState [b] (a :: localEnv {rec:0}) ((a, b) :: localFunDump {rec:0})).dumpVal : ({rec:0} : Closure a b) -> Meaning (localFunDump {rec:0}).envVal : ({rec:0} : Closure a b) -> Meaning (localEnv {rec:0})0 .localEnv : Closure a b -> Env0 .localFunDump : Closure a b -> FunDump0 .localEnv : Closure a b -> Env0 localEnv : Closure a b -> Env0 .localFunDump : Closure a b -> FunDump0 localFunDump : Closure a b -> FunDump.code : ({rec:0} : Closure a b) -> Steps (MkState [] (a :: localEnv {rec:0}) ((a, b) :: localFunDump {rec:0})) (MkState [b] (a :: localEnv {rec:0}) ((a, b) :: localFunDump {rec:0}))code : ({rec:0} : Closure a b) -> Steps (MkState [] (a :: localEnv {rec:0}) ((a, b) :: localFunDump {rec:0})) (MkState [b] (a :: localEnv {rec:0}) ((a, b) :: localFunDump {rec:0})).envVal : ({rec:0} : Closure a b) -> Meaning (localEnv {rec:0})envVal : ({rec:0} : Closure a b) -> Meaning (localEnv {rec:0}).dumpVal : ({rec:0} : Closure a b) -> Meaning (localFunDump {rec:0})dumpVal : ({rec:0} : Closure a b) -> Meaning (localFunDump {rec:0})eqb : (ty : Ty) -> Meaning ty -> Meaning ty -> Booleqbs : (ty : Ty) -> Meaning (TyList ty) -> Meaning (TyList ty) -> Boolsteps : Meaning st -> Steps st st' -> Late (Meaning st')step : Meaning st -> Step st st' -> Late (Meaning st')run : Steps (MkState [] [] []) (MkState (ty :: {_:12217}) [] []) -> Nat -> Maybe (Meaning ty)