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

add Object#__tag__ #7

Merged
merged 2 commits into from
Mar 22, 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
9 changes: 6 additions & 3 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,16 +340,19 @@ module.exports = function(grunt) {
}

function makeBrowserTest() {
var tests, tmpl;
var tmpl, tests, consts;

tmpl = grunt.file.read("assets/index.tmpl");

tests = grunt.file.expand("src/sc/**/*_test.js");
tests = tests.sort(testSorter).map(function(filepath) {
return " <script src=\"../../../" + filepath + "\"></script>";
});

tmpl = grunt.file.read("assets/index.tmpl");
tmpl = tmpl.replace("#{TESTS}", tests.join("\n"));

consts = grunt.file.read("src/const.js").trim();
tmpl = tmpl.replace("#{CONSTS}", consts);

grunt.file.write("docs/report/test/index.html", tmpl);
}

Expand Down
3 changes: 3 additions & 0 deletions assets/index.tmpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Online Test Suite - SCScript</title>
<link rel="stylesheet" href="../../../assets/mocha.css">
<script src="../../../assets/jquery.min.js"></script>
<script src="../../../assets/mocha.js"></script>
Expand All @@ -15,6 +17,7 @@
SCScript.install(function(sc) {
window.sc = sc;
});
#{CONSTS}
mocha.setup("bdd");
$(function() {
mocha.run();
Expand Down
29 changes: 28 additions & 1 deletion 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.4" };
var sc = { VERSION: "0.0.5" };

// src/sc/sc.js
(function(sc) {
Expand Down Expand Up @@ -252,6 +252,9 @@ var sc = { VERSION: "0.0.4" };
js: function() {
return this._raw;
},
__tag__: function() {
return 1;
},
__num__: function() {
return 0;
},
Expand Down Expand Up @@ -322,6 +325,9 @@ var sc = { VERSION: "0.0.4" };
constructor: Integer,
$new: function() {
throw new Error("Integer.new is illegal, should use literal.");
},
__tag__: function() {
return 2;
}
});

Expand Down Expand Up @@ -355,6 +361,9 @@ var sc = { VERSION: "0.0.4" };
constructor: Float,
$new: function() {
throw new Error("Float.new is illegal, should use literal.");
},
__tag__: function() {
return 9;
}
});

Expand Down Expand Up @@ -395,6 +404,9 @@ var sc = { VERSION: "0.0.4" };
$new: function() {
throw new Error("Symbol.new is illegal, should use literal.");
},
__tag__: function() {
return 3;
},
__str__: function() {
return this._raw;
}
Expand Down Expand Up @@ -434,6 +446,9 @@ var sc = { VERSION: "0.0.4" };
constructor: Nil,
$new: function() {
throw new Error("Nil.new is illegal, should use literal.");
},
__tag__: function() {
return 5;
}
});

Expand Down Expand Up @@ -496,6 +511,9 @@ var sc = { VERSION: "0.0.4" };
$new: function() {
throw new Error("Char.new is illegal, should use literal.");
},
__tag__: function() {
return 4;
},
__str__: function() {
return this._raw;
}
Expand Down Expand Up @@ -545,13 +563,19 @@ var sc = { VERSION: "0.0.4" };
constructor: True,
$new: function() {
throw new Error("True.new is illegal, should use literal.");
},
__tag__: function() {
return 7;
}
});

sc.lang.klass.define("False", "Boolean", {
constructor: False,
$new: function() {
throw new Error("False.new is illegal, should use literal.");
},
__tag__: function() {
return 6;
}
});

Expand Down Expand Up @@ -616,6 +640,9 @@ var sc = { VERSION: "0.0.4" };
$new: function() {
throw new Error("String.new is illegal, should use literal.");
},
__tag__: function() {
return 10;
},
__str__: function() {
return this._raw;
}
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.4",
"version": "0.0.5",
"author": "Nao Yonamine <mohayonao@gmail.com>",
"homepage": "http://mohayonao.github.io/SCScript/",
"bugs": "https://github.com/mohayonao/SCScript/issues",
Expand Down
27 changes: 26 additions & 1 deletion src/const.js
Original file line number Diff line number Diff line change
@@ -1 +1,26 @@
module.exports = {};
(function(global) {
"use strict";

var C = {
TAG_NOT_INITIALIZED: 0x00,
TAG_OBJ: 0x01,
TAG_INT: 0x02,
TAG_SYM: 0x03,
TAG_CHAR: 0x04,
TAG_NIL: 0x05,
TAG_FALSE: 0x06,
TAG_TRUE: 0x07,
TAG_PTR: 0x08,
TAG_FLOAT: 0x09,
TAG_STR: 0x0a,
TAG_UNUSED: 0xff,
};

if (typeof global.sc !== "undefined") {
global.sc.C = C;
}
if (typeof module !== "undefined") {
module.exports = C;
}

})(this.self||global);
3 changes: 3 additions & 0 deletions src/sc/lang/classlib/Collections/String.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
$new: function() {
throw new Error("String.new is illegal, should use literal.");
},
__tag__: function() {
return sc.C.TAG_STR;
},
__str__: function() {
return this._raw;
}
Expand Down
6 changes: 6 additions & 0 deletions src/sc/lang/classlib/Collections/String_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ describe("class String", function() {
expect(test).to.be.equal("str");
});
});
describe("#__tag__", function() {
it("should return TAG_STR", function() {
var test = $SC.String("str").__tag__();
expect(test).to.be.equal(sc.C.TAG_STR);
});
});
describe("#__str__", function() {
it("should return JavaScript string", function() {
var test = $SC.String("str").__str__();
Expand Down
6 changes: 6 additions & 0 deletions src/sc/lang/classlib/Core/Boolean.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,19 @@
constructor: True,
$new: function() {
throw new Error("True.new is illegal, should use literal.");
},
__tag__: function() {
return sc.C.TAG_TRUE;
}
});

sc.lang.klass.define("False", "Boolean", {
constructor: False,
$new: function() {
throw new Error("False.new is illegal, should use literal.");
},
__tag__: function() {
return sc.C.TAG_FALSE;
}
});

Expand Down
12 changes: 12 additions & 0 deletions src/sc/lang/classlib/Core/Boolean_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ describe("class True", function() {
expect(test).to.be.equal(true);
});
});
describe("#__tag__", function() {
it("should return TAG_TRUE", function() {
var test = $SC.True().__tag__();
expect(test).to.be.equal(sc.C.TAG_TRUE);
});
});
});
describe("class False", function() {
describe("$SC.False", function() {
Expand Down Expand Up @@ -88,4 +94,10 @@ describe("class False", function() {
expect(test).to.be.equal(false);
});
});
describe("#__tag__", function() {
it("should return TAG_FALSE", function() {
var test = $SC.False().__tag__();
expect(test).to.be.equal(sc.C.TAG_FALSE);
});
});
});
3 changes: 3 additions & 0 deletions src/sc/lang/classlib/Core/Char.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
$new: function() {
throw new Error("Char.new is illegal, should use literal.");
},
__tag__: function() {
return sc.C.TAG_CHAR;
},
__str__: function() {
return this._raw;
}
Expand Down
6 changes: 6 additions & 0 deletions src/sc/lang/classlib/Core/Char_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ describe("class Char", function() {
expect(test).to.be.equal("a");
});
});
describe("#__tag__", function() {
it("should return TAG_CHAR", function() {
var test = $SC.Char("a").__tag__();
expect(test).to.be.equal(sc.C.TAG_CHAR);
});
});
describe("#__str__", function() {
it("should return JavaScript string", function() {
var test = $SC.Char("a").__str__();
Expand Down
3 changes: 3 additions & 0 deletions src/sc/lang/classlib/Core/Nil.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
constructor: Nil,
$new: function() {
throw new Error("Nil.new is illegal, should use literal.");
},
__tag__: function() {
return sc.C.TAG_NIL;
}
});

Expand Down
6 changes: 6 additions & 0 deletions src/sc/lang/classlib/Core/Nil_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,10 @@ describe("class Nil", function() {
expect(test).to.be.equal(null);
});
});
describe("#__tag__", function() {
it("should return TAG_NIL", function() {
var test = $SC.Nil().__tag__();
expect(test).to.be.equal(sc.C.TAG_NIL);
});
});
});
3 changes: 3 additions & 0 deletions src/sc/lang/classlib/Core/Object.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
js: function() {
return this._raw;
},
__tag__: function() {
return sc.C.TAG_OBJ;
},
__num__: function() {
return 0;
},
Expand Down
6 changes: 6 additions & 0 deletions src/sc/lang/classlib/Core/Object_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ describe("class Object", function() {
expect(test).to.be.equal(instance);
});
});
describe("#__tag__", function() {
it("should return TAG_OBJ", function() {
var test = Object.new().__tag__();
expect(test).to.be.equal(sc.C.TAG_OBJ);
});
});
describe("#__num__", function() {
it("should return 0 as JavaScript number", function() {
var test = Object.new().__num__();
Expand Down
3 changes: 3 additions & 0 deletions src/sc/lang/classlib/Core/Symbol.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
$new: function() {
throw new Error("Symbol.new is illegal, should use literal.");
},
__tag__: function() {
return sc.C.TAG_SYM;
},
__str__: function() {
return this._raw;
}
Expand Down
6 changes: 6 additions & 0 deletions src/sc/lang/classlib/Core/Symbol_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ describe("class Symbol", function() {
expect(test).to.be.equal("sym");
});
});
describe("#__tag__", function() {
it("should return TAG_SYM", function() {
var test = $SC.Symbol("sym").__tag__();
expect(test).to.be.equal(sc.C.TAG_SYM);
});
});
describe("#__str__", function() {
it("should return JavaScript string", function() {
var test = $SC.Symbol("sym").__str__();
Expand Down
3 changes: 3 additions & 0 deletions src/sc/lang/classlib/Math/Float.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
constructor: Float,
$new: function() {
throw new Error("Float.new is illegal, should use literal.");
},
__tag__: function() {
return sc.C.TAG_FLOAT;
}
});

Expand Down
6 changes: 6 additions & 0 deletions src/sc/lang/classlib/Math/Float_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,10 @@ describe("class Float", function() {
expect(test).to.be.equal(2014.0322);
});
});
describe("#__tag__", function() {
it("should return TAG_FLOAT", function() {
var test = $SC.Float(2014.0323).__tag__();
expect(test).to.be.equal(sc.C.TAG_FLOAT);
});
});
});
3 changes: 3 additions & 0 deletions src/sc/lang/classlib/Math/Integer.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
constructor: Integer,
$new: function() {
throw new Error("Integer.new is illegal, should use literal.");
},
__tag__: function() {
return sc.C.TAG_INT;
}
});

Expand Down
6 changes: 6 additions & 0 deletions src/sc/lang/classlib/Math/Integer_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,10 @@ describe("class Integer", function() {
expect(test).to.be.equal(2014);
});
});
describe("#__tag__", function() {
it("should return TAG_INT", function() {
var test = $SC.Integer(2014).__tag__();
expect(test).to.be.equal(sc.C.TAG_INT);
});
});
});