Last active
August 29, 2015 14:07
-
-
Save catharinejm/b1228a5ecc58fd66375c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (ns asm-test.test-class | |
| (:import [clojure.asm ClassWriter ClassVisitor Opcodes Type] | |
| [clojure.asm.commons GeneratorAdapter Method] | |
| [clojure.lang DynamicClassLoader Compiler RT])) | |
| (def cw (ClassWriter. ClassWriter/COMPUTE_MAXS)) | |
| (. cw (visit Opcodes/V1_5 Opcodes/ACC_PUBLIC | |
| "asm_test/test_class/TestClass" nil "java/lang/Object" (make-array String 0))) | |
| (let [m (Method. "doit" Type/VOID_TYPE (into-array Type [(Type/getType String)])) | |
| gen (GeneratorAdapter. (bit-or Opcodes/ACC_PUBLIC Opcodes/ACC_STATIC) | |
| m nil nil cw)] | |
| (.visitCode gen) | |
| (. gen push "clojure.core") | |
| (. gen push "*out*") | |
| (. gen invokeStatic (Type/getType clojure.lang.RT) (. Method getMethod "clojure.lang.Var var(String,String)")) | |
| (. gen invokeVirtual (Type/getType clojure.lang.Var) (. Method getMethod "java.lang.Object get()")) | |
| (. gen dup) | |
| (. gen checkCast (Type/getType java.io.PrintWriter)) | |
| (. gen loadArg 0) | |
| (. gen invokeVirtual (Type/getType java.io.PrintWriter) (. Method getMethod "void println(String)")) | |
| (.returnValue gen) | |
| (.endMethod gen)) | |
| (.visitEnd cw) | |
| (. @Compiler/LOADER (defineClass "asm_test.test_class.TestClass" (.toByteArray cw) nil)) | |
| (import 'asm_test.test_class.TestClass) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment