mirror of
https://github.com/anoma/juvix.git
synced 2024-12-26 17:13:35 +03:00
97030f8cb4
- ⚠️ Depends on #2644 The `effectful` library does not support the `Embed` effect out of the box. However, it offers `IOE`, which is equivalent to `Embed IO` from polysemy. In preparation to a possible migration to `effectful`, this pr hides the general `Embed` effect from the prelude and it exports a specialized `EmbedIO` in its place.
38 lines
1.3 KiB
Haskell
38 lines
1.3 KiB
Haskell
module AsmInterpreter where
|
|
|
|
import App
|
|
import CommonOptions
|
|
import Juvix.Compiler.Asm.Data.InfoTable qualified as Asm
|
|
import Juvix.Compiler.Asm.Extra qualified as Asm
|
|
import Juvix.Compiler.Asm.Interpreter qualified as Asm
|
|
import Juvix.Compiler.Asm.Pretty qualified as Asm
|
|
import Juvix.Compiler.Asm.Transformation.Validate qualified as Asm
|
|
|
|
runAsm :: forall r. (Members '[EmbedIO, App] r) => Bool -> Asm.InfoTable -> Sem r ()
|
|
runAsm bValidate tab =
|
|
let v = if bValidate then Asm.validate' tab else Nothing
|
|
in case v of
|
|
Just err ->
|
|
exitJuvixError (JuvixError err)
|
|
Nothing ->
|
|
case tab ^. Asm.infoMainFunction of
|
|
Just sym -> do
|
|
r <- doRun tab (Asm.lookupFunInfo tab sym)
|
|
case r of
|
|
Left err ->
|
|
exitJuvixError (JuvixError err)
|
|
Right Asm.ValVoid ->
|
|
return ()
|
|
Right val -> do
|
|
renderStdOut (Asm.ppOut (Asm.defaultOptions tab) val)
|
|
putStrLn ""
|
|
Nothing ->
|
|
exitMsg (ExitFailure 1) "no 'main' function"
|
|
where
|
|
doRun ::
|
|
Asm.InfoTable ->
|
|
Asm.FunctionInfo ->
|
|
Sem r (Either Asm.AsmError Asm.Val)
|
|
doRun tab' funInfo =
|
|
embed $ Asm.catchRunErrorIO (Asm.runCodeIO tab' funInfo)
|