Diff
Not logged in

Differences From Artifact [b8f99f303d4d3a98]:

To Artifact [38155bcc400d812f]:


1 -/** 1 +/** 2 2 * Authors: k.inaba 3 3 * License: NYSL 0.9982 http://www.kmonos.net/nysl/ 4 4 * 5 5 * Runtime data structures for Polemy programming language. 6 6 */ 7 7 module polemy.value; 8 8 import polemy._common; ................................................................................ 11 11 /// Raised when something went wrong in runtime 12 12 13 13 class RuntimeException : Exception 14 14 { 15 15 const LexPosition pos; 16 16 17 17 this( const LexPosition pos, string msg ) 18 - { super(sprintf!"%s [%s]"(msg, pos)); this.pos = pos; } 19 - this( string msg ) { super(msg); this.pos = null; } 18 + { super(sprintf!"%s at [%s]"(msg, pos)); this.pos = pos; } 20 19 } 21 20 22 21 /// Runtime values of Polemy 23 22 24 23 abstract class Value 25 24 { 26 25 } ................................................................................ 63 62 class Table : Value 64 63 { 65 64 enum Kind {PropagateSet, NotPropagateSet}; 66 65 67 66 this( Table proto=null, Kind k = Kind.PropagateSet ) 68 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) ) 73 - data[i][lay] = v; 71 + if( setIfExist(i, lay, v) ) 72 + return; 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 78 if( i in data ) 79 79 return data[i][lay]; 80 80 if( prototype is null ) 81 - throw new RuntimeException(sprintf!"variable %s not found"(i)); 81 + throw new RuntimeException(pos, sprintf!"variable %s not found"(i)); 82 82 return prototype.get(i, lay); 83 83 } 84 84 85 85 private: 86 86 Table prototype; 87 87 Kind kind; 88 88 Value[Layer][string] data;