Skip to content

Instantly share code, notes, and snippets.

@joinr
Last active January 11, 2019 21:55
Show Gist options
  • Save joinr/a5068b4fb2df9cc34416634f92cd8fc7 to your computer and use it in GitHub Desktop.
Save joinr/a5068b4fb2df9cc34416634f92cd8fc7 to your computer and use it in GitHub Desktop.
clj loop disassembled
//(decomp/decompile (let [bound 10]
// (loop [x 1
// acc (java.util.ArrayList.)]
// (if (== bound x)
// acc
// (recur (unchecked-inc x)
// (if (odd? x) (doto ^java.util.ArrayList acc (.add (* x x)))
// acc))))))
// Decompiling class: user$fn__13411
import java.util.*;
import clojure.lang.*;
public final class user$fn__13411 extends AFunction
{
public static final Var const__4;
public static Object invokeStatic() {
final long bound = 10L;
long x = 1L;
Object acc = new ArrayList();
while (bound != x) {
final long n = x + 1L;
final Object invoke = ((IFn)const__4.getRawRoot()).invoke(Numbers.num(x));
Object o2 = null;
Label_0111: {
if (invoke != null) {
if (invoke != Boolean.FALSE) {
final Object o = acc;
acc = null;
Object G__13412 = o;
final Boolean b = ((ArrayList)G__13412).add(Numbers.num(Numbers.multiply(x, x))) ? Boolean.TRUE : Boolean.FALSE;
o2 = G__13412;
G__13412 = null;
break Label_0111;
}
}
o2 = acc;
acc = null;
}
acc = o2;
x = n;
}
final Object o3 = acc;
acc = null;
return o3;
}
@Override
public Object invoke() {
return invokeStatic();
}
static {
const__4 = RT.var("clojure.core", "odd?");
}
}
(defun blah () (loop for i from 1 to 10
if (oddp i)
do (progn nil)))
(disassemble #'blah)
; disassembly for BLAH
; Size: 43 bytes. Origin: #x1002C7B12C
; 2C: 498B4C2458 MOV RCX, [R12+88] ; no-arg-parsing entry point
; thread.binding-stack-pointer
; 31: 48894DF8 MOV [RBP-8], RCX
; 35: B902000000 MOV ECX, 2
; 3A: EB08 JMP L1
; 3C: 0F1F4000 NOP
; 40: L0: 4883C102 ADD RCX, 2
; 44: L1: 4883F914 CMP RCX, 20
; 48: 7EF6 JLE L0
; 4A: BA17001020 MOV EDX, #x20100017 ; NIL
; 4F: 488BE5 MOV RSP, RBP
; 52: F8 CLC
; 53: 5D POP RBP
; 54: C3 RET
; 55: CC10 BREAK 16 ; Invalid argument count trap
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment