Skip to content

Commit f40a4ef

Browse files
committed
Edits suggested by Adam
1 parent f141999 commit f40a4ef

File tree

9 files changed

+24
-14
lines changed

9 files changed

+24
-14
lines changed

makefile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ example-names = mandelbrot pi sierpinski rejection-sampler \
129129
# TODO: re-enable
130130
# fft vega-plotting
131131

132-
test-names = uexpr-tests adt-tests type-tests module-tests eval-tests show-tests \
132+
test-names = uexpr-tests adt-tests type-tests eval-tests show-tests \
133133
shadow-tests monad-tests io-tests exception-tests sort-tests \
134134
ad-tests parser-tests serialize-tests parser-combinator-tests \
135135
record-variant-tests typeclass-tests complex-tests trig-tests \
@@ -148,7 +148,12 @@ doc-example-names = $(example-names:%=doc/examples/%.html)
148148

149149
doc-lib-names = $(lib-names:%=doc/lib/%.html)
150150

151-
tests: quine-tests repl-test
151+
module-tests:
152+
misc/check-quine tests/module-tests.dx \
153+
$(dex) --prelude lib/prelude.dx --lib-path tests script --allow-errors
154+
155+
156+
tests: quine-tests repl-test module-tests
152157

153158
quine-tests: $(quine-test-targets)
154159

src/lib/Builder.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ module Builder (
3939
emitBlock, emitDecls, BuilderEmissions, emitAtomToName,
4040
TopBuilder (..), TopBuilderT (..), liftTopBuilderTWith, runTopBuilderT, TopBuilder2,
4141
emitSourceMap, emitSynthCandidates, emitTopLet, emitImpFunBinding,
42-
lookupLoadedModule, loadModule, getAllRequiredObjectFiles, extendCache,
42+
lookupLoadedModule, bindModule, getAllRequiredObjectFiles, extendCache,
4343
extendImpCache, queryImpCache, extendObjCache, queryObjCache, getCache, emitObjFile,
4444
TopEnvFrag (..), lookupModule, emitPartialTopEnvFrag,
4545
inlineLastDecl, fabricateEmitsEvidence, fabricateEmitsEvidenceM,
@@ -162,8 +162,8 @@ emitTopLet hint letAnn expr = do
162162
emitImpFunBinding :: (Mut n, TopBuilder m) => NameHint -> ImpFunction n -> m n (ImpFunName n)
163163
emitImpFunBinding hint f = emitBinding hint $ ImpFunBinding f
164164

165-
loadModule :: (Mut n, TopBuilder m) => ModuleSourceName -> ModuleName n -> m n ()
166-
loadModule sourceName internalName = do
165+
bindModule :: (Mut n, TopBuilder m) => ModuleSourceName -> ModuleName n -> m n ()
166+
bindModule sourceName internalName = do
167167
let loaded = LoadedModules $ M.singleton sourceName internalName
168168
emitPartialTopEnvFrag $ mempty {fragLoadedModules = loaded}
169169

src/lib/Err.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ catchIOExcept :: MonadIO m => IO a -> m (Except a)
230230
catchIOExcept m = liftIO $ (liftM Success m) `catches`
231231
[ Handler \(e::Errs) -> return $ Failure e
232232
, Handler \(e::IOError) -> return $ Failure $ Errs [Err DataIOErr mempty $ show e]
233-
-- , Handler \(e::SomeException) -> return $ Failure $ Errs [Err CompilerErr mempty $ show e]
233+
, Handler \(e::SomeException) -> return $ Failure $ Errs [Err CompilerErr mempty $ show e]
234234
]
235235

236236
liftMaybe :: MonadFail m => Maybe a -> m a

src/lib/Syntax.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,9 @@ type AtomSubstVal = SubstVal AtomNameC Atom :: V
304304

305305
-- === envs and modules ===
306306

307+
-- `ModuleEnv` contains data that only makes sense in the context of evaluating
308+
-- a particular module. `TopEnv` contains everything that makes sense "between"
309+
-- evaluating modules.
307310
data Env n = Env
308311
{ topEnv :: TopEnv n
309312
, moduleEnv :: ModuleEnv n }

src/lib/TopLevel.hs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ class Monad m => PassCtxReader m where
8282
type TopLogger m = (MonadIO m, MonadLogger [Output] m)
8383

8484
class ( forall n. Fallible (m n)
85-
-- , forall n. Catchable (m n)
8685
, forall n. MonadLogger [Output] (m n)
8786
, forall n. Catchable (m n)
8887
, forall n. ConfigReader (m n)
@@ -159,7 +158,7 @@ ensureModuleLoaded moduleSourceName = do
159158
depsRequired <- findDepsTransitively moduleSourceName
160159
forM_ depsRequired \md -> do
161160
evaluated <- evalPartiallyParsedUModuleCached md
162-
loadModule (umppName md) evaluated
161+
bindModule (umppName md) evaluated
163162

164163
evalSourceBlock :: (Topper m, Mut n) => SourceBlock -> m n Result
165164
evalSourceBlock block = do
@@ -534,15 +533,18 @@ logPass passName cont = do
534533

535534
loadModuleSource :: MonadIO m => EvalConfig -> ModuleSourceName -> m File
536535
loadModuleSource config moduleName = do
537-
fnameStem <- case moduleName of
538-
OrdinaryModule moduleName' -> return moduleName'
539-
Prelude -> return "prelude"
536+
fullPath <- case moduleName of
537+
OrdinaryModule moduleName' -> findFullPath $ moduleName' ++ ".dx"
538+
Prelude -> case preludeFile config of
539+
Nothing -> findFullPath "prelude.dx"
540+
Just path -> return path
540541
Main -> error "shouldn't be trying to load the source for main"
541-
let fname = fnameStem ++ ".dx"
542-
fullPath <- case libPath config of
542+
readFileWithHash fullPath
543+
where
544+
findFullPath :: MonadIO m => FilePath -> m FilePath
545+
findFullPath fname = case libPath config of
543546
Nothing -> liftIO $ getDataFileName $ "lib/" ++ fname
544547
Just path -> return $ path </> fname
545-
readFileWithHash fullPath
546548

547549
-- === saving cache to disk ===
548550

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)