diff options
author | Rich Hickey <richhickey@gmail.com> | 2006-05-08 22:21:41 +0000 |
---|---|---|
committer | Rich Hickey <richhickey@gmail.com> | 2006-05-08 22:21:41 +0000 |
commit | 73cee2f442cb69ef87facafadd385cc6a67018e0 (patch) | |
tree | 3597c552933bf3a4c1f0e3d7e92da6f5cf062491 /src | |
parent | 4d932c3722fb0d6c2fce8271c7190366c26a283e (diff) |
added static invoke
Diffstat (limited to 'src')
-rw-r--r-- | src/lisp/clojure.lisp | 63 | ||||
-rw-r--r-- | src/lisp/test.lisp | 13 |
2 files changed, 51 insertions, 25 deletions
diff --git a/src/lisp/clojure.lisp b/src/lisp/clojure.lisp index 7b62279d..2b8653db 100644 --- a/src/lisp/clojure.lisp +++ b/src/lisp/clojure.lisp @@ -749,34 +749,49 @@ (:expression (let* ((fexpr (@ :fexpr expr)) (global-binding? (eql :global-binding (@ :type fexpr))) + (host-symbol? (eql :host-symbol (@ :type fexpr))) (static-method? (will-be-static-method fexpr)) (args (@ :args expr))) - (when (not (or global-binding? static-method?)) - (format t "((IFn)")) - (emit :fn fexpr) - (when (not (or global-binding? static-method?)) - (format t ")")) - (unless static-method? - (format t ".invoke")) - (format t "(__tld") - (when static-method? - (let ((closes (@ :closes (first (@ :methods (@ :fn fexpr)))))) - (format t "~{, ~A~}" - (mapcar (lambda (b) - (binding-name b)) - closes)))) - (format t "~{, ~A~}" - (mapcar (lambda (e) - (emit-to-string - (emit :expression e))) - (ldiff args (nthcdr +MAX-POSITIONAL-ARITY+ args)))) - (when (nthcdr +MAX-POSITIONAL-ARITY+ args) - (format t ",new Object[]{~{~A~^,~}}" + (cond + (host-symbol? + (let* ((host-name (symbol-name (@ :symbol fexpr))) + (dot-pos (position #\. host-name :from-end t )) + (class-name (subseq host-name 0 dot-pos)) + (member-name (subseq host-name (1+ dot-pos)))) + (format t "Reflector.invokeStaticMethod(~S,~S,new Object[]{~{~A~^,~}})" + member-name + (fully-qualified-class-name class-name) + (mapcar (lambda (e) + (emit-to-string + (emit :expression e))) + args)))) + (t + (when (not (or global-binding? static-method?)) + (format t "((IFn)")) + (emit :fn fexpr) + (when (not (or global-binding? static-method?)) + (format t ")")) + (unless static-method? + (format t ".invoke")) + (format t "(__tld") + (when static-method? + (let ((closes (@ :closes (first (@ :methods (@ :fn fexpr)))))) + (format t "~{, ~A~}" + (mapcar (lambda (b) + (binding-name b)) + closes)))) + (format t "~{, ~A~}" (mapcar (lambda (e) (emit-to-string - (emit :expression e))) - (nthcdr +MAX-POSITIONAL-ARITY+ args)))) - (format t ")"))))) + (emit :expression e))) + (ldiff args (nthcdr +MAX-POSITIONAL-ARITY+ args)))) + (when (nthcdr +MAX-POSITIONAL-ARITY+ args) + (format t ",new Object[]{~{~A~^,~}}" + (mapcar (lambda (e) + (emit-to-string + (emit :expression e))) + (nthcdr +MAX-POSITIONAL-ARITY+ args)))) + (format t ")"))))))) diff --git a/src/lisp/test.lisp b/src/lisp/test.lisp index 2482fdf6..7da3e320 100644 --- a/src/lisp/test.lisp +++ b/src/lisp/test.lisp @@ -1,5 +1,8 @@ (in-module "clojure") +#+:JVM(import "java.lang" '(String Class)) +#+:CLI(import "System, mscorlib" '(String Type)) + (defn f0 ()) (defn f1 (x) x) @@ -121,4 +124,12 @@ '(1 2 3 (4 5))) (defn fcast () - (if (int 7) (char 17) (long 29999)))
\ No newline at end of file + (if (int 7) (char 17) (long 29999))) + +(defn fmem () + #+:JVM + (when (Class.forName "Object") + (String.valueOf 7)) + #+:CLI + (when (Type.GetType "Object") + (String.Intern "fred")))
\ No newline at end of file |