-
Notifications
You must be signed in to change notification settings - Fork 10
/
tclass.nim
175 lines (165 loc) · 5.21 KB
/
tclass.nim
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
import unittest
import dali
const
Application = "Landroid/app/Application;"
Activity = "Landroid/app/Activity;"
Bundle = "Landroid/os/Bundle;"
HelloAndroid = "Lcom/android/hello/HelloAndroid;"
# TODO: test "hello_world.apk":
# # needs support for arrays, see tdex.nim
# discard dclass hw {.public.}
discard dclass com.bugsnag.dexexample.BugsnagApp {.public.} of Application:
proc `<init>`() {.public, constructor, regs:1, ins:1, outs:1.} =
invoke_direct 0, jproto Application.`<init>`()
return_void
discard dclass com.android.hello.HelloAndroid {.public.} of Activity:
proc `<init>`() {.public, constructor, regs:1, ins:1, outs:1.} =
invoke_direct(0, jproto Activity.`<init>`())
return_void()
proc fooBar(Bundle, View, int)
proc onCreate(Bundle) {.public, regs:3, ins:2, outs:2.} =
invoke_super(1, 2, jproto Activity.onCreate(Bundle))
const_high16(0, 0x7f03)
invoke_virtual(1, 0, jproto HelloAndroid.setContentView(int))
return_void()
test "bugsnag.apk":
let c =
dclass com.bugsnag.dexexample.BugsnagApp {.public.} of Application:
proc `<init>`() {.public, constructor, regs:1, ins:1, outs:1.} =
invoke_direct(0, jproto Application.`<init>`())
return_void()
checkpoint c.repr
check c.equals ClassDef(
class: "Lcom/bugsnag/dexexample/BugsnagApp;",
access: {Public}, # TODO
superclass: SomeType("Landroid/app/Application;"),
class_data: ClassData(
direct_methods: @[
EncodedMethod(
m: Method(
class: "Lcom/bugsnag/dexexample/BugsnagApp;",
name: "<init>",
prototype: Prototype(
ret: "V",
params: @[],
),
),
access: {Public, Constructor},
code: SomeCode(Code(
registers: 1,
ins: 1,
outs: 1,
instrs: @[
invoke_direct(0, Method(class: "Landroid/app/Application;", name: "<init>",
prototype: Prototype(ret: "V", params: @[]))),
return_void(),
],
)),
)
]
)
)
test "hello_android.apk":
let c =
dclass com.android.hello.HelloAndroid {.public.} of Activity:
proc `<init>`() {.public, constructor, regs:1, ins:1, outs:1.} =
invoke_direct(0, jproto Activity.`<init>`())
return_void()
proc onCreate(Bundle) {.public, regs:3, ins:2, outs:2.} =
invoke_super(1, 2, jproto Activity.onCreate(Bundle))
const_high16(0, 0x7f03)
invoke_virtual(1, 0, jproto HelloAndroid.setContentView(int))
return_void()
checkpoint c.repr
check c.equals ClassDef(
class: "Lcom/android/hello/HelloAndroid;",
access: {Public},
superclass: SomeType("Landroid/app/Activity;"),
class_data: ClassData(
direct_methods: @[
EncodedMethod(
m: Method(
class: "Lcom/android/hello/HelloAndroid;",
name: "<init>",
prototype: Prototype(ret: "V", params: @[]),
),
access: {Public, Constructor},
code: SomeCode(Code(
registers: 1,
ins: 1,
outs: 1,
instrs: @[
invoke_direct(0, Method(class: "Landroid/app/Activity;", name: "<init>",
prototype: Prototype(ret: "V", params: @[]))),
return_void(),
],
)),
),
],
virtual_methods: @[
EncodedMethod(
m: Method(
class: "Lcom/android/hello/HelloAndroid;",
name: "onCreate",
prototype: Prototype(
ret: "V",
params: @["Landroid/os/Bundle;"],
),
),
access: {Public},
code: SomeCode(Code(
registers: 3,
ins: 2,
outs: 2,
instrs: @[
invoke_super(1, 2, Method(class: "Landroid/app/Activity;", name: "onCreate",
prototype: Prototype(ret: "V", params: @["Landroid/os/Bundle;"]))),
const_high16(0, 0x7f03),
invoke_virtual(1, 0, Method(class: "Lcom/android/hello/HelloAndroid;", name: "setContentView",
prototype: Prototype(ret: "V", params: @["I"]))),
return_void(),
],
)),
),
],
)
)
test "with NimSelf":
let c =
dclass com.akavel.HasSelf {.public, nimSelf.}:
proc `<init>`() {.public, constructor, regs:1, ins:1, outs:0.} =
return_void()
checkpoint c.repr
check c.equals ClassDef(
class: "Lcom/akavel/HasSelf;",
superclass: NoType(),
access: {Public},
class_data: ClassData(
instance_fields: @[
EncodedField(
f: Field(
class: "Lcom/akavel/HasSelf;",
name: "nimSelf",
typ: "J"),
access: {Private}),
],
direct_methods: @[
EncodedMethod(
m: Method(
class: "Lcom/akavel/HasSelf;",
name: "<init>",
prototype: Prototype(ret: "V", params: @[]),
),
access: {Public, Constructor},
code: SomeCode(Code(
registers: 1,
ins: 1,
outs: 0,
instrs: @[
return_void(),
],
)),
),
],
)
)