1
1
mirror of https://github.com/anoma/juvix.git synced 2024-12-13 11:16:48 +03:00
juvix/app/RegInterpreter.hs
Łukasz Czajka a110297a69
JuvixReg interpreter (#2635)
* Closes #2577 
* Adds the `juvix dev reg run file.jvr` command.
* Adds interpreter tests.
2024-02-15 10:46:19 +01:00

30 lines
920 B
Haskell

module RegInterpreter where
import App
import CommonOptions
import Juvix.Compiler.Reg.Data.InfoTable qualified as Reg
import Juvix.Compiler.Reg.Interpreter qualified as Reg
import Juvix.Compiler.Reg.Pretty qualified as Reg
runReg :: forall r. (Members '[Embed IO, App] r) => Reg.InfoTable -> Sem r ()
runReg tab =
case tab ^. Reg.infoMainFunction of
Just sym -> do
r <- doRun tab (Reg.lookupFunInfo tab sym)
case r of
Left err ->
exitJuvixError (JuvixError err)
Right Reg.ValVoid ->
return ()
Right val -> do
renderStdOut (Reg.ppOut (Reg.defaultOptions tab) val)
putStrLn ""
Nothing ->
exitMsg (ExitFailure 1) "no 'main' function"
where
doRun ::
Reg.InfoTable ->
Reg.FunctionInfo ->
Sem r (Either Reg.RegError Reg.Val)
doRun tab' funInfo = runError $ Reg.runFunctionIO stdin stdout tab' [] funInfo