aboutsummaryrefslogtreecommitdiff
path: root/clojurescript/clj.js
diff options
context:
space:
mode:
authorChouser <chouser@n01se.net>2008-10-15 05:23:21 +0000
committerChouser <chouser@n01se.net>2008-10-15 05:23:21 +0000
commit5e53e7aca850e8937bdbf0f0194371c50fa36258 (patch)
treea6f7f45d142e7693144549c31be2f7c16db73bcb /clojurescript/clj.js
parent7d343ae94fc925d2a37bae02978d0ec04f409d4e (diff)
ClojureScript: update for Clojure SVN 1067, plus other bug fixes.
Diffstat (limited to 'clojurescript/clj.js')
-rw-r--r--clojurescript/clj.js68
1 files changed, 45 insertions, 23 deletions
diff --git a/clojurescript/clj.js b/clojurescript/clj.js
index 11f84ac9..887aade5 100644
--- a/clojurescript/clj.js
+++ b/clojurescript/clj.js
@@ -26,25 +26,30 @@ clojure = {
}
},
lang: {
- Namespace: function( m ) { clojure.JS.merge( this, m || {} ); }
+ Namespace: function( n, m ) {
+ this.name = n;
+ clojure.JS.merge( this, m || {} );
+ }
}
};
clojure.JS.Class.constructor = clojure.JS.Class;
+clojure.JS.Class.classset = { Class: true };
if( ! clojure.JS.global["java"] ) {
- java = { lang: { String: {}, Character: {}, Class: {} },
+ java = { lang: { String: {}, Character: {}, Class: {}, Number: {},
+ Boolean: {} },
math: { BigDecimal: {} },
- util: { regex: { Pattern: {} } } };
+ util: { Collection: {}, Map: {}, Set: {}, regex: { Pattern: {} } } };
}
-clojure = new clojure.lang.Namespace({
+clojure = new clojure.lang.Namespace("clojure",{
in_ns: function(s) {
var i, nsparts = s.substring(1).split('.'),
base = clojure.JS.global;
for( i = 0; i < nsparts.length; ++i ) {
if( ! base[nsparts[i]] ) {
- base[nsparts[i]] = new clojure.lang.Namespace();
+ base[nsparts[i]] = new clojure.lang.Namespace(nsparts[i]);
}
base = base[nsparts[i]];
}
@@ -84,7 +89,7 @@ clojure = new clojure.lang.Namespace({
}
else {
s = clojure.seq( oldargs[ arglen - 1 ] );
- for( ; s && arglen < f.arity; s = s.rest() ) {
+ for( ; s && newargs.length < f.arity; s = s.rest() ) {
newargs.push( s.first() );
}
if( s )
@@ -213,7 +218,7 @@ clojure = new clojure.lang.Namespace({
throw ("count not supported on: " + (typeof x) + " " + x.constructor);
},
class_: function(o) {
- if( o === null )
+ if( o === null || o === undefined )
return null;
if( typeof o === clojure.JS.functionType && ! ("constructor" in o) )
return java.lang.Class;
@@ -282,7 +287,7 @@ clojure = new clojure.lang.Namespace({
},
definterface: function( pkg, name, implement ) {
var cls = pkg[ name ] = {};
- clojure.JS.implement( cls, name, implement );
+ clojure.JS.implement( cls, name, null, implement );
return cls;
},
defclass: function( pkg, name, opts ) {
@@ -308,6 +313,12 @@ clojure = new clojure.lang.Namespace({
return false; // builtin class that doesn't match?
return o.constructor.classset[ c.classname ];
},
+ relayMethod: function( method, jsclass, javaclass, ctor ) {
+ method.addMethod( jsclass, function(o,w) {
+ return (clojure.get( method.methodTable, javaclass )
+ .apply(null, [ctor ? ctor(o) : o, w]));
+ });
+ },
bitcount: function(n){
var rtn = 0;
for( ; n; n >>= 1) {
@@ -350,7 +361,12 @@ clojure = new clojure.lang.Namespace({
case java.lang.String:
case java.lang.Character:
case java.lang.Class:
+ case java.lang.Number:
+ case java.lang.Boolean:
case java.math.BigDecimal:
+ case java.util.Collection:
+ case java.util.Map:
+ case java.util.Set:
case java.util.regex.Pattern:
return 0x7A830001;
}
@@ -405,7 +421,14 @@ clojure = new clojure.lang.Namespace({
},
makeStringBuilder: function(s) {
return new clojure.JS.StringBuilder( s===undefined ? "" : s );
- }
+ },
+ className: function(c) {
+ if( "classname" in c )
+ return c.classname;
+ if( "name" in c )
+ return c.name;
+ return "" + c;
+ },
}
}
});
@@ -431,6 +454,8 @@ clojure.JS.defclass( clojure.JS, "String", {
}
});
+clojure.JS.defclass( clojure.lang, "Symbol", {});
+
clojure.JS.definterface( clojure.lang, "IObj" );
clojure.JS.defclass( clojure.lang, "Obj", {
@@ -1378,7 +1403,7 @@ clojure.JS.defclass( clojure.lang, "PersistentHashMap", {
return this;
if( newroot == null )
return this.empty();
- return new cloljure.lang.PersistentHashMap(
+ return new clojure.lang.PersistentHashMap(
this._meta, this._count-1, newroot );
},
count: function(){ return this._count; },
@@ -1556,7 +1581,7 @@ clojure.JS.defclass( clojure.lang.PersistentHashMap, "BitmapIndexedNode", {
return null;
newnodes = this.nodes.slice();
newnodes.splice( idx, 1 );
- return new BIN( bitmap & ~bit, newnodes, this.shift );
+ return new BIN( this.bitmap & ~bit, newnodes, this.shift );
}
newnodes = this.nodes.slice();
newnodes[ idx ] = n;
@@ -1876,21 +1901,14 @@ clojure.print_method = new clojure.lang.MultiFn(
function (x, writer){ return clojure.class_(x); },
clojure.keyword("","default"));
-clojure.print_method.addMethod( String, function(s,w) {
- return (clojure.get( clojure.print_method.methodTable, java.lang.String )
- .apply(null, [new clojure.JS.String(s), w]));
-});
-
-clojure.print_method.addMethod( java.lang.Class, function(c,w) {
- return clojure.print_method.apply( null, [""+c, w] );
-});
-
-clojure.print_method.addMethod( clojure.JS.Class, function(c,w) {
- return w.write( c.classname );
-});
+clojure.JS.relayMethod( clojure.print_method, Number, java.lang.Number );
+clojure.JS.relayMethod( clojure.print_method, String, java.lang.String,
+ function(o) { return new clojure.JS.String(o); } );
clojure.JS.def(clojure,"_STAR_print_readably_STAR_",true);
+clojure.JS.implement( clojure.lang.Namespace, "Namespace" );
+
clojure.lang.Namespace.find = function( s ) {
return clojure.JS.global[ s.substring(1) ];
};
@@ -1899,6 +1917,10 @@ clojure.lang.Namespace.prototype.getMappings = function() {
return this;
};
+clojure.lang.Namespace.prototype.hashCode = function() {
+ return clojure.hash( this.name );
+};
+
(function() {
var buf = [];
function write(s) {