2025-01-01 08:17:05 -06:00
|
|
|
module FileEval where
|
2024-12-29 21:49:57 -06:00
|
|
|
|
|
|
|
import Eval
|
|
|
|
import Parser
|
|
|
|
import Research
|
|
|
|
|
|
|
|
import System.IO
|
|
|
|
|
|
|
|
import qualified Data.Map as Map
|
|
|
|
|
2025-01-01 18:53:56 -06:00
|
|
|
evaluateFileResult :: FilePath -> IO T
|
|
|
|
evaluateFileResult filePath = do
|
2024-12-29 21:49:57 -06:00
|
|
|
contents <- readFile filePath
|
2024-12-30 14:19:43 -06:00
|
|
|
let asts = parseTricu contents
|
2025-01-01 18:53:56 -06:00
|
|
|
let finalEnv = evalTricu Map.empty asts
|
2024-12-30 14:19:43 -06:00
|
|
|
case Map.lookup "__result" finalEnv of
|
2024-12-29 21:49:57 -06:00
|
|
|
Just finalResult -> return finalResult
|
2025-01-02 19:08:14 -06:00
|
|
|
Nothing -> errorWithoutStackTrace "No expressions to evaluate found"
|
2025-01-01 18:05:21 -06:00
|
|
|
|
2025-01-01 18:53:56 -06:00
|
|
|
evaluateFile :: FilePath -> IO Env
|
|
|
|
evaluateFile filePath = do
|
|
|
|
contents <- readFile filePath
|
|
|
|
let asts = parseTricu contents
|
|
|
|
pure $ evalTricu Map.empty asts
|
|
|
|
|
|
|
|
evaluateFileWithContext :: Env -> FilePath -> IO Env
|
|
|
|
evaluateFileWithContext env filePath = do
|
2025-01-01 18:05:21 -06:00
|
|
|
contents <- readFile filePath
|
|
|
|
let asts = parseTricu contents
|
2025-01-01 18:53:56 -06:00
|
|
|
pure $ evalTricu env asts
|