Skip to content

Commit

Permalink
fix main function not being called
Browse files Browse the repository at this point in the history
  • Loading branch information
antonkesy committed Mar 7, 2024
1 parent f19766a commit 47fe76e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ developProgram :: String
developProgram =
-- "int i = 1; int j = 2; int l = 3 + 4; int k = i + j + l; k = k * 0;"
-- "void test(int i, int k) { }"
-- "int main() { print(); }"
"print()"
-- "print()"
"int main() { print(); }"

main :: IO ()
main = do
Expand Down
2 changes: 1 addition & 1 deletion src/Interpreter/BuiltIn.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ printBuiltIn =
[CustomType "String"]
UnitType
( \[CustomType "String"] -> do
putStrLn "Hello, World!"
putStrLn "Hello, World!\n"
pure UnitType
)
4 changes: 3 additions & 1 deletion src/Interpreter/Interpreter.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ interpret (Program statements) = do
where
addMainFunctionCall = if hasMainFunction then mainFunctionCall else []
mainFunctionCall = [ExpressionStatement (AtomicExpression (FunctionCallAtomic "main" []))]
hasMainFunction = False
hasMainFunction = Prelude.filter isMainFunction statements /= []
isMainFunction (FunctionDefinitionStatement (Function "main" _ _ _)) = True
isMainFunction _ = False
isFunctionDefinition (FunctionDefinitionStatement _) = True
isFunctionDefinition _ = False
getFunctionName (FunctionDefinitionStatement (Function name _ _ _)) = name
Expand Down

0 comments on commit 47fe76e

Please sign in to comment.