shivers-cfg-0.1.1: Implementation of Shivers' Control-Flow Analysis

Safe HaskellNone
LanguageHaskell98

Eval

Contents

Description

Here, a standard semantic for the language defined in CPSScheme is implemented, following the definitions in Olin Shivers' "Control-Flow Analysis of Higher-Order Languages".

Synopsis

Types

type Closure = (Lambda, BEnv) Source

A closure is a lambda expression bound to a binding environment

type Contour = Integer Source

A contour is an identifier for the contours (or dynamic frames) generated at each call of a lambda expression

type BEnv = Label :⇀ Contour Source

A binding environment maps the labels of Lambda and Let bindings to the innermost contour generated for these expressions

type VEnv = (Var Contour) :⇀ D Source

A variable environment maps variable names together with a contour to a value. The second parameter is required to allow for different, shadowed bindings of the same variable to coexist.

data D Source

A semantical value can either be

Constructors

DI Const

A constant

DC Closure

A closed lambda expression

DP Prim

A primitive value

Stop

The special continuation passed to the outermost lambda of a program

Instances

type Ans = Const Source

The result of evaluating is a constant (or a thrown exception) value.

Evaluation functions

evalCPS :: Prog -> Ans Source

evalCPS evaluates a whole program, by initializing the envirnoments and passing the Stop continuation to the outermost lambda

evalV :: Val -> BEnv -> VEnv -> D Source

evalC (called A by Shivers) evaluates a syntactical value to a semantical piece of data.

evalF :: D -> [D] -> VEnv -> Contour -> Ans Source

evalF evaluates a function call, distinguishing between lambda expressions, primitive operations and the special Stop continuation. It calles evalC for the function bodies.

evalC :: Call -> BEnv -> VEnv -> Contour -> Ans Source

evalC evaluates the body of a function, which can either be an application (which is then evaluated using evalF) or a Let statement.