Diff
Not logged in

Differences From Artifact [b8f99f303d4d3a98]:

To Artifact [38155bcc400d812f]:


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 * 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; ................................................................................................................................................................................ 11 /// Raised when something went wrong in runtime 11 /// Raised when something went wrong in runtime 12 12 13 class RuntimeException : Exception 13 class RuntimeException : Exception 14 { 14 { 15 const LexPosition pos; 15 const LexPosition pos; 16 16 17 this( const LexPosition pos, string msg ) 17 this( const LexPosition pos, string msg ) 18 { super(sprintf!"%s [%s]"(msg, pos)); this.pos = pos; } | 18 { super(sprintf!"%s at [%s]"(msg, pos)); this.pos = pos; } 19 this( string msg ) { super(msg); this.pos = null; } < 20 } 19 } 21 20 22 /// Runtime values of Polemy 21 /// Runtime values of Polemy 23 22 24 abstract class Value 23 abstract class Value 25 { 24 { 26 } 25 } ................................................................................................................................................................................ 63 class Table : Value 62 class Table : Value 64 { 63 { 65 enum Kind {PropagateSet, NotPropagateSet}; 64 enum Kind {PropagateSet, NotPropagateSet}; 66 65 67 this( Table proto=null, Kind k = Kind.PropagateSet ) 66 this( Table proto=null, Kind k = Kind.PropagateSet ) 68 { this.prototype = proto; this.kind = k; } 67 { this.prototype = proto; this.kind = k; } 69 68 70 void set(string i, Layer lay, Value v) | 69 void set(string i, Layer lay, Value v, in LexPosition pos=null) 71 { 70 { 72 if( !setIfExist(i, lay, v) ) | 71 if( setIfExist(i, lay, v) ) > 72 return; 73 data[i][lay] = v; | 73 data[i][lay] = v; 74 } 74 } 75 75 76 Value get(string i, Layer lay) | 76 Value get(string i, Layer lay, in LexPosition pos=null) 77 { 77 { 78 if( i in data ) 78 if( i in data ) 79 return data[i][lay]; 79 return data[i][lay]; 80 if( prototype is null ) 80 if( prototype is null ) 81 throw new RuntimeException(sprintf!"variable %s not foun | 81 throw new RuntimeException(pos, sprintf!"variable %s not 82 return prototype.get(i, lay); 82 return prototype.get(i, lay); 83 } 83 } 84 84 85 private: 85 private: 86 Table prototype; 86 Table prototype; 87 Kind kind; 87 Kind kind; 88 Value[Layer][string] data; 88 Value[Layer][string] data;