aboutsummaryrefslogtreecommitdiff
path: root/clojurescript
diff options
context:
space:
mode:
authorChouser <chouser@n01se.net>2008-09-16 03:08:49 +0000
committerChouser <chouser@n01se.net>2008-09-16 03:08:49 +0000
commit0857ce7475d4c16ee1f2cd550e0b281a1a51bd8e (patch)
treebecf180d8219ef42c468a7a0091515bd46ed18e7 /clojurescript
parent384245bfd53480891ca251bbb026560bac984586 (diff)
ClojureScript: fix locals names and removed *check-arity* (which was kinda borken anyway)
Diffstat (limited to 'clojurescript')
-rw-r--r--clojurescript/clj.js7
-rw-r--r--clojurescript/tojs.clj26
2 files changed, 17 insertions, 16 deletions
diff --git a/clojurescript/clj.js b/clojurescript/clj.js
index deaa9523..988173b6 100644
--- a/clojurescript/clj.js
+++ b/clojurescript/clj.js
@@ -52,7 +52,12 @@ clojure = {
}
}
},
- lang: {}
+ lang: {
+ Numbers: {
+ isPos: function(x) { return x > 0; },
+ dec: function(x) { return x - 1; }
+ }
+ }
};
clojure.lang.ArraySeq = function( _meta, a, i ) {
diff --git a/clojurescript/tojs.clj b/clojurescript/tojs.clj
index 64881f95..982ddcc2 100644
--- a/clojurescript/tojs.clj
+++ b/clojurescript/tojs.clj
@@ -12,7 +12,6 @@
(lvl v)
(str sb)))
-(def *arity-check* false)
(def *has-recur*)
(defmulti tojs (fn [e ctx] (class e)))
@@ -25,8 +24,8 @@
(str (tojs (.var e) ctx) "=" (tojs (.init e) ctx)))
(defn fnmethod [fm maxm ctx]
- (let [lm (into {} (map (fn [[lb lb] i] [lb (str (.name lb) "_" i)])
- (.locals fm) (iterate inc 0)))
+ (let [lm (into {} (for [[lb lb] (.locals fm)]
+ [lb (str (.name lb) "_" (.idx lb))]))
thisfn (some #(when (= (.name %) (:fnname ctx)) %) (keys lm))
[body has-recur] (binding [*has-recur* false]
[(tojs (.body fm)
@@ -62,19 +61,16 @@
manym (< 1 (count (.methods e)))
newctx (assoc ctx :fnname (.thisName e))]
(vstr ["(function("
- (vec (interpose "," (map #(vector (.name %) "_" (.idx %))
- (.reqParms maxm))))
+ (vec (interpose "," (for [lb (.reqParms maxm)]
+ [(.name lb) "_" (.idx lb)])))
"){\n"
(vec (for [fm (.methods e) :when (not= fm (.variadicMethod e))]
- [(when manym
- ["if(arguments.length==" (count (.reqParms fm)) "){\n"])
- (fnmethod fm maxm newctx)
- (when manym "}\n")]))
- (if (.variadicMethod e)
- [(fnmethod (.variadicMethod e) maxm newctx) "\n"]
- (when *arity-check*
- ["throw \"Wrong number of args passed to: "
- (.thisName e) "\";\n"]))
+ (if manym
+ ["if(arguments.length==" (count (.reqParms fm)) "){\n"
+ (fnmethod fm maxm newctx) "}\n"]
+ (fnmethod fm maxm newctx))))
+ (when (.variadicMethod e)
+ [(fnmethod (.variadicMethod e) maxm newctx) "\n"])
"})"])))
(defmethod tojs clojure.lang.Compiler$BodyExpr [e ctx]
@@ -289,4 +285,4 @@
;(simple-tests)
;(testboot)
-(filetojs "t01.cljs")
+(filetojs (first *command-line-args*))