Skip to content
This repository has been archived by the owner on Dec 19, 2023. It is now read-only.

Commit

Permalink
fix norm in computeAst
Browse files Browse the repository at this point in the history
  • Loading branch information
TTENSHII committed Dec 17, 2023
1 parent 0d30b98 commit 99c2a7a
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions src/Computing/ComputeAST.hs
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,22 @@ handleSimpleList env (Symbol ">=" : rest) = superiorOrEqual env rest
handleSimpleList env (Symbol "if" : rest) = handleIf env rest
handleSimpleList env (Symbol smbl : rest) =
case getFunctionByName env smbl of
Nothing -> (registerError env ("Function " ++ smbl ++ " not found"), Right (undefined))
Nothing -> (registerError env ("Function " ++ smbl ++ " not found"),
Right (undefined))
Just func ->
case computeFunction env func rest of
(_, Left (Just result)) -> (env, Left (Just result))
(newEnv, _) -> (env { errors = errors newEnv }, Right (undefined))
handleSimpleList env _ = (registerError env "Bad function call", Right (undefined))
(newEnv, _) -> (env {errors = errors newEnv}, Right(undefined))
handleSimpleList env _ =
(registerError env "Bad function call", Right (undefined))

----------------------------------------------------------------------------------
-----------------------------------------------------------------------------

handleLambda :: Env -> Tree -> (Env, Result)
handleLambda env (List (List (Symbol "lambda" : List fnParams : fnBodies): (List args): _))
= computeFunction env (Function "" (getParams (List fnParams)) fnBodies) args
handleLambda env (List (List (Symbol "lambda" : List fnParams : fnBodies):
(List args): _)) =
computeFunction env
(Function "" (getParams (List fnParams)) fnBodies) args
handleLambda env _ = (registerError env "Bad lambda", Left (Nothing))

--------------------------- COMPUTE FUNCTIONS --------------------------------
Expand All @@ -94,16 +98,18 @@ computeFunctionBody env (Function _ fnParams (x:_)) args =
computeFunction :: Env -> Function -> [Tree] -> (Env, Result)
computeFunction env (Function fnName fnParams (x:xs:rest)) args =
case computeFunctionBody env (Function fnName fnParams [x]) args of
(newEnv, Left (Nothing)) -> computeFunction newEnv (Function fnName fnParams (xs:rest)) args
(_, _) -> (registerError env "Return needs to be the last statement", Right (undefined))
(newEnv, Left (Nothing)) ->
computeFunction newEnv (Function fnName fnParams (xs:rest)) args
(_, _) ->
(registerError env "Bad return placement", Right (undefined))
computeFunction env (Function fnName fnParams (x:_)) args =
case computeFunctionBody env (Function fnName fnParams [x]) args of
(newEnv, Left (Just replaced)) -> computeAST newEnv replaced
(newEnv, _) -> (registerError newEnv "Missing return in function", Right (undefined))
(newEnv, _) ->
(registerError newEnv "Missing return in func", Right (undefined))
computeFunction env _ _ =
(registerError env "Bad function call", Right (undefined))


--------------------------- COMPUTE AST -------------------------------------

computeASTWithoutList :: Env -> Tree -> (Env, Result)
Expand Down

0 comments on commit 99c2a7a

Please sign in to comment.