Skip to content

Commit

Permalink
Fixed standard alises
Browse files Browse the repository at this point in the history
  • Loading branch information
lyncmi07 committed Sep 1, 2019
1 parent 0d90558 commit 7f35586
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 27 deletions.
11 changes: 4 additions & 7 deletions src/Com/NoSyn/Ast/If/Expression.hs
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,8 @@ validFunctionPredicate' pg ((_, (VPointer x _)):xs) (y:ys)
validFunctionPredicate' pg (x@(_, paramVariable@(VVariadic paramType _)):[]) (y:ys)
| paramType `Set.member` y = validFunctionPredicate' pg [x] ys
| otherwise = case (getAlphaTypeName (aliases pg) paramVariable) >>= (\x -> return $ x `Set.member` y) of
Valid _ x -> x
Valid _ x -> x && ((length ys) == 0)
_ -> False
-- | (getAlphaTypeName (aliases pg) paramVariable) `Set.member` y = (length ys) == 0
-- | otherwise = False

generateExpression::ProgramEnvironment -> Expression -> CompilerStatus String
generateExpression programEnvironment functionCall@(EFuncCall _ _) = do
Expand All @@ -131,12 +129,11 @@ generateExpressionForConstParameter _ generatedExpression _ = return generatedEx

validateAndGenerateD::ProgramEnvironment -> Set Ident -> Expression -> CompilerStatus (Either (Set Ident) (Ident, String))
validateAndGenerateD programEnvironment returnTypes functionCall@(EFuncCall funcName paramExprs) = do
-- unaliasedNonPointerReturnTypes <- sequence [lookupAtomicNoSynType x (aliases programEnvironment) | x <- (Data.Set.toList returnTypes), backTake 3 x /= "PTR"]
possibleFunctions <- possibleFunctionsFromReturnTypes programEnvironment nonPointerReturnTypes funcName (length paramExprs)
unaliasedNonPointerReturnTypes <- sequence [lookupAtomicNoSynType x (aliases programEnvironment) | x <- (Data.Set.toList returnTypes), backTake 3 x /= "PTR"]
possibleFunctions <- possibleFunctionsFromReturnTypes programEnvironment (Data.Set.fromList unaliasedNonPointerReturnTypes) funcName (length paramExprs)
let parameterSets = parameterSetsFromPossibleFunctions possibleFunctions paramExprs in
validateAndGenerateD' programEnvironment nonPointerReturnTypes parameterSets functionCall
validateAndGenerateD' programEnvironment (Data.Set.fromList unaliasedNonPointerReturnTypes) parameterSets functionCall
where
nonPointerReturnTypes = Data.Set.fromList $ Prelude.filter (\x -> backTake 3 x /= "PTR") (Data.Set.toList returnTypes)
backTake x = reverse.(Prelude.take x).reverse

validateAndGenerateD programEnvironment returnTypes (EConst const) = do
Expand Down
24 changes: 14 additions & 10 deletions src/Com/NoSyn/Ast/If/Parameter.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Com.NoSyn.Ast.Traits.Listable as Listable
import Data.List
import Data.Map
import Com.NoSyn.Environment.ProgramEnvironment
import Com.NoSyn.Environment.AliasEnvironment
import Com.NoSyn.Error.CompilerStatus

type Parameters = Block Parameter
Expand Down Expand Up @@ -61,14 +62,17 @@ getAtomicTypeName pg paramType = lookupAtomicNoSynType paramType
instance Blockable Parameter where
blockSeparator _ = ", "

parameterToTuple::Parameter -> (Ident, Variable)
parameterToTuple (PConst paramType paramName) =
(paramName , (VConst paramType paramName))
parameterToTuple (PPointer paramType paramName) =
(paramName , (VPointer paramType paramName))
parameterToTuple (PVariadic paramType paramName) =
(paramName, (VVariadic paramType paramName))
parameterToTuple::AliasEnvironment -> Parameter -> CompilerStatus (Ident, Variable)
parameterToTuple aliasEnvironment (PConst paramType paramName) = do
realParamType <- lookupAtomicNoSynType paramType aliasEnvironment
return (paramName , (VConst realParamType paramName))
parameterToTuple aliasEnvironment (PPointer paramType paramName) = do
realParamType <- lookupAtomicNoSynType paramType aliasEnvironment
return (paramName , (VPointer realParamType paramName))
parameterToTuple aliasEnvironment (PVariadic paramType paramName) = do
realParamType <- lookupAtomicNoSynType paramType aliasEnvironment
return (paramName, (VVariadic realParamType paramName))

parametersToTuples::Parameters -> [(Ident, Variable)]
parametersToTuples parameters =
Prelude.map parameterToTuple (Listable.toList parameters)
parametersToTuples::AliasEnvironment -> Parameters -> CompilerStatus [(Ident, Variable)]
parametersToTuples aliasEnvironment parameters =
sequence $ Prelude.map (parameterToTuple aliasEnvironment) (Listable.toList parameters)
16 changes: 8 additions & 8 deletions src/Com/NoSyn/Evaluation/Program/Internal/FunctionEvaluation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ programFunctionDefinitionEvaluate' aliasEnvironment (_:xs) currentFunctionEnviro
createFunctionEntry::AliasEnvironment -> FunctionDefinition -> CompilerStatus (Ident, FunctionOverload)
createFunctionEntry aliasEnvironment (FDNative functionName returnType parameters)= do
_ <- lookupDType returnType aliasEnvironment
_ <- sequence $ Prelude.map (\(_, x) -> lookupDType (getTypeNoCheck x) aliasEnvironment) (parametersToTuples parameters)
return (functionName, FO { returnType = returnType, parameters = parameterOMap, parentModule = Nothing })
where
parameterOMap = (Data.Map.Ordered.fromList (parametersToTuples parameters))
unaliasedParameterList <- parametersToTuples aliasEnvironment parameters
unaliasedReturnType <- lookupAtomicNoSynType returnType aliasEnvironment
_ <- sequence $ Prelude.map (\(_, x) -> lookupDType (getTypeNoCheck x) aliasEnvironment) unaliasedParameterList
return (functionName, FO { returnType = unaliasedReturnType, parameters = (Data.Map.Ordered.fromList unaliasedParameterList), parentModule = Nothing })
createFunctionEntry aliasEnvironment (FDNoSyn functionName returnType parameters _)= do
_ <- lookupDType returnType aliasEnvironment
_ <- sequence $ Prelude.map (\(_, x) -> lookupDType (getTypeNoCheck x) aliasEnvironment) (parametersToTuples parameters)
return (functionName, FO { returnType = returnType, parameters = parameterOMap, parentModule = Nothing})
where
parameterOMap = (Data.Map.Ordered.fromList (parametersToTuples parameters))
unaliasedParameterList <- parametersToTuples aliasEnvironment parameters
unaliasedReturnType <- lookupAtomicNoSynType returnType aliasEnvironment
_ <- sequence $ Prelude.map (\(_, x) -> lookupDType (getTypeNoCheck x) aliasEnvironment) unaliasedParameterList
return (functionName, FO { returnType = unaliasedReturnType, parameters = (Data.Map.Ordered.fromList unaliasedParameterList), parentModule = Nothing})


4 changes: 2 additions & 2 deletions test/aliases.ns.disable → test/aliases.ns
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ Nothing infix_:=_(Int* a, AnotherInt b) {
assignment(b, b);
}

Nothing infix_+_(Int* a, AnotherInt b) {
Nothing infix_+_(AnotherInt* a, AnotherInt b) {
a := add(a, b);
}

Int add(Int a, Int b) {
Int add(Int a, AnotherInt b) {
a;
}

0 comments on commit 7f35586

Please sign in to comment.