mirror of
https://github.com/macocianradu/RosettaHaskellCompiler.git
synced 2026-03-18 13:00:08 +00:00
Added local environments to functions
This commit is contained in:
@@ -36,8 +36,8 @@ func EquityPriceObservation: <"Function specification for the observation of an
|
||||
func Something: <"asd">
|
||||
inputs:
|
||||
equity1 boolean (1..1)
|
||||
something1 boolean (1..1)
|
||||
determinationMethod ObservationPrimitive (1..1)
|
||||
output:
|
||||
valuation ObservationPrimitive (1..1)
|
||||
valuation ObservationPrimitive (0..1)
|
||||
|
||||
assign-output: if True and False then determinationMethod else determinationMethod
|
||||
assign-output: if True and False then determinationMethod
|
||||
@@ -59,13 +59,12 @@ defaultMap = [
|
||||
-- |Checks whether a function is valid (inputs, outputs are of valid type and all variables are defined) and adds it to the symbol table
|
||||
addFunction :: ([Type], [Symbol]) -> Function -> Either [TypeCheckError] [Symbol]
|
||||
addFunction (definedTypes, definedSymbols) (MakeFunction name _ inps out _)
|
||||
| null (lefts checkedInputs) && isRight checkedOutput = Right $ Func name (map typeAndCardinality (rights checkedInputs)) (attributeType $ fromRightUnsafe checkedOutput, Model.Type.cardinality out) : allSymbols
|
||||
| null (lefts checkedInputs) && isRight checkedOutput = Right $ Func name (map typeAndCardinality (rights checkedInputs)) (attributeType $ fromRightUnsafe checkedOutput, Model.Type.cardinality out) : definedSymbols
|
||||
| isLeft checkedOutput = Left [fromLeftUnsafe checkedOutput]
|
||||
| otherwise = Left $ lefts checkedInputs
|
||||
where
|
||||
checkedInputs = checkAttributes definedTypes inps
|
||||
checkedOutput = head $ checkAttributes definedTypes [out]
|
||||
allSymbols = addVariables definedSymbols inps
|
||||
|
||||
-- |Adds a newly defined variable to the symbol table
|
||||
addVariables :: [Symbol] -> [TypeAttribute] -> [Symbol]
|
||||
|
||||
@@ -9,13 +9,14 @@ import Data.Char
|
||||
|
||||
-- |Checks if all the inputs and the out of a function call have valid types, and then checks that the assign-output expression is valid
|
||||
checkFunction :: ([Type], [Symbol]) -> Function -> Either [TypeCheckError] Function
|
||||
checkFunction (definedTypes, definedFunctions) (MakeFunction name desc inp out ex)
|
||||
checkFunction (definedTypes, symbols) (MakeFunction name desc inp out ex)
|
||||
| isRight checkedEx && isRight checkedOut && null (lefts checkedIn) =
|
||||
case typeMatch (attributeType $ fromRightUnsafe checkedOut, Model.Type.cardinality out) (fromRightUnsafe checkedEx) of
|
||||
Right _ -> Right $ MakeFunction (toLower (head name) : tail name) desc (rights checkedIn) (fromRightUnsafe checkedOut) ex
|
||||
Left err -> Left [err]
|
||||
| otherwise = Left $ lefts [checkedOut] ++ lefts checkedIn ++ lefts [checkedEx]
|
||||
where
|
||||
checkedEx = checkExpression definedFunctions ex
|
||||
localEnv = addVariables symbols inp
|
||||
checkedEx = checkExpression localEnv ex
|
||||
checkedIn = checkAttributes definedTypes inp
|
||||
checkedOut = head $ checkAttributes definedTypes [out]
|
||||
Reference in New Issue
Block a user