Check-in [820e7198cc]
Not logged in
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
Changes

Modified main.d from [521e3de53633ae4a] to [5cef40bce7835081].

2 2 * Authors: k.inaba 3 3 * License: NYSL 0.9982 (http://www.kmonos.net/nysl/ 4 4 * 5 5 * Entry point for Polemy interpreter. 6 6 */ 7 7 8 8 import std.stdio; 9 -import polemy.lex; 10 -import polemy.parse; 9 +import polemy.eval; 11 10 12 -static ~this() { readln(); } // workaround for enabling "pause" under Poseidon 11 +version(unittest) 12 + static ~this() { readln(); } // workaround for enabling "pause" under Poseidon 13 13 14 14 void main() 15 15 { 16 16 writeln( "test ok" ); 17 17 }

Modified polemy/ast.d from [a264a204623245e6] to [6aa982b32b1d6e05].

1 -/* 1 +/** 2 2 * Authors: k.inaba 3 3 * License: NYSL 0.9982 http://www.kmonos.net/nysl/ 4 4 * 5 5 * Syntax tree for Polemy programming language. 6 6 */ 7 7 module polemy.ast; 8 8 import polemy._common;

Modified polemy/eval.d from [cea762cacb86424f] to [f2bd29fa05629861].

7 7 module polemy.eval; 8 8 import polemy._common; 9 9 import polemy.lex : LexPosition; 10 10 import polemy.ast; 11 11 import polemy.parse; 12 12 import polemy.runtime; 13 13 import std.typecons; 14 +import std.stdio; 14 15 15 16 Context createGlobalContext() 16 17 { 17 18 auto ctx = new Context; 18 19 ctx.add("+", new FunValue(delegate Value(immutable LexPosition pos, Value[] args){ 19 20 if( args.length != 2 ) 20 21 throw new PolemyRuntimeException("+ takes two arguments!! ["~to!string(pos)~"]"); ................................................................................ 42 43 ctx.add("/", new FunValue(delegate Value(immutable LexPosition pos, Value[] args){ 43 44 if( args.length != 2 ) 44 45 throw new PolemyRuntimeException("/ takes two arguments!! ["~to!string(pos)~"]"); 45 46 if( auto x = cast(IntValue)args[0] ) 46 47 if( auto y = cast(IntValue)args[1] ) 47 48 return new IntValue(x.data/y.data); 48 49 throw new PolemyRuntimeException("cannot add non-integers ["~to!string(pos)~"]"); 50 + })); 51 + ctx.add("print", new FunValue(delegate Value(immutable LexPosition pos, Value[] args){ 52 + foreach(a; args) 53 + write(a); 54 + writeln(""); 55 + return new UndefinedValue; 49 56 })); 50 57 return ctx; 51 58 } 52 59 53 60 Tuple!(Value,"val",Context,"ctx") evalString(T...)(T params) 54 61 { 55 62 return eval( parserFromString(params).parseProgram() ); ................................................................................ 167 174 } 168 175 unittest 169 176 { 170 177 auto r = evalString(`var x = 1; var f = fun(){x=x+1;}; f(); f(); f();`); 171 178 assert( r.ctx["x"] == new IntValue(BigInt(4)) ); 172 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 44 assert( !__traits(compiles, p.column =222) ); 45 45 } 46 46 47 47 /// Represents a lexer token 48 48 49 49 class Token 50 50 { 51 - enum Kind {identifier, stringLiteral, number}; 51 + /// currently we have three kinds of token 52 + enum Kind { 53 + identifier, /// anything other than others 54 + stringLiteral, /// "string literal" 55 + number /// 42 56 + }; 52 57 immutable LexPosition pos; /// position where the token occurred in the source 53 58 immutable string str; /// the token string itself 54 59 immutable Kind kind; /// which kind of token? 55 60 56 61 mixin SimpleConstructor; 57 62 mixin SimpleCompare; 58 63 }

Modified polemy/parse.d from [1d6de9cb69bbf7d4] to [fe0b0bcfc1d8a230].

1 -/* 1 +/** 2 2 * Authors: k.inaba 3 3 * License: NYSL 0.9982 http://www.kmonos.net/nysl/ 4 4 * 5 5 * Parser for Polemy programming language 6 6 */ 7 7 module polemy.parse; 8 8 import polemy._common;

Modified polemy/runtime.d from [eb7f695558db6c0f] to [2eb228662dba6e2d].

18 18 { 19 19 } 20 20 21 21 class UndefinedValue : Value 22 22 { 23 23 mixin SimpleConstructor; 24 24 mixin SimpleCompare; 25 + override string toString() const { return "(undefined)"; } 25 26 } 26 27 27 28 class IntValue : Value 28 29 { 29 30 BigInt data; 30 31 mixin SimpleConstructor; 31 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 39 class StrValue : Value 35 40 { 36 41 string data; 37 42 mixin SimpleConstructor; 38 43 mixin SimpleCompare; 44 + override string toString() const { return data; } 39 45 } 40 46 41 47 class FunValue : Value 42 48 { 43 49 Value delegate(immutable LexPosition pos, Value[]) data; 44 50 mixin SimpleConstructor; 45 51 Value call(immutable LexPosition pos, Value[] args) { return data(pos,args); } 52 + override string toString() const { return sprintf!"(function:%s:%s)"(data.ptr,data.funcptr); } 46 53 } 47 54 import std.stdio; 48 55 class Context 49 56 { 50 57 Context parent; 51 58 Value[string] table; 52 59 this(Context parent = null) { this.parent = parent; }

Modified polemy/tricks.d from [16f826d18ff480be] to [b521ec130c690547].

39 39 { 40 40 super(ps); 41 41 static if(this.tupleof.length>0) 42 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 48 /*mixin*/ template SimpleCompare() 49 49 { 50 50 override bool opEquals(Object rhs_) const 51 51 { 52 52 if( auto rhs = cast(typeof(this))rhs_ ) 53 53 {