Diff
Not logged in

Differences From Artifact [636370f08c051cf2]:

To Artifact [e659b2cb410288fd]:


6 */ 6 */ 7 module main; 7 module main; 8 import std.stdio; 8 import std.stdio; 9 import std.algorithm; 9 import std.algorithm; 10 import std.array; 10 import std.array; 11 import polemy.value; 11 import polemy.value; 12 import polemy.failure; 12 import polemy.failure; > 13 import polemy.layer; 13 import polemy.parse; 14 import polemy.parse; 14 import polemy.ast; 15 import polemy.ast; 15 import polemy.eval; 16 import polemy.eval; 16 import polemy.layer; < 17 17 18 enum VersionNoMajor = 0; 18 enum VersionNoMajor = 0; 19 enum VersionNoMinor = 1; 19 enum VersionNoMinor = 1; 20 enum VersionNoRev = 0; 20 enum VersionNoRev = 0; 21 21 22 /// Read-Eval-Print-Loop 22 /// Read-Eval-Print-Loop 23 23 24 class REPL 24 class REPL 25 { 25 { > 26 Evaluator ev; 26 /// Load the prelude environment 27 /// Load the prelude environment 27 this() 28 this() 28 { 29 { 29 ctx = createGlobalContext(); | 30 ev = new Evaluator; 30 } 31 } 31 32 32 /// Print the version number etc. 33 /// Print the version number etc. 33 void greet() 34 void greet() 34 { 35 { 35 writefln("Welcome to Polemy %d.%d.%d", VersionNoMajor, VersionNo 36 writefln("Welcome to Polemy %d.%d.%d", VersionNoMajor, VersionNo 36 } 37 } 37 38 38 /// Run one file on the global scope 39 /// Run one file on the global scope 39 void runFile(string filename) 40 void runFile(string filename) 40 { 41 { 41 eval(parseFile(filename), ctx, false, ValueLayer); | 42 ev.evalFile(filename); 42 } 43 } 43 44 44 /// Repeat the singleInteraction 45 /// Repeat the singleInteraction 45 void replLoop() 46 void replLoop() 46 { 47 { 47 while( singleInteraction() ) {} 48 while( singleInteraction() ) {} 48 } 49 } ................................................................................................................................................................................ 74 { 75 { 75 scope(failure) 76 scope(failure) 76 { buf = ""; lineno = nextlineno; } 77 { buf = ""; lineno = nextlineno; } 77 78 78 buf ~= s; 79 buf ~= s; 79 nextlineno ++; 80 nextlineno ++; 80 try 81 try 81 { lastVal = eval(parseString(buf, "<REPL>", lineno), ctx | 82 { lastVal = ev.evalString(buf, "<REPL>", lineno); } 82 catch( UnexpectedEOF ) 83 catch( UnexpectedEOF ) 83 { return false; } // wait 84 { return false; } // wait 84 buf = ""; 85 buf = ""; 85 lineno = nextlineno; 86 lineno = nextlineno; 86 return true; 87 return true; 87 } 88 } 88 } 89 }