occam-verify-cli 1.0.768 → 1.0.781

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. package/lib/context/file/nominal.js +11 -11
  2. package/lib/context/illative.js +28 -0
  3. package/lib/context/nested.js +31 -0
  4. package/lib/context/proof.js +242 -0
  5. package/lib/context/thetic.js +28 -0
  6. package/lib/context.js +19 -21
  7. package/lib/element/assertion/contained.js +32 -24
  8. package/lib/element/assertion/defined.js +47 -40
  9. package/lib/element/assertion/property.js +18 -13
  10. package/lib/element/assertion/satisfies.js +12 -9
  11. package/lib/element/assertion/subproof.js +28 -26
  12. package/lib/element/assertion/type.js +14 -12
  13. package/lib/element/assumption.js +40 -50
  14. package/lib/element/combinator/bracketed.js +3 -3
  15. package/lib/element/combinator.js +20 -20
  16. package/lib/element/conclusion.js +33 -29
  17. package/lib/element/constructor.js +19 -18
  18. package/lib/element/deduction.js +33 -29
  19. package/lib/element/equality.js +13 -15
  20. package/lib/element/equivalence.js +59 -52
  21. package/lib/element/equivalences.js +4 -2
  22. package/lib/element/frame.js +74 -53
  23. package/lib/element/hypothesis.js +7 -5
  24. package/lib/element/judgement.js +41 -74
  25. package/lib/element/label.js +22 -22
  26. package/lib/element/metavariable.js +31 -11
  27. package/lib/element/proofAssertion/premise.js +48 -35
  28. package/lib/element/proofAssertion/step.js +77 -22
  29. package/lib/element/proofAssertion/supposition.js +48 -34
  30. package/lib/element/proofAssertion.js +1 -14
  31. package/lib/element/reference.js +80 -53
  32. package/lib/element/signature.js +44 -3
  33. package/lib/element/statement.js +28 -29
  34. package/lib/element/subproof.js +2 -2
  35. package/lib/element/substitution/frame.js +24 -19
  36. package/lib/element/substitution/metaLevel.js +31 -27
  37. package/lib/element/substitution/reference.js +11 -10
  38. package/lib/element/substitution/statement.js +30 -23
  39. package/lib/element/substitution/term.js +11 -10
  40. package/lib/element/term.js +24 -20
  41. package/lib/element/topLevelMetaAssertion.js +2 -2
  42. package/lib/element/variable.js +6 -2
  43. package/lib/process/assign.js +10 -4
  44. package/lib/process/unify.js +8 -8
  45. package/lib/process/validate.js +10 -8
  46. package/lib/utilities/context.js +68 -23
  47. package/lib/utilities/element.js +55 -27
  48. package/lib/utilities/json.js +8 -8
  49. package/lib/utilities/string.js +12 -1
  50. package/lib/utilities/unification.js +14 -12
  51. package/lib/utilities/validation.js +55 -40
  52. package/package.json +4 -4
  53. package/src/context/file/nominal.js +14 -16
  54. package/src/context/illative.js +17 -0
  55. package/src/context/nested.js +21 -0
  56. package/src/context/{scoped.js → proof.js} +65 -51
  57. package/src/context/thetic.js +17 -0
  58. package/src/context.js +30 -36
  59. package/src/element/assertion/contained.js +44 -31
  60. package/src/element/assertion/defined.js +55 -46
  61. package/src/element/assertion/property.js +23 -15
  62. package/src/element/assertion/satisfies.js +15 -10
  63. package/src/element/assertion/subproof.js +34 -31
  64. package/src/element/assertion/type.js +18 -13
  65. package/src/element/assumption.js +40 -69
  66. package/src/element/combinator/bracketed.js +2 -2
  67. package/src/element/combinator.js +23 -29
  68. package/src/element/conclusion.js +37 -40
  69. package/src/element/constructor.js +29 -34
  70. package/src/element/deduction.js +36 -39
  71. package/src/element/equality.js +16 -18
  72. package/src/element/equivalence.js +76 -67
  73. package/src/element/equivalences.js +5 -2
  74. package/src/element/frame.js +96 -65
  75. package/src/element/hypothesis.js +7 -6
  76. package/src/element/judgement.js +45 -45
  77. package/src/element/label.js +25 -31
  78. package/src/element/metavariable.js +48 -21
  79. package/src/element/proofAssertion/premise.js +63 -49
  80. package/src/element/proofAssertion/step.js +47 -26
  81. package/src/element/proofAssertion/supposition.js +64 -50
  82. package/src/element/proofAssertion.js +0 -22
  83. package/src/element/reference.js +119 -80
  84. package/src/element/signature.js +5 -2
  85. package/src/element/statement.js +30 -35
  86. package/src/element/subproof.js +1 -1
  87. package/src/element/substitution/frame.js +27 -26
  88. package/src/element/substitution/metaLevel.js +38 -42
  89. package/src/element/substitution/reference.js +13 -14
  90. package/src/element/substitution/statement.js +35 -33
  91. package/src/element/substitution/term.js +13 -14
  92. package/src/element/term.js +42 -34
  93. package/src/element/topLevelMetaAssertion.js +1 -1
  94. package/src/element/variable.js +8 -1
  95. package/src/process/assign.js +9 -3
  96. package/src/process/unify.js +7 -7
  97. package/src/process/validate.js +9 -8
  98. package/src/utilities/context.js +82 -31
  99. package/src/utilities/element.js +68 -31
  100. package/src/utilities/json.js +13 -13
  101. package/src/utilities/string.js +16 -2
  102. package/src/utilities/unification.js +18 -16
  103. package/src/utilities/validation.js +73 -53
  104. package/lib/context/scoped.js +0 -232
  105. package/lib/utilities/statement.js +0 -78
  106. package/lib/utilities/term.js +0 -17
  107. package/src/utilities/statement.js +0 -74
  108. package/src/utilities/term.js +0 -10
@@ -2,12 +2,12 @@
2
2
 
3
3
  import { asynchronousUtilities } from "occam-languages";
4
4
 
5
+ import elements from "../../elements";
5
6
  import ProofAssertion from "../proofAssertion";
6
7
 
7
8
  import { define } from "../../elements";
8
9
  import { unifyStatements } from "../../utilities/unification";
9
- import { attempt, asyncReconcile } from "../../utilities/context";
10
- import { propertyAssertionFromStatement } from "../../utilities/statement";
10
+ import { derive, attempt, descend, asyncReconcile } from "../../utilities/context";
11
11
 
12
12
  const { asyncSome } = asynchronousUtilities;
13
13
 
@@ -46,18 +46,12 @@ export default define(class Step extends ProofAssertion {
46
46
  return qualified;
47
47
  }
48
48
 
49
- isStated() {
50
- const qualified = this.isQualified(),
51
- stated = qualified; ///
52
-
53
- return stated;
54
- }
55
-
56
49
  compareTermAndPropertyRelation(term, propertyRelation, context) {
57
50
  let comparesToTermAndPropertyRelation = false;
58
51
 
59
- const statement = this.getStatement(),
60
- propertyAssertion = propertyAssertionFromStatement(statement, context);
52
+ const { PropertyAssertion } = elements,
53
+ statement = this.getStatement(),
54
+ propertyAssertion = PropertyAssertion.fromStatement(statement, context);
61
55
 
62
56
  if (propertyAssertion !== null) {
63
57
  comparesToTermAndPropertyRelation = propertyAssertion.compareTermAndPropertyRelation(term, propertyRelation, context);
@@ -107,22 +101,24 @@ export default define(class Step extends ProofAssertion {
107
101
 
108
102
  context.trace(`Validating the '${stepString}' step...`);
109
103
 
110
- attempt((context) => {
111
- const statementValidates = this.validateStatement(context);
104
+ derive((context) => {
105
+ attempt((context) => {
106
+ const statementValidates = this.validateStatement(context);
112
107
 
113
- if (statementValidates) {
114
- const referenceValidates = this.validateReference(context);
108
+ if (statementValidates) {
109
+ const referenceValidates = this.validateReference(context);
115
110
 
116
- if (referenceValidates) {
117
- const satisfiesAssertioValidates = this.validateSatisfiesAssertion(context);
111
+ if (referenceValidates) {
112
+ const satisfiesAssertioValidates = this.validateSatisfiesAssertion(context);
118
113
 
119
- if (satisfiesAssertioValidates) {
120
- context.commit(this);
114
+ if (satisfiesAssertioValidates) {
115
+ context.commit(this);
121
116
 
122
- validates = true;
117
+ validates = true;
118
+ }
123
119
  }
124
120
  }
125
- }
121
+ }, context);
126
122
  }, context);
127
123
 
128
124
  if (validates) {
@@ -155,6 +151,30 @@ export default define(class Step extends ProofAssertion {
155
151
  return referenceValidates;
156
152
  }
157
153
 
154
+ validateStatement(context) {
155
+ let statementValidates = false;
156
+
157
+ const stepString = this.getString();
158
+
159
+ context.trace(`Validating the '${stepString}' step's statement... `);
160
+
161
+ let statement;
162
+
163
+ statement = this.getStatement();
164
+
165
+ statement = statement.validate(context); ///
166
+
167
+ if (statement !== null) {
168
+ statementValidates = true;
169
+ }
170
+
171
+ if (statementValidates) {
172
+ context.debug(`...validated the '${stepString}' step statement. `);
173
+ }
174
+
175
+ return statementValidates;
176
+ }
177
+
158
178
  validateSatisfiesAssertion(context) {
159
179
  let satisfiesAssertionValidates = true; ///
160
180
 
@@ -164,12 +184,13 @@ export default define(class Step extends ProofAssertion {
164
184
 
165
185
  context.trace(`Validating the '${stepString}' step's '${satisfiesAssertionString}' satisfies assertion... `);
166
186
 
167
- const stated = true,
168
- satisfiesAssertion = this.satisfiesAssertion.validate(stated, context);
187
+ descend((context) => {
188
+ const satisfiesAssertion = this.satisfiesAssertion.validate(context);
169
189
 
170
- if (satisfiesAssertion === null) {
171
- satisfiesAssertionValidates = false;
172
- }
190
+ if (satisfiesAssertion === null) {
191
+ satisfiesAssertionValidates = false;
192
+ }
193
+ }, context);
173
194
 
174
195
  if (satisfiesAssertionValidates) {
175
196
  context.debug(`...validating the '${stepString}' step's '${satisfiesAssertionString}' satisfies assertion. `);
@@ -5,8 +5,7 @@ import ProofAssertion from "../proofAssertion";
5
5
  import { define } from "../../elements";
6
6
  import { instantiateSupposition} from "../../process/instantiate";
7
7
  import { procedureCallFromSuppositionNode } from "../../utilities/element";
8
- import { join, attempt, reconcile, instantiate } from "../../utilities/context";
9
- import { ephemeralContextFromJSON, ephemeralContextToEphemeralContextJSON } from "../../utilities/json";
8
+ import { join, declare, attempt, reconcile, serialise, unserialise, instantiate } from "../../utilities/context";
10
9
 
11
10
  export default define(class Supposition extends ProofAssertion {
12
11
  constructor(context, string, node, statement, procedureCall) {
@@ -26,12 +25,6 @@ export default define(class Supposition extends ProofAssertion {
26
25
  return suppositionNode;
27
26
  }
28
27
 
29
- isStated() {
30
- const stated = true; ///
31
-
32
- return stated;
33
- }
34
-
35
28
  async verify(context) {
36
29
  let verifies = false;
37
30
 
@@ -64,29 +57,31 @@ export default define(class Supposition extends ProofAssertion {
64
57
 
65
58
  context.trace(`Validatting the '${suppositionString}' supposition...`);
66
59
 
67
- attempt((context) => {
68
- const statement = this.getStatement(),
69
- procedureCall = this.getProcedureCall();
70
-
71
- if (statement !== null) {
72
- const statementValidates = this.validateStatement(context);
60
+ declare((context) => {
61
+ attempt((context) => {
62
+ const statement = this.getStatement(),
63
+ procedureCall = this.getProcedureCall();
73
64
 
74
- if (statementValidates) {
75
- context.commit(this);
65
+ if (statement !== null) {
66
+ const statementValidates = this.validateStatement(context);
76
67
 
77
- validates = true;
68
+ if (statementValidates) {
69
+ validates = true;
70
+ }
78
71
  }
79
- }
80
72
 
81
- if (procedureCall !== null) {
82
- const procedureCallValidates = this.validateProcedureCall(context);
73
+ if (procedureCall !== null) {
74
+ const procedureCallValidates = this.validateProcedureCall(context);
83
75
 
84
- if (procedureCallValidates) {
85
- context.commit(this);
76
+ if (procedureCallValidates) {
77
+ validates = true;
78
+ }
79
+ }
86
80
 
87
- validates = true;
81
+ if (validates) {
82
+ context.commit(this);
88
83
  }
89
- }
84
+ }, context);
90
85
  }, context);
91
86
 
92
87
  if (validates) {
@@ -96,6 +91,30 @@ export default define(class Supposition extends ProofAssertion {
96
91
  return validates;
97
92
  }
98
93
 
94
+ validateStatement(context) {
95
+ let statementValidates = false;
96
+
97
+ const suppositionString = this.getString();
98
+
99
+ context.trace(`Validating the '${suppositionString}' supposition's statement... `);
100
+
101
+ let statement;
102
+
103
+ statement = this.getStatement();
104
+
105
+ statement = statement.validate(context); ///
106
+
107
+ if (statement !== null) {
108
+ statementValidates = true;
109
+ }
110
+
111
+ if (statementValidates) {
112
+ context.debug(`...validated the '${suppositionString}' supposition statement. `);
113
+ }
114
+
115
+ return statementValidates;
116
+ }
117
+
99
118
  validateProcedureCall(context) {
100
119
  let procedureCallValidates = false;
101
120
 
@@ -288,42 +307,37 @@ export default define(class Supposition extends ProofAssertion {
288
307
  }
289
308
 
290
309
  toJSON() {
291
- let context;
292
-
293
- context = this.getContext();
294
-
295
- const ephemeralContext = context, ///
296
- ephemeralContextJSON = ephemeralContextToEphemeralContextJSON(ephemeralContext),
297
- contextJSON = ephemeralContextJSON; ///
310
+ const context = this.getContext();
298
311
 
299
- context = contextJSON; ///
312
+ return serialise((context) => {
313
+ const string = this.getString(),
314
+ json = {
315
+ context,
316
+ string
317
+ };
300
318
 
301
- const string = this.getString(),
302
- json = {
303
- context,
304
- string
305
- };
306
-
307
- return json;
319
+ return json;
320
+ }, context);
308
321
  }
309
322
 
310
323
  static name = "Supposition";
311
324
 
312
325
  static fromJSON(json, context) {
313
- const ephemeralContext = ephemeralContextFromJSON(json, context);
326
+ let supposition;
314
327
 
315
- context = ephemeralContext; ///
328
+ unserialise((json, context) => {
329
+ instantiate((context) => {
330
+ const { string } = json,
331
+ suppositionNode = instantiateSupposition(string, context),
332
+ node = suppositionNode, ///
333
+ statement = statementFromSuppositionNode(suppositionNode, context),
334
+ procedureCall = procedureCallFromSuppositionNode(suppositionNode, context);
316
335
 
317
- return instantiate((context) => {
318
- const { string } = json,
319
- suppositionNode = instantiateSupposition(string, context),
320
- node = suppositionNode, ///
321
- statement = statementFromSuppositionNode(suppositionNode, context),
322
- procedureCall = procedureCallFromSuppositionNode(suppositionNode, context),
323
- supposition = new Supposition(context, string, node, statement, procedureCall);
336
+ supposition = new Supposition(context, string, node, statement, procedureCall);
337
+ }, context);
338
+ }, json, context);
324
339
 
325
- return supposition;
326
- }, context);
340
+ return supposition;
327
341
  }
328
342
  });
329
343
 
@@ -51,28 +51,6 @@ export default class ProofAssertion extends Element {
51
51
  return comparesToStatement;
52
52
  }
53
53
 
54
- validateStatement(context) {
55
- let statementValidates = false;
56
-
57
- const statementString = this.statement.getString(),
58
- proofAssertionString = this.getString(); ///
59
-
60
- context.trace(`Validating the '${proofAssertionString}' proof assertion's '${statementString}' statement... `);
61
-
62
- const stated = this.isStated(),
63
- statement = this.statement.validate(stated, context);
64
-
65
- if (statement !== null) {
66
- statementValidates = true;
67
- }
68
-
69
- if (statementValidates) {
70
- context.debug(`...validated the '${proofAssertionString}' proof assertion's '${statementString}' statement. `);
71
- }
72
-
73
- return statementValidates;
74
- }
75
-
76
54
  unifyStatement(statement, generalContext, specificContext) {
77
55
  let statementUnifies = false;
78
56
 
@@ -3,23 +3,27 @@
3
3
  import { Element } from "occam-languages";
4
4
 
5
5
  import { define } from "../elements";
6
- import { instantiate } from "../utilities/context";
7
6
  import { instantiateReference } from "../process/instantiate";
8
7
  import { REFERENCE_META_TYPE_NAME } from "../metaTypeNames";
9
- import { metavariableFromReferenceNode } from "../utilities/element";
10
- import { unifyMetavariableIntrinsically } from "../process/unify";
8
+ import { serialise, reconcile, unserialise, instantiate } from "../utilities/context";
9
+ import { metavariableFromReferenceNode, topLevelMetaAssertionFromReferenceNode } from "../utilities/element";
11
10
 
12
11
  export default define(class Reference extends Element {
13
- constructor(context, string, node, metavariable) {
12
+ constructor(context, string, node, metavariable, topLevelMetaAssertion) {
14
13
  super(context, string, node);
15
14
 
16
15
  this.metavariable = metavariable;
16
+ this.topLevelMetaAssertion = topLevelMetaAssertion;
17
17
  }
18
18
 
19
19
  getMetavariable() {
20
20
  return this.metavariable;
21
21
  }
22
22
 
23
+ getTopLevelMetaAssertion() {
24
+ return this.topLevelMetaAssertion;
25
+ }
26
+
23
27
  getReferenceNode() {
24
28
  const node = this.getNode(),
25
29
  referenceNode = node; ///
@@ -27,8 +31,6 @@ export default define(class Reference extends Element {
27
31
  return referenceNode;
28
32
  }
29
33
 
30
- getName() { return this.metavariable.getName(); }
31
-
32
34
  getMetavariableName() {
33
35
  const metavariableName = this.metavariable.getName();
34
36
 
@@ -41,6 +43,14 @@ export default define(class Reference extends Element {
41
43
  return metavariableNode;
42
44
  }
43
45
 
46
+ isEqualTo(reference) {
47
+ const referenceNode = reference.getNode(),
48
+ referenceNodeMatches = this.matchReferenceNode(referenceNode),
49
+ equalTo = referenceNodeMatches; ///
50
+
51
+ return equalTo;
52
+ }
53
+
44
54
  matchReferenceNode(referenceNode) {
45
55
  const node = referenceNode, ///
46
56
  nodeMatches = this.matchNode(node),
@@ -49,21 +59,7 @@ export default define(class Reference extends Element {
49
59
  return referenceNodeMatches;
50
60
  }
51
61
 
52
- findValidRefernece(context) {
53
- const metavariableNode = this.getMetavariableNode(),
54
- reference = context.findReferenceByMetavariableNode(metavariableNode),
55
- validReference = reference; ///
56
-
57
- return validReference;
58
- }
59
-
60
- isEqualTo(reference) {
61
- const referenceNode = reference.getNode(),
62
- referenceNodeMatches = this.matchReferenceNode(referenceNode),
63
- equalTo = referenceNodeMatches; ///
64
-
65
- return equalTo;
66
- }
62
+ matchMetavariableNode(metavariableNode) { return this.metavariable.matchMetavariableNode(metavariableNode); }
67
63
 
68
64
  compareParameter(parameter) {
69
65
  let comparesToParamter = false;
@@ -103,7 +99,36 @@ export default define(class Reference extends Element {
103
99
 
104
100
  compareMetavariableName(metavariableName) { return this.metavariable.compareMetavariableName(metavariableName); }
105
101
 
106
- matchMetavariableNode(metavariableNode) { return this.metavariable.matchMetavariableNode(metavariableNode); }
102
+ compareTopLevelMetaAssertion(topLevelMetaAssertion) {
103
+ let topLevelMetaAssertionCompares = false;
104
+
105
+ const context = this.getContext(),
106
+ referenceString = this.getString(), ///
107
+ topLevelMetaAssertionString = topLevelMetaAssertion.getString();
108
+
109
+ context.trace(`Comparing the '${topLevelMetaAssertionString}' top level meta-assertion to the '${referenceString}' reference...`);
110
+
111
+ const label = topLevelMetaAssertion.getLabel(),
112
+ labelUnifies = this.unifyLabel(label);
113
+
114
+ if (labelUnifies) {
115
+ topLevelMetaAssertionCompares = true;
116
+ }
117
+
118
+ if (topLevelMetaAssertionCompares) {
119
+ context.trace(`...compared the '${topLevelMetaAssertionString}' top level meta-assertion to the '${referenceString}' reference.`);
120
+ }
121
+
122
+ return topLevelMetaAssertionCompares;
123
+ }
124
+
125
+ findValidRefernece(context) {
126
+ const metavariableNode = this.getMetavariableNode(),
127
+ reference = context.findReferenceByMetavariableNode(metavariableNode),
128
+ validReference = reference; ///
129
+
130
+ return validReference;
131
+ }
107
132
 
108
133
  validate(context) {
109
134
  let reference = null;
@@ -112,10 +137,10 @@ export default define(class Reference extends Element {
112
137
 
113
138
  context.trace(`Validating the '${referenceString}' reference...`);
114
139
 
115
- const validRefernece = this.findValidRefernece(context);
140
+ const validReference = this.findValidRefernece(context);
116
141
 
117
- if (validRefernece !== null) {
118
- reference = validRefernece; ///
142
+ if (validReference !== null) {
143
+ reference = validReference; ///
119
144
 
120
145
  context.debug(`...the '${referenceString}' reference is already valid.`);
121
146
  } else {
@@ -130,7 +155,7 @@ export default define(class Reference extends Element {
130
155
 
131
156
  if (metaType === null) {
132
157
  const reference = this, ///
133
- labelPresent = context.isLabelPresentByReference(reference, context);
158
+ labelPresent = context.isLabelPresentByReference(reference);
134
159
 
135
160
  if (labelPresent) {
136
161
  validates = true;
@@ -170,6 +195,8 @@ export default define(class Reference extends Element {
170
195
  const referenceString = this.getString(), ///
171
196
  metavariableString = this.metavariable.getString();
172
197
 
198
+ context = this.getContext();
199
+
173
200
  context.trace(`Validating the '${referenceString}' reference's '${metavariableString}' metavariable...'`);
174
201
 
175
202
  const metavariable = this.metavariable.validate(context);
@@ -187,29 +214,23 @@ export default define(class Reference extends Element {
187
214
  return metavariableValidates;
188
215
  }
189
216
 
190
- unifyLabel(label, context) {
191
- let labelUnifies;
192
-
193
- const specificContext = context; ///
194
-
195
- context = this.getContext();
196
-
197
- const generalContext = context; ///
217
+ unifyLabel(label) {
218
+ let labelUnifies = false;
198
219
 
199
- context = specificContext; ///
200
-
201
- const reference = this, ///
220
+ const context = label.getContext(),
202
221
  labelString = label.getString(),
203
- referenceString = reference.getString();
222
+ referenceString = this.getString(); ///
204
223
 
205
224
  context.trace(`Unifying the '${labelString}' label with the '${referenceString}' reference...`);
206
225
 
207
- const labelMetavariable = label.getMetavariable(),
208
- generalMetavariable = this.metavariable, ///
209
- specificMetavariable = labelMetavariable, ///
210
- metavariableUnifiesIntrinsically = unifyMetavariableIntrinsically(generalMetavariable, specificMetavariable, generalContext, specificContext);
226
+ reconcile((context) => {
227
+ const metavariable = label.getMetavariable(),
228
+ metavariableUnifies = this.unifyMetavariable(metavariable, context);
211
229
 
212
- labelUnifies = metavariableUnifiesIntrinsically; ///
230
+ if (metavariableUnifies) {
231
+ labelUnifies = true;
232
+ }
233
+ }, context);
213
234
 
214
235
  if (labelUnifies) {
215
236
  context.debug(`...unified the '${labelString}' label with the '${referenceString}' reference.`);
@@ -221,22 +242,20 @@ export default define(class Reference extends Element {
221
242
  unifyMetavariable(metavariable, context) {
222
243
  let metavariableUnifies = false;
223
244
 
224
- const specificContext = context; ///
245
+ const referenceString = this.getString(), ///
246
+ metavariableString = metavariable.getString();
225
247
 
226
- context = this.getContext();
248
+ context.trace(`Unifying the '${metavariableString}' metavariable with the '${referenceString}' reference...`);
227
249
 
228
- const generalContext = context; ///
250
+ const specificContext = context; ///
229
251
 
230
- context = specificContext; ///
252
+ context = this.getContext();
231
253
 
232
- const referenceString = this.getString(), ///
233
- metavariableString = metavariable.getString();
254
+ const generalContext = context; ///
234
255
 
235
- context.trace(`Unifying the '${metavariableString}' metavariable with the '${referenceString}' reference...`);
256
+ context = specificContext; ///
236
257
 
237
- const generalMetavariable = this.metavariable, ///
238
- specificMetavariable = metavariable, ///
239
- metavariableUnifiesIntrinsically = unifyMetavariableIntrinsically(generalMetavariable, specificMetavariable, generalContext, specificContext);
258
+ const metavariableUnifiesIntrinsically = this.metavariable.unifyMetavariableIntrinsically(metavariable, generalContext, specificContext);
240
259
 
241
260
  if (metavariableUnifiesIntrinsically) {
242
261
  metavariableUnifies = true;
@@ -249,52 +268,72 @@ export default define(class Reference extends Element {
249
268
  return metavariableUnifies;
250
269
  }
251
270
 
252
- compareTopLevelMetaAssertion(topLevelMetaAssertion, context) {
253
- let topLevelMetaAssertionCompares = false;
271
+ unifyTopLevelMetaAssertion(topLevelMetaAssertion, context) {
272
+ let topLevelMetaAssertionUUnifies = false;
254
273
 
255
- const reference = this, ///
256
- referenceString = reference.getString(),
274
+ const label = topLevelMetaAssertion.getLabel(),
275
+ referenceString = this.getString(), ///
257
276
  topLevelMetaAssertionString = topLevelMetaAssertion.getString();
258
277
 
259
- context.trace(`Comparing the '${topLevelMetaAssertionString}' top level meta-assertion to the '${referenceString}' reference...`);
278
+ context.trace(`Unifying the '${topLevelMetaAssertionString}' top level meta-assertion with the '${referenceString}' reference...`);
260
279
 
261
- const label = topLevelMetaAssertion.getLabel(),
262
- labelUnifies = this.unifyLabel(label, context);
280
+ const specificContext = context; ///
263
281
 
264
- if (labelUnifies) {
265
- topLevelMetaAssertionCompares = true;
266
- }
282
+ context = label.getContext();
267
283
 
268
- if (topLevelMetaAssertionCompares) {
269
- context.trace(`...compared the '${topLevelMetaAssertionString}' top level meta-assertion to the '${referenceString}' reference.`);
284
+ reconcile((context) => {
285
+ const metavariable = label.getMetavariable(),
286
+ metavariableUnifies = this.unifyMetavariable(metavariable, context);
287
+
288
+ if (metavariableUnifies) {
289
+ this.topLevelMetaAssertion = topLevelMetaAssertion;
290
+
291
+ context.commit(specificContext);
292
+
293
+ topLevelMetaAssertionUUnifies = true;
294
+ }
295
+ }, context);
296
+
297
+ context = specificContext; ///
298
+
299
+ if (topLevelMetaAssertionUUnifies) {
300
+ context.debug(`...unified the '${topLevelMetaAssertionString}' top level meta-assertion with the '${referenceString}' reference.`);
270
301
  }
271
302
 
272
- return topLevelMetaAssertionCompares;
303
+ return topLevelMetaAssertionUUnifies;
273
304
  }
274
305
 
275
306
  toJSON() {
276
- const string = this.getString(),
277
- json = {
278
- string
279
- };
307
+ const context = this.getContext();
308
+
309
+ return serialise((context) => {
310
+ const string = this.getString(),
311
+ json = {
312
+ context,
313
+ string
314
+ };
280
315
 
281
- return json;
316
+ return json;
317
+ }, context);
282
318
  }
283
319
 
284
320
  static name = "Reference";
285
321
 
286
322
  static fromJSON(json, context) {
287
- return instantiate((context) => {
288
- const { string } = json,
289
- referenceNode = instantiateReference(string, context),
290
- node = referenceNode, ///
291
- metavariable = metavariableFromReferenceNode(referenceNode, context);
323
+ let reference;
292
324
 
293
- context = null;
325
+ unserialise((json, context) => {
326
+ instantiate((context) => {
327
+ const { string } = json,
328
+ referenceNode = instantiateReference(string, context),
329
+ node = referenceNode, ///
330
+ metavariable = metavariableFromReferenceNode(referenceNode, context),
331
+ topLevelMetaAssertion = topLevelMetaAssertionFromReferenceNode(referenceNode, context);
294
332
 
295
- const reference = new Reference(context, string, node, metavariable);
333
+ reference = new Reference(context, string, node, metavariable, topLevelMetaAssertion);
334
+ }, context);
335
+ }, json, context);
296
336
 
297
- return reference;
298
- }, context);
337
+ return reference;
299
338
  }
300
339
  });
@@ -3,6 +3,8 @@
3
3
  import { Element } from "occam-languages";
4
4
  import { arrayUtilities } from "necessary";
5
5
 
6
+ import elements from "../elements";
7
+
6
8
  import { define } from "../elements";
7
9
  import { instantiate } from "../utilities/context";
8
10
  import { instantiateSignature } from "../process/instantiate";
@@ -125,9 +127,10 @@ export default define(class Signature extends Element {
125
127
  termsA = this.terms, ///
126
128
  termsB = terms, ///
127
129
  matches = match(termsA, termsB, (termA, termB) => {
128
- const term = termB, ///
130
+ const { Variable } = elements,
131
+ term = termB, ///
129
132
  context = generalContext, ///
130
- variable = variableFromTerm(term, context);
133
+ variable = Variable.fromTerm(term, context);
131
134
 
132
135
  if (variable !== null) {
133
136
  const term = termA, ///