sutori-0.2.4: Sutori language compiler

Safe HaskellSafe
LanguageHaskell2010

Sutori.TAC

Description

 

Synopsis

Documentation

data TACTable Source #

The actual generated code is a list of instruction triplets and a list of pointers to them

Constructors

TACTable

Maps inc labels to their instruction number

Fields

data TACAddress Source #

TACAddress for TAC Instructions

Constructors

TACGlobal SutID

An actual ID from the source code. Used for global (scope 0) variables

TACOffset Int

An offset from the current frame pointer

TACLit SutLiteral

A literal value either explicit in the source code or calculated on the run.

TACID Int

The TAC number that calculated the relevant expression.

TACLabel Int

An incremental label to some code.

TACFun SutID

A function name/label

data TACType Source #

A TAC Instruction to be appended to the generated intermediate code

Constructors

Basic

For simple expressions.

Fields

SysCall

Perform a syscall (IO, Mem, else)

Fields

Copy

Copy operation, from a address to another

Addr

Address for an indirection

Jump

Unconditional jump, just where to.

JumpUnless

Condition jump

Pointed

Assign an address from a indirect pointer.

Param

Stack a function parameter

Call

Call a function of so many (already stacked) parameters

Return

Return from a function (possibly a value).

Instances

data TAC Source #

TAC Instruction

Constructors

TAC

An instruction

Fields

Label Int

A numbered label to output literally

FunLabel SutID

A string label to output literally

Instances

Show TAC Source # 

Methods

showsPrec :: Int -> TAC -> ShowS #

show :: TAC -> String #

showList :: [TAC] -> ShowS #

addTAC :: TAC -> SutMonad TACAddress Source #

Appends to the TAC table a new triplet, references it on the instructions TAC table

Returns the Address of the inserted TAC

TODO: Figure out how to remove duplicated code.

genCode :: SutMonad TACTable Source #

Generates code from the already built mainModule AST

Generates in order: TAC for main/global code, then TACs for each function.