language-qux-0.1.1.3: Utilities for working with the Qux language

Copyright(c) Henry J. Wylde, 2015
LicenseBSD3
Maintainerpublic@hjwylde.com
Safe HaskellSafe
LanguageHaskell2010

Language.Qux.Interpreter

Contents

Description

Functions for executing a program and retrieving the return result.

This module assumes the program is well-formed. That is, it must be well-typed (see Language.Qux.TypeChecker).

Synopsis

Environment

type Execution = EitherT Value Evaluation Source

An environment that holds the global state (Reader Context) and the local state (Locals). It supports breaking out of execution (via 'EitherT Value').

type Evaluation = StateT Locals (Reader Context) Source

An environment that holds the global state (Reader Context) and the local state (Locals). Purely for evaluation of expressions---this environment does not support breaking out of execution.

Contexts

data Context Source

Global context that holds function definitions. The function name, parameter names and statements are held.

type Locals = Map Id Value Source

Local context.

context :: Program -> Context Source

Returns a context for the given program.

Interpreter

Program execution

exec :: Program -> Id -> [Value] -> Value Source

exec program entry arguments executes entry (passing it arguments) in the context of program. This function wraps execFunction by building and evaluating the environment under the hood.

execStmt :: Stmt -> Execution () Source

Executes the statement in a breaking environment.

Expression evaluation

evalExpr :: Expr -> Evaluation Value Source

Reduces the expression to a value (normal form).