Overview
SHA1 Hash: | 820e7198cc2279657a8ddb6982bb25289e600ac1 |
---|---|
Date: | 2010-11-08 00:03:38 |
User: | kinaba |
Comment: | Made helloworld work. |
Timelines: | family | ancestors | descendants | both | trunk |
Downloads: | Tarball | ZIP archive |
Other Links: | files | file ages | manifest |
Tags And Properties
- branch=trunk inherited from [f65680e1d2]
- sym-trunk inherited from [f65680e1d2]
Changes
Modified main.d from [521e3de53633ae4a] to [5cef40bce7835081].
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 8 import std.stdio; 8 import std.stdio; 9 import polemy.lex; | 9 import polemy.eval; 10 import polemy.parse; < 11 10 > 11 version(unittest) 12 static ~this() { readln(); } // workaround for enabling "pause" under Poseidon | 12 static ~this() { readln(); } // workaround for enabling "pause" under Po 13 13 14 void main() 14 void main() 15 { 15 { 16 writeln( "test ok" ); 16 writeln( "test ok" ); 17 } 17 }
Modified polemy/ast.d from [a264a204623245e6] to [6aa982b32b1d6e05].
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 * 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;
Modified polemy/eval.d from [cea762cacb86424f] to [f2bd29fa05629861].
7 module polemy.eval; 7 module polemy.eval; 8 import polemy._common; 8 import polemy._common; 9 import polemy.lex : LexPosition; 9 import polemy.lex : LexPosition; 10 import polemy.ast; 10 import polemy.ast; 11 import polemy.parse; 11 import polemy.parse; 12 import polemy.runtime; 12 import polemy.runtime; 13 import std.typecons; 13 import std.typecons; > 14 import std.stdio; 14 15 15 Context createGlobalContext() 16 Context createGlobalContext() 16 { 17 { 17 auto ctx = new Context; 18 auto ctx = new Context; 18 ctx.add("+", new FunValue(delegate Value(immutable LexPosition pos, Valu 19 ctx.add("+", new FunValue(delegate Value(immutable LexPosition pos, Valu 19 if( args.length != 2 ) 20 if( args.length != 2 ) 20 throw new PolemyRuntimeException("+ takes two arguments! 21 throw new PolemyRuntimeException("+ takes two arguments! ................................................................................................................................................................................ 42 ctx.add("/", new FunValue(delegate Value(immutable LexPosition pos, Valu 43 ctx.add("/", new FunValue(delegate Value(immutable LexPosition pos, Valu 43 if( args.length != 2 ) 44 if( args.length != 2 ) 44 throw new PolemyRuntimeException("/ takes two arguments! 45 throw new PolemyRuntimeException("/ takes two arguments! 45 if( auto x = cast(IntValue)args[0] ) 46 if( auto x = cast(IntValue)args[0] ) 46 if( auto y = cast(IntValue)args[1] ) 47 if( auto y = cast(IntValue)args[1] ) 47 return new IntValue(x.data/y.data); 48 return new IntValue(x.data/y.data); 48 throw new PolemyRuntimeException("cannot add non-integers ["~to! 49 throw new PolemyRuntimeException("cannot add non-integers ["~to! > 50 })); > 51 ctx.add("print", new FunValue(delegate Value(immutable LexPosition pos, > 52 foreach(a; args) > 53 write(a); > 54 writeln(""); > 55 return new UndefinedValue; 49 })); 56 })); 50 return ctx; 57 return ctx; 51 } 58 } 52 59 53 Tuple!(Value,"val",Context,"ctx") evalString(T...)(T params) 60 Tuple!(Value,"val",Context,"ctx") evalString(T...)(T params) 54 { 61 { 55 return eval( parserFromString(params).parseProgram() ); 62 return eval( parserFromString(params).parseProgram() ); ................................................................................................................................................................................ 167 } 174 } 168 unittest 175 unittest 169 { 176 { 170 auto r = evalString(`var x = 1; var f = fun(){x=x+1;}; f(); f(); f();`); 177 auto r = evalString(`var x = 1; var f = fun(){x=x+1;}; f(); f(); f();`); 171 assert( r.ctx["x"] == new IntValue(BigInt(4)) ); 178 assert( r.ctx["x"] == new IntValue(BigInt(4)) ); 172 assert( r.val == new IntValue(BigInt(4)) ); 179 assert( r.val == new IntValue(BigInt(4)) ); 173 } 180 } > 181 unittest > 182 { > 183 evalString(`print("Hello, world!");`); > 184 evalString(`print(fun(){});`); > 185 }
Modified polemy/lex.d from [fb4085e84f38ed6a] to [e43d60d2bdfc662b].
44 assert( !__traits(compiles, p.column =222) ); 44 assert( !__traits(compiles, p.column =222) ); 45 } 45 } 46 46 47 /// Represents a lexer token 47 /// Represents a lexer token 48 48 49 class Token 49 class Token 50 { 50 { > 51 /// currently we have three kinds of token 51 enum Kind {identifier, stringLiteral, number}; | 52 enum Kind { > 53 identifier, /// anything other than others > 54 stringLiteral, /// "string literal" > 55 number /// 42 > 56 }; 52 immutable LexPosition pos; /// position where the token occurred in the 57 immutable LexPosition pos; /// position where the token occurred in the 53 immutable string str; /// the token string itself 58 immutable string str; /// the token string itself 54 immutable Kind kind; /// which kind of token? 59 immutable Kind kind; /// which kind of token? 55 60 56 mixin SimpleConstructor; 61 mixin SimpleConstructor; 57 mixin SimpleCompare; 62 mixin SimpleCompare; 58 } 63 }
Modified polemy/parse.d from [1d6de9cb69bbf7d4] to [fe0b0bcfc1d8a230].
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 * 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;
Modified polemy/runtime.d from [eb7f695558db6c0f] to [2eb228662dba6e2d].
18 { 18 { 19 } 19 } 20 20 21 class UndefinedValue : Value 21 class UndefinedValue : Value 22 { 22 { 23 mixin SimpleConstructor; 23 mixin SimpleConstructor; 24 mixin SimpleCompare; 24 mixin SimpleCompare; > 25 override string toString() const { return "(undefined)"; } 25 } 26 } 26 27 27 class IntValue : Value 28 class IntValue : Value 28 { 29 { 29 BigInt data; 30 BigInt data; 30 mixin SimpleConstructor; 31 mixin SimpleConstructor; 31 mixin SimpleCompare; 32 mixin SimpleCompare; > 33 override string toString() const { > 34 const(char)[] cs; data.toString((const(char)[] s){cs=s;}, null); > 35 return to!string(cs); > 36 } 32 } 37 } 33 38 34 class StrValue : Value 39 class StrValue : Value 35 { 40 { 36 string data; 41 string data; 37 mixin SimpleConstructor; 42 mixin SimpleConstructor; 38 mixin SimpleCompare; 43 mixin SimpleCompare; > 44 override string toString() const { return data; } 39 } 45 } 40 46 41 class FunValue : Value 47 class FunValue : Value 42 { 48 { 43 Value delegate(immutable LexPosition pos, Value[]) data; 49 Value delegate(immutable LexPosition pos, Value[]) data; 44 mixin SimpleConstructor; 50 mixin SimpleConstructor; 45 Value call(immutable LexPosition pos, Value[] args) { return data(pos,ar 51 Value call(immutable LexPosition pos, Value[] args) { return data(pos,ar > 52 override string toString() const { return sprintf!"(function:%s:%s)"(dat 46 } 53 } 47 import std.stdio; 54 import std.stdio; 48 class Context 55 class Context 49 { 56 { 50 Context parent; 57 Context parent; 51 Value[string] table; 58 Value[string] table; 52 this(Context parent = null) { this.parent = parent; } 59 this(Context parent = null) { this.parent = parent; }
Modified polemy/tricks.d from [16f826d18ff480be] to [b521ec130c690547].
39 { 39 { 40 super(ps); 40 super(ps); 41 static if(this.tupleof.length>0) 41 static if(this.tupleof.length>0) 42 this.tupleof = params; 42 this.tupleof = params; 43 } 43 } 44 } 44 } 45 45 46 /// Mixing-in the (MOST-DERIVED) member-wise comparator for a class | 46 /// Mixing-in the MOST-DERIVED-member-wise comparator for a class 47 47 48 /*mixin*/ template SimpleCompare() 48 /*mixin*/ template SimpleCompare() 49 { 49 { 50 override bool opEquals(Object rhs_) const 50 override bool opEquals(Object rhs_) const 51 { 51 { 52 if( auto rhs = cast(typeof(this))rhs_ ) 52 if( auto rhs = cast(typeof(this))rhs_ ) 53 { 53 {