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

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

Language.Qux.Annotated.TypeResolver

Contents

Description

Type resolving functions that transform the abstract syntax tree to a typed one.

These functions will transform every Expr into an TypedExpr and return the transformed tree. The Language.Qux.Annotated.TypeChecker and Language.Qux.Llvm.Compiler modules require the tree to be typed.

Synopsis

Environment

type Resolve = Reader Context Source

A type that allows resolving types. Requires a Context for evaluation.

runResolve :: Resolve a -> Context -> a Source

Runs the given resolve with the context.

Global context

data Context Source

Global context that holds function definition types.

Constructors

Context 

Fields

functions :: Map Id [Type]

A map of function names to parameter types.

context :: Program -> Context Source

Returns a context for the given program.

emptyContext :: Context Source

An empty context.

Local context

type Locals = Map Id Type Source

Local context. This is a map of variable names to types (e.g., parameters).

retrieve :: MonadReader Context m => Id -> StateT Locals m (Maybe [Type]) Source

Retrieves the type of the given identifier. Preference is placed on local variables. A local variable type is a singleton list, while a function type is it's parameter types and return type.

Type resolving

resolve :: Program SourcePos -> Program SourcePos Source

Resolves the types of the program, returning the modified syntax tree.

resolveProgram :: Program SourcePos -> Resolve (Program SourcePos) Source

Resolves the types of a program.

resolveDecl :: Decl SourcePos -> Resolve (Decl SourcePos) Source

Resolves the types of a declaration.

resolveStmt :: Stmt SourcePos -> StateT Locals Resolve (Stmt SourcePos) Source

Resolves the types of a statement.

resolveExpr :: Expr SourcePos -> StateT Locals Resolve (Expr SourcePos) Source

Resolves the types of an expression.

resolveValue :: Value -> Type Source

Resolves the type of a value.

extractType :: Expr a -> Type Source

Extracts the type from a TypedExpr. If the expression isn't an TypedExpr, an error is raised.