Permalink
Browse files

repl prelude override

  • Loading branch information...
1 parent f273a9e commit 6f62bc2126a19c81c4c6916e51b9e9a821241672 @galchinsky galchinsky committed Nov 20, 2012
Showing with 24 additions and 13 deletions.
  1. +3 −3 compiler/clay.cpp
  2. +17 −8 compiler/loader.cpp
  3. +2 −2 compiler/loader.hpp
  4. +2 −0 lib-clay/prelude/repl/repl.clay
View
@@ -1096,11 +1096,11 @@ int main2(int argc, char **argv, char const* const* envp) {
vector<string> sourceFiles;
if (!clayScript.empty()) {
clayScriptSource = clayScriptImports + "main() {\n" + clayScript + "}";
- m = loadProgramSource("-e", clayScriptSource, verbose);
+ m = loadProgramSource("-e", clayScriptSource, verbose, repl);
} else if (generateDeps)
- m = loadProgram(clayFile, &sourceFiles, verbose);
+ m = loadProgram(clayFile, &sourceFiles, verbose, repl);
else
- m = loadProgram(clayFile, NULL, verbose);
+ m = loadProgram(clayFile, NULL, verbose, repl);
loadTimer.stop();
compileTimer.start();
View
@@ -396,23 +396,32 @@ static void loadDependents(ModulePtr m, vector<string> *sourceFiles, bool verbos
}
}
-static ModulePtr loadPrelude(vector<string> *sourceFiles, bool verbose) {
- DottedNamePtr dottedName = new DottedName();
- dottedName->parts.push_back(Identifier::get("prelude"));
- return loadModuleByName(dottedName, sourceFiles, verbose);
+static ModulePtr loadPrelude(vector<string> *sourceFiles, bool verbose, bool repl) {
+ if (!repl) {
+ DottedNamePtr dottedName = new DottedName();
+ dottedName->parts.push_back(Identifier::get("prelude"));
+ return loadModuleByName(dottedName, sourceFiles, verbose);
+ } else {
+ DottedNamePtr dottedName = new DottedName();
+ dottedName->parts.push_back(Identifier::get("prelude"));
+ dottedName->parts.push_back(Identifier::get("repl"));
+ ModulePtr m = loadModuleByName(dottedName, sourceFiles, verbose);
+ globalModules["prelude"] = m;
+ return m;
+ }
}
-ModulePtr loadProgram(llvm::StringRef fileName, vector<string> *sourceFiles, bool verbose) {
+ModulePtr loadProgram(llvm::StringRef fileName, vector<string> *sourceFiles, bool verbose, bool repl) {
globalMainModule = parse("", loadFile(fileName, sourceFiles));
- ModulePtr prelude = loadPrelude(sourceFiles, verbose);
+ ModulePtr prelude = loadPrelude(sourceFiles, verbose, repl);
loadDependents(globalMainModule, sourceFiles, verbose);
installGlobals(globalMainModule);
initModule(prelude);
initModule(globalMainModule);
return globalMainModule;
}
-ModulePtr loadProgramSource(llvm::StringRef name, llvm::StringRef source, bool verbose) {
+ModulePtr loadProgramSource(llvm::StringRef name, llvm::StringRef source, bool verbose, bool repl) {
SourcePtr mainSource = new Source(name,
llvm::MemoryBuffer::getMemBufferCopy(source));
if (llvmDIBuilder != NULL) {
@@ -423,7 +432,7 @@ ModulePtr loadProgramSource(llvm::StringRef name, llvm::StringRef source, bool v
globalMainModule = parse("", mainSource);
// Don't keep track of source files for -e script
- ModulePtr prelude = loadPrelude(NULL, verbose);
+ ModulePtr prelude = loadPrelude(NULL, verbose, repl);
loadDependents(globalMainModule, NULL, verbose);
installGlobals(globalMainModule);
initModule(prelude);
View
@@ -16,8 +16,8 @@ void getProcedureMonoTypes(ProcedureMono &mono, EnvPtr env,
void initLoader();
void setSearchPath(const llvm::ArrayRef<PathString> path);
-ModulePtr loadProgram(llvm::StringRef fileName, vector<string> *sourceFiles, bool verbose);
-ModulePtr loadProgramSource(llvm::StringRef name, llvm::StringRef source, bool verbose);
+ModulePtr loadProgram(llvm::StringRef fileName, vector<string> *sourceFiles, bool verbose, bool repl);
+ModulePtr loadProgramSource(llvm::StringRef name, llvm::StringRef source, bool verbose, bool repl);
ModulePtr loadedModule(llvm::StringRef module);
ModulePtr preludeModule();
ModulePtr primitivesModule();
@@ -0,0 +1,2 @@
+public import prelude.*;
+public import printer.*;

0 comments on commit 6f62bc2

Please sign in to comment.