Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Compile Clojure regex literals.
Classfile /home/mark/src/clj-re/target/classes/clj_re/core$simple.class
Last modified 13-Jun-2018; size 1119 bytes
MD5 checksum 7a8f0ea3a3b22a33c335acffef1eda0a
Compiled from "core.clj"
public final class clj_re.core$simple extends clojure.lang.AFunction
minor version: 0
major version: 49
flags: ACC_PUBLIC, ACC_FINAL, ACC_SUPER
Constant pool:
#1 = Utf8 clj_re/core$simple
#2 = Class #1 // clj_re/core$simple
#3 = Utf8 clojure/lang/AFunction
#4 = Class #3 // clojure/lang/AFunction
#5 = Utf8 core.clj
#6 = Utf8 <init>
#7 = Utf8 ()V
#8 = NameAndType #6:#7 // "<init>":()V
#9 = Methodref #4.#8 // clojure/lang/AFunction."<init>":()V
#10 = Utf8 invokeStatic
#11 = Utf8 (Ljava/lang/Object;)Ljava/lang/Object;
#12 = Utf8 const__0
#13 = Utf8 Lclojure/lang/Var;
#14 = NameAndType #12:#13 // const__0:Lclojure/lang/Var;
#15 = Fieldref #2.#14 // clj_re/core$simple.const__0:Lclojure/lang/Var;
#16 = Utf8 clojure/lang/Var
#17 = Class #16 // clojure/lang/Var
#18 = Utf8 getRawRoot
#19 = Utf8 ()Ljava/lang/Object;
#20 = NameAndType #18:#19 // getRawRoot:()Ljava/lang/Object;
#21 = Methodref #17.#20 // clojure/lang/Var.getRawRoot:()Ljava/lang/Object;
#22 = Utf8 clojure/lang/IFn
#23 = Class #22 // clojure/lang/IFn
#24 = Utf8 const__1
#25 = Utf8 Ljava/lang/Object;
#26 = NameAndType #24:#25 // const__1:Ljava/lang/Object;
#27 = Fieldref #2.#26 // clj_re/core$simple.const__1:Ljava/lang/Object;
#28 = Utf8 invoke
#29 = Utf8 (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
#30 = NameAndType #28:#29 // invoke:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
#31 = InterfaceMethodref #23.#30 // clojure/lang/IFn.invoke:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
#32 = Utf8 x
#33 = NameAndType #10:#11 // invokeStatic:(Ljava/lang/Object;)Ljava/lang/Object;
#34 = Methodref #2.#33 // clj_re/core$simple.invokeStatic:(Ljava/lang/Object;)Ljava/lang/Object;
#35 = Utf8 <clinit>
#36 = Utf8 clojure.core
#37 = String #36 // clojure.core
#38 = Utf8 re-find
#39 = String #38 // re-find
#40 = Utf8 clojure/lang/RT
#41 = Class #40 // clojure/lang/RT
#42 = Utf8 var
#43 = Utf8 (Ljava/lang/String;Ljava/lang/String;)Lclojure/lang/Var;
#44 = NameAndType #42:#43 // var:(Ljava/lang/String;Ljava/lang/String;)Lclojure/lang/Var;
#45 = Methodref #41.#44 // clojure/lang/RT.var:(Ljava/lang/String;Ljava/lang/String;)Lclojure/lang/Var;
#46 = Utf8 some.*regex.*literal
#47 = String #46 // some.*regex.*literal
#48 = Utf8 java/util/regex/Pattern
#49 = Class #48 // java/util/regex/Pattern
#50 = Utf8 compile
#51 = Utf8 (Ljava/lang/String;)Ljava/util/regex/Pattern;
#52 = NameAndType #50:#51 // compile:(Ljava/lang/String;)Ljava/util/regex/Pattern;
#53 = Methodref #49.#52 // java/util/regex/Pattern.compile:(Ljava/lang/String;)Ljava/util/regex/Pattern;
#54 = Utf8 Code
#55 = Utf8 LineNumberTable
#56 = Utf8 LocalVariableTable
#57 = Utf8 SourceFile
#58 = Utf8 SourceDebugExtension
{
public static final clojure.lang.Var const__0;
descriptor: Lclojure/lang/Var;
flags: ACC_PUBLIC, ACC_STATIC, ACC_FINAL
public static final java.lang.Object const__1;
descriptor: Ljava/lang/Object;
flags: ACC_PUBLIC, ACC_STATIC, ACC_FINAL
public clj_re.core$simple();
descriptor: ()V
flags: ACC_PUBLIC
Code:
stack=1, locals=1, args_size=1
0: aload_0
1: invokespecial #9 // Method clojure/lang/AFunction."<init>":()V
4: return
LineNumberTable:
line 4: 0
public static java.lang.Object invokeStatic(java.lang.Object);
descriptor: (Ljava/lang/Object;)Ljava/lang/Object;
flags: ACC_PUBLIC, ACC_STATIC
Code:
stack=4, locals=1, args_size=1
0: getstatic #15 // Field const__0:Lclojure/lang/Var;
3: invokevirtual #21 // Method clojure/lang/Var.getRawRoot:()Ljava/lang/Object;
6: checkcast #23 // class clojure/lang/IFn
9: getstatic #27 // Field const__1:Ljava/lang/Object;
12: aload_0
13: aconst_null
14: astore_0
15: invokeinterface #31, 3 // InterfaceMethod clojure/lang/IFn.invoke:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
20: areturn
LocalVariableTable:
Start Length Slot Name Signature
0 20 0 x Ljava/lang/Object;
LineNumberTable:
line 4: 0
line 5: 6
line 5: 15
public java.lang.Object invoke(java.lang.Object);
descriptor: (Ljava/lang/Object;)Ljava/lang/Object;
flags: ACC_PUBLIC
Code:
stack=2, locals=2, args_size=2
0: aload_1
1: aconst_null
2: astore_1
3: invokestatic #34 // Method invokeStatic:(Ljava/lang/Object;)Ljava/lang/Object;
6: areturn
LineNumberTable:
line 4: 3
public static {};
descriptor: ()V
flags: ACC_PUBLIC, ACC_STATIC
Code:
stack=2, locals=0, args_size=0
0: ldc #37 // String clojure.core
2: ldc #39 // String re-find
4: invokestatic #45 // Method clojure/lang/RT.var:(Ljava/lang/String;Ljava/lang/String;)Lclojure/lang/Var;
7: checkcast #17 // class clojure/lang/Var
10: putstatic #15 // Field const__0:Lclojure/lang/Var;
13: ldc #47 // String some.*regex.*literal
15: invokestatic #53 // Method java/util/regex/Pattern.compile:(Ljava/lang/String;)Ljava/util/regex/Pattern;
18: putstatic #27 // Field const__1:Ljava/lang/Object;
21: return
LineNumberTable:
line 4: 0
}
SourceFile: "core.clj"
SourceDebugExtension:
SMAP
core.java
Clojure
*S Clojure
*F
+ 1 core.clj
clj_re/core.clj
*L
2#1,4:2
*E
(ns clj-re.core
(:gen-class))
(defn simple [x]
(re-find #"some.*regex.*literal" x)) ;; this regex ends up as a `static final Pattern ...` in the compiled code
@overthink

This comment has been minimized.

Copy link
Owner Author

@overthink overthink commented Jun 13, 2018

In the compiled code, public static final clojure.lang.Var const__0 ends up as a var containing the clojure.core/re-find function (IFn instance). public static final java.lang.Object const__1 ends up as the compiled Pattern object for #"some.*regex.*literal" (https://gist.github.com/overthink/c9408d72e52a45a2a33015221b551788#file-core-simple-class-L134-L135). So each invocation of simple just references the compiled regex.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment