Skip to content

Commit

Permalink
Merge pull request #40 from mohayonao/fix-compiler-newFrom
Browse files Browse the repository at this point in the history
fix compiler
  • Loading branch information
mohayonao committed May 17, 2014
2 parents 615dfcf + 43c5659 commit 67712c9
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 10 deletions.
15 changes: 15 additions & 0 deletions build/scscript-classlib.js
Original file line number Diff line number Diff line change
Expand Up @@ -4085,6 +4085,21 @@ SCScript.install(function(sc) {
var $int_1 = utils.$int_1;
var SCArray = $SC("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
4 changes: 2 additions & 2 deletions build/scscript.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(function(global) {
"use strict";

var sc = { VERSION: "0.0.30" };
var sc = { VERSION: "0.0.31" };

// src/sc/sc.js
(function(sc) {
Expand Down Expand Up @@ -4182,7 +4182,7 @@ var sc = { VERSION: "0.0.30" };
var node, method;
var marker;

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

marker = Marker.create(this.lexer);
Expand Down
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.30",
"version": "0.0.31",
"author": "Nao Yonamine <mohayonao@gmail.com>",
"homepage": "http://mohayonao.github.io/SCScript/",
"bugs": "https://github.com/mohayonao/SCScript/issues",
Expand Down
15 changes: 15 additions & 0 deletions src/sc/classlib/Collections/Collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,21 @@ SCScript.install(function(sc) {
var $int_1 = utils.$int_1;
var SCArray = $SC("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: 9 additions & 0 deletions src/sc/classlib/Collections/Collection_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@
test = instance.valueOf();
expect(test).to.equal(instance);
});
it("._newFrom", function() {
var test;
var $aCollection;

$aCollection = $([ 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
2 changes: 1 addition & 1 deletion src/sc/lang/compiler/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@
var node, method;
var marker;

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

marker = Marker.create(this.lexer);
Expand Down
12 changes: 6 additions & 6 deletions src/sc/lang/compiler/test-cases.js
Original file line number Diff line number Diff line change
Expand Up @@ -5708,7 +5708,7 @@
"Set[3, 4, 5]": {
compiled: [
"SCScript(function($this, $SC) {",
" return $SC('Set').newFrom($SC.Array([",
" return $SC('Set')._newFrom($SC.Array([",
" $SC.Integer(3),",
" $SC.Integer(4),",
" $SC.Integer(5),",
Expand All @@ -5732,7 +5732,7 @@
},
method: {
type: Syntax.Identifier,
name: "newFrom",
name: "_newFrom",
range: [ 3, 3 ],
loc: {
start: { line: 1, column: 3 },
Expand Down Expand Up @@ -5800,7 +5800,7 @@
"Array [ 1, 2 ].at(0)": { // (Array [ 1, 2 ]).at(0)
compiled: [
"SCScript(function($this, $SC) {",
" return $SC('Array').newFrom($SC.Array([",
" return $SC('Array')._newFrom($SC.Array([",
" $SC.Integer(1),",
" $SC.Integer(2),",
" ])).at($SC.Integer(0));",
Expand All @@ -5825,7 +5825,7 @@
},
method: {
type: Syntax.Identifier,
name: "newFrom",
name: "_newFrom",
range: [ 6, 6 ],
loc: {
start: { line: 1, column: 6 },
Expand Down Expand Up @@ -5912,7 +5912,7 @@
"Array [ 1, 2 ][0]": { // (Array [ 1, 2 ])[0]
compiled: [
"SCScript(function($this, $SC) {",
" return $SC('Array').newFrom($SC.Array([",
" return $SC('Array')._newFrom($SC.Array([",
" $SC.Integer(1),",
" $SC.Integer(2),",
" ])).at($SC.Integer(0));",
Expand All @@ -5938,7 +5938,7 @@
},
method: {
type: Syntax.Identifier,
name: "newFrom",
name: "_newFrom",
range: [ 6, 6 ],
loc: {
start: { line: 1, column: 6 },
Expand Down

0 comments on commit 67712c9

Please sign in to comment.