reworked guard comparison

This commit is contained in:
seven-phases-max
2014-05-17 00:36:38 +04:00
parent 08e2fc4136
commit c4e2514905
9 changed files with 192 additions and 93 deletions

View File

@@ -14,34 +14,20 @@ tree.Condition.prototype = {
this.rvalue = visitor.visit(this.rvalue);
},
eval: function (env) {
var a = this.lvalue.eval(env),
b = this.rvalue.eval(env);
var i = this.index, result;
result = (function (op) {
var result = (function (op, a, b) {
switch (op) {
case 'and':
return a && b;
case 'or':
return a || b;
case 'and': return a && b;
case 'or': return a || b;
default:
if (a.compare) {
result = a.compare(b);
} else if (b.compare) {
result = b.compare(a);
} else {
throw { type: "Type",
message: "Unable to perform comparison",
index: i };
}
switch (result) {
switch (tree.compare(a, b)) {
case -1: return op === '<' || op === '=<' || op === '<=';
case 0: return op === '=' || op === '>=' || op === '=<' || op === '<=';
case 1: return op === '>' || op === '>=';
default: return false;
}
}
})(this.op);
}) (this.op, this.lvalue.eval(env), this.rvalue.eval(env));
return this.negate ? !result : result;
}
};