diff options
| author | Mirek Kratochvil <exa.exa@gmail.com> | 2023-03-04 13:51:22 +0100 |
|---|---|---|
| committer | Mirek Kratochvil <exa.exa@gmail.com> | 2023-03-04 13:52:24 +0100 |
| commit | b41711713002a8980a783d36164fbecbaddc1986 (patch) | |
| tree | 9083928bad521047d48bce8860821cfde8601303 /app | |
| parent | 1521c628a07a74860fd87512d1dbd5131124ee2d (diff) | |
| download | prlg-b41711713002a8980a783d36164fbecbaddc1986.tar.gz prlg-b41711713002a8980a783d36164fbecbaddc1986.tar.bz2 | |
load a prelude
Diffstat (limited to 'app')
| -rw-r--r-- | app/Builtins.hs | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/app/Builtins.hs b/app/Builtins.hs index 357c490..eb2dac1 100644 --- a/app/Builtins.hs +++ b/app/Builtins.hs @@ -1,5 +1,7 @@ module Builtins where +import Paths_prlg + import Code (Builtin(..), Code, Datum(..), Instr(..), InterpFn) import CodeLens import qualified Compiler as Co @@ -329,6 +331,17 @@ addBi b n a = addProc [[U (LocalRef $ r - 1) | r <- [1 .. a]] ++ [Invoke $ bi b]] n a {- loading code -} +doLoad :: Bool -> String -> InterpFn +doLoad queryMode fn = do + src' <- liftIO $ catch (Right <$> readFile fn) (pure . Left) + case src' of + Right src -> do + res <- runExceptT $ processInput fn queryMode src + case res of + Right _ -> continue + Left e -> prlgError $ "loading from '" ++ fn ++ "': " ++ e + Left e -> prlgError $ show (e :: IOException) + load :: Bool -> InterpFn load queryMode = withArgs [0] $ \[arg] -> do @@ -337,14 +350,7 @@ load queryMode = case derefHeap heap arg of BoundRef _ (Atom a) -> do let fn = itos M.! a - src' <- liftIO $ catch (Right <$> readFile fn) (pure . Left) - case src' of - Right src -> do - res <- runExceptT $ processInput fn queryMode src - case res of - Right _ -> continue - Left e -> prlgError $ "loading from '" ++ fn ++ "': " ++ e - Left e -> prlgError $ show (e :: IOException) + doLoad queryMode (itos M.! a) _ -> prlgError "load needs an atom" {- actual prlgude -} @@ -426,3 +432,7 @@ addPrelude = do addBi nl "nl" 0 {- debug -} addBi (use id >>= liftIO . print >> pure Nothing) "interpreter_trace" 0 + {- load the prelude file -} + preludeFile <- liftIO $ getDataFileName "prelude.pl" + doLoad False preludeFile + pure () |
