sin(2) is 0.91, and if we try that prior to sin(1), that's the answer we get. But here, the result is 0.84 from both.
The problem seems to be that the JIT always executes the function "main" if it exists:
EE.withModuleInEngine executionEngine m $ \ee -> do
mainfn <- EE.getFunction ee (AST.Name "main")
case mainfn of
Just fn -> do
res <- run fn
putStrLn $ "Evaluated to: " ++ show res
Nothing -> return ()
but in codegenTop we use define double "main", which only generates a function named "main" if it doesn't already exist. If it does exist, we get "main.1", "main.2" and so on.
Solution might be to have a version of define that handles these name conflicts like the current one, and a version that allows overwriting them. (Somehow? We can filter moduleDefinitions, but presumably mkName "main" will still give us "main.1".) I'm not sure if that's the best way to go about it.
For example
sin(2) is 0.91, and if we try that prior to sin(1), that's the answer we get. But here, the result is 0.84 from both.
The problem seems to be that the JIT always executes the function "main" if it exists:
but in
codegenTop
we usedefine double "main"
, which only generates a function named "main" if it doesn't already exist. If it does exist, we get "main.1", "main.2" and so on.Solution might be to have a version of
define
that handles these name conflicts like the current one, and a version that allows overwriting them. (Somehow? We can filtermoduleDefinitions
, but presumablymkName "main"
will still give us "main.1".) I'm not sure if that's the best way to go about it.