4198578702 2010-11-07 kinaba: /** 4198578702 2010-11-07 kinaba: * Authors: k.inaba 4198578702 2010-11-07 kinaba: * License: NYSL 0.9982 http://www.kmonos.net/nysl/ 4198578702 2010-11-07 kinaba: * 4198578702 2010-11-07 kinaba: * Runtime data structures for Polemy programming language. 423f308350 2010-11-07 kinaba: */ 4198578702 2010-11-07 kinaba: module polemy.runtime; 4198578702 2010-11-07 kinaba: import polemy._common; 423f308350 2010-11-07 kinaba: 423f308350 2010-11-07 kinaba: class PolemyRuntimeException : Exception 423f308350 2010-11-07 kinaba: { 423f308350 2010-11-07 kinaba: this(string msg) { super(msg); } 423f308350 2010-11-07 kinaba: } 423f308350 2010-11-07 kinaba: 423f308350 2010-11-07 kinaba: abstract class Value 423f308350 2010-11-07 kinaba: { 423f308350 2010-11-07 kinaba: } 423f308350 2010-11-07 kinaba: 423f308350 2010-11-07 kinaba: class IntValue : Value 423f308350 2010-11-07 kinaba: { 423f308350 2010-11-07 kinaba: BigInt data; 423f308350 2010-11-07 kinaba: mixin SimpleConstructor; 423f308350 2010-11-07 kinaba: mixin SimpleCompare; 423f308350 2010-11-07 kinaba: } 423f308350 2010-11-07 kinaba: 423f308350 2010-11-07 kinaba: class StrValue : Value 423f308350 2010-11-07 kinaba: { 423f308350 2010-11-07 kinaba: string data; 423f308350 2010-11-07 kinaba: mixin SimpleConstructor; 423f308350 2010-11-07 kinaba: mixin SimpleCompare; 423f308350 2010-11-07 kinaba: } 423f308350 2010-11-07 kinaba: 423f308350 2010-11-07 kinaba: class Context 423f308350 2010-11-07 kinaba: { 423f308350 2010-11-07 kinaba: Context parent; 423f308350 2010-11-07 kinaba: Value[string] table; 423f308350 2010-11-07 kinaba: this(Context parent = null) { this.parent = parent; } 423f308350 2010-11-07 kinaba: 423f308350 2010-11-07 kinaba: void add(string i, Value v) 423f308350 2010-11-07 kinaba: { 423f308350 2010-11-07 kinaba: table[i] = v; 423f308350 2010-11-07 kinaba: } 423f308350 2010-11-07 kinaba: 423f308350 2010-11-07 kinaba: Value opIndex(string i) 423f308350 2010-11-07 kinaba: { 423f308350 2010-11-07 kinaba: if( i in table ) 423f308350 2010-11-07 kinaba: return table[i]; 423f308350 2010-11-07 kinaba: if( parent is null ) 423f308350 2010-11-07 kinaba: throw new PolemyRuntimeException(sprintf!"variable %s not found"(i)); 423f308350 2010-11-07 kinaba: return parent[i]; 423f308350 2010-11-07 kinaba: } 423f308350 2010-11-07 kinaba: 423f308350 2010-11-07 kinaba: void opIndexAssign(Value v, string i) 423f308350 2010-11-07 kinaba: { 423f308350 2010-11-07 kinaba: if( i in table ) 423f308350 2010-11-07 kinaba: return table[i] = v; 423f308350 2010-11-07 kinaba: if( parent is null ) 423f308350 2010-11-07 kinaba: throw new PolemyRuntimeException(sprintf!"variable %s not found"(i)); 423f308350 2010-11-07 kinaba: return parent[i] = v; 423f308350 2010-11-07 kinaba: } 423f308350 2010-11-07 kinaba: }