diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/Interpreter.hs | 32 | ||||
| -rw-r--r-- | src/Utils.hs | 3 |
2 files changed, 29 insertions, 6 deletions
diff --git a/src/Interpreter.hs b/src/Interpreter.hs index 33e36ea..37996f4 100644 --- a/src/Interpreter.hs +++ b/src/Interpreter.hs @@ -191,12 +191,34 @@ evaluateImport d env asts = do case args of [AST { astNode = ASTSymbol qualifier }, AST { astNode = ASTString path }] -> do - (importedEnv, _) <- runScriptFile builtinEnv path - let nameMangled = M.mapKeys (\k -> qualifier ++ ":" ++ k) importedEnv - return (M.union env nameMangled, importAst { astNode = ASTUnit }) + (evaledRawEnv, _) <- runScriptFile builtinEnv path + let exportsVecASTM = M.lookup "exports" evaledRawEnv + exportedEnv <- case exportsVecASTM of + Just (AST { astNode = ASTVector exportsVec }) -> do + exportSyms <- exportsVec $> + mapM (\case AST { astNode = ASTSymbol sym } -> return sym + ast -> throwL (astPos ast) $ "non-symbol value in exports vector: " ++ show ast) + let resultEnv = M.filterWithKey (\k _ -> L.elem k exportSyms) evaledRawEnv + return resultEnv + Just ast -> throwL (astPos ast) $ "exports symbol set to non-symbol value: " ++ show ast + Nothing -> throwL (astPos importAst) $ "no exports vector defined in file: " ++ path + + let nameMangled = M.mapKeys (\k -> qualifier ++ ":" ++ k) exportedEnv + return $ (M.union env nameMangled, importAst { astNode = ASTUnit }) [AST { astNode = ASTString path }] -> do - (importedEnv, _) <- runScriptFile builtinEnv path - return (M.union env importedEnv, importAst { astNode = ASTUnit }) + (evaledRawEnv, _) <- runScriptFile builtinEnv path + let exportsVecASTM = M.lookup "exports" evaledRawEnv + exportedEnv <- case exportsVecASTM of + Just (AST { astNode = ASTVector exportsVec }) -> do + exportSyms <- exportsVec $> + mapM (\case AST { astNode = ASTSymbol sym } -> return sym + ast -> throwL (astPos ast) $ "non-symbol value in exports vector: " ++ show ast) + let resultEnv = M.filterWithKey (\k _ -> L.elem k exportSyms) evaledRawEnv + return resultEnv + Just ast -> throwL (astPos ast) $ "exports symbol set to non-symbol value: " ++ show ast + Nothing -> throwL (astPos importAst) $ "no exports vector defined in file: " ++ path + + return $ (M.union env exportedEnv, importAst { astNode = ASTUnit }) _ -> throwL (astPos importAst) $ "invalid arguments passed to import!: " ++ show args evaluateUserFunction :: Depth -> Env -> [AST] -> LContext (Env, AST) diff --git a/src/Utils.hs b/src/Utils.hs index 2a2f607..1e9afc5 100644 --- a/src/Utils.hs +++ b/src/Utils.hs @@ -18,7 +18,8 @@ data Config = Config { configVerboseMode :: Bool, configShowHelp :: Bool, configPrintEvaled :: Bool, - configPrintCallStack :: Bool + configPrintCallStack :: Bool, + configUseREPL :: Bool } type LContext a = ReaderT Config (ExceptT LException IO) a |
