Skip to content

Commit

Permalink
stub: add basic binary operators
Browse files Browse the repository at this point in the history
See #10
  • Loading branch information
a8m authored and indutny committed Dec 24, 2014
1 parent fc0ca6f commit 9edf4d4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
10 changes: 9 additions & 1 deletion lib/js/platform/base/stub.js
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ function binaryStubs() {
});
}, this);

var ops = [ '<', '<=' ];
var ops = [ '<', '<=', '>', '>=', '==', '!=' ];
ops.forEach(function(op) {
this.declareStub('binary/' + op, function() {/*
block BinaryLogic -> LeftSmi, LeftNonSmi
Expand All @@ -664,6 +664,14 @@ function binaryStubs() {
smiCompare %"<", left, right
#elif op === '<='
smiCompare %"<=", left, right
#elif op === '>'
smiCompare %"<", right, left
#elif op === '>='
smiCompare %"<=", right, left
#elif op === '=='
smiCompare %"==", right, left
#elif op === '!='
smiCompare %"!=", right, left
#endif
block True
Expand Down
26 changes: 23 additions & 3 deletions test/api-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,32 @@ describe('js.js API', function() {
it('should do basic binary logic', function() {
var fn = compile(function() { 1 < 2; });
assert.equal(fn.call(null, []).cast().value(), true);
var fn = compile(function() { 2 < 2; });
fn = compile(function() { 2 < 2; });
assert.equal(fn.call(null, []).cast().value(), false);
var fn = compile(function() { 2 <= 2; });
fn = compile(function() { 2 <= 2; });
assert.equal(fn.call(null, []).cast().value(), true);
var fn = compile(function() { 3 <= 2; });
fn = compile(function() { 3 <= 2; });
assert.equal(fn.call(null, []).cast().value(), false);

fn = compile(function() { 1 > 2; });
assert.equal(fn.call(null, []).cast().value(), false);
fn = compile(function() { 3 > 2; });
assert.equal(fn.call(null, []).cast().value(), true);
fn = compile(function() { 2 >= 2; });
assert.equal(fn.call(null, []).cast().value(), true);
fn = compile(function() { 3 >= 2; });
assert.equal(fn.call(null, []).cast().value(), true);
fn = compile(function() { 1 >= 2; });
assert.equal(fn.call(null, []).cast().value(), false);

fn = compile(function() { 1 == 2; });
assert.equal(fn.call(null, []).cast().value(), false);
fn = compile(function() { 2 == 2; });
assert.equal(fn.call(null, []).cast().value(), true);
fn = compile(function() { 2 != 2; });
assert.equal(fn.call(null, []).cast().value(), false);
fn = compile(function() { 3 != 2; });
assert.equal(fn.call(null, []).cast().value(), true);
});

it('should do string literal', function() {
Expand Down

0 comments on commit 9edf4d4

Please sign in to comment.