File tree Expand file tree Collapse file tree 2 files changed +16
-31
lines changed
Expand file tree Collapse file tree 2 files changed +16
-31
lines changed Original file line number Diff line number Diff 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- )
2210import System.Environment
2311
24- import Interpreter
25- ( Repl
26- , execute
27- , initial
28- )
12+ import qualified Interpreter
2913import Data.IORef
3014
3115{- ----------------------------------------------------------------------------
3216 Rendering Logic
3317------------------------------------------------------------------------------}
34- type RefRepl = IORef Repl
18+ type RefRepl = IORef Interpreter. Repl
3519
3620eval :: RefRepl -> String -> IO String
3721eval 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
4836initDisco :: IO RefRepl
4937initDisco = 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
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ module Main where
33import Control.Monad (when )
44import 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
You can’t perform that action at this time.
0 commit comments