janus-0.1.0.0: Simple scripting language written in Haskell, project for Fuctional Programming Course at AGH UST

Safe HaskellNone
LanguageHaskell2010

Language.Janus.Interp

Synopsis

Documentation

data EvalState Source #

Intepreter state.

data EvalError Source #

Interpreter error.

Constructors

OpCallTypeError String [[TypeRep]] [TypeRep]

Operator invocation type error

ItemCallError Item EvalError

Callable (e.g. function) call error

IndexOutOfBounds

Tried to access out of bounds index

InternalError String

Internal interpreter error - a bug

InvalidPointer Ptr

Tried to access unallocated memory cell

ExpectedBool Val

Expected boolean value (e.g. in condition)

ExpectedRef

Expected reference (e.g. in call operator)

NotCallable Val

Given value is not callable

OutOfMemory

Cannot allocate more memory cells

UndefinedSymbol String

Cannot resolve requested symbol

CustomError String

In-code exception

type InterpM = StateT EvalState (ExceptT EvalError IO) Source #

Interpreter monad.

runInterpM :: InterpM a -> IO (Either EvalError a) Source #

Run action inside clean InterpM.

run :: Evaluable a => a -> IO (Either EvalError Val) Source #

Evaluate Evaluable entity inside clean InterpM.

deref :: Ref -> InterpM Val Source #

Dereference a Ref - get Val given reference points to.

refset :: Ref -> Val -> InterpM () Source #

Alter value given Ref points to.

pushScope :: InterpM () Source #

Push new scope.

popFrame :: InterpM () Source #

Pop top stack frame.

memIsFree :: Ptr -> InterpM Bool Source #

Check whether given pointer points to unallocated memory cell.

memGetVal :: Ptr -> InterpM Val Source #

Get value of given memory cell.

memGetRc :: Ptr -> InterpM Word Source #

Get reference count of given memory cell.

malloc :: Val -> InterpM Ptr Source #

Allocate value in interpreter memory. Returns new memory cell's address.

memset :: Ptr -> Val -> InterpM () Source #

Set value at given address.

rcIncr :: Ptr -> InterpM () Source #

Increment reference count of memory cell at given address.

rcDecr :: Ptr -> InterpM () Source #

Decrement reference count of memory cell at given address. If the RC will reach 0, the cell will be deallocated.

lookupVar :: String -> InterpM Ptr Source #

Lookup variable in all available scopes.

putVar :: String -> Ptr -> InterpM () Source #

Create new, or change existing, variable binding. If the variable has been already exising, its old value's reference count will be decremented.

evalVal :: String -> InterpM Val Source #

   evalVal name = lookupVar name >>= memGetVal

allVars :: InterpM [String] Source #

Enumerate all visible symbols.

class Evaluable a where Source #

The Evaluable class denotes enitity which can be evaluated to Val.

Minimal complete definition

eval

Methods

eval :: a -> InterpM Val Source #

class RefEvaluable a where Source #

The RefEvaluable class denotes enitity which can be evaluated to Ref

Minimal complete definition

evalRef | tryEvalRef

class Callable a where Source #

The Callable class denotes enitity which can be called, such as functions.

Minimal complete definition

call

Methods

call :: a -> [Val] -> InterpM Val Source #

Instances

valGetIdx Source #

Arguments

:: Val

Container value

-> Val

Index

-> InterpM Val

Value inside container at given index

valSetIdx Source #

Arguments

:: Val

Container value

-> Val

Index

-> Val

New Value

-> InterpM Val

New container with value at given index changed