Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
- add main.$currentThread
- fix constant values
- rename null -> nil
- README++
  • Loading branch information
mohayonao committed Jun 14, 2014
1 parent 761cb3f commit 1879353
Show file tree
Hide file tree
Showing 18 changed files with 97 additions and 69 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
SCSCRIPT
========
[![Build Status](https://travis-ci.org/mohayonao/SCScript.png?branch=master)](https://travis-ci.org/mohayonao/SCScript) [![Coverage Status](https://coveralls.io/repos/mohayonao/SCScript/badge.png?branch=master)](https://coveralls.io/r/mohayonao/SCScript?branch=master) [![Code Climate](https://codeclimate.com/github/mohayonao/SCScript.png)](https://codeclimate.com/github/mohayonao/SCScript) [![Dependency Status](https://david-dm.org/mohayonao/SCScript.png)](https://david-dm.org/mohayonao/SCScript)

JavaScript port of SuperCollider
[![Build Status](https://travis-ci.org/mohayonao/SCScript.png?branch=master)](https://travis-ci.org/mohayonao/SCScript)
[![Coverage Status](https://coveralls.io/repos/mohayonao/SCScript/badge.png?branch=master)](https://coveralls.io/r/mohayonao/SCScript?branch=master)
[![Code Climate](https://codeclimate.com/github/mohayonao/SCScript.png)](https://codeclimate.com/github/mohayonao/SCScript)
[![Dependency Status](https://david-dm.org/mohayonao/SCScript.png)](https://david-dm.org/mohayonao/SCScript)

JavaScript port of [SuperCollider](http://supercollider.sourceforge.net/)

work in progress..

Expand Down
1 change: 0 additions & 1 deletion demo/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
font-size: 14px;
font-weight: 400;
white-space: nowrap;
display: none;
}

#sidemenu h1 {
Expand Down
47 changes: 16 additions & 31 deletions src/const.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,24 @@
(function(global) {
"use strict";

var TYPE_NUM = 0x100;
var TYPE_BOOL = 0x200;
var TYPE_STR = 0x400;
var TYPE_SIG = 0x800;

var C = {
TYPE_NUM : TYPE_NUM,
TYPE_BOOL: TYPE_BOOL,
TYPE_STR : TYPE_STR,
TYPE_SIG : TYPE_SIG,

TAG_NOT_INITIALIZED: 0x00,
TAG_OBJ : 0x01,
TAG_INT : 0x02 | TYPE_BOOL | TYPE_NUM,
TAG_SYM : 0x03 | TYPE_STR,
TAG_CHAR : 0x04 | TYPE_STR,
TAG_NIL : 0x05 | TYPE_BOOL | TYPE_NUM,
TAG_FALSE : 0x06 | TYPE_BOOL | TYPE_NUM,
TAG_TRUE : 0x07 | TYPE_BOOL | TYPE_NUM,
TAG_PTR : 0x08,
TAG_FLOAT : 0x09 | TYPE_BOOL | TYPE_NUM,
TAG_STR : 0x0a | TYPE_STR,
TAG_ARRAY : 0x0b,
TAG_FUNCTION : 0x0c,
TAG_UNUSED : 0xff,

STATE_INIT : 0,
STATE_RUNNING : 3,
STATE_SUSPENDED: 5,
STATE_DONE : 6,
TAG_OBJ : 0,
TAG_INT : 1,
TAG_FLOAT : 2,
TAG_SYM : 3,
TAG_CHAR : 4,
TAG_NIL : 5,
TAG_BOOL : 6,
TAG_STR : 7,
TAG_FUNC : 8,
TAG_THREAD: 9,

STATE_LOOP_BREAK: 10,
STATE_PENDING : 20,
STATE_INIT : 0,
STATE_RUNNING : 3,
STATE_SUSPENDED : 5,
STATE_DONE : 6,
STATE_LOOP_BREAK: -1,
STATE_PENDING : -2,
};

if (typeof global.sc !== "undefined") {
Expand Down
8 changes: 0 additions & 8 deletions src/sc/classlib/Collections/Array_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,6 @@
return $.Array((source || []).map($$));
};
});
it("#__tag", function() {
var instance, test;

instance = this.createInstance();

test = instance.__tag;
expect(test).to.be.a("JSNumber").that.equals(sc.TAG_ARRAY);
});
it("#valueOf", function() {
var instance, test;

Expand Down
8 changes: 8 additions & 0 deletions src/sc/classlib/Collections/String_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@
return $.String(str || "str");
};
});
it("#__tag", function() {
var instance, test;

instance = this.createInstance();

test = instance.__tag;
expect(test).to.be.a("JSNumber").that.equals(sc.TAG_STR);
});
it("#__str__", function() {
var instance, test;

Expand Down
8 changes: 8 additions & 0 deletions src/sc/classlib/Core/Function_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@
}, def);
};
});
it("#__tag", function() {
var instance, test;

instance = this.createInstance();

test = instance.__tag;
expect(test).to.be.a("JSNumber").that.equals(sc.TAG_FUNC);
});
it.skip("<def", function() {
});
it(".new", function() {
Expand Down
8 changes: 8 additions & 0 deletions src/sc/classlib/Core/Nil_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@
return $.Nil();
};
});
it("#__tag", function() {
var instance, test;

instance = this.createInstance();

test = instance.__tag;
expect(test).to.be.a("JSNumber").that.equals(sc.TAG_NIL);
});
it("#__num__", function() {
var instance, test;

Expand Down
8 changes: 8 additions & 0 deletions src/sc/classlib/Core/Symbol_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@
return $.Symbol(value || "sym");
};
});
it("#__tag", function() {
var instance, test;

instance = this.createInstance();

test = instance.__tag;
expect(test).to.be.a("JSNumber").that.equals(sc.TAG_SYM);
});
it("#__sym__", function() {
var instance, test;

Expand Down
5 changes: 4 additions & 1 deletion src/sc/classlib/Core/Thread.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ SCScript.install(function(sc) {
var random = sc.libs.random;

sc.lang.klass.define("Thread : Stream", function(spec, utils) {
spec.__tag = sc.TAG_THREAD;

spec.constructor = function SCThread() {
this.__super__("Stream");
Expand All @@ -18,7 +19,7 @@ SCScript.install(function(sc) {
}, "func");

spec._init = function($func) {
if ($func.__tag !== sc.TAG_FUNCTION) {
if ($func.__tag !== sc.TAG_FUNC) {
throw new Error("Thread.init failed");
}
this._bytecode = $func._;
Expand Down Expand Up @@ -98,6 +99,8 @@ SCScript.install(function(sc) {
sc.lang.klass.define("Routine : Thread", function(spec, utils) {
var $nil = utils.$nil;

spec.__routine = true;

spec.constructor = function SCRoutine() {
this.__super__("Thread");
};
Expand Down
16 changes: 16 additions & 0 deletions src/sc/classlib/Core/Thread_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@
}));
};
});
it("#__tag", function() {
var instance, test;

instance = this.createInstance();

test = instance.__tag;
expect(test).to.be.a("JSNumber").that.equals(sc.TAG_THREAD);
});
it("<state", function() {
var instance, test;

Expand Down Expand Up @@ -131,6 +139,14 @@
}));
};
});
it("#__routine", function() {
var instance, test;

instance = this.createInstance();

test = instance.__routine;
expect(test).to.be.a("JSBoolean").that.is.true;
});
it(".new", function() {
var instance;

Expand Down
2 changes: 1 addition & 1 deletion src/sc/lang/compiler/codegen_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
body: [
{
type: Syntax.Literal,
value: "null",
value: "nil",
valueType: Token.NilLiteral
}
]
Expand Down
2 changes: 1 addition & 1 deletion src/sc/lang/compiler/lexer.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@
break;
case "nil":
type = Token.NilLiteral;
value = "null";
value = "nil";
break;
case "true":
type = Token.TrueLiteral;
Expand Down
2 changes: 1 addition & 1 deletion src/sc/lang/compiler/lexer_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@
"nil": [
{
type: Token.NilLiteral,
value: "null",
value: "nil",
range: [ 0, 3 ],
loc: {
start: { line: 1, column: 0 },
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 @@ -1448,7 +1448,7 @@
}
}

return Node.createLiteral({ value: "null", valueType: Token.NilLiteral });
return Node.createLiteral({ value: "nil", valueType: Token.NilLiteral });
};

SCParser.prototype.parseLabel = function() {
Expand Down
14 changes: 7 additions & 7 deletions src/sc/lang/compiler/test-cases.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
body: [
{
type: Syntax.Literal,
value: "null",
value: "nil",
valueType: Token.NilLiteral,
range: [ 0, 3 ],
loc: {
Expand Down Expand Up @@ -3130,7 +3130,7 @@
body: [
{
type: Syntax.Literal,
value: "null",
value: "nil",
valueType: Token.NilLiteral,
range: [ 17, 20 ],
loc: {
Expand Down Expand Up @@ -3239,7 +3239,7 @@
body: [
{
type: Syntax.Literal,
value: "null",
value: "nil",
valueType: Token.NilLiteral,
range: [ 21, 24 ],
loc: {
Expand Down Expand Up @@ -3296,7 +3296,7 @@
body: [
{
type: Syntax.Literal,
value: "null",
value: "nil",
valueType: Token.NilLiteral,
range: [ 15, 18 ],
loc: {
Expand Down Expand Up @@ -3676,7 +3676,7 @@
body: [
{
type: Syntax.Literal,
value: "null",
value: "nil",
valueType: Token.NilLiteral,
range: [ 76, 79 ],
loc: {
Expand All @@ -3703,7 +3703,7 @@
elements: [
{
type: Syntax.Literal,
value: "null",
value: "nil",
valueType: Token.NilLiteral,
range: [ 7, 10 ],
loc: {
Expand Down Expand Up @@ -4067,7 +4067,7 @@
},
right: {
type: Syntax.Literal,
value: "null",
value: "nil",
valueType: Token.NilLiteral,
range: [ 12, 15 ],
loc: {
Expand Down
14 changes: 6 additions & 8 deletions src/sc/lang/klass/constructors.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,24 @@
this.__super__("Object");
}
klass.define("Boolean", {
constructor: SCBoolean
constructor: SCBoolean,
__tag: sc.TAG_BOOL
});

function SCTrue() {
this.__super__("Boolean");
this._ = true;
}
klass.define("True : Boolean", {
constructor: SCTrue,
__tag: sc.TAG_TRUE
constructor: SCTrue
});

function SCFalse() {
this.__super__("Boolean");
this._ = false;
}
klass.define("False : Boolean", {
constructor: SCFalse,
__tag: sc.TAG_FALSE
constructor: SCFalse
});

klass.define("Magnitude", {
Expand Down Expand Up @@ -129,8 +128,7 @@
this.__super__("ArrayedCollection");
}
klass.define("Array : ArrayedCollection", {
constructor: SCArray,
__tag: sc.TAG_ARRAY
constructor: SCArray
});

function SCString() {
Expand Down Expand Up @@ -184,7 +182,7 @@
}
klass.define("Function : AbstractFunction", {
constructor: SCFunction,
__tag: sc.TAG_FUNCTION
__tag: sc.TAG_FUNC
});

function SCRef() {
Expand Down
8 changes: 5 additions & 3 deletions src/sc/lang/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
var $ = sc.lang.$;
var random = sc.libs.random;

main.$currentEnv = null;
main.$currentEnv = null;
main.$currentThread = null;

main.run = function(func) {
if (!initialize.done) {
Expand All @@ -28,7 +29,8 @@
return [];
}));

main.$currentEnv = $("Environment").new();
main.$currentEnv = $("Environment").new();
main.$currentThread = $process._$mainThread;

// $interpreter._$s = SCServer.default();

Expand Down Expand Up @@ -60,7 +62,7 @@
};

$.ThisThread = function() {
return main.$process.mainThread();
return main.$currentThread;
};

sc.lang.main = main;
Expand Down
5 changes: 2 additions & 3 deletions src/sc/test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,8 @@
var type;

if (isSCObject(obj)) {
switch (obj.__tag) {
case sc.TAG_FALSE: return "SCBoolean";
case sc.TAG_TRUE : return "SCBoolean";
if (obj.__tag === sc.TAG_BOOL) {
return "SCBoolean";
}
return "SC" + obj.__className;
}
Expand Down

0 comments on commit 1879353

Please sign in to comment.