diff options
author | Rich Hickey <richhickey@gmail.com> | 2006-05-04 12:45:53 +0000 |
---|---|---|
committer | Rich Hickey <richhickey@gmail.com> | 2006-05-04 12:45:53 +0000 |
commit | 6758d50fecc5b042a3d880ca9bf0fe17014aec1a (patch) | |
tree | 0f65e839a95a8e341ffed86b7955bfcce5711278 /src | |
parent | 2b24aa4ccdc69cd73878af135999c5487635c1c1 (diff) |
added string, number and char literals, RT.ch()
Diffstat (limited to 'src')
-rw-r--r-- | src/cli/runtime/RT.cs | 7 | ||||
-rw-r--r-- | src/lisp/clojure.lisp | 42 | ||||
-rw-r--r-- | src/lisp/test.lisp | 19 | ||||
-rw-r--r-- | src/org/clojure/runtime/RT.java | 5 |
4 files changed, 52 insertions, 21 deletions
diff --git a/src/cli/runtime/RT.cs b/src/cli/runtime/RT.cs index 0f2efee9..11aa7bda 100644 --- a/src/cli/runtime/RT.cs +++ b/src/cli/runtime/RT.cs @@ -71,7 +71,12 @@ public class RT }
}
-
+
+static public Object ch(char c)
+ {
+ return c;
+ }
+
static public Cons cons(Object x, Cons y)
{
return new Cons(x, y);
diff --git a/src/lisp/clojure.lisp b/src/lisp/clojure.lisp index 13386e0b..55693909 100644 --- a/src/lisp/clojure.lisp +++ b/src/lisp/clojure.lisp @@ -303,16 +303,7 @@ (defun get-next-id () (incf *next-id*)) -(defvar *texpr* (newobj :type :t)) -(defun analyze (context form) - "context - one of :top :return :statement :expression :fn" - (cond - ((consp form) (analyze-op context (first form) form)) - ((or (null form)(eql '|nil| form)) nil) - ((eql '|t| form) *texpr*) - ((symbolp form) (analyze-symbol context form)) - (t (newobj :type :literal :val form)))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; macros ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -372,6 +363,17 @@ ;(defmacro |block| (&body body) ; `(|let| nil ,@body)) +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; analyze and emit ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(defun analyze (context form) + "context - one of :top :return :statement :expression :fn" + (cond + ((consp form) (analyze-op context (first form) form)) + ((or (null form)(eql '|nil| form)) nil) + ((eql '|t| form) t) + ((symbolp form) (analyze-symbol context form)) + (t form))) + (defun analyze-op (context op form) (case op (|quote| (analyze-quote context form)) @@ -401,7 +403,8 @@ (defun emit (context expr) (cond ((null expr) (emit-nil context)) - (t (ccase (@ :type expr) + ((typep expr 'hash-table) ;objs + (ccase (@ :type expr) (:defn* (emit-defn* context expr)) (:fn* (emit-fn* context expr)) (:binding (emit-binding context expr)) @@ -419,7 +422,24 @@ (:loop (emit-loop context expr)) (:break (emit-break context expr)) (:try (emit-try context expr)) - (:bind(emit-bind context expr)))))) + (:bind(emit-bind context expr)))) + (t (emit-other context expr)))) + +(defun emit-other (context expr) + (ccase context + (:statement);no-op + (:return (emit-return expr)) + (:expression + (cond + ((null expr) (emit-nil context)) + ((eql t expr) (format t "RT.T")) + ((stringp expr) (format t "~S" expr)) + ((characterp expr) (format t "RT.ch('~A')" expr)) + ((numberp expr) + (case expr + (0 (format t "Num.ZERO")) + (1 (format t "Num.ONE")) + (t (format t "Num.from(~A)" expr)))))))) (defun emit-return (expr) (format t "return ") diff --git a/src/lisp/test.lisp b/src/lisp/test.lisp index d724da70..e9efc969 100644 --- a/src/lisp/test.lisp +++ b/src/lisp/test.lisp @@ -44,7 +44,7 @@ (defn fif (a b x y z) (if a (if (if x y z) - y + 0 z) b)) @@ -67,8 +67,8 @@ (and x y z))) (defn fset (x y z) - (set x a) - (set b y) + (set x 1) + (set b #\y) (if (set (:foo x) z) (set (.bar y) z) (set (foo x y) z))) @@ -94,8 +94,8 @@ (try (let ((ex x)) (try - (foo x) - (fred ex) + (foo x 2) + (fred ex "string") (bar x))) (foo x) (fred ex) @@ -103,12 +103,13 @@ (try (foo x) (fred ex) - (bar x))) + (bar x) + "foo")) (defn fbind (a b c x) - (bind ((x a) - (y b)) + (bind ((x t) + (y 17)) c) - (bind ((x a) + (bind ((x nil) (y b)) c))
\ No newline at end of file diff --git a/src/org/clojure/runtime/RT.java b/src/org/clojure/runtime/RT.java index 8f9fa679..75e16afb 100644 --- a/src/org/clojure/runtime/RT.java +++ b/src/org/clojure/runtime/RT.java @@ -67,6 +67,11 @@ static public Iter iter(Object coll) } +static public Character ch(char c) + { + return new Character(c); + } + static public Cons cons(Object x, Cons y) { return new Cons(x, y); |