Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

integrate $.SegFunction and $.Function #53

Merged
merged 1 commit into from
Jun 11, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.42",
"version": "0.0.43",
"author": "Nao Yonamine <mohayonao@gmail.com>",
"homepage": "http://mohayonao.github.io/SCScript/",
"bugs": "https://github.com/mohayonao/SCScript/issues",
Expand Down
18 changes: 12 additions & 6 deletions src/sc/classlib/Collections/Array.js
Original file line number Diff line number Diff line change
Expand Up @@ -662,20 +662,26 @@ SCScript.install(function(sc) {
// TODO: implements source

spec.asUGenInput = function($for) {
return this.collect($.Function(function($_) {
return $_.asUGenInput($for);
return this.collect($.Function(function() {
return [ function($_) {
return $_.asUGenInput($for);
} ];
}));
};

spec.asAudioRateInput = function($for) {
return this.collect($.Function(function($_) {
return $_.asAudioRateInput($for);
return this.collect($.Function(function() {
return [ function($_) {
return $_.asAudioRateInput($for);
} ];
}));
};

spec.asControlInput = function() {
return this.collect($.Function(function($_) {
return $_.asControlInput();
return this.collect($.Function(function() {
return [ function($_) {
return $_.asControlInput();
} ];
}));
};

Expand Down
55 changes: 28 additions & 27 deletions src/sc/classlib/Collections/Array_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

require("./Array");

var $$ = sc.test.object;
var testCase = sc.test.testCase;

var $ = sc.lang.$;
Expand All @@ -12,7 +13,7 @@
before(function() {
SCArray = $("Array");
this.createInstance = function(source) {
return $.Array((source || []).map(sc.test.encode));
return $.Array((source || []).map($$));
};
});
it("#__tag", function() {
Expand All @@ -26,17 +27,17 @@
it("#valueOf", function() {
var instance, test;

instance = this.createInstance([ $.String("freq"), $.Integer(440) ]);
instance = this.createInstance([ $$("freq"), $$(440) ]);

test = instance.valueOf();
expect(test).to.be.a("JSArray").to.eql([ "freq", 440 ]);
});
it(".newClear", function() {
var test = SCArray.newClear($.Integer(4));
var test = SCArray.newClear($$(4));
expect(test).to.be.a("SCArray").that.eqls([ null, null, null, null ]);
});
it(".with", function() {
var test = SCArray.with($.Integer(0), $.Integer(1), $.Integer(2));
var test = SCArray.with($$(0), $$(1), $$(2));
expect(test).to.be.a("SCArray").that.eqls([ 0, 1, 2 ]);
});
it("#reverse", function() {
Expand Down Expand Up @@ -707,25 +708,25 @@
var $ugen1, $ugen2, $ugen3;
var $for;

$elem1 = sc.test.object({
$elem1 = $$({
asUGenInput: this.spy(function() {
return $ugen1;
})
});
$elem2 = sc.test.object({
$elem2 = $$({
asUGenInput: this.spy(function() {
return $ugen2;
})
});
$elem3 = sc.test.object({
$elem3 = $$({
asUGenInput: this.spy(function() {
return $ugen3;
})
});
$ugen1 = sc.test.object();
$ugen2 = sc.test.object();
$ugen3 = sc.test.object();
$for = sc.test.object();
$ugen1 = $$();
$ugen2 = $$();
$ugen3 = $$();
$for = $$();

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

Expand All @@ -741,25 +742,25 @@
var $ugen1, $ugen2, $ugen3;
var $for;

$elem1 = sc.test.object({
$elem1 = $$({
asAudioRateInput: this.spy(function() {
return $ugen1;
})
});
$elem2 = sc.test.object({
$elem2 = $$({
asAudioRateInput: this.spy(function() {
return $ugen2;
})
});
$elem3 = sc.test.object({
$elem3 = $$({
asAudioRateInput: this.spy(function() {
return $ugen3;
})
});
$ugen1 = sc.test.object();
$ugen2 = sc.test.object();
$ugen3 = sc.test.object();
$for = sc.test.object();
$ugen1 = $$();
$ugen2 = $$();
$ugen3 = $$();
$for = $$();

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

Expand All @@ -774,24 +775,24 @@
var $elem1, $elem2, $elem3;
var $ugen1, $ugen2, $ugen3;

$elem1 = sc.test.object({
$elem1 = $$({
asControlInput: this.spy(function() {
return $ugen1;
})
});
$elem2 = sc.test.object({
$elem2 = $$({
asControlInput: this.spy(function() {
return $ugen2;
})
});
$elem3 = sc.test.object({
$elem3 = $$({
asControlInput: this.spy(function() {
return $ugen3;
})
});
$ugen1 = sc.test.object();
$ugen2 = sc.test.object();
$ugen3 = sc.test.object();
$ugen1 = $$();
$ugen2 = $$();
$ugen3 = $$();

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

Expand Down Expand Up @@ -836,9 +837,9 @@
var $mul, $add;

spy = this.spy(sc.test.func);
$mul = sc.test.object();
$add = sc.test.object();
this.stub(sc.lang.klass, "get").withArgs("MulAdd").returns(sc.test.object({
$mul = $$();
$add = $$();
this.stub(sc.lang.klass, "get").withArgs("MulAdd").returns($$({
new: spy
}));

Expand Down
48 changes: 32 additions & 16 deletions src/sc/classlib/Collections/ArrayedCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,14 @@ SCScript.install(function(sc) {
$find = $find.asArray();
$replace = $replace.asArray();
$.Function(function() {
return ($index = $array.find($find)).notNil();
return [ function() {
return ($index = $array.find($find)).notNil();
} ];
}).while($.Function(function() {
$out = $out ["++"] ($array.keep($index)) ["++"] ($replace);
$array = $array.drop($index ["+"] ($find.size()));
return [ function() {
$out = $out ["++"] ($array.keep($index)) ["++"] ($replace);
$array = $array.drop($index ["+"] ($find.size()));
} ];
}));

return $out ["++"] ($array);
Expand Down Expand Up @@ -432,8 +436,10 @@ SCScript.install(function(sc) {
this._ThrowIfImmutable();

if ($aCollection.isCollection().__bool__()) {
$aCollection.do($.Function(function($item) {
$this._.push($this.__elem__($item));
$aCollection.do($.Function(function() {
return [ function($item) {
$this._.push($this.__elem__($item));
} ];
}));
} else {
this.add($aCollection);
Expand Down Expand Up @@ -612,8 +618,10 @@ SCScript.install(function(sc) {

$minItem = this.minItem();
$maxItem = this.maxItem();
return this.collect($.Function(function($el) {
return $el.$("linlin", [ $minItem, $maxItem, $min, $max ]);
return this.collect($.Function(function() {
return [ function($el) {
return $el.$("linlin", [ $minItem, $maxItem, $min, $max ]);
} ];
}));
}, "min=0.0; max=1.0");

Expand Down Expand Up @@ -660,9 +668,11 @@ SCScript.install(function(sc) {
$flat = this.flat();

return $another.deepCollect($.Integer(0x7FFFFFFF), $.Function(function() {
var $item = $flat.perform($indexing, $index);
$index = $index.__inc__();
return $item;
return [ function() {
var $item = $flat.perform($indexing, $index);
$index = $index.__inc__();
return $item;
} ];
}));
}, "another; indexing=\\wrapAt");

Expand All @@ -680,8 +690,10 @@ SCScript.install(function(sc) {
return this.at($int_0).unbubble($depth, $levels.__dec__());
}

return this.collect($.Function(function($item) {
return $item.unbubble($depth.__dec__());
return this.collect($.Function(function() {
return [ function($item) {
return $item.unbubble($depth.__dec__());
} ];
}));
}, "depth=0; levels=1");

Expand All @@ -693,8 +705,10 @@ SCScript.install(function(sc) {
return $.Array([ this.bubble($depth, $levels.__dec__()) ]);
}

return this.collect($.Function(function($item) {
return $item.bubble($depth.__dec__(), $levels);
return this.collect($.Function(function() {
return [ function($item) {
return $item.bubble($depth.__dec__(), $levels);
} ];
}));
}, "depth=0; levels=1");

Expand All @@ -719,8 +733,10 @@ SCScript.install(function(sc) {
}

cuts = $$cuts._.slice(1);
return $list.collect($.Function(function($item) {
return $item.$("slice", cuts);
return $list.collect($.Function(function() {
return [ function($item) {
return $item.$("slice", cuts);
} ];
})).unbubble();
}, "*cuts");

Expand Down
21 changes: 11 additions & 10 deletions src/sc/classlib/Collections/ArrayedCollection_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

require("./ArrayedCollection");

var $$ = sc.test.object;
var testCase = sc.test.testCase;

var $ = sc.lang.$;
Expand All @@ -13,7 +14,7 @@
before(function() {
SCArrayedCollection = $("ArrayedCollection");
this.createInstance = function(source, immutable) {
var instance = $.Array((source || []).map(sc.test.encode), !!immutable);
var instance = $.Array((source || []).map($$), !!immutable);
var testMethod = this.test.title.substr(1);
sc.test.setSingletonMethod(instance, "ArrayedCollection", testMethod);
return instance;
Expand All @@ -23,7 +24,7 @@
var instance, test;
var $obj;

$obj = sc.test.object();
$obj = $$();

instance = this.createInstance();

Expand Down Expand Up @@ -518,7 +519,7 @@
var $array;

spy = this.spy(sc.test.func);
$array = sc.test.object();
$array = $$();

instance = this.createInstance([ 1, 2, 3 ]);
instance.overWrite = spy;
Expand Down Expand Up @@ -974,7 +975,7 @@
var $function;

iter = {};
$function = sc.test.object();
$function = $$();
this.stub(iterator, "array$do", function() {
return iter;
});
Expand All @@ -992,7 +993,7 @@
var $function;

iter = {};
$function = sc.test.object();
$function = $$();
this.stub(iterator, "array$reverseDo", function() {
return iter;
});
Expand Down Expand Up @@ -1298,7 +1299,7 @@
it("#valueOf", function() {
var instance, test, expected;

instance = SCInt8Array.newFrom(sc.test.encode([ 0, 255, 256 ]));
instance = SCInt8Array.newFrom($$([ 0, 255, 256 ]));
test = instance.valueOf();

expected = new Int8Array([ 0, -1, 0 ]);
Expand All @@ -1314,7 +1315,7 @@
it("#valueOf", function() {
var instance, test, expected;

instance = SCInt16Array.newFrom(sc.test.encode([ 0, 65535, 65536 ]));
instance = SCInt16Array.newFrom($$([ 0, 65535, 65536 ]));
test = instance.valueOf();

expected = new Int16Array([ 0, -1, 0 ]);
Expand All @@ -1330,7 +1331,7 @@
it("#valueOf", function() {
var instance, test, expected;

instance = SCInt32Array.newFrom(sc.test.encode([ 0, 4294967295, 4294967296 ]));
instance = SCInt32Array.newFrom($$([ 0, 4294967295, 4294967296 ]));
test = instance.valueOf();

expected = new Int32Array([ 0, -1, 0 ]);
Expand All @@ -1346,7 +1347,7 @@
it("#valueOf", function() {
var instance, test, expected;

instance = SCFloatArray.newFrom(sc.test.encode([ 0, 0.5, -0.5 ]));
instance = SCFloatArray.newFrom($$([ 0, 0.5, -0.5 ]));
test = instance.valueOf();

expected = new Float32Array([ 0, 0.5, -0.5 ]);
Expand All @@ -1362,7 +1363,7 @@
it("#valueOf", function() {
var instance, test, expected;

instance = SCDoubleArray.newFrom(sc.test.encode([ 0, 0.5, -0.5 ]));
instance = SCDoubleArray.newFrom($$([ 0, 0.5, -0.5 ]));
test = instance.valueOf();

expected = new Float64Array([ 0, 0.5, -0.5 ]);
Expand Down
Loading