-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathManualFoob2.j
149 lines (134 loc) · 3.78 KB
/
ManualFoob2.j
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
;; Manually fixed fib mockup (the funcalls are manually added)
.class ManualFoob2
.super Procedure
.method public toString()Ljava/lang/String;
ldc "#<a mazy mockup of (nlambda fib (n) (if (= n 0) 0 (if (= n 1) 1 (+ (fib (- n 1)) (fib (- n 2))))))>"
areturn
.end method
.method public <init>()V
.limit stack 2
.limit locals 1
aload_0
ldc "ManualFoob2"
invokenonvirtual Procedure.<init>(Ljava/lang/String;)V
return
.end method
;; Written not entirely manually...
.method public run([LLispObject;)LLispObject;
.limit locals 255
.limit stack 255
;; Manually coded unpackage of array. In a "real" version we'd probably astore to 5 instead so we can keep the array for shits and giggles... (actually we might keep it for closure purposes! gosh this idea just came to me! although we would probably need to always access the array directly). The checkcast might or mighn't be in a real version.
aload 1
iconst_0
aaload
; checkcast LispFixnum ; This could be done using SBCL-style optional declarations that also are assertions
astore 2
;; (lambda (n) (if (= n 0) 0 (if (= n 1) 1 (+ (fib (- n 1)) (fib (- n 2))))))
;; (if (= n 0) 0 (if (= n 1) 1 (+ (fib (- n 1)) (fib (- n 2)))))
aload 2
new LispFixnum
dup
ldc2_w 0
invokenonvirtual LispFixnum.<init>(J)V
invokevirtual java/lang/Object.equals(Ljava/lang/Object;)Z
ifeq L4
new LispFixnum
dup
ldc2_w 123
invokenonvirtual LispFixnum.<init>(J)V
goto L3
L4:
aconst_null
L3:
ifnonnull L2 ; branches to the true-expr
;; (if (= n 1) 1 (+ (fib (- n 1)) (fib (- n 2))))
aload 2
new LispFixnum
dup
ldc2_w 1
invokenonvirtual LispFixnum.<init>(J)V
invokevirtual java/lang/Object.equals(Ljava/lang/Object;)Z
ifeq L8
new LispFixnum
dup
ldc2_w 123
invokenonvirtual LispFixnum.<init>(J)V
goto L7
L8:
aconst_null
L7:
ifnonnull L6 ; branches to the true-expr
; Obtained from disasm of ManualFoob3, with some changes
aload 0
iconst_1
anewarray LispObject
dup
iconst_0
aload 2
checkcast LispNumber
new LispFixnum
dup
ldc2_w 1
invokenonvirtual LispFixnum.<init>(J)V
invokevirtual LispNumber.sub(LLispNumber;)LLispNumber;
aastore
invokevirtual Procedure.run([LLispObject;)LLispObject;
checkcast LispNumber
aload 0
iconst_1
anewarray LispObject
dup
iconst_0
aload 2
checkcast LispNumber
new LispFixnum
dup
ldc2_w 2
invokenonvirtual LispFixnum.<init>(J)V
invokevirtual LispNumber.sub(LLispNumber;)LLispNumber;
aastore
invokevirtual Procedure.run([LLispObject;)LLispObject;
checkcast LispNumber
invokevirtual LispNumber.add(LLispNumber;)LLispNumber;
; aload 0
; aload 2
; checkcast LispNumber
; new LispFixnum
; dup
; ldc2_w 1
; invokenonvirtual LispFixnum.<init>(J)V
; checkcast LispNumber
; invokevirtual LispNumber.sub(LLispNumber;)LLispNumber;
; invokevirtual ManualFoob.run(LLispObject;)LLispObject;
; checkcast LispNumber
; aload 0
; aload 2
; checkcast LispNumber
; new LispFixnum
; dup
; ldc2_w 2
; invokenonvirtual LispFixnum.<init>(J)V
; checkcast LispNumber
; invokevirtual LispNumber.sub(LLispNumber;)LLispNumber;
; invokevirtual ManualFoob.run(LLispObject;)LLispObject;
; checkcast LispNumber
; invokevirtual LispNumber.add(LLispNumber;)LLispNumber;
goto L5 ; Don't also run the true-expr like a fool
L6:
new LispFixnum
dup
ldc2_w 1
invokenonvirtual LispFixnum.<init>(J)V
L5:
;; endif
goto L1 ; Don't also run the true-expr like a fool
L2:
new LispFixnum
dup
ldc2_w 0
invokenonvirtual LispFixnum.<init>(J)V
L1:
;; endif
areturn
;; endlambda
.end method