Skip to content

Commit

Permalink
Merge pull request #13 from mohayonao/classlib
Browse files Browse the repository at this point in the history
add duplicate checking in sc.lang.klass.refine
  • Loading branch information
mohayonao committed Mar 23, 2014
2 parents 7dd23fc + d1644c1 commit e273374
Show file tree
Hide file tree
Showing 12 changed files with 79 additions and 74 deletions.
64 changes: 27 additions & 37 deletions build/scscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,26 +91,42 @@ var sc = { VERSION: "0.0.7" };
}
};

var def = function(className, spec, classMethods, instanceMethods) {
var def = function(className, spec, classMethods, instanceMethods, opts) {

var setMethod = function(methods, methodName, func) {
var dot;

if (methods.hasOwnProperty(methodName) && !(opts && opts.force)) {
dot = methods === classMethods ? "." : "#";
throw new Error(className + dot + methodName + " is already defined.");
}

methods[methodName] = func;
};

Object.keys(spec).forEach(function(methodName) {
var thrower;

if (methodName === "constructor") {
return;
}

if (throwError.hasOwnProperty(methodName)) {
thrower = throwError[methodName];
spec[methodName].forEach(function(methodName) {
if (methodName.charCodeAt(0) === 0x24) { // u+0024 is '$'
methodName = methodName.substr(1);
classMethods[methodName] = thrower(className + "." + methodName);
setMethod(classMethods, methodName, thrower(className + "." + methodName));
} else {
instanceMethods[methodName] = thrower(className + "#" + methodName);
setMethod(instanceMethods, methodName, thrower(className + "#" + methodName));
}
});
} else if (methodName.charCodeAt(0) === 0x24) { // u+0024 is '$'
classMethods[methodName.substr(1)] = spec[methodName];
} else {
instanceMethods[methodName] = spec[methodName];
if (methodName.charCodeAt(0) === 0x24) { // u+0024 is '$'
setMethod(classMethods, methodName.substr(1), spec[methodName]);
} else {
setMethod(instanceMethods, methodName, spec[methodName]);
}
}
});
};
Expand Down Expand Up @@ -147,7 +163,7 @@ var sc = { VERSION: "0.0.7" };

metaClass = constructor.metaClass;

def(className, spec, metaClass._MetaSpec.prototype, constructor.prototype);
def(className, spec, metaClass._MetaSpec.prototype, constructor.prototype, opts);

metaClass._Spec = constructor;
metaClass._isMetaClass = true;
Expand All @@ -156,7 +172,7 @@ var sc = { VERSION: "0.0.7" };
classes[className] = null;
};

sc.lang.klass.refine = function(className, spec) {
sc.lang.klass.refine = function(className, spec, opts) {
var metaClass;

if (!metaClasses.hasOwnProperty(className)) {
Expand All @@ -165,7 +181,7 @@ var sc = { VERSION: "0.0.7" };
);
}
metaClass = metaClasses[className];
def(className, spec, metaClass._MetaSpec.prototype, metaClass._Spec.prototype);
def(className, spec, metaClass._MetaSpec.prototype, metaClass._Spec.prototype, opts);
};

sc.lang.klass.get = function(name) {
Expand Down Expand Up @@ -266,6 +282,8 @@ var sc = { VERSION: "0.0.7" };
// src/sc/lang/classlib/Core/Object.js
(function(sc) {

// var $SC = sc.lang.$SC;

sc.lang.klass.refine("Object", {
js: function() {
return this._raw;
Expand Down Expand Up @@ -422,7 +440,6 @@ var sc = { VERSION: "0.0.7" };
"alwaysYield",
"yieldAndReset",
"idle",
"while",
"dependants",
"changed",
"addDependant",
Expand Down Expand Up @@ -490,7 +507,6 @@ var sc = { VERSION: "0.0.7" };
"archiveAsObject",
"checkCanArchive",
"writeTextArchive",
"protect",
"$readTextArchive",
"asTextArchive",
"getContainedObjects",
Expand Down Expand Up @@ -664,16 +680,12 @@ var sc = { VERSION: "0.0.7" };
"putN",
"putAll",
"do",
"while",
"subSample",
"loop",
"generate",
"while",
"collect",
"reject",
"while",
"select",
"while",
"dot",
"interlace",
"appendStream",
Expand Down Expand Up @@ -917,8 +929,6 @@ var sc = { VERSION: "0.0.7" };
"writeInputSpec",
"series",
"seriesIter",
"while",
"while",
"degreeToKey",
"keyToDegree",
"nearestInList",
Expand Down Expand Up @@ -1478,10 +1488,7 @@ var sc = { VERSION: "0.0.7" };
"numVars",
"varArgs",
"loop",
"loop",
"block",
"block",
"try",
"asRoutine",
"dup",
"sum",
Expand Down Expand Up @@ -1765,7 +1772,6 @@ var sc = { VERSION: "0.0.7" };
"flopDict",
"histo",
"printAll",
"printAll",
"printcsAll",
"dumpAll",
"printOn",
Expand All @@ -1789,7 +1795,6 @@ var sc = { VERSION: "0.0.7" };
"$series",
"$geom",
"$fib",
"while",
"$rand",
"$exprand",
"$rand2",
Expand All @@ -1808,7 +1813,6 @@ var sc = { VERSION: "0.0.7" };
"indicesOfEqual",
"find",
"findAll",
"while",
"indexOfGreaterThan",
"indexIn",
"indexInBetween",
Expand Down Expand Up @@ -2024,19 +2028,11 @@ var sc = { VERSION: "0.0.7" };
"mergeSort",
"mergeSortTemp",
"mergeTemp",
"while",
"while",
"while",
"insertionSort",
"insertionSortRange",
"while",
"while",
"hoareMedian",
"hoareFind",
"while",
"hoarePartition",
"while",
"while",
"$streamContents",
"$streamContentsLimit",
"wrapAt",
Expand Down Expand Up @@ -2075,9 +2071,7 @@ var sc = { VERSION: "0.0.7" };
"indexOf",
"indexOfGreaterThan",
"takeThese",
"while",
"replace",
"while",
"slotSize",
"slotAt",
"slotPut",
Expand Down Expand Up @@ -2226,13 +2220,11 @@ var sc = { VERSION: "0.0.7" };
"containsi",
"findRegexp",
"findAllRegexp",
"while",
"find",
"findBackwards",
"endsWith",
"beginsWith",
"findAll",
"while",
"replace",
"escapeChar",
"shellQuote",
Expand Down Expand Up @@ -2430,9 +2422,7 @@ var sc = { VERSION: "0.0.7" };
"$make",
"$use",
"make",
"protect",
"use",
"protect",
"eventAt",
"composeEvents",
"$pop",
Expand Down
2 changes: 0 additions & 2 deletions src/sc/lang/classlib/Collections/ArrayedCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
"indexOf",
"indexOfGreaterThan",
"takeThese",
"while",
"replace",
"while",
"slotSize",
"slotAt",
"slotPut",
Expand Down
1 change: 0 additions & 1 deletion src/sc/lang/classlib/Collections/Collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@
"flopDict",
"histo",
"printAll",
"printAll",
"printcsAll",
"dumpAll",
"printOn",
Expand Down
2 changes: 0 additions & 2 deletions src/sc/lang/classlib/Collections/Environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
"$make",
"$use",
"make",
"protect",
"use",
"protect",
"eventAt",
"composeEvents",
"$pop",
Expand Down
10 changes: 0 additions & 10 deletions src/sc/lang/classlib/Collections/SequenceableCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"$series",
"$geom",
"$fib",
"while",
"$rand",
"$exprand",
"$rand2",
Expand All @@ -27,7 +26,6 @@
"indicesOfEqual",
"find",
"findAll",
"while",
"indexOfGreaterThan",
"indexIn",
"indexInBetween",
Expand Down Expand Up @@ -243,19 +241,11 @@
"mergeSort",
"mergeSortTemp",
"mergeTemp",
"while",
"while",
"while",
"insertionSort",
"insertionSortRange",
"while",
"while",
"hoareMedian",
"hoareFind",
"while",
"hoarePartition",
"while",
"while",
"$streamContents",
"$streamContentsLimit",
"wrapAt",
Expand Down
2 changes: 0 additions & 2 deletions src/sc/lang/classlib/Collections/String.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,11 @@
"containsi",
"findRegexp",
"findAllRegexp",
"while",
"find",
"findBackwards",
"endsWith",
"beginsWith",
"findAll",
"while",
"replace",
"escapeChar",
"shellQuote",
Expand Down
3 changes: 0 additions & 3 deletions src/sc/lang/classlib/Core/Function.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@
"numVars",
"varArgs",
"loop",
"loop",
"block",
"block",
"try",
"asRoutine",
"dup",
"sum",
Expand Down
4 changes: 2 additions & 2 deletions src/sc/lang/classlib/Core/Object.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
require("../../klass");
require("../../dollarSC");

// var $SC = sc.lang.$SC;

sc.lang.klass.refine("Object", {
js: function() {
return this._raw;
Expand Down Expand Up @@ -160,7 +162,6 @@
"alwaysYield",
"yieldAndReset",
"idle",
"while",
"dependants",
"changed",
"addDependant",
Expand Down Expand Up @@ -228,7 +229,6 @@
"archiveAsObject",
"checkCanArchive",
"writeTextArchive",
"protect",
"$readTextArchive",
"asTextArchive",
"getContainedObjects",
Expand Down
2 changes: 0 additions & 2 deletions src/sc/lang/classlib/Math/SimpleNumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,6 @@
"writeInputSpec",
"series",
"seriesIter",
"while",
"while",
"degreeToKey",
"keyToDegree",
"nearestInList",
Expand Down
4 changes: 0 additions & 4 deletions src/sc/lang/classlib/Streams/Stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,12 @@
"putN",
"putAll",
"do",
"while",
"subSample",
"loop",
"generate",
"while",
"collect",
"reject",
"while",
"select",
"while",
"dot",
"interlace",
"appendStream",
Expand Down

0 comments on commit e273374

Please sign in to comment.