stgi-1.1: Educational implementation of the STG (Spineless Tagless G-machine)

Safe HaskellNone
LanguageHaskell2010

Stg.Marshal.FromStg

Description

Extract Haskell values from running STG programs.

Synopsis

Documentation

class FromStg value where Source #

Look up the value of a global variable.

Instances of this class should have a corresponding ToStg instance to inject a value into the program, with the two being inverse to each other (up to forcing the generated thunks).

Minimal complete definition

fromStgAddr

Methods

fromStg :: StgState -> Var -> Either FromStgError value Source #

Retrieve the value of a global variable.

fromStgAddr :: StgState -> MemAddr -> Either FromStgError value Source #

Retrieve the value of a heap address.

fromStgPrim :: Integer -> Either FromStgError value Source #

Used only for looking up primitive integers.

Instances

FromStg Bool Source # 
FromStg Integer Source #

Works for both boxed (Int# 1#) and unboxed (1#) integers.

FromStg () Source # 
FromStg a => FromStg [a] Source # 
FromStg a => FromStg (Maybe a) Source # 
(FromStg a, FromStg b) => FromStg (Either a b) Source # 
(FromStg a, FromStg b) => FromStg (a, b) Source # 
(FromStg a, FromStg b, FromStg c) => FromStg (a, b, c) Source # 
(FromStg a, FromStg b, FromStg c, FromStg d) => FromStg (a, b, c, d) Source # 
(FromStg a, FromStg b, FromStg c, FromStg d, FromStg e) => FromStg (a, b, c, d, e) Source # 

Methods

fromStg :: StgState -> Var -> Either FromStgError (a, b, c, d, e) Source #

fromStgAddr :: StgState -> MemAddr -> Either FromStgError (a, b, c, d, e) Source #

fromStgPrim :: Integer -> Either FromStgError (a, b, c, d, e) Source #

data FromStgError Source #

Classifies the different errors that can happen when extracting a value from an STG state.

Constructors

TypeMismatch

e.g. asking for an Int# at an address that contains a Cons

IsWrongLambdaType LambdaType

Tried retrieving a non-constructor

IsBlackhole

Tried retrieving a black hole

BadArity

e.g. Cons x y z

NotFound NotInScope

An unsuccessful variable lookup

AddrNotOnHeap 
NoConstructorMatch

None of the given alternatives matched the given constructor, e.g. when trying to receive a Left as a Just