Skip to content

Commit 719e22c

Browse files
Load module when evaluating an expression
1 parent f6b7285 commit 719e22c

File tree

2 files changed

+16
-31
lines changed

2 files changed

+16
-31
lines changed

src/Eval.hs

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,56 +4,39 @@ module Eval
44
( RefRepl
55
, initDisco
66
, eval
7+
, loadFile
78
) where
89

9-
import Control.Monad (forM_)
10-
import Disco.Module
11-
( Resolver (..)
12-
, resolveModule
13-
)
14-
import Disco.Names
15-
( ModuleProvenance
16-
)
17-
import Polysemy
18-
( Embed
19-
, Sem
20-
, runM
21-
)
2210
import System.Environment
2311

24-
import Interpreter
25-
( Repl
26-
, execute
27-
, initial
28-
)
12+
import qualified Interpreter
2913
import Data.IORef
3014

3115
{-----------------------------------------------------------------------------
3216
Rendering Logic
3317
------------------------------------------------------------------------------}
34-
type RefRepl = IORef Repl
18+
type RefRepl = IORef Interpreter.Repl
3519

3620
eval :: RefRepl -> String -> IO String
3721
eval ref command = do
3822
repl0 <- readIORef ref
39-
(result, repl1) <- execute command repl0
23+
(result, repl1) <- Interpreter.execute command repl0
4024
writeIORef ref repl1
4125
pure result
4226

43-
resolveModule'
44-
:: Resolver -> String
45-
-> Sem '[Embed IO] (Maybe (FilePath, ModuleProvenance))
46-
resolveModule' = resolveModule
27+
loadFile :: RefRepl -> String -> IO String
28+
loadFile ref s = do
29+
writeFile "disco-live.disco" s
30+
repl0 <- readIORef ref
31+
(result, repl1) <-
32+
Interpreter.execute (":load disco-live.disco") repl0
33+
writeIORef ref repl1
34+
pure result
4735

4836
initDisco :: IO RefRepl
4937
initDisco = do
5038
-- NOTE: We set path environment variables here,
5139
-- because processing the .wasm module with `wizer` may bake
5240
-- them into the code.
5341
setEnv "disco_datadir" "stdlib"
54-
55-
-- Debug output
56-
s <- runM $ resolveModule' FromStdlib "num"
57-
print s
58-
59-
newIORef initial
42+
newIORef Interpreter.initial

src/Main.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module Main where
33
import Control.Monad (when)
44
import GHC.Wasm.Prim
55

6-
import Eval (RefRepl, eval, initDisco)
6+
import Eval (RefRepl, eval, initDisco, loadFile)
77

88
{-----------------------------------------------------------------------------
99
JavaScript Imports
@@ -81,6 +81,8 @@ handleEval ref = do
8181
expr <- fromJSString <$> js_input_value exprIn
8282

8383
logHistory $ "disco> " <> expr
84+
result <- loadFile ref module_
85+
logHistory result
8486
result <- eval ref expr
8587
logHistory result
8688

0 commit comments

Comments
 (0)