Navigation Menu

Skip to content

Commit

Permalink
v0.1.9
Browse files Browse the repository at this point in the history
* Fixed issues where notNode was not retracting all contexts when a fact was retracted
* Fixed issue #50 in compiling rule with or condition
* Fixed issue #53 in constraints with hash refrences.
* Merged pull request #49
* Added tests for logicalNot and truthy statements
  • Loading branch information
doug-martin committed Aug 22, 2013
1 parent 9ffebc3 commit c8d46f4
Show file tree
Hide file tree
Showing 20 changed files with 596 additions and 409 deletions.
8 changes: 8 additions & 0 deletions docs/History.html
Expand Up @@ -178,6 +178,14 @@






<h1>0.1.9</h1>
<ul>
<li>Fixed issues where notNode was not retracting all contexts when a fact was retracted</li>
<li>Fixed issue <a href="https://github.com/C2FO/nools/issues/50">50</a> in compiling rule with or condition</li>
<li>Fixed issue <a href="https://github.com/C2FO/nools/issues/53">53</a> in constraints with hash refrences.</li>
<li>Merged pull request <a href="https://github.com/C2FO/nools/pull/49">49</a></li>
<li>Added tests for logicalNot and truthy statements</li>
</ul>
<h1>0.1.8 / 2013-08-14</h1> <h1>0.1.8 / 2013-08-14</h1>
<ul> <ul>
<li>Fixed scoping issue where scoped variables defined in compile were not available to defined classes or functions.</li> <li>Fixed scoping issue where scoped variables defined in compile were not available to defined classes or functions.</li>
Expand Down
10 changes: 5 additions & 5 deletions docs/nools.js

Large diffs are not rendered by default.

34 changes: 21 additions & 13 deletions history.md
@@ -1,19 +1,27 @@
#0.1.8 / 2013-08-14 # 0.1.9

* Fixed issues where notNode was not retracting all contexts when a fact was retracted
* Fixed issue [50](https://github.com/C2FO/nools/issues/50) in compiling rule with or condition
* Fixed issue [53](https://github.com/C2FO/nools/issues/53) in constraints with hash refrences.
* Merged pull request [49](https://github.com/C2FO/nools/pull/49)
* Added tests for logicalNot and truthy statements

# 0.1.8 / 2013-08-14


* Fixed scoping issue where scoped variables defined in compile were not available to defined classes or functions. * Fixed scoping issue where scoped variables defined in compile were not available to defined classes or functions.


#0.1.7 / 2013-06-25 # 0.1.7 / 2013-06-25


* Fixed constraint parser to not evaluate functions that have the same name as operators as operators. * Fixed constraint parser to not evaluate functions that have the same name as operators as operators.
* Fixed the `getMatcher` to properly return an equality expression for constraints that do not have an explicit equality * Fixed the `getMatcher` to properly return an equality expression for constraints that do not have an explicit equality
* Added new diganosis example * Added new diganosis example
* Changed Fibonacci example to support larger number * Changed Fibonacci example to support larger number


#v0.1.6 / 2012-06-17 # v0.1.6 / 2012-06-17


* Fixed issue with the use of next in async actions * Fixed issue with the use of next in async actions


#v0.1.5 / 2013-06-17 # v0.1.5 / 2013-06-17


* More Examples * More Examples
* Changed nools compile to transpile to Javascript! * Changed nools compile to transpile to Javascript!
Expand All @@ -22,7 +30,7 @@
* Manners Benchmark (32): Before ~10s, Now ~4sec * Manners Benchmark (32): Before ~10s, Now ~4sec
* WaltzDB: Before ~30sec, Now ~15sec * WaltzDB: Before ~30sec, Now ~15sec


#v0.1.4 / 2013-05-25 # v0.1.4 / 2013-05-25


* Added new agenda-group (#29) * Added new agenda-group (#29)
* More documentation * More documentation
Expand All @@ -32,15 +40,15 @@
* Scope * Scope
* Cleaned up agenda and made more modular * Cleaned up agenda and made more modular


#v0.1.3 / 2013-05-24 # v0.1.3 / 2013-05-24


* Fixed memory leak with FactHashes for the agendas * Fixed memory leak with FactHashes for the agendas


#v0.1.2 / 2013-05-24 # v0.1.2 / 2013-05-24


* Removed unneeded calls to `.then` to address performance degredation (#30) * Removed unneeded calls to `.then` to address performance degredation (#30)


#v0.1.1 / 2013-05-23 # v0.1.1 / 2013-05-23


* Updated grunt * Updated grunt
* Fixed nextTick issues for node v0.10 #32 * Fixed nextTick issues for node v0.10 #32
Expand All @@ -52,7 +60,7 @@
* Rebuilt nools.js and nools.min.js * Rebuilt nools.js and nools.min.js
* Added more tests for new globals feature * Added more tests for new globals feature


#0.1.0 / 2013-02-27 # 0.1.0 / 2013-02-27


* Browser support! * Browser support!
* Support for compiling nools dsl from string source or path * Support for compiling nools dsl from string source or path
Expand All @@ -71,18 +79,18 @@
* More Examples (requirejs, browser, conways game of life) * More Examples (requirejs, browser, conways game of life)
* More tests and better coverage on or and not nodes. * More tests and better coverage on or and not nodes.


#0.0.5 / 2012-09-10 # 0.0.5 / 2012-09-10
* Fix for issue [#13](https://github.com/C2FO/nools/issues/13) where identifiers were not gathered in property chains that contained functions. * Fix for issue [#13](https://github.com/C2FO/nools/issues/13) where identifiers were not gathered in property chains that contained functions.


#0.0.4 / 2012-09-10 # 0.0.4 / 2012-09-10
* Added travis CI * Added travis CI


#0.0.3 / 2012-09-06 # 0.0.3 / 2012-09-06
* Updates for repo rename * Updates for repo rename
* code clean up * code clean up




#0.0.2 / 2012-05-22 # 0.0.2 / 2012-05-22
* Increased performance * Increased performance
* Manners benchmark 800% * Manners benchmark 800%
* Added Parser for nools DSL * Added Parser for nools DSL
Expand Down
6 changes: 3 additions & 3 deletions lib/compile/transpile.js
Expand Up @@ -63,10 +63,10 @@ function constraintsToJs(constraint, identifiers) {
constraint = constraint.slice(0); constraint = constraint.slice(0);
var ret = []; var ret = [];
if (constraint[0] === "or") { if (constraint[0] === "or") {
ret.push('"' + constraint.shift() + '", '); ret.push('["' + constraint.shift() + '"');
ret = ret.concat(extd.map(constraint, function (c) { ret.push(extd.map(constraint,function (c) {
return constraintsToJs(c, identifiers); return constraintsToJs(c, identifiers);
})); }).join(",") + "]");
return ret; return ret;
} else if (constraint[0] === "not") { } else if (constraint[0] === "not") {
ret.push('"', constraint.shift(), '", '); ret.push('"', constraint.shift(), '", ');
Expand Down
18 changes: 12 additions & 6 deletions lib/constraintMatcher.js
Expand Up @@ -89,7 +89,7 @@ var lang = {
if (c1[2] === c2[2]) { if (c1[2] === c2[2]) {
if (indexOf(["string", "number", "boolean", "regexp", "identifier", "null"], c1[2]) !== -1) { if (indexOf(["string", "number", "boolean", "regexp", "identifier", "null"], c1[2]) !== -1) {
ret = c1[0] === c2[0]; ret = c1[0] === c2[0];
} else if (c1[2] === "unminus") { } else if (c1[2] === "unary" || c1[2] === "logicalNot") {
ret = this.equal(c1[0], c2[0]); ret = this.equal(c1[0], c2[0]);
} else { } else {
ret = this.equal(c1[0], c2[0]) && this.equal(c1[1], c2[1]); ret = this.equal(c1[0], c2[0]) && this.equal(c1[1], c2[1]);
Expand All @@ -113,7 +113,8 @@ var lang = {
rule2 !== "number" && rule2 !== "number" &&
rule2 !== "boolean" && rule2 !== "boolean" &&
rule2 !== "regexp" && rule2 !== "regexp" &&
rule2 !== "unminus") { rule2 !== "unary" &&
rule2 !== "unary") {
//its an expression so keep going //its an expression so keep going
if (rule2 === "prop") { if (rule2 === "prop") {
ret = ret.concat(this.getIdentifiers(rule[0])); ret = ret.concat(this.getIdentifiers(rule[0]));
Expand Down Expand Up @@ -167,7 +168,8 @@ var lang = {
rule2 === "in" || rule2 === "in" ||
rule2 === "notIn" || rule2 === "notIn" ||
rule2 === "prop" || rule2 === "prop" ||
rule2 === "function") { rule2 === "function" ||
rule2 === "logicalNot") {
if (some(this.getIdentifiers(rule), function (i) { if (some(this.getIdentifiers(rule), function (i) {
return i !== alias && !(i in definedFuncs) && !(i in scope); return i !== alias && !(i in definedFuncs) && !(i in scope);
})) { })) {
Expand All @@ -189,11 +191,11 @@ var lang = {
}, },


and: function (lhs, rhs) { and: function (lhs, rhs) {
return [this.parse(lhs), "&&", this.parse(rhs)].join(" "); return ["(", this.parse(lhs), "&&", this.parse(rhs), ")"].join(" ");
}, },


or: function (lhs, rhs) { or: function (lhs, rhs) {
return [this.parse(lhs), "||", this.parse(rhs)].join(" "); return ["(", this.parse(lhs), "||", this.parse(rhs), ")"].join(" ");
}, },


prop: function (name, prop) { prop: function (name, prop) {
Expand All @@ -204,7 +206,7 @@ var lang = {
} }
}, },


unminus: function (lhs) { unary: function (lhs) {
return -1 * this.parse(lhs); return -1 * this.parse(lhs);
}, },


Expand Down Expand Up @@ -311,6 +313,10 @@ var lang = {


"null": function () { "null": function () {
return "null"; return "null";
},

logicalNot: function (lhs) {
return ["!(", this.parse(lhs), ")"].join("");
} }
}; };


Expand Down
77 changes: 56 additions & 21 deletions lib/nodes/notNode.js
Expand Up @@ -9,6 +9,7 @@ JoinNode.extend({
constructor: function () { constructor: function () {
this._super(arguments); this._super(arguments);
this.leftTupleMemory = {}; this.leftTupleMemory = {};
this.allTuples = {};
}, },




Expand Down Expand Up @@ -50,25 +51,24 @@ JoinNode.extend({




retractLeft: function (fact) { retractLeft: function (fact) {
var contexts = this.leftMemory[fact.id], i, l; var factId = fact.id, tuples = this.allTuples[fact.id] || [], context, blocking, blocker;
if (!contexts) { while (tuples.length) {
var leftContexts = this.leftTupleMemory[fact.id], leftContext; context = tuples.pop();
delete this.leftTupleMemory[fact.id]; if (indexOf(context.factIds, factId) !== -1) {
if (leftContexts) { this.__removeFromAllTupleMemory(context);
for (i = 0, l = leftContexts.length; i < l; i++) { this.__removeFromLeftMemory(context);
leftContext = leftContexts[i]; this.__removeFromLeftTupleMemory(context);
var blocking = leftContext.blocker.blocking; if ((blocker = context.blocker)) {
blocking.splice(indexOf(blocking, leftContext), 1); blocking = blocker.blocking;
blocking.splice(indexOf(blocking, context), 1);
context.blocker = null;
} }
} }
} else {
delete this.leftMemory[fact.id];
var tuples = this.leftTuples;
for (i = 0, l = contexts.length; i < l; i++) {
tuples.splice(indexOf(tuples, contexts[i]), 1);
}
} }
delete this.leftMemory[factId];
delete this.leftTupleMemory[factId];
this.propagateRetract(fact); this.propagateRetract(fact);

}, },


assertLeft: function (context) { assertLeft: function (context) {
Expand Down Expand Up @@ -111,20 +111,20 @@ JoinNode.extend({
}, },


__removeFromLeftMemory: function (context) { __removeFromLeftMemory: function (context) {
var leftMemories = this.leftMemory[context.fact.id], lc, tuples = this.leftTuples; var leftMemories = this.leftMemory[context.fact.id] || [], lc, tuples = this.leftTuples;
for (var i = 0, l = leftMemories.length; i < l; i++) { for (var i = 0, l = tuples.length; i < l; i++) {
lc = leftMemories[i]; lc = tuples[i];
if (lc === context) { if (lc === context) {
leftMemories.splice(i, 1); tuples.splice(i, 1);
tuples.splice(indexOf(tuples, lc), 1); leftMemories.splice(indexOf(leftMemories, lc), 1);
break; break;
} }
} }
return this; return this;
}, },


__removeFromLeftTupleMemory: function (context) { __removeFromLeftTupleMemory: function (context) {
var leftMemories = this.leftTupleMemory[context.fact.id], lc; var leftMemories = this.leftTupleMemory[context.fact.id] || [], lc;
for (var i = 0, l = leftMemories.length; i < l; i++) { for (var i = 0, l = leftMemories.length; i < l; i++) {
lc = leftMemories[i]; lc = leftMemories[i];
if (lc === context) { if (lc === context) {
Expand All @@ -135,6 +135,40 @@ JoinNode.extend({
return this; return this;
}, },


__addToAllTupleMemory: function (context) {
var factIds = context.factIds, i = -1, l = factIds.length, factId, allTuples = this.allTuples, tuples;
while (++i < l) {
factId = factIds[i];
tuples = allTuples[factId] = (allTuples[factId] || []);
if (indexOf(tuples, context) === -1) {
tuples.push(context);
}
}
return this;

},

__removeFromAllTupleMemory: function (context) {
var factIds = context.factIds, i = -1, l = factIds.length, factId, allTuples = this.allTuples, tuples, index;
while (++i < l) {
factId = factIds[i];
tuples = allTuples[factId];
index = indexOf(tuples, context);
if (index !== -1) {
tuples.splice(i, 1);
}
}
return this;

},


__addToLeftMemory: function (context) {
this._super(arguments);
this.__addToAllTupleMemory(context);
return this;
},

__addToLeftTupleMemory: function (context) { __addToLeftTupleMemory: function (context) {
var o = context.fact; var o = context.fact;
var lm = this.leftTupleMemory[o.id]; var lm = this.leftTupleMemory[o.id];
Expand All @@ -143,6 +177,7 @@ JoinNode.extend({
this.leftTupleMemory[o.id] = lm; this.leftTupleMemory[o.id] = lm;
} }
lm.push(context); lm.push(context);
this.__addToAllTupleMemory(context);
return this; return this;
} }
} }
Expand Down
4 changes: 3 additions & 1 deletion lib/parser/constraint/grammar.js
Expand Up @@ -48,6 +48,7 @@ var grammar = {
["\\]", "return ']';"], ["\\]", "return ']';"],
["\\[", "return '[';"], ["\\[", "return '[';"],
["\\)", "return ')';"], ["\\)", "return ')';"],
["!", "return '!';"],
["$", "return 'EOF';"] ["$", "return 'EOF';"]
] ]
}, },
Expand All @@ -59,7 +60,8 @@ var grammar = {


"UNARY_EXPRESSION": [ "UNARY_EXPRESSION": [
"LITERAL_EXPRESSION", "LITERAL_EXPRESSION",
[ "- UNARY_EXPRESSION", "$$ = [$2, null, 'unminus'];"] [ "- UNARY_EXPRESSION", "$$ = [$2, null, 'unary'];"],
[ "! UNARY_EXPRESSION", "$$ = [$2, null, 'logicalNot'];"]
], ],


"MULTIPLICATIVE_EXPRESSION": [ "MULTIPLICATIVE_EXPRESSION": [
Expand Down

0 comments on commit c8d46f4

Please sign in to comment.