aboutsummaryrefslogtreecommitdiff
path: root/coffee/printer.coffee
diff options
context:
space:
mode:
authorJoel Martin <github@martintribe.org>2014-11-08 16:56:36 -0600
committerJoel Martin <github@martintribe.org>2015-01-09 16:16:45 -0600
commit891c3f3b478292ad0bfca44b0dc098a2aecc9a5d (patch)
treed30c7923ffee7699cfca94af84f3be297448fff2 /coffee/printer.coffee
parent9b3362e86a57ed7f14c5fd018c37713185e0c154 (diff)
downloadmal-891c3f3b478292ad0bfca44b0dc098a2aecc9a5d.tar.gz
mal-891c3f3b478292ad0bfca44b0dc098a2aecc9a5d.zip
CoffeeScript: add all steps. Self-hosting.
Diffstat (limited to 'coffee/printer.coffee')
-rw-r--r--coffee/printer.coffee24
1 files changed, 24 insertions, 0 deletions
diff --git a/coffee/printer.coffee b/coffee/printer.coffee
new file mode 100644
index 0000000..7844416
--- /dev/null
+++ b/coffee/printer.coffee
@@ -0,0 +1,24 @@
+types = require "./types.coffee"
+
+exports.println = (args...) -> console.log(args.join(" ")) || null
+
+exports._pr_str = _pr_str = (obj, print_readably=true) ->
+ _r = print_readably
+ switch types._obj_type obj
+ when 'list' then '(' + obj.map((e) -> _pr_str(e,_r)).join(' ') + ')'
+ when 'vector' then '[' + obj.map((e) -> _pr_str(e,_r)).join(' ') + ']'
+ when 'hash-map'
+ ret = []
+ ret.push(_pr_str(k,_r), _pr_str(v,_r)) for k,v of obj
+ '{' + ret.join(' ') + '}'
+ when 'string'
+ if _r then '"' + (obj.replace(/\\/g, '\\\\')
+ .replace(/"/g, '\\"')
+ .replace(/\n/g, '\\n')) + '"'
+ else obj
+ when 'symbol' then obj.name
+ when 'nil' then 'nil'
+ when 'atom' then "(atom " + _pr_str(obj.val,_r) + ")"
+ else obj.toString()
+
+# vim: ts=2:sw=2