Changeset 15066
- Timestamp:
- 06/09/17 19:26:28 (6 years ago)
- Location:
- trunk/abcl/contrib/jss
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/abcl/contrib/jss/README.markdown
r14587 r15066 53 53 An interactive restart is available to resolve class ambiguity. 54 54 55 Static calls are possible as well with the #" macro, but the56 first argument MUST BE A SYMBOL to distinguish 55 Static calls are possible as well with the SHARPSIGN-QUOTATION_MARK 56 macro, but the first argument *must* be a symbol to distinguish 57 57 58 58 (#"getProperties" "java.lang.System") … … 97 97 the moment (lazy) 98 98 99 (japropos string) finds all class names matching string 99 (japropos string) 100 100 101 (jcmn class-name) lists the names of all methods for the class 101 finds all class names matching STRING. 102 102 103 (jcmn class-name) 104 105 lists the names of all methods for the CLASS-NAME. 106 107 Java static fields may be addressed via the SHARPSIGN-QUOTATION_MARK macro as 108 109 (#"{java.lang.System}.{fileSeparator}") 110 111 ### Javaparser 112 113 On the reference of the JAVAPARSER system, one may use a Java DSL to 114 specify invocation and chains: 115 116 (asdf:make :javaparser) 117 (#"'#1"new ByteBuddy() 118 .subclass(Object.class,t) 119 .method(ElementMatchers.named("toString")) 120 .intercept(FixedValue.value("Hello World!")) 121 .make() 122 .load(getClass().getClassLoader()) 123 .getLoaded()" 124 103 125 Compatibility 104 126 ------------- … … 134 156 <> dc:created "2005" ; 135 157 dc:author "Mark <evenson.not.org@gmail.com>"; 136 dc:revised "0 6-DEC-2012" ;137 <> abcl:documents <urn:abcl.org/release/1.3.0-dev/contrib/jss#3.0.5" .158 dc:revised "09-JUN-2017" ; 159 asdf:long-description <urn:abcl.org/release/1.5.0/contrib/jss/README.markdown#3.3.0>" . 138 160 139 161 -
trunk/abcl/contrib/jss/javaparser.lisp
r15065 r15066 66 66 (defun read-invoke/javaparser (stream char arg) 67 67 (if (eql arg 1) 68 (if (ignore-errors (jclass "com.github.javaparser.ParseStart")) ;; chosen randomly, TODO memoize 68 69 (if (ignore-errors 70 (jclass "com.github.javaparser.ParseStart")) ;; chosen randomly, TODO memoize 69 71 (read-sharp-java-expression stream) 70 72 ;; Deal with possiblity of not loading jar 71 73 (error "Cannot load javaparser code needed for the #1 macro")) 72 (progn 73 (unread-char char stream) 74 (let ((name (read stream))) 75 (if (or (find #\. name) (find #\{ name)) 76 (jss-transform-to-field name) 77 (let ((object-var (gensym)) 78 (args-var (gensym))) 79 `(lambda (,object-var &rest ,args-var) 80 (invoke-restargs ,name ,object-var ,args-var ,(eql arg 0))))))))) 74 (read-invoke stream char arg))) 81 75 (set-dispatch-macro-character #\# #\" 'read-invoke/javaparser)) 82 76 -
trunk/abcl/contrib/jss/jss.asd
r15046 r15066 3 3 :author "Alan Ruttenberg, Mark Evenson" 4 4 :long-description "<urn:abcl.org/release/1.5.0/contrib/jss#>" 5 :version "3. 2.4"5 :version "3.3.0" 6 6 :components ((:module base :pathname "" :serial t 7 7 :components ((:file "packages") -
trunk/abcl/contrib/jss/t/javaparser.lisp
r15065 r15066 1 1 (in-package :cl-user) 2 3 #+(or) ;;4 (in-package :jss)5 2 6 3 (defparameter expanded '(let ((jss::this jss::*object-for-this*)) … … 33 30 34 31 (prove:plan 1) 35 (proveis jss::source 36 jss::expanded) 32 (prove:is source expanded) 37 33 38 34 (prove:finalize) -
trunk/abcl/contrib/jss/t/jss-tests.lisp
r15065 r15066 1 1 (in-package :cl-user) 2 2 3 (defpackage jss-test 4 (:use :cl :cl-user :jss :prove)) 3 (prove:plan 6) 5 4 6 (in-package :jss-test) 7 8 (plan 6) 9 10 (is (read-from-string "#\"{bar}.{foo}\"") '(get-java-field bar foo t)) 11 (is (read-from-string "#\"q.bar.{foo}\"") '(get-java-field (load-time-value (find-java-class "q.bar")) foo t)) 12 (is (read-from-string "#\"{bar}.foo\"") '(get-java-field bar "foo" t)) 13 (is-error (read-from-string "#\".bar.foo\"") 'simple-error) 5 (prove:is 6 (read-from-string "#\"{bar}.{foo}\"") 7 '(get-java-field bar foo t)) 8 (prove:is 9 (read-from-string "#\"q.bar.{foo}\"") 10 '(get-java-field (load-time-value (find-java-class "q.bar")) foo t)) 11 (prove:is 12 (read-from-string "#\"{bar}.foo\"") 13 '(get-java-field bar "foo" t)) 14 (prove:is-error 15 (read-from-string "#\".bar.foo\"") 16 'simple-error) 14 17 ;;; http://abcl.org/trac/ticket/205 15 (is (with-constant-signature ((substring "substring")) (substring "01234" 2)) "234") 18 (prove:is 19 (with-constant-signature ((substring "substring")) 20 (substring "01234" 2)) "234") 16 21 ;;; http://abcl.org/trac/ticket/229 - note: version of test for this ticket was broken in tests.lisp 17 ( is (#"toString" (find "size"18 (#"getMethods" (find-java-class "java.util.Collections$UnmodifiableMap"))19 22 (prove:is (#"toString" 23 (find "size" (#"getMethods" (find-java-class "java.util.Collections$UnmodifiableMap")) 24 :test 'string-equal :key #"getName")) 20 25 (#"toString" (java::jmethod "java.util.Collections$UnmodifiableMap" "size" ))) 21 26 22 27 ;; test that optimized jss is much faster than unoptimized 23 (defun optimized-jss (count) 24 (loop repeat count do (#"compile" 'regex.Pattern ".*"))) 28 (let () 29 (defun optimized-jss (count) 30 (loop repeat count do (#"compile" 'regex.Pattern ".*"))) 31 (let ((jss::*inhibit-jss-optimization* t)) 32 (defun unoptimized-jss (count) 33 (loop repeat count do (#"compile" 'regex.Pattern ".*")))) 34 (defun just-loop (count) 35 (loop repeat count)) 36 (let ((jss::*inhibit-jss-optimization* nil)) 37 (compile 'just-loop) 38 (compile 'optimized-jss)) 39 (let ((jss::*inhibit-jss-optimization* t)) 40 (compile 'unoptimized-jss)) 25 41 26 (let ((jss::*inhibit-jss-optimization* t)) 27 (defun unoptimized-jss (count) 28 (loop repeat count do (#"compile" 'regex.Pattern ".*")))) 42 (defmacro timeit (&body body) 43 `(let ((start (#"currentTimeMillis" 'system))) 44 ,@body 45 (- (#"currentTimeMillis" 'system) start))) 29 46 30 (defun just-loop (count) 31 (loop repeat count)) 32 33 (let ((jss::*inhibit-jss-optimization* nil)) 34 (compile 'just-loop) 35 (compile 'optimized-jss)) 36 (let ((jss::*inhibit-jss-optimization* t)) 37 (compile 'unoptimized-jss)) 38 39 (defmacro timeit (&body body) 40 `(let ((start (#"currentTimeMillis" 'system))) 41 ,@body 42 (- (#"currentTimeMillis" 'system) start))) 43 44 45 (plan 1) 46 (is-type (let ((just-loop (timeit (just-loop 10000)))) 47 (prove:plan 1) 48 (prove:is-type (let ((just-loop (timeit (just-loop 10000)))) 47 49 (+ 0.0 48 50 (/ (- (timeit (optimized-jss 10000)) just-loop) 49 51 (- (timeit (unoptimized-jss 10000)) just-loop)))) 50 '(float 0 0.1)) 52 '(float 0 0.1) 53 "Testing JSS compiler optimizationâŠ")) 51 54 52 (p lan 2)55 (prove:plan 2) 53 56 (let* ((jss::*inhibit-jss-optimization* nil) 54 (optimized-jss (macroexpand (precompiler::precompile-form '(#"compile" 'regex.Pattern ".*") t)))) 57 (optimized-jss 58 (macroexpand (precompiler::precompile-form 59 '(#"compile" 'regex.Pattern ".*") t)))) 55 60 (let* ((jss::*inhibit-jss-optimization* t) 56 (unoptimized-jss (macroexpand (precompiler::precompile-form '(#"compile" 'regex.Pattern ".*") t)))) 57 (is (car optimized-jss) 'java:jstatic) 58 (is (caar unoptimized-jss) 'lambda))) 61 (unoptimized-jss 62 (macroexpand (precompiler::precompile-form '(#"compile" 'regex.Pattern ".*") t)))) 63 (prove:is (car optimized-jss) 'java:jstatic) 64 (prove:is (caar unoptimized-jss) 'lambda))) 59 65 60 ( finalize)66 (prove:finalize) 61 67
Note: See TracChangeset
for help on using the changeset viewer.