SHA1 Hash: | 3464a035ec56f3b045c3de08f56e6c19b722d5c1 |
---|---|
Date: | 2010-11-21 01:35:14 |
User: | kinaba |
Comment: | source code cleanup |
Timelines: | family | ancestors | descendants | both | trunk |
Downloads: | Tarball | ZIP archive |
Other Links: | files | file ages | manifest |
- branch=trunk inherited from [f65680e1d2]
- sym-trunk inherited from [f65680e1d2]
Modified .poseidon from [c60d98a3acceffca] to [3a1ec7254a3a05f2].
30 <source> 30 <source> 31 <name>d2stacktrace\dbghelp.d</name> 31 <name>d2stacktrace\dbghelp.d</name> 32 <name>d2stacktrace\stacktrace.d</name> 32 <name>d2stacktrace\stacktrace.d</name> 33 <name>main.d</name> 33 <name>main.d</name> 34 <name>polemy\_common.d</name> 34 <name>polemy\_common.d</name> 35 <name>polemy\ast.d</name> 35 <name>polemy\ast.d</name> 36 <name>polemy\eval.d</name> 36 <name>polemy\eval.d</name> > 37 <name>polemy\failure.d</name> 37 <name>polemy\lex.d</name> 38 <name>polemy\lex.d</name> 38 <name>polemy\parse.d</name> 39 <name>polemy\parse.d</name> 39 <name>polemy\value.d</name> 40 <name>polemy\value.d</name> 40 <name>tricks\test.d</name> 41 <name>tricks\test.d</name> 41 <name>tricks\tricks.d</name> 42 <name>tricks\tricks.d</name> 42 </source> 43 </source> 43 <interface /> 44 <interface />
Modified doc/candydoc/modules.ddoc from [d7e1d5353bbe670c] to [16e1e2b29a0a959b].
1 MODULES = 1 MODULES = 2 $(MODULE main) 2 $(MODULE main) 3 $(MODULE tricks.tricks) 3 $(MODULE tricks.tricks) 4 $(MODULE tricks.test) 4 $(MODULE tricks.test) 5 $(MODULE polemy._common) 5 $(MODULE polemy._common) > 6 $(MODULE polemy.failure) 6 $(MODULE polemy.lex) 7 $(MODULE polemy.lex) 7 $(MODULE polemy.parse) 8 $(MODULE polemy.parse) 8 $(MODULE polemy.ast) 9 $(MODULE polemy.ast) 9 $(MODULE polemy.eval) 10 $(MODULE polemy.eval) 10 $(MODULE polemy.value) 11 $(MODULE polemy.value)
Modified main.d from [d5ef45952651bda8] to [3594122dc7a67c3c].
1 /** 1 /** 2 * Authors: k.inaba 2 * Authors: k.inaba 3 * License: NYSL 0.9982 (http://www.kmonos.net/nysl/ | 3 * License: NYSL 0.9982 (http://www.kmonos.net/nysl/) 4 * 4 * 5 * Entry point for Polemy interpreter. 5 * Entry point for Polemy interpreter. 6 */ 6 */ 7 < > 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 polemy.value; 11 import polemy.value; 11 import polemy.lex; | 12 import polemy.failure; 12 import polemy.parse; 13 import polemy.parse; 13 import polemy.ast; 14 import polemy.ast; 14 import polemy.eval; 15 import polemy.eval; 15 16 > 17 enum VersionNoMajor = 0; > 18 enum VersionNoMinor = 1; > 19 enum VersionNoRev = 0; > 20 16 /// Tenuki Read-Eval-Print-Loop | 21 /// Read-Eval-Print-Loop > 22 17 class REPL 23 class REPL 18 { 24 { > 25 /// Load the prelude environment > 26 this() > 27 { > 28 ctx = createGlobalContext(); > 29 } > 30 > 31 /// Print the version number etc. > 32 void greet() > 33 { > 34 writefln("Welcome to Polemy %d.%d.%d", VersionNoMajor, VersionNo > 35 } > 36 > 37 /// Run one file on the global scope > 38 void runFile(string filename) > 39 { > 40 eval(parseFile(filename), ctx, false, "@v"); > 41 } > 42 > 43 /// Repeat the singleInteraction > 44 void replLoop() > 45 { > 46 while( singleInteraction() ) {} > 47 } > 48 > 49 /// Read one line from stdin, and do some reaction > 50 bool singleInteraction() > 51 { > 52 writef(">> ", lineno); > 53 string line = readln(); > 54 if( line.startsWith("exit") || line.startsWith("quit") ) > 55 return false; > 56 try { > 57 if( tryRun(line) ) > 58 writeln(lastVal); > 59 } catch(Throwable e) { > 60 writeln(e); > 61 } > 62 return true; > 63 } > 64 > 65 private: 19 Table ctx; 66 Table ctx; 20 string buf; 67 string buf; 21 Value lastVal; 68 Value lastVal; 22 int lineno = 1; 69 int lineno = 1; 23 int nextlineno = 1; 70 int nextlineno = 1; 24 this() { ctx = createGlobalContext(); } < 25 this(string filename) { < 26 ctx = createGlobalContext(); < 27 eval(parseFile(filename), ctx, false, "@v"); < 28 } < 29 71 30 bool tryRun( string s ) 72 bool tryRun( string s ) 31 { 73 { 32 scope(failure) 74 scope(failure) 33 { buf = ""; lineno = nextlineno; } 75 { buf = ""; lineno = nextlineno; } 34 76 35 buf ~= s; 77 buf ~= s; ................................................................................................................................................................................ 38 { lastVal = eval(parseString(buf, "<REPL>", lineno), ctx 80 { lastVal = eval(parseString(buf, "<REPL>", lineno), ctx 39 catch( UnexpectedEOF ) 81 catch( UnexpectedEOF ) 40 { return false; } // wait 82 { return false; } // wait 41 buf = ""; 83 buf = ""; 42 lineno = nextlineno; 84 lineno = nextlineno; 43 return true; 85 return true; 44 } 86 } > 87 } > 88 > 89 /// Advance args[] to point the argument list fed to the script. > 90 /// Returns the name of the source file to run, or returns "" if > 91 /// no filename was given. Also, returns to libs[] the list of > 92 /// library source to load. > 93 > 94 string parseArgv(ref string[] args, out string[] libs) > 95 { > 96 args.popFront(); 45 97 46 bool singleInteraction() | 98 while( !args.empty && args.front=="-l" ) { 47 { < > 99 args.popFront(); 48 writef(">> ", lineno); | 100 if( !args.empty ) { 49 string line = readln(); | 101 libs ~= args.front(); 50 if( line.startsWith("exit") || line.startsWith("quit") ) | 102 args.popFront(); 51 return false; < 52 try { < 53 if( tryRun(line) ) < 54 { < 55 // for debugging. < 56 //try { < 57 // writeln(tableToAST("@v", cast(Table)last < 58 //} catch(Throwable e) { < 59 // writeln(e); < 60 //} < 61 writeln(lastVal); < 62 } < 63 } catch(Throwable e) { < 64 writeln(e); < 65 } 103 } > 104 } > 105 > 106 if( args.empty ) 66 return true; | 107 return ""; > 108 else { > 109 scope(exit) args.popFront; > 110 return args.front; 67 } 111 } 68 } 112 } 69 113 70 /// Entry point. If args.length==1, invoke REPL. | 114 /// Entry point. 71 /// If args.length==3 && args[1]=="-l" read args[2] and invoke REPL. < 72 /// Otherwise interpret the argument as a filename. < > 115 73 void main( string[] args ) 116 void main( string[] args ) 74 { 117 { 75 if( args.length <= 1 ) | 118 string[] libs; > 119 string src = parseArgv(args, libs); 76 { | 120 77 writeln("Welcome to Polemy 0.1.0"); < 78 for(auto r = new REPL; r.singleInteraction();) {} | 121 auto r = new REPL; 79 } < > 122 if( src.empty ) 80 else if( args.length>=3 && args[1]=="-l" ) | 123 r.greet(); 81 { < > 124 foreach(lb; libs) 82 writeln("Welcome to Polemy 0.1.0"); | 125 r.runFile(lb); 83 for(auto r = new REPL(args[2]); r.singleInteraction();) {} | 126 if( src.empty ) 84 } < > 127 r.replLoop(); 85 else 128 else 86 { < 87 evalFile(args[1]); < 88 } < > 129 r.runFile(src); 89 } 130 }
Modified polemy/_common.d from [ae51765dfb783149] to [05624ab3274c99f8].
9 public import tricks.tricks; 9 public import tricks.tricks; 10 public import std.algorithm; 10 public import std.algorithm; 11 public import std.array; 11 public import std.array; 12 public import std.bigint; 12 public import std.bigint; 13 public import std.conv : text; 13 public import std.conv : text; 14 public import std.exception; 14 public import std.exception; 15 public import std.range; 15 public import std.range; 16 public import std.stdio : writeln; // for debugging... | 16 public import std.stdio : DBG = writeln;
Modified polemy/ast.d from [f8a685431329b03d] to [351d6a36d1e1b0e0].
2 * Authors: k.inaba 2 * Authors: k.inaba 3 * License: NYSL 0.9982 http://www.kmonos.net/nysl/ 3 * License: NYSL 0.9982 http://www.kmonos.net/nysl/ 4 * 4 * 5 * Syntax tree for Polemy programming language. 5 * Syntax tree for Polemy programming language. 6 */ 6 */ 7 module polemy.ast; 7 module polemy.ast; 8 import polemy._common; 8 import polemy._common; 9 import polemy.lex; | 9 import polemy.failure; 10 10 11 /// 11 /// 12 abstract class AST 12 abstract class AST 13 { 13 { 14 immutable LexPosition pos; 14 immutable LexPosition pos; 15 mixin SimpleConstructor; 15 mixin SimpleConstructor; 16 mixin SimplePatternMatch; 16 mixin SimplePatternMatch;
Modified polemy/eval.d from [360da420d41dfbbf] to [97875541a42dbc7a].
2 * Authors: k.inaba 2 * Authors: k.inaba 3 * License: NYSL 0.9982 http://www.kmonos.net/nysl/ 3 * License: NYSL 0.9982 http://www.kmonos.net/nysl/ 4 * 4 * 5 * Evaluator for Polemy programming language. 5 * Evaluator for Polemy programming language. 6 */ 6 */ 7 module polemy.eval; 7 module polemy.eval; 8 import polemy._common; 8 import polemy._common; 9 import polemy.lex : LexPosition; | 9 import polemy.failure; 10 import polemy.ast; 10 import polemy.ast; 11 import polemy.parse; 11 import polemy.parse; 12 import polemy.value; 12 import polemy.value; 13 import std.typecons; 13 import std.typecons; 14 import std.stdio; 14 import std.stdio; 15 15 16 /// 16 ///
Added polemy/failure.d version [ceae1b272549ae1a]
> 1 /** > 2 * Authors: k.inaba > 3 * License: NYSL 0.9982 http://www.kmonos.net/nysl/ > 4 * > 5 * Error Information for Polemy Programming Language > 6 */ > 7 module polemy.failure; > 8 import polemy._common; > 9 > 10 /// Represents a position in source codes > 11 > 12 class LexPosition > 13 { > 14 immutable string filename; /// name of the source file > 15 immutable int lineno; /// 1-origin > 16 immutable int column; /// 1-origin > 17 > 18 mixin SimpleClass; > 19 override string toString() const > 20 { > 21 return sprintf!("%s:%d:%d")(filename, lineno, column); > 22 } > 23 > 24 static immutable LexPosition dummy; > 25 static this(){ dummy = new immutable(LexPosition)("<unnamed>",0,0); } > 26 } > 27 > 28 unittest > 29 { > 30 auto p = new LexPosition("hello.cpp", 123, 45); > 31 > 32 assert_eq( p.filename, "hello.cpp" ); > 33 assert_eq( p.lineno, 123 ); > 34 assert_eq( p.column, 45 ); > 35 assert_eq( text(p), "hello.cpp:123:45" ); > 36 > 37 assert( !__traits(compiles, new LexPosition) ); > 38 assert( !__traits(compiles, p.filename="foo") ); > 39 assert( !__traits(compiles, p.lineno =789) ); > 40 assert( !__traits(compiles, p.column =222) ); > 41 > 42 auto q = new LexPosition("hello.cpp", 123, 46); > 43 assert_lt( p, q ); > 44 assert_ne( p, q ); > 45 } > 46 > 47 /*mixin*/ > 48 template ExceptionWithPosition() > 49 { > 50 const LexPosition pos; > 51 this( const LexPosition pos, string msg, string file=null, size_t line=0 > 52 { > 53 if(pos is null) > 54 super(sprintf!("[???????] %s")(msg), file, line, next); > 55 else > 56 super(sprintf!("[%s] %s")(pos, msg), file, line, next); > 57 this.pos = pos; > 58 } > 59 } > 60 > 61 class UnexpectedEOF : Exception { mixin ExceptionWithPosition; } /// EOF during > 62 class LexException : Exception { mixin ExceptionWithPosition; } /// Lexer errors > 63 class ParseException : Exception { mixin ExceptionWithPosition; } /// Parser err > 64 class RuntimeException : Exception { mixin ExceptionWithPosition; } /// Evaluato
Modified polemy/lex.d from [514757ca55e253b4] to [480bb741b8b1612b].
2 * Authors: k.inaba 2 * Authors: k.inaba 3 * License: NYSL 0.9982 http://www.kmonos.net/nysl/ 3 * License: NYSL 0.9982 http://www.kmonos.net/nysl/ 4 * 4 * 5 * Lexer for Polemy programming language. 5 * Lexer for Polemy programming language. 6 */ 6 */ 7 module polemy.lex; 7 module polemy.lex; 8 import polemy._common; 8 import polemy._common; > 9 import polemy.failure; 9 import std.file : readText; 10 import std.file : readText; 10 import std.ctype : isspace, isalnum; 11 import std.ctype : isspace, isalnum; 11 12 12 /*mixin*/ < 13 template ExceptionWithPosition() < 14 { < 15 const LexPosition pos; < 16 this( const LexPosition pos, string msg, string file=null, size_t line=0 < 17 { < 18 if(pos is null) < 19 super(sprintf!"[??] %s"(msg), file, line, next); < 20 else < 21 super(sprintf!"[%s] %s"(pos, msg), file, line, next); < 22 this.pos = pos; < 23 } < 24 } < 25 < 26 /// Thrown when encountered an EOF in the middle of a lexical token < 27 < 28 class UnexpectedEOF : Exception < 29 { < 30 mixin ExceptionWithPosition; < 31 } < 32 < 33 /// Thrown when encountered a lexical error < 34 < 35 class LexException : Exception < 36 { < 37 mixin ExceptionWithPosition; < 38 }; < 39 < 40 /// Represents a position in source codes < 41 < 42 class LexPosition < 43 { < 44 immutable string filename; /// name of the source file < 45 immutable int lineno; /// 1-origin < 46 immutable int column; /// 1-origin < 47 < 48 mixin SimpleClass; < 49 override string toString() const < 50 { return sprintf!"%s:%d:%d"(filename, lineno, column); } < 51 < 52 static immutable LexPosition dummy; < 53 static this(){ dummy = new immutable(LexPosition)("<unnamed>",0,0); } < 54 } < 55 < 56 unittest < 57 { < 58 auto p = new LexPosition("hello.cpp", 123, 45); < 59 < 60 assert_eq( p.filename, "hello.cpp" ); < 61 assert_eq( p.lineno, 123 ); < 62 assert_eq( p.column, 45 ); < 63 assert_eq( text(p), "hello.cpp:123:45" ); < 64 < 65 assert( !__traits(compiles, new LexPosition) ); < 66 assert( !__traits(compiles, p.filename="foo") ); < 67 assert( !__traits(compiles, p.lineno =789) ); < 68 assert( !__traits(compiles, p.column =222) ); < 69 < 70 auto q = new LexPosition("hello.cpp", 123, 46); < 71 assert_lt( p, q ); < 72 assert_ne( p, q ); < 73 } < 74 < 75 /// Represents a lexer token 13 /// Represents a lexer token 76 14 77 class Token 15 class Token 78 { 16 { 79 immutable LexPosition pos; /// Position where the token occurred in t 17 immutable LexPosition pos; /// Position where the token occurred in t 80 immutable string str; /// The token string itself 18 immutable string str; /// The token string itself 81 immutable bool quoted; /// Was it a "quoted" token or unquoted? 19 immutable bool quoted; /// Was it a "quoted" token or unquoted?
Modified polemy/parse.d from [6bec0997c5764737] to [a024e7c2d40e70c4].
2 * Authors: k.inaba 2 * Authors: k.inaba 3 * License: NYSL 0.9982 http://www.kmonos.net/nysl/ 3 * License: NYSL 0.9982 http://www.kmonos.net/nysl/ 4 * 4 * 5 * Parser for Polemy programming language 5 * Parser for Polemy programming language 6 */ 6 */ 7 module polemy.parse; 7 module polemy.parse; 8 import polemy._common; 8 import polemy._common; > 9 import polemy.failure; 9 import polemy.lex; 10 import polemy.lex; 10 import polemy.ast; 11 import polemy.ast; 11 12 12 /// Thrown when encountered a syntax error < 13 < 14 class ParseException : Exception < 15 { < 16 mixin ExceptionWithPosition; < 17 } < 18 < 19 /// Parse a string and return its AST 13 /// Parse a string and return its AST 20 /// Throws: ParseException, LexException, UnexpectedEOF 14 /// Throws: ParseException, LexException, UnexpectedEOF 21 15 22 AST parseString(S, T...)(S str, T fn_ln_cn) 16 AST parseString(S, T...)(S str, T fn_ln_cn) 23 { 17 { 24 return parserFromString(str, fn_ln_cn).parse(); 18 return parserFromString(str, fn_ln_cn).parse(); 25 } 19 }
Modified polemy/value.d from [ff42bce4fb7dc674] to [f1d2e31afdaaee9d].
2 * Authors: k.inaba 2 * Authors: k.inaba 3 * License: NYSL 0.9982 http://www.kmonos.net/nysl/ 3 * License: NYSL 0.9982 http://www.kmonos.net/nysl/ 4 * 4 * 5 * Runtime data structures for Polemy programming language. 5 * Runtime data structures for Polemy programming language. 6 */ 6 */ 7 module polemy.value; 7 module polemy.value; 8 import polemy._common; 8 import polemy._common; 9 import polemy.lex; | 9 import polemy.failure; 10 import polemy.ast; 10 import polemy.ast; 11 11 12 /// Raised when something went wrong in runtime < 13 < 14 class RuntimeException : Exception < 15 { < 16 mixin ExceptionWithPosition; < 17 } < 18 < 19 /// Runtime values of Polemy 12 /// Runtime values of Polemy 20 13 21 abstract class Value 14 abstract class Value 22 { 15 { 23 } 16 } 24 17 25 /// 18 ///
Modified readme.txt from [b45d599d08f18ee0] to [6629940451babbd3].
46 46 47 > polemy foo.pmy 47 > polemy foo.pmy 48 executes foo.pmy 48 executes foo.pmy 49 49 50 > polemy -l foo.pmy 50 > polemy -l foo.pmy 51 after executing foo.pmy, starts REPL 51 after executing foo.pmy, starts REPL 52 52 > 53 > polemy -l foo.pmy -l bar.pmy buz.pmy > 54 executes foo.pmy, bar.bmy, and then buz.pmy > 55 53 56 54 57 55 <<Syntax>> 58 <<Syntax>> 56 59 57 Comment is "# ... \n" 60 Comment is "# ... \n" 58 61 59 E ::= 62 E ::=