锁定老帖子 主题:Clojure Hacking Guide
精华帖 (11) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2010-07-11
最后修改:2010-07-11
这题目起的哗众取宠,其实只是想介绍下怎么查看Clojure动态生成的字节码,这对分析Clojure的内部实现很重要。
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
// ClassWriter cw = new ClassWriter(0); ClassVisitor cv = cw;
ClassVisitor cv = new TraceClassVisitor(new CheckClassAdapter(cw), new PrintWriter(System.out));
java clojure.main
user=> (+ 1 2)
compile 1
// class version 49.0 (49) // access flags 33 public class user$eval__4346 extends clojure/lang/AFunction { // compiled from: NO_SOURCE_FILE // debug info: SMAP eval__4346.java Clojure *S Clojure *F + 1 NO_SOURCE_FILE NO_SOURCE_PATH *L 0#1,1:0 *E // access flags 25 public final static Lclojure/lang/Var; const__0 // access flags 25 public final static Ljava/lang/Object; const__1 // access flags 25 public final static Ljava/lang/Object; const__2 // access flags 9 public static <clinit>()V L0 LINENUMBER 2 L0 LDC "clojure.core" LDC "+" INVOKESTATIC clojure/lang/RT.var (Ljava/lang/String;Ljava/lang/String;)Lclojure/lang/Var; CHECKCAST clojure/lang/Var PUTSTATIC user$eval__4346.const__0 : Lclojure/lang/Var; ICONST_1 INVOKESTATIC java/lang/Integer.valueOf (I)Ljava/lang/Integer; PUTSTATIC user$eval__4346.const__1 : Ljava/lang/Object; ICONST_2 INVOKESTATIC java/lang/Integer.valueOf (I)Ljava/lang/Integer; PUTSTATIC user$eval__4346.const__2 : Ljava/lang/Object; RETURN MAXSTACK = 0 MAXLOCALS = 0 // access flags 1 public <init>()V L0 LINENUMBER 2 L0 L1 ALOAD 0 INVOKESPECIAL clojure/lang/AFunction.<init> ()V L2 RETURN MAXSTACK = 0 MAXLOCALS = 0 // access flags 1 public invoke()Ljava/lang/Object; throws java/lang/Exception L0 LINENUMBER 2 L0 L1 LINENUMBER 2 L1 GETSTATIC user$eval__4346.const__1 : Ljava/lang/Object; GETSTATIC user$eval__4346.const__2 : Ljava/lang/Object; INVOKESTATIC clojure/lang/Numbers.add (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Number; L2 LOCALVARIABLE this Ljava/lang/Object; L0 L2 0 ARETURN MAXSTACK = 0 MAXLOCALS = 0 } 3
声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2010-07-12
建议加一个副标题 ---- 怎么查看Clojure动态生成的字节码
|
|
返回顶楼 | |
发表时间:2010-07-18
感觉很不错,研究一下。有没有对于asm的介绍啊
|
|
返回顶楼 | |
浏览 3712 次