Diff
Not logged in

Differences From Artifact [737774791c82ade1]:

To Artifact [01c119756ed23ca5]:


8 8 import polemy._common; 9 9 import polemy.lex; 10 10 11 11 /// Raised when something went wrong in runtime 12 12 13 13 class RuntimeException : Exception 14 14 { 15 - const LexPosition pos; 16 - 17 - this( const LexPosition pos, string msg, string file=null, size_t line=0, Throwable next=null ) 18 - { super(sprintf!"[%s] %s"(pos, msg), file, line, next); this.pos = pos; } 15 + mixin ExceptionWithPosition; 19 16 } 20 17 21 18 /// Runtime values of Polemy 22 19 23 20 abstract class Value 24 21 { 25 22 } 26 23 27 24 class IntValue : Value 28 25 { 29 26 BigInt data; 30 27 31 - mixin SimpleConstructor; 32 - mixin SimpleCompare; 28 + mixin SimpleClass; 33 29 override string toString() const { return std.bigint.toDecimalString(cast(BigInt)data); } 34 30 } 35 31 36 32 class StrValue : Value 37 33 { 38 34 string data; 39 35 40 - mixin SimpleConstructor; 41 - mixin SimpleCompare; 36 + mixin SimpleClass; 42 37 override string toString() const { return data; } 43 38 } 44 39 45 40 class FunValue : Value 46 41 { 47 - Value delegate(immutable LexPosition pos, Value[]) data; 42 + Value delegate(immutable LexPosition pos, string lay, Value[]) data; 48 43 49 44 mixin SimpleConstructor; 50 45 alias data call; 51 46 override string toString() const { return sprintf!"(function:%s:%s)"(data.ptr,data.funcptr); } 52 47 } 53 48 54 49 /// Layer ID ................................................................................ 103 98 unittest 104 99 { 105 100 Table c0 = new Table; 106 101 Table c01 = new Table(c0, Table.Kind.NotPropagateSet); 107 102 Table c012 = new Table(c01, Table.Kind.PropagateSet); 108 103 Table c013 = new Table(c01, Table.Kind.PropagateSet); 109 104 110 - assert_nothrow( c012.set("x", "@val", new IntValue(BigInt(12))) ); 111 - assert_throw!RuntimeException( c013.get("x", "@val") ); 112 - assert_nothrow( c013.set("x", "@val", new IntValue(BigInt(13))) ); 113 - assert_eq( c013.get("x", "@val"), new IntValue(BigInt(13)) ); 114 - assert_eq( c012.get("x", "@val"), new IntValue(BigInt(12)) ); 115 - assert_throw!RuntimeException( c01.get("x", "@val") ); 105 + assert_nothrow( c012.set("x", "@v", new IntValue(BigInt(12))) ); 106 + assert_throw!RuntimeException( c013.get("x", "@v") ); 107 + assert_nothrow( c013.set("x", "@v", new IntValue(BigInt(13))) ); 108 + assert_eq( c013.get("x", "@v"), new IntValue(BigInt(13)) ); 109 + assert_eq( c012.get("x", "@v"), new IntValue(BigInt(12)) ); 110 + assert_throw!RuntimeException( c01.get("x", "@v") ); 111 + 112 + assert_nothrow( c01.set("y", "@v", new IntValue(BigInt(1))) ); 113 + assert_eq( c013.get("y", "@v"), new IntValue(BigInt(1)) ); 114 + assert_eq( c012.get("y", "@v"), new IntValue(BigInt(1)) ); 115 + assert_eq( c01.get("y", "@v"), new IntValue(BigInt(1)) ); 116 116 117 - assert_nothrow( c01.set("y", "@val", new IntValue(BigInt(1))) ); 118 - assert_eq( c013.get("y", "@val"), new IntValue(BigInt(1)) ); 119 - assert_eq( c012.get("y", "@val"), new IntValue(BigInt(1)) ); 120 - assert_eq( c01.get("y", "@val"), new IntValue(BigInt(1)) ); 117 + assert_nothrow( c0.set("z", "@v", new IntValue(BigInt(0))) ); 118 + assert_eq( c013.get("z", "@v"), new IntValue(BigInt(0)) ); 119 + assert_eq( c012.get("z", "@v"), new IntValue(BigInt(0)) ); 120 + assert_eq( c01.get("z", "@v"), new IntValue(BigInt(0)) ); 121 + assert_eq( c0.get("z", "@v"), new IntValue(BigInt(0)) ); 121 122 122 - assert_nothrow( c0.set("z", "@val", new IntValue(BigInt(0))) ); 123 - assert_eq( c013.get("z", "@val"), new IntValue(BigInt(0)) ); 124 - assert_eq( c012.get("z", "@val"), new IntValue(BigInt(0)) ); 125 - assert_eq( c01.get("z", "@val"), new IntValue(BigInt(0)) ); 126 - assert_eq( c0.get("z", "@val"), new IntValue(BigInt(0)) ); 123 + assert_nothrow( c012.set("y", "@v", new IntValue(BigInt(444))) ); 124 + assert_eq( c013.get("y", "@v"), new IntValue(BigInt(444)) ); 125 + assert_eq( c012.get("y", "@v"), new IntValue(BigInt(444)) ); 126 + assert_eq( c01.get("y", "@v"), new IntValue(BigInt(444)) ); 127 127 128 - assert_nothrow( c012.set("y", "@val", new IntValue(BigInt(444))) ); 129 - assert_eq( c013.get("y", "@val"), new IntValue(BigInt(444)) ); 130 - assert_eq( c012.get("y", "@val"), new IntValue(BigInt(444)) ); 131 - assert_eq( c01.get("y", "@val"), new IntValue(BigInt(444)) ); 132 - 133 - assert_nothrow( c012.set("z", "@val", new IntValue(BigInt(555))) ); 134 - assert_eq( c013.get("z", "@val"), new IntValue(BigInt(0)) ); 135 - assert_eq( c012.get("z", "@val"), new IntValue(BigInt(555)) ); 136 - assert_eq( c01.get("z", "@val"), new IntValue(BigInt(0)) ); 137 - assert_eq( c0.get("z", "@val"), new IntValue(BigInt(0)) ); 128 + assert_nothrow( c012.set("z", "@v", new IntValue(BigInt(555))) ); 129 + assert_eq( c013.get("z", "@v"), new IntValue(BigInt(0)) ); 130 + assert_eq( c012.get("z", "@v"), new IntValue(BigInt(555)) ); 131 + assert_eq( c01.get("z", "@v"), new IntValue(BigInt(0)) ); 132 + assert_eq( c0.get("z", "@v"), new IntValue(BigInt(0)) ); 138 133 139 134 // [TODO] define the semantics and test @layers 140 135 }