Skip to content

Commit

Permalink
Merge pull request #49 from mohayonao/fix-compiler
Browse files Browse the repository at this point in the history
fix compiler
  • Loading branch information
mohayonao committed May 28, 2014
2 parents d92b937 + f7b7944 commit 265e3b1
Show file tree
Hide file tree
Showing 9 changed files with 212 additions and 122 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.39",
"version": "0.0.40",
"author": "Nao Yonamine <mohayonao@gmail.com>",
"homepage": "http://mohayonao.github.io/SCScript/",
"bugs": "https://github.com/mohayonao/SCScript/issues",
Expand Down
15 changes: 0 additions & 15 deletions src/sc/classlib/Collections/Collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,6 @@ SCScript.install(function(sc) {
var $int_1 = utils.$int_1;
var SCArray = $("Array");

// e.g. Array [ 1, 2, 3 ]
spec.$_newFrom = function($anArray) {
var $newCollection;
var array, i, imax;

$newCollection = this.new($anArray.size());

array = $anArray._;
for (i = 0, imax = array.length; i < imax; ++i) {
$newCollection.add(array[i]);
}

return $newCollection;
};

spec.$newFrom = fn(function($aCollection) {
var $newCollection;

Expand Down
9 changes: 0 additions & 9 deletions src/sc/classlib/Collections/Collection_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,6 @@
test = instance.valueOf();
expect(test).to.equal(instance);
});
it("._newFrom", function() {
var test;
var $aCollection;

$aCollection = sc.test.encode([ 1, 2, 3, 4, 5 ]);

test = SCCollection._newFrom.call(SCArray, $aCollection);
expect(test).to.be.a("SCArray").that.eqls([ 1, 2, 3, 4, 5 ]);
});
it(".newFrom", function() {
var test;
var $aCollection;
Expand Down
14 changes: 14 additions & 0 deletions src/sc/classlib/Core/Kernel.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,20 @@ SCScript.install(function(sc) {
// TODO: implements $findAllReferences
// TODO: implements allSubclasses
// TODO: implements superclasses

spec["[]"] = function($anArray) {
var $newCollection;
var array, i, imax;

$newCollection = this.new($anArray.size());

array = $anArray._;
for (i = 0, imax = array.length; i < imax; ++i) {
$newCollection.$("add", [ array[i] ]);
}

return $newCollection;
};
});


Expand Down
44 changes: 39 additions & 5 deletions src/sc/classlib/Core/Kernel_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
"use strict";

require("./Kernel");
require("../Collections/Set");

var $ = sc.lang.$;

describe("SCKernel", function() {
describe("SCClass", function() {
var SCClass, SCMeta_Class;
before(function() {
SCClass = $("Class");
Expand All @@ -24,30 +25,63 @@
var test = SCClass.name();
expect(test).to.be.a("SCString").that.equals("Class");
});
it("#[]", function() {
var test;
test = $("Set")["[]"](sc.test.encode([ 1, 2, 3, 4 ]));
expect(test).to.be.a("SCSet").that.eqls([ 1, 2, 3, 4 ]);
});
});

describe("SCProcess", function() {
var SCProcess;
before(function() {
SCProcess = $("Process");
this.createInstance = function() {
return SCProcess.new();
};
});
it("<interpreter", function() {
var instance, test;

instance = this.createInstance();
test = instance.interpreter();

expect(test).to.be.a("SCNil");
});
it("<mainThread", function() {
var instance, test;

instance = this.createInstance();
test = instance.mainThread();

expect(test).to.be.a("SCNil");
});
});

describe("SCMain", function() {
var SCMain;
before(function() {
SCMain = $("Main");
});
it(".new", function() {
expect(function() {
SCProcess.new();
SCMain.new();
}).to.not.throw();
});
});

describe("SCInterpreter", function() {
var SCInterpreter, $interpreter;
var SCInterpreter;
before(function() {
SCInterpreter = $("Interpreter");
$interpreter = SCInterpreter.new();
this.createInstance = function() {
return SCInterpreter.new();
};
});
it("<>a..z / #clearAll", function() {
var instance;

instance = $interpreter;
instance = this.createInstance();

"abcdefghijklmnopqrstuvwxyz".split("").forEach(function(ch) {
var test, $value;
Expand Down
16 changes: 16 additions & 0 deletions src/sc/classlib/Core/Object.js
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,22 @@ SCScript.install(function(sc) {
// TODO: implements genCurrent
// TODO: implements $classRedirect
// TODO: implements help

spec["[]"] = function($index) {
return this.$("at", [ $index ]);
};

spec["[]_"] = function($index, $value) {
return this.$("put", [ $index, $value ]);
};

spec["[..]"] = function($first, $second, $last) {
return this.$("copySeries", [ $first, $second, $last ]);
};

spec["[..]_"] = function($first, $second, $last, $value) {
return this.$("putSeries", [ $first, $second, $last, $value ]);
};
});

});
120 changes: 89 additions & 31 deletions src/sc/classlib/Core/Object_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1498,7 +1498,7 @@
var instance = this.createInstance();
expect(instance.asControlInput).to.be.nop;
});
it("asAudioRateInput", sinon.test(function() {
it("#asAudioRateInput", sinon.test(function() {
var instance, test, spy, rate;

spy = this.spy(sc.test.func);
Expand All @@ -1522,65 +1522,123 @@
expect(spy).to.be.calledWith(instance);
expect(spy).to.be.calledLastIn(test);
}));
it.skip("slotSize", function() {
it.skip("#slotSize", function() {
});
it.skip("slotAt", function() {
it.skip("#slotAt", function() {
});
it.skip("slotPut", function() {
it.skip("#slotPut", function() {
});
it.skip("slotKey", function() {
it.skip("#slotKey", function() {
});
it.skip("slotIndex", function() {
it.skip("#slotIndex", function() {
});
it.skip("slotsDo", function() {
it.skip("#slotsDo", function() {
});
it.skip("slotValuesDo", function() {
it.skip("#slotValuesDo", function() {
});
it.skip("getSlots", function() {
it.skip("#getSlots", function() {
});
it.skip("setSlots", function() {
it.skip("#setSlots", function() {
});
it.skip("instVarSize", function() {
it.skip("#instVarSize", function() {
});
it.skip("instVarAt", function() {
it.skip("#instVarAt", function() {
});
it.skip("instVarPut", function() {
it.skip("#instVarPut", function() {
});
it.skip("writeArchive", function() {
it.skip("#writeArchive", function() {
});
it.skip("$readArchive", function() {
it.skip(".readArchive", function() {
});
it.skip("asArchive", function() {
it.skip("#asArchive", function() {
});
it.skip("initFromArchive", function() {
it.skip("#initFromArchive", function() {
});
it.skip("archiveAsCompileString", function() {
it.skip("#archiveAsCompileString", function() {
});
it.skip("archiveAsObject", function() {
it.skip("#archiveAsObject", function() {
});
it.skip("checkCanArchive", function() {
it.skip("#checkCanArchive", function() {
});
it.skip("writeTextArchive", function() {
it.skip("#writeTextArchive", function() {
});
it.skip("$readTextArchive", function() {
it.skip(".readTextArchive", function() {
});
it.skip("asTextArchive", function() {
it.skip("#asTextArchive", function() {
});
it.skip("getContainedObjects", function() {
it.skip("#getContainedObjects", function() {
});
it.skip("writeBinaryArchive", function() {
it.skip("#riteBinaryArchive", function() {
});
it.skip("$readBinaryArchive", function() {
it.skip(".readBinaryArchive", function() {
});
it.skip("asBinaryArchive", function() {
it.skip("#asBinaryArchive", function() {
});
it.skip("genNext", function() {
it.skip("#genNext", function() {
});
it.skip("genCurrent", function() {
it.skip("#genCurrent", function() {
});
it.skip("$classRedirect", function() {
it.skip(".classRedirect", function() {
});
it.skip("help", function() {
it.skip("#help", function() {
});
it("#[]", sinon.test(function() {
var instance, test;
var $index;

$index = sc.test.object();

instance = this.createInstance();
instance.at = this.spy(sc.test.func);

test = instance["[]"]($index);
expect(instance.at).to.be.calledWith($index);
expect(instance.at).to.be.calledLastIn(test);
}));
it("#[]_", sinon.test(function() {
var instance, test;
var $index, $value;

$index = sc.test.object();
$value = sc.test.object();

instance = this.createInstance();
instance.put = this.spy(sc.test.func);

test = instance["[]_"]($index, $value);
expect(instance.put).to.be.calledWith($index, $value);
expect(instance.put).to.be.calledLastIn(test);
}));
it("#[..]", sinon.test(function() {
var instance, test;
var $first, $second, $last;

$first = sc.test.object();
$second = sc.test.object();
$last = sc.test.object();

instance = this.createInstance();
instance.copySeries = this.spy(sc.test.func);

test = instance["[..]"]($first, $second, $last);
expect(instance.copySeries).to.be.calledWith($first, $second, $last);
expect(instance.copySeries).to.be.calledLastIn(test);
}));
it("#[..]_", sinon.test(function() {
var instance, test;
var $first, $second, $last, $value;

$first = sc.test.object();
$second = sc.test.object();
$last = sc.test.object();
$value = sc.test.object();

instance = this.createInstance();
instance.putSeries = this.spy(sc.test.func);

test = instance["[..]_"]($first, $second, $last, $value);
expect(instance.putSeries).to.be.calledWith($first, $second, $last, $value);
expect(instance.putSeries).to.be.calledLastIn(test);
}));
});
})();
18 changes: 5 additions & 13 deletions src/sc/lang/compiler/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -400,10 +400,10 @@

token = this.lex();
right = this.parseAssignmentExpression();
methodName = renameGetterToSetter(left.method.name);
methodName = left.method.name + "_";
left.method.name = methodName;
left.args.list = node.args.list.concat(right);
if (methodName.charAt(methodName.length - 1) === "_") {
if (left.stamp !== "[") {
left.stamp = "=";
}
node = marker.update().apply(left, true);
Expand Down Expand Up @@ -765,7 +765,7 @@
var node, method;
var marker;

method = Node.createIdentifier("_newFrom");
method = Node.createIdentifier("[]");
method = Marker.create(this.lexer).apply(method);

marker = Marker.create(this.lexer);
Expand All @@ -778,13 +778,13 @@
SCParser.prototype.parseLeftHandSideListAt = function(expr) {
var indexes, method;

method = Node.createIdentifier("at");
method = Node.createIdentifier("[]");
method = Marker.create(this.lexer).apply(method);

indexes = this.parseListIndexer();
if (indexes) {
if (indexes.length === 3) {
method.name = "copySeries";
method.name = "[..]";
}
} else {
this.throwUnexpected(this.lookahead);
Expand Down Expand Up @@ -1517,14 +1517,6 @@
return marker.update().apply(id);
};

var renameGetterToSetter = function(methodName) {
switch (methodName) {
case "at" : return "put";
case "copySeries": return "putSeries";
}
return methodName + "_";
};

var calcBinaryPrecedence = function(token, binaryPrecedence) {
var prec = 0;

Expand Down
Loading

0 comments on commit 265e3b1

Please sign in to comment.