Skip to content

Commit

Permalink
Merge pull request #111 from mohayonao/dev
Browse files Browse the repository at this point in the history
fix-up internal
  • Loading branch information
mohayonao committed Jul 6, 2014
2 parents f48dfa5 + b8eedd5 commit 16aa6f8
Show file tree
Hide file tree
Showing 71 changed files with 696 additions and 497 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "scscript",
"version": "0.0.69",
"version": "0.0.70",
"author": "Nao Yonamine <mohayonao@gmail.com>",
"homepage": "http://mohayonao.github.io/SCScript/",
"bugs": "https://github.com/mohayonao/SCScript/issues",
Expand All @@ -25,7 +25,8 @@
"dependencies": {
"escodegen": "^1.3.3",
"esprima": "^1.2.2",
"optionator": "^0.4.0"
"optionator": "^0.4.0",
"sushi-repl": "^1.0.1"
},
"devDependencies": {
"chai": "^1.9.1",
Expand Down
9 changes: 8 additions & 1 deletion src/const.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,14 @@
NOP: 1,
NIL: 2,
TRUE: 3,
FALSE: 4
FALSE: 4,

ERRID_SUBCLASS_RESPONSIBILITY: 1,
ERRID_DOES_NOT_UNDERSTAND: 2,
ERRID_SHOULD_NOT_IMPLEMENT: 3,
ERRID_NOT_YET_IMPLEMENTED: 4,
ERRID_NOT_SUPPORTED: 5,
ERRID_SHOULD_USE_LITERALS: 6
};

if (typeof global.sc !== "undefined") {
Expand Down
6 changes: 3 additions & 3 deletions src/sc/classlib/Collections/Collection_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
var instance;

instance = this.createInstance();
expect(instance.do.__errorType).to.equal("subclassResponsibility");
expect(instance.do.__errorType).to.equal(sc.ERRID_SUBCLASS_RESPONSIBILITY);
});
it.skip("#iter", function() {
});
Expand Down Expand Up @@ -217,7 +217,7 @@
var instance;

instance = this.createInstance();
expect(instance.add.__errorType).to.equal("subclassResponsibility");
expect(instance.add.__errorType).to.equal(sc.ERRID_SUBCLASS_RESPONSIBILITY);
});
it("#addAll", function() {
testCase(this, [
Expand All @@ -233,7 +233,7 @@
var instance;

instance = this.createInstance();
expect(instance.remove.__errorType).to.equal("subclassResponsibility");
expect(instance.remove.__errorType).to.equal(sc.ERRID_SUBCLASS_RESPONSIBILITY);
});
it("#removeAll", function() {
testCase(this, [
Expand Down
4 changes: 2 additions & 2 deletions src/sc/classlib/Collections/Dictionary_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,11 @@
});
it("#remove", function() {
var instance = this.createInstance();
expect(instance.remove.__errorType).to.equal("shouldNotImplement");
expect(instance.remove.__errorType).to.equal(sc.ERRID_SHOULD_NOT_IMPLEMENT);
});
it("#removeFail", function() {
var instance = this.createInstance();
expect(instance.removeFail.__errorType).to.equal("shouldNotImplement");
expect(instance.removeFail.__errorType).to.equal(sc.ERRID_SHOULD_NOT_IMPLEMENT);
});
it("#keysValuesDo", sinon.test(function() {
var instance, test;
Expand Down
12 changes: 1 addition & 11 deletions src/sc/classlib/Core/Boolean.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ SCScript.install(function(sc) {
return String(this._);
});

builder.addClassMethod("new", function() {
throw new Error("Boolean.new is illegal, should use literal.");
});
builder.shouldUseLiterals("new");

builder.addMethod("xor", function($bool) {
return $.Boolean(this === $bool).not();
Expand Down Expand Up @@ -54,10 +52,6 @@ SCScript.install(function(sc) {
});

sc.lang.klass.refine("True", function(builder) {
builder.addClassMethod("new", function() {
throw new Error("True.new is illegal, should use literal.");
});

builder.addMethod("if", {
args: "trueFunc"
}, function($trueFunc) {
Expand Down Expand Up @@ -96,10 +90,6 @@ SCScript.install(function(sc) {
});

sc.lang.klass.refine("False", function(builder) {
builder.addClassMethod("new", function() {
throw new Error("False.new is illegal, should use literal.");
});

builder.addMethod("if", {
args: "trueFunc; falseFunc"
}, function($trueFunc, $falseFunc) {
Expand Down
8 changes: 3 additions & 5 deletions src/sc/classlib/Core/Boolean_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@
expect(test).to.be.a("JSString").that.equals("false");
});
it(".new", function() {
expect(function() {
SCBoolean.new();
}).to.throw("should use literal");
expect(SCBoolean.new.__errorType).to.equal(sc.ERRID_SHOULD_USE_LITERALS);
});
it("#xor", function() {
testCase(this, [
Expand Down Expand Up @@ -86,7 +84,7 @@
it(".new", function() {
expect(function() {
SCTrue.new();
}).to.throw("should use literal");
}).to.throw("should use literals");
});
it("#if", sinon.test(function() {
var instance, test;
Expand Down Expand Up @@ -176,7 +174,7 @@
it(".new", function() {
expect(function() {
SCFalse.new();
}).to.throw("should use literal");
}).to.throw("should use literals");
});
it("#if", sinon.test(function() {
var instance, test;
Expand Down
4 changes: 1 addition & 3 deletions src/sc/classlib/Core/Char.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ SCScript.install(function(sc) {
return $.Char(",");
});

builder.addClassMethod("new", function() {
throw new Error("Char.new is illegal, should use literal.");
});
builder.shouldUseLiterals("new");

// TODO: implements hash

Expand Down
4 changes: 1 addition & 3 deletions src/sc/classlib/Core/Char_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@
expect(test).to.be.a("SCChar").that.equals(",");
});
it(".new", function() {
expect(function() {
SCChar.new();
}).to.throw("should use literal");
expect(SCChar.new.__errorType).to.equal(sc.ERRID_SHOULD_USE_LITERALS);
});
it.skip("#hash", function() {
});
Expand Down
5 changes: 2 additions & 3 deletions src/sc/classlib/Core/Function.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ SCScript.install(function(sc) {

sc.lang.klass.refine("Function", function(builder, _) {
// TODO: implements def
builder.addClassMethod("new", function() {
throw new Error("Function.new is illegal, should use literal.");
});

builder.shouldUseLiterals("new");

builder.addMethod("isFunction", sc.TRUE);

Expand Down
4 changes: 1 addition & 3 deletions src/sc/classlib/Core/Function_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@
it.skip("<def", function() {
});
it(".new", function() {
expect(function() {
SCFunction.new();
}).to.throw("should use literal");
expect(SCFunction.new.__errorType).to.equal(sc.ERRID_SHOULD_USE_LITERALS);
});
it("#isFunction", function() {
var instance, test;
Expand Down
4 changes: 1 addition & 3 deletions src/sc/classlib/Core/Nil.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ SCScript.install(function(sc) {
return "nil";
});

builder.addClassMethod("new", function() {
throw new Error("Nil.new is illegal, should use literal.");
});
builder.shouldUseLiterals("new");

builder.addMethod("isNil", sc.TRUE);
builder.addMethod("notNil", sc.FALSE);
Expand Down
4 changes: 1 addition & 3 deletions src/sc/classlib/Core/Nil_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@
expect(test).to.be.a("JSString").that.equals("nil");
});
it(".new", function() {
expect(function() {
SCNil.new();
}).to.throw("should use literal");
expect(SCNil.new.__errorType).to.equal(sc.ERRID_SHOULD_USE_LITERALS);
});
it("#isNil", function() {
var instance, test;
Expand Down
38 changes: 24 additions & 14 deletions src/sc/classlib/Core/Object.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,23 @@ SCScript.install(function(sc) {
return $.Boolean(this.__class === $aClass);
});

var respondsTo = function($this, $aSymbol) {
return typeof $this[
$aSymbol ? $aSymbol.__sym__() : /* istanbul ignore next */ ""
] === "function";
};
function sym2str($aSymbol) {
return $aSymbol ? $aSymbol.__sym__() : /* istanbul ignore next */ "";
}

function getFunction($this, methodName) {
if (/^([a-z]\w*|[-+*\/%<=>!?&|@]+)$/.test(methodName)) {
if (typeof $this[methodName] === "function") {
return $this[methodName];
}
}
return null;
}

function respondsTo($this, $aSymbol) {
var func = getFunction($this, sym2str($aSymbol));
return func && !func.__errorType;
}

builder.addMethod("respondsTo", function($aSymbol) {
var $this = this;
Expand All @@ -137,18 +149,16 @@ SCScript.install(function(sc) {
return $.Boolean(respondsTo(this, $aSymbol));
});

var performMsg = function($this, msg) {
var selector, method;

selector = msg[0] ? msg[0].__sym__() : /* istanbul ignore next */ "";
method = $this[selector];
function performMsg($this, msg) {
var methodName = sym2str(msg[0]);
var func = getFunction($this, methodName);

if (method) {
return method.apply($this, msg.slice(1));
if (func) {
return func.apply($this, msg.slice(1));
}

throw new Error(strlib.format("Message '#{0}' not understood.", selector));
};
throw new Error(strlib.format("Message '#{0}' is not understood.", methodName));
}

builder.addMethod("performMsg", function($msg) {
return performMsg(this, $msg ? $msg.asArray()._ : /* istanbul ignore next */ []);
Expand Down
3 changes: 1 addition & 2 deletions src/sc/classlib/Core/Object_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -582,12 +582,11 @@
var instance, test;
var SCOneShotStream$new = this.spy(sc.test.func());

instance = this.createInstance();
this.stub(sc.lang.klass, "get").withArgs("OneShotStream").returns($$({
new: SCOneShotStream$new
}));

instance = this.createInstance();

test = instance.iter();
expect(SCOneShotStream$new ).to.be.calledWith(instance);
expect(SCOneShotStream$new ).to.be.calledLastIn(test);
Expand Down
4 changes: 1 addition & 3 deletions src/sc/classlib/Core/Symbol.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ SCScript.install(function(sc) {
return this._;
});

builder.addClassMethod("new", function() {
throw new Error("Symbol.new is illegal, should use literal.");
});
builder.shouldUseLiterals("new");

builder.addMethod("asSymbol");

Expand Down
4 changes: 1 addition & 3 deletions src/sc/classlib/Core/Symbol_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@
expect(test).to.be.a("JSString").that.equals("sym");
});
it(".new", function() {
expect(function() {
SCSymbol.new();
}).to.throw("should use literal");
expect(SCSymbol.new.__errorType).to.equal(sc.ERRID_SHOULD_USE_LITERALS);
});
it("#asSymbol", function() {
var instance;
Expand Down
4 changes: 0 additions & 4 deletions src/sc/classlib/Math/Float.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ SCScript.install(function(sc) {
return String(this._);
});

builder.addClassMethod("new", function() {
throw new Error("Float.new is illegal, should use literal.");
});

builder.addMethod("isFloat", sc.TRUE);
builder.addMethod("asFloat");

Expand Down
2 changes: 1 addition & 1 deletion src/sc/classlib/Math/Float_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
it(".new", function() {
expect(function() {
SCFloat.new();
}).to.throw("should use literal");
}).to.throw("should use literals");
});
it("#isFloat", function() {
testCase(this, [
Expand Down
4 changes: 0 additions & 4 deletions src/sc/classlib/Math/Integer.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ SCScript.install(function(sc) {
return String("" + this._);
});

builder.addClassMethod("new", function() {
throw new Error("Integer.new is illegal, should use literal.");
});

builder.addMethod("isInteger", sc.TRUE);

builder.addMethod("hash", function() {
Expand Down
2 changes: 1 addition & 1 deletion src/sc/classlib/Math/Integer_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
it(".new", function() {
expect(function() {
SCInteger.new();
}).to.throw("should use literal");
}).to.throw("should use literals");
});
it("#isInteger", function() {
testCase(this, [
Expand Down
14 changes: 7 additions & 7 deletions src/sc/classlib/Math/Number_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,31 @@
});
it("#+", function() {
var instance = this.createInstance();
expect(instance["+"].__errorType).to.equal("subclassResponsibility");
expect(instance["+"].__errorType).to.equal(sc.ERRID_SUBCLASS_RESPONSIBILITY);
});
it("#-", function() {
var instance = this.createInstance();
expect(instance["-"].__errorType).to.equal("subclassResponsibility");
expect(instance["-"].__errorType).to.equal(sc.ERRID_SUBCLASS_RESPONSIBILITY);
});
it("#*", function() {
var instance = this.createInstance();
expect(instance["*"].__errorType).to.equal("subclassResponsibility");
expect(instance["*"].__errorType).to.equal(sc.ERRID_SUBCLASS_RESPONSIBILITY);
});
it("#/", function() {
var instance = this.createInstance();
expect(instance["/"].__errorType).to.equal("subclassResponsibility");
expect(instance["/"].__errorType).to.equal(sc.ERRID_SUBCLASS_RESPONSIBILITY);
});
it("#mod", function() {
var instance = this.createInstance();
expect(instance.mod.__errorType).to.equal("subclassResponsibility");
expect(instance.mod.__errorType).to.equal(sc.ERRID_SUBCLASS_RESPONSIBILITY);
});
it("#div", function() {
var instance = this.createInstance();
expect(instance.div.__errorType).to.equal("subclassResponsibility");
expect(instance.div.__errorType).to.equal(sc.ERRID_SUBCLASS_RESPONSIBILITY);
});
it("#pow", function() {
var instance = this.createInstance();
expect(instance.pow.__errorType).to.equal("subclassResponsibility");
expect(instance.pow.__errorType).to.equal(sc.ERRID_SUBCLASS_RESPONSIBILITY);
});
it("#performBinaryOpOnSeqColl", sinon.test(function() {
var instance, test;
Expand Down
2 changes: 2 additions & 0 deletions src/sc/classlib/Math/SimpleNumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ SCScript.install(function(sc) {
return this._;
});

builder.shouldUseLiterals("new");

builder.addMethod("isValidUGenInput", function() {
return $.Boolean(!isNaN(this._));
});
Expand Down
Loading

0 comments on commit 16aa6f8

Please sign in to comment.