Skip to content

Commit

Permalink
browser compatibility fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
santoshrajan committed Sep 14, 2012
1 parent a3aeeda commit 45c42d0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/ls.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var banner = "// Generated by LispyScript v" + this.version + "\n",
isWhitespace = /\s/, isWhitespace = /\s/,
isFunction = /^function/, isFunction = /^function/,
validName = /^[a-zA-Z_$][0-9a-zA-Z_$]*$/, validName = /^[a-zA-Z_$][0-9a-zA-Z_$]*$/,
noReturn = /^var|set|throw\b/, noReturn = /^var\b|^set\b|^throw\b/,
indent = -4, indent = -4,
keywords = {}, keywords = {},
macros = {}, macros = {},
Expand Down
24 changes: 15 additions & 9 deletions src/macros.ls
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -16,23 +16,26 @@
(= (typeof ~obj) "boolean")) (= (typeof ~obj) "boolean"))


(macro number? (obj) (macro number? (obj)
(= (toString.call ~obj) "[object Number]")) (= (Object.prototype.toString.call ~obj) "[object Number]"))


(macro string? (obj) (macro string? (obj)
(= (toString.call ~obj) "[object String]")) (= (Object.prototype.toString.call ~obj) "[object String]"))


(macro array? (obj) (macro array? (obj)
(= (toString.call ~obj) "[object Array]")) (= (Object.prototype.toString.call ~obj) "[object Array]"))


(macro object? (obj) (macro object? (obj)
((function (obj) ((function (obj)
(= obj (Object obj))) ~obj)) (= obj (Object obj))) ~obj))


(macro function? (obj) (macro function? (obj)
(= (toString.call ~obj) "[object Function]")) (= (Object.prototype.toString.call ~obj) "[object Function]"))


(macro arguments? (obj) (macro arguments? (obj)
(= (toString.call ~obj) "[object Arguments]")) ((function (obj)
(if (= (Object.prototype.toString.call obj) "[object Arguments]")
true
(! (! (&& obj obj.callee))))) ~obj))


(macro do (rest...) (macro do (rest...)
((function () ~rest...))) ((function () ~rest...)))
Expand All @@ -50,7 +53,7 @@


(macro eachKey (rest...) (macro eachKey (rest...)
((function (o f s) ((function (o f s)
(javascript "var k;if(Object.keys){k=Object.keys(o)}else{k=[];for(var i in obj)k.push(i)}") (javascript "var k;if(Object.keys){k=Object.keys(o)}else{k=[];for(var i in o)k.push(i)}")
(each k (each k
(function (elem) (function (elem)
(f.call s (get elem o) elem o)))) ~rest...)) (f.call s (get elem o) elem o)))) ~rest...))
Expand Down Expand Up @@ -130,13 +133,16 @@
(var _curr 0) (var _curr 0)
(var next (var next
(function () (function ()
(get _curr++ actions))) (var ne (get _curr++ actions))
(if ne
ne
(throw "Call to (next) beyond sequence."))))
(var actions (new Array ~rest...)) (var actions (new Array ~rest...))
~@init ~@init
((next))))))) ((next)))))))


(macro assert (cond message) (macro assert (cond message)
(if (= true ~cond) (if (= true ~cond)
(console.log (+ "Passed - " ~message)) (str "Passed - " ~message "\n")
(throw (+ "Failed - " ~message)))) (str "Failed - " ~message "\n")))


0 comments on commit 45c42d0

Please sign in to comment.