Diff
Not logged in

Differences From Artifact [737774791c82ade1]:

To Artifact [01c119756ed23ca5]:


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