Skip to content

Commit

Permalink
Merge pull request #61 from mohayonao/improve-bytecode
Browse files Browse the repository at this point in the history
improve bytecode
  • Loading branch information
mohayonao committed Jun 12, 2014
2 parents 352fa88 + c309fe0 commit ae12f5e
Show file tree
Hide file tree
Showing 16 changed files with 559 additions and 318 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "scscript",
"version": "0.0.46",
"version": "0.0.47",
"author": "Nao Yonamine <mohayonao@gmail.com>",
"homepage": "http://mohayonao.github.io/SCScript/",
"bugs": "https://github.com/mohayonao/SCScript/issues",
Expand Down
8 changes: 4 additions & 4 deletions src/const.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
TAG_FUNCTION : 0x0c,
TAG_UNUSED : 0xff,

THREAD_STATE_INIT : 0,
THREAD_STATE_RUNNING : 3,
THREAD_STATE_SUSPENDED: 5,
THREAD_STATE_DONE : 6,
STATE_INIT : 0,
STATE_RUNNING : 3,
STATE_SUSPENDED: 5,
STATE_DONE : 6,

LOOP_BREAK: 0xffff,
};
Expand Down
22 changes: 11 additions & 11 deletions src/sc/classlib/Collections/Collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ SCScript.install(function(sc) {
return [ function($item) {
if (!$aCollection.$("includes", [ $item ]).__bool__()) {
$res = $false;
this.__break__();
this.break();
}
} ];
}));
Expand Down Expand Up @@ -292,7 +292,7 @@ SCScript.install(function(sc) {
return [ function($item2) {
if ($item1 === $item2) {
$res = $true;
this.__break__();
this.break();
}
} ];
}));
Expand All @@ -307,7 +307,7 @@ SCScript.install(function(sc) {
return [ function($item2) {
if ($item1 ["=="] ($item2).__bool__()) {
$res = $true;
this.__break__();
this.break();
}
} ];
}));
Expand All @@ -322,7 +322,7 @@ SCScript.install(function(sc) {
return [ function($item) {
if ($this.includes($item).__bool__()) {
$res = $true;
this.__break__();
this.break();
}
} ];
}));
Expand All @@ -337,7 +337,7 @@ SCScript.install(function(sc) {
return [ function($item) {
if (!$this.includes($item).__bool__()) {
$res = $false;
this.__break__();
this.break();
}
} ];
}));
Expand Down Expand Up @@ -411,7 +411,7 @@ SCScript.install(function(sc) {
return [ function($elem, $i) {
if ($function.value($elem, $i).__bool__()) {
$res = $elem;
this.__break__();
this.break();
}
} ];
}));
Expand All @@ -426,7 +426,7 @@ SCScript.install(function(sc) {
return [ function($elem, $i) {
if ($function.value($elem, $i).__bool__()) {
$res = $i;
this.__break__();
this.break();
}
} ];
}));
Expand Down Expand Up @@ -493,7 +493,7 @@ SCScript.install(function(sc) {
if ($function.value($elem, $i).__bool__()) {
$res = $elem;
} else {
this.__break__();
this.break();
}
} ];
}));
Expand All @@ -508,7 +508,7 @@ SCScript.install(function(sc) {
if ($function.value($elem, $i).__bool__()) {
$res = $i;
} else {
this.__break__();
this.break();
}
} ];
}));
Expand Down Expand Up @@ -578,7 +578,7 @@ SCScript.install(function(sc) {
return [ function($elem, $i) {
if ($function.value($elem, $i).__bool__()) {
$res = $true;
this.__break__();
this.break();
}
} ];
}));
Expand All @@ -593,7 +593,7 @@ SCScript.install(function(sc) {
return [ function($elem, $i) {
if (!$function.value($elem, $i).__bool__()) {
$res = $false;
this.__break__();
this.break();
}
} ];
}));
Expand Down
8 changes: 4 additions & 4 deletions src/sc/classlib/Collections/Dictionary.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ SCScript.install(function(sc) {
return [ function($k, $v) {
if ($k.matchItem($key).__bool__()) {
ret = $v;
this.__break__();
this.break();
}
} ];
}));
Expand Down Expand Up @@ -227,7 +227,7 @@ SCScript.install(function(sc) {
return [ function($item2) {
if ($item1 ["=="] ($item2).__bool__()) {
$ret = $true;
this.__break__();
this.break();
}
} ];
}));
Expand Down Expand Up @@ -445,7 +445,7 @@ SCScript.install(function(sc) {
return [ function($key, $val) {
if ($argValue ["=="] ($val).__bool__()) {
$ret = $key;
this.__break__();
this.break();
}
} ];
}));
Expand Down Expand Up @@ -648,7 +648,7 @@ SCScript.install(function(sc) {
return [ function($key, $val) {
if ($argValue === $val) {
$ret = $key;
this.__break__();
this.break();
}
} ];
}));
Expand Down
6 changes: 3 additions & 3 deletions src/sc/classlib/Collections/SequenceableCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ SCScript.install(function(sc) {
return [ function($item, $i) {
if ($item ["!="] ($aCollection.$("at", [ $i ])).__bool__()) {
$res = $false;
this.__break__();
this.break();
}
} ];
}));
Expand Down Expand Up @@ -179,7 +179,7 @@ SCScript.install(function(sc) {
return [ function($elem, $i) {
if ($item === $elem) {
$ret = $i;
this.__break__();
this.break();
}
} ];
}));
Expand Down Expand Up @@ -303,7 +303,7 @@ SCScript.install(function(sc) {
$step = $diff;
} else if ($step ["!="] ($diff).__bool__()) {
$res = $false;
this.__break__();
this.break();
}
} ];
}));
Expand Down
11 changes: 6 additions & 5 deletions src/sc/classlib/Core/AbstractFunction_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -984,21 +984,22 @@
it.skip("#valueArrayEnvir", function() {
});
it("#do", sinon.test(function() {
var instance, test;
var instance, test, spy;
var $elem1, $elem2, $function;

spy = this.spy();
$elem1 = $$();
$elem2 = $$();
$function = $$({ value: this.spy() });
$function = $$(spy);

instance = this.createInstance();
instance.array_($$([ $elem1, $elem2 ]));

test = instance.do($function);
expect(test).to.equal(instance);
expect($function.value).to.callCount(2);
expect($function.value.args[0]).to.eql($$([ $elem1, 0 ])._);
expect($function.value.args[1]).to.eql($$([ $elem2, 1 ])._);
expect(spy).to.callCount(2);
expect(spy.args[0]).to.eql($$([ $elem1, 0 ])._);
expect(spy.args[1]).to.eql($$([ $elem2, 1 ])._);
}));
it("#flop", function() {
var instance, test;
Expand Down
4 changes: 3 additions & 1 deletion src/sc/classlib/Core/Object.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ SCScript.install(function(sc) {
var slice = [].slice;
var $ = sc.lang.$;
var fn = sc.lang.fn;
var bytecode = sc.lang.bytecode;

sc.lang.klass.refine("Object", function(spec, utils) {
var $nil = utils.$nil;
Expand Down Expand Up @@ -494,7 +495,8 @@ SCScript.install(function(sc) {
};

spec.yield = function() {
// TODO: implements yield
bytecode.yield(this);
return this;
};

// TODO: implements alwaysYield
Expand Down
13 changes: 11 additions & 2 deletions src/sc/classlib/Core/Object_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

var $ = sc.lang.$;
var iterator = sc.lang.iterator;
var bytecode = sc.lang.bytecode;

describe("SCObject", function() {
var SCObject;
Expand Down Expand Up @@ -1126,8 +1127,16 @@
},
]);
});
it.skip("#yield", function() {
});
it("#yield", sinon.test(function() {
var instance, test;

instance = this.createInstance();
this.stub(bytecode, "yield");

test = instance.yield();
expect(test).to.equal(instance);
expect(bytecode.yield).to.be.calledWith(instance);
}));
it.skip("#alwaysYield", function() {
});
it.skip("#yieldAndReset", function() {
Expand Down
2 changes: 1 addition & 1 deletion src/sc/classlib/Core/Thread.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ SCScript.install(function(sc) {
};

spec._init = function() {
this._state = sc.C.THREAD_STATE_INIT;
this._state = sc.C.STATE_INIT;
this._randgen = new random.RandGen((Math.random() * 4294967295) >>> 0);
return this;
};
Expand Down
2 changes: 1 addition & 1 deletion src/sc/classlib/Core/Thread_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
instance = this.createInstance();

test = instance.state();
expect(test).to.be.a("SCInteger").that.equals(sc.C.THREAD_STATE_INIT);
expect(test).to.be.a("SCInteger").that.equals(sc.C.STATE_INIT);
});
it.skip("<parent", function() {
});
Expand Down
Loading

0 comments on commit ae12f5e

Please sign in to comment.