Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
Sutori.Parser.Expressions
Contents
Description
- type ExprTransform = SutExpression -> SutExpression
- type SutUnaryOp = SutExpression -> SutMonad SutExpression
- type SutBinaryOp = SutExpression -> SutExpression -> SutMonad SutExpression
- exprLiteral :: SutPrimitive -> SutLiteral -> SutMonad SutExpression
- literalBool :: Bool -> SutMonad SutExpression
- literalChar :: String -> SutMonad SutExpression
- literalInt :: Int -> SutMonad SutExpression
- literalFloat :: Float -> SutMonad SutExpression
- literalString :: String -> SutMonad SutExpression
- constructStruct :: [(SutID, SutExpression)] -> SutMonad SutExpression
- memberType :: (SutID, SutType) -> SutMonad (SutID, SutTypeID)
- unaryPlus :: SutUnaryOp
- unaryMinus :: SutUnaryOp
- unaryNot :: SutUnaryOp
- generalizeExprType :: SutExpression -> SutExpression -> SutType
- binaryOp :: ExprTransform -> ExprTransform -> ExprTransform -> SutOperator -> SutBinaryOp
- numericBinaryOp :: SutOperator -> SutBinaryOp
- booleanBinaryOp :: SutOperator -> SutBinaryOp
- sortBinaryOp :: SutOperator -> SutBinaryOp
- eqBinaryOp :: SutOperator -> SutBinaryOp
- opAddition :: SutBinaryOp
- opSubstraction :: SutBinaryOp
- opMultiplication :: SutBinaryOp
- opDivision :: SutBinaryOp
- opIntDivision :: SutBinaryOp
- opModulo :: SutBinaryOp
- opPower :: SutBinaryOp
- opGreaterEqual :: SutBinaryOp
- opLessEqual :: SutBinaryOp
- opLess :: SutBinaryOp
- opGreater :: SutBinaryOp
- opAnd :: SutBinaryOp
- opOr :: SutBinaryOp
- opEqual :: SutBinaryOp
- opNotEqual :: SutBinaryOp
- assignment :: SutBinaryOp
- arrayGet :: SutBinaryOp
- memberGet :: SutExpression -> SutID -> SutMonad SutExpression
- createPointer :: SutID -> SutTypeID -> SutMonad SutExpression
- dereference :: SutUnaryOp
- functionCall :: SutID -> [SutExpression] -> SutMonad SutExpression
- checkParamTypes :: [SutType] -> [SutExpression] -> SutMonad ()
- constructArray :: [SutExpression] -> SutMonad SutExpression
- checkArrayType :: SutExpression -> SutType -> [SutType] -> SutMonad ()
Documentation
type ExprTransform = SutExpression -> SutExpression Source #
Represents a transformation from an expression to another
Ex. Change of type to TypeError
type SutUnaryOp = SutExpression -> SutMonad SutExpression Source #
Represents a unary operation expression constructor
type SutBinaryOp = SutExpression -> SutExpression -> SutMonad SutExpression Source #
Represents a binary operation expression constructor
Expressions
Literals
exprLiteral :: SutPrimitive -> SutLiteral -> SutMonad SutExpression Source #
Generates AST expression for the given literal
literalBool :: Bool -> SutMonad SutExpression Source #
literalInt :: Int -> SutMonad SutExpression Source #
constructStruct :: [(SutID, SutExpression)] -> SutMonad SutExpression Source #
Constructs a struct from the list of ID -> Expression mappings
Right now, we implement these by storing the member IDs into the type graph
Note: We do not allow duplicated member IDs
memberType :: (SutID, SutType) -> SutMonad (SutID, SutTypeID) Source #
Transforms a member with its type definition to a member with its type ID
Simple Operations
Unary operations
Helpers
generalizeExprType :: SutExpression -> SutExpression -> SutType Source #
Gives the most general type from two expressions to which they can be casted
Arguments
:: ExprTransform | Transform for first operand |
-> ExprTransform | Transform for second operand |
-> ExprTransform | Transform result |
-> SutOperator | Operator |
-> SutBinaryOp | Both operands and result |
General constructor for binary operation with the given operator applying the given checks
numericBinaryOp :: SutOperator -> SutBinaryOp Source #
Binary operation specific constructor check
booleanBinaryOp :: SutOperator -> SutBinaryOp Source #
Binary operation specific constructor check
sortBinaryOp :: SutOperator -> SutBinaryOp Source #
Binary operation specific constructor check
eqBinaryOp :: SutOperator -> SutBinaryOp Source #
Binary operation specific constructor check
Numerical binary operations
Sorting/Comparison operations
opGreaterEqual :: SutBinaryOp Source #
(>=) receives two "sortable" types
opLessEqual :: SutBinaryOp Source #
(<=) receives two "sortable" types
opLess :: SutBinaryOp Source #
(<) receives two "sortable" types
opGreater :: SutBinaryOp Source #
(>) receives two "sortable" types
Boolean binary operations
opAnd :: SutBinaryOp Source #
Boolean AND receives two booleans
opOr :: SutBinaryOp Source #
Boolean OR receives two booleans
opEqual :: SutBinaryOp Source #
Equality check receives two "equalable" types
opNotEqual :: SutBinaryOp Source #
NotEquality check receives two "equalable" types
Complex operations
assignment :: SutBinaryOp Source #
An assignement to the left side of the value from the right side
This checks that a general type for converting the right side exists
Note: An assignment is both an instruction and an expression
Note: It is known the left side is assignable
Note: Right side must be of a more specific type than left side
arrayGet :: SutBinaryOp Source #
The indexation of the array in the left side with the key/index on the right side
This checks the left side is actually of an array type
Note: It is known the left side is assignable and the right side is int expression
Note: Left side must be array type
memberGet :: SutExpression -> SutID -> SutMonad SutExpression Source #
The access to a membercomponent (ID right) of a thingmachine (left)
This checks left side is either a Machine or a Thing, and that it knows a member with the ID
Note: It is known the left lise is assignable
createPointer :: SutID -> SutTypeID -> SutMonad SutExpression Source #
Creates a direction to a value of type given
Note: We are already given the existent type ID
Note: Left side is known to be a person
dereference :: SutUnaryOp Source #
Creates a dereferencing expression for the given expression
This checks the expression is a direction to somewhere
Note: It is know the expression is assignable
functionCall :: SutID -> [SutExpression] -> SutMonad SutExpression Source #
A call to a function (ID) with parameters (given list)
This checks for the correct number of arguments and their types
Note: Left side is known to be existent function (?)
checkParamTypes :: [SutType] -> [SutExpression] -> SutMonad () Source #
Compares the given formal and actual parameters types
constructArray :: [SutExpression] -> SutMonad SutExpression Source #
Constructs an array from the list of expressions All expressions must be of the same type
Note: Sutori grammar doesn't allow empty arrays
checkArrayType :: SutExpression -> SutType -> [SutType] -> SutMonad () Source #
Checks the type of the array is consistent with the types of its elements