ruby-libjit 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +6 -0
- data/LGPL +515 -0
- data/LICENSE +20 -0
- data/README +50 -0
- data/ext/extconf.rb +100 -0
- data/ext/insns.inc.rpp +204 -0
- data/ext/jit.c +1521 -0
- data/ext/method_data.c +385 -0
- data/ext/method_data.c.rpp +294 -0
- data/ext/method_data.h +11 -0
- data/ext/minimal_node.c +35 -0
- data/ext/minimal_node.h +52 -0
- data/ext/rubyjit.h +20 -0
- data/ext/rubypp.rb +97 -0
- data/lib/jit/array.rb +135 -0
- data/lib/jit/function.rb +201 -0
- data/lib/jit/struct.rb +163 -0
- data/lib/jit/value.rb +199 -0
- data/lib/jit.rb +5 -0
- data/sample/fib.rb +29 -0
- data/sample/gcd_benchmark.rb +117 -0
- data/sample/simple.rb +15 -0
- data/test/test_jit_array.rb +70 -0
- data/test/test_jit_function.rb +329 -0
- data/test/test_jit_struct.rb +111 -0
- data/test/test_jit_value.rb +258 -0
- metadata +77 -0
@@ -0,0 +1,329 @@
|
|
1
|
+
require 'jit/function'
|
2
|
+
require 'jit/value'
|
3
|
+
require 'test/unit'
|
4
|
+
|
5
|
+
class TestJitFunction < Test::Unit::TestCase
|
6
|
+
def test_if_false
|
7
|
+
function = nil
|
8
|
+
JIT::Context.build do |context|
|
9
|
+
signature = JIT::Type.create_signature(
|
10
|
+
JIT::ABI::CDECL,
|
11
|
+
JIT::Type::INT,
|
12
|
+
[ JIT::Type::INT ])
|
13
|
+
function = JIT::Function.compile(context, signature) do |f|
|
14
|
+
result = f.value(JIT::Type::INT)
|
15
|
+
result.store f.const(JIT::Type::INT, 1)
|
16
|
+
f.if(f.get_param(0)) {
|
17
|
+
result.store f.const(JIT::Type::INT, 2)
|
18
|
+
} .end
|
19
|
+
f.insn_return result
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
assert_equal(1, function.apply(0))
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_if_true
|
27
|
+
function = nil
|
28
|
+
JIT::Context.build do |context|
|
29
|
+
signature = JIT::Type.create_signature(
|
30
|
+
JIT::ABI::CDECL,
|
31
|
+
JIT::Type::INT,
|
32
|
+
[ JIT::Type::INT ])
|
33
|
+
function = JIT::Function.compile(context, signature) do |f|
|
34
|
+
result = f.value(JIT::Type::INT)
|
35
|
+
result.store f.const(JIT::Type::INT, 1)
|
36
|
+
f.if(f.get_param(0)) {
|
37
|
+
result.store f.const(JIT::Type::INT, 2)
|
38
|
+
} .end
|
39
|
+
f.insn_return result
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
assert_equal(2, function.apply(1))
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_if_false_else
|
47
|
+
function = nil
|
48
|
+
JIT::Context.build do |context|
|
49
|
+
signature = JIT::Type.create_signature(
|
50
|
+
JIT::ABI::CDECL,
|
51
|
+
JIT::Type::INT,
|
52
|
+
[ JIT::Type::INT ])
|
53
|
+
function = JIT::Function.compile(context, signature) do |f|
|
54
|
+
result = f.value(JIT::Type::INT)
|
55
|
+
result.store f.const(JIT::Type::INT, 1)
|
56
|
+
f.if(f.get_param(0)) {
|
57
|
+
result.store f.const(JIT::Type::INT, 2)
|
58
|
+
} .else {
|
59
|
+
result.store f.const(JIT::Type::INT, 3)
|
60
|
+
} .end
|
61
|
+
f.insn_return result
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
assert_equal(3, function.apply(0))
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_if_true_else
|
69
|
+
function = nil
|
70
|
+
JIT::Context.build do |context|
|
71
|
+
signature = JIT::Type.create_signature(
|
72
|
+
JIT::ABI::CDECL,
|
73
|
+
JIT::Type::INT,
|
74
|
+
[ JIT::Type::INT ])
|
75
|
+
function = JIT::Function.compile(context, signature) do |f|
|
76
|
+
result = f.value(JIT::Type::INT)
|
77
|
+
result.store f.const(JIT::Type::INT, 1)
|
78
|
+
f.if(f.get_param(0)) {
|
79
|
+
result.store f.const(JIT::Type::INT, 2)
|
80
|
+
} .else {
|
81
|
+
result.store f.const(JIT::Type::INT, 3)
|
82
|
+
} .end
|
83
|
+
f.insn_return result
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
assert_equal(2, function.apply(1))
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_if_false_else_if_true_else
|
91
|
+
function = nil
|
92
|
+
JIT::Context.build do |context|
|
93
|
+
signature = JIT::Type.create_signature(
|
94
|
+
JIT::ABI::CDECL,
|
95
|
+
JIT::Type::INT,
|
96
|
+
[ JIT::Type::INT, JIT::Type::INT ])
|
97
|
+
function = JIT::Function.compile(context, signature) do |f|
|
98
|
+
result = f.value(JIT::Type::INT)
|
99
|
+
result.store f.const(JIT::Type::INT, 1)
|
100
|
+
f.if(f.get_param(0)) {
|
101
|
+
result.store f.const(JIT::Type::INT, 2)
|
102
|
+
} .elsif(f.get_param(1)) {
|
103
|
+
result.store f.const(JIT::Type::INT, 3)
|
104
|
+
} .else {
|
105
|
+
result.store f.const(JIT::Type::INT, 4)
|
106
|
+
} .end
|
107
|
+
f.insn_return result
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
assert_equal(3, function.apply(0, 1))
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_if_true_else_if_false_else
|
115
|
+
function = nil
|
116
|
+
JIT::Context.build do |context|
|
117
|
+
signature = JIT::Type.create_signature(
|
118
|
+
JIT::ABI::CDECL,
|
119
|
+
JIT::Type::INT,
|
120
|
+
[ JIT::Type::INT, JIT::Type::INT ])
|
121
|
+
function = JIT::Function.compile(context, signature) do |f|
|
122
|
+
result = f.value(JIT::Type::INT)
|
123
|
+
result.store f.const(JIT::Type::INT, 1)
|
124
|
+
f.if(f.get_param(0)) {
|
125
|
+
result.store f.const(JIT::Type::INT, 2)
|
126
|
+
} .elsif(f.get_param(1)) {
|
127
|
+
result.store f.const(JIT::Type::INT, 3)
|
128
|
+
} .else {
|
129
|
+
result.store f.const(JIT::Type::INT, 4)
|
130
|
+
} .end
|
131
|
+
f.insn_return result
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
assert_equal(2, function.apply(1, 0))
|
136
|
+
end
|
137
|
+
|
138
|
+
def test_if_false_else_if_false_else
|
139
|
+
function = nil
|
140
|
+
JIT::Context.build do |context|
|
141
|
+
signature = JIT::Type.create_signature(
|
142
|
+
JIT::ABI::CDECL,
|
143
|
+
JIT::Type::INT,
|
144
|
+
[ JIT::Type::INT, JIT::Type::INT ])
|
145
|
+
function = JIT::Function.compile(context, signature) do |f|
|
146
|
+
result = f.value(JIT::Type::INT)
|
147
|
+
result.store f.const(JIT::Type::INT, 1)
|
148
|
+
f.if(f.get_param(0)) {
|
149
|
+
result.store f.const(JIT::Type::INT, 2)
|
150
|
+
} .elsif(f.get_param(1)) {
|
151
|
+
result.store f.const(JIT::Type::INT, 3)
|
152
|
+
} .else {
|
153
|
+
result.store f.const(JIT::Type::INT, 4)
|
154
|
+
} .end
|
155
|
+
f.insn_return result
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
assert_equal(4, function.apply(0, 0))
|
160
|
+
end
|
161
|
+
|
162
|
+
def test_while_true_enters_loop
|
163
|
+
function = nil
|
164
|
+
JIT::Context.build do |context|
|
165
|
+
signature = JIT::Type.create_signature(
|
166
|
+
JIT::ABI::CDECL,
|
167
|
+
JIT::Type::INT,
|
168
|
+
[ ])
|
169
|
+
function = JIT::Function.compile(context, signature) do |f|
|
170
|
+
true_value = f.const(JIT::Type::INT, 1)
|
171
|
+
false_value = f.const(JIT::Type::INT, 0)
|
172
|
+
f.while(proc { true_value }) {
|
173
|
+
f.insn_return true_value
|
174
|
+
}.end
|
175
|
+
f.insn_return false_value
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
assert_equal(1, function.apply)
|
180
|
+
end
|
181
|
+
|
182
|
+
def test_while_true_reenters_loop
|
183
|
+
function = nil
|
184
|
+
JIT::Context.build do |context|
|
185
|
+
signature = JIT::Type.create_signature(
|
186
|
+
JIT::ABI::CDECL,
|
187
|
+
JIT::Type::INT,
|
188
|
+
[ ])
|
189
|
+
function = JIT::Function.compile(context, signature) do |f|
|
190
|
+
value = f.value(JIT::Type::INT)
|
191
|
+
value.store(f.const(JIT::Type::INT, 0))
|
192
|
+
f.while(proc { value < f.const(JIT::Type::INT, 2) }) {
|
193
|
+
value.store(value + f.const(JIT::Type::INT, 1))
|
194
|
+
}.end
|
195
|
+
f.insn_return value
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
assert_equal(2, function.apply)
|
200
|
+
end
|
201
|
+
|
202
|
+
def test_while_false_does_not_enter_loop
|
203
|
+
function = nil
|
204
|
+
JIT::Context.build do |context|
|
205
|
+
signature = JIT::Type.create_signature(
|
206
|
+
JIT::ABI::CDECL,
|
207
|
+
JIT::Type::INT,
|
208
|
+
[ ])
|
209
|
+
function = JIT::Function.compile(context, signature) do |f|
|
210
|
+
true_value = f.const(JIT::Type::INT, 1)
|
211
|
+
false_value = f.const(JIT::Type::INT, 0)
|
212
|
+
f.while(proc { false_value }) {
|
213
|
+
f.insn_return true_value
|
214
|
+
}.end
|
215
|
+
f.insn_return false_value
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
assert_equal(0, function.apply)
|
220
|
+
end
|
221
|
+
|
222
|
+
def test_until_false_enters_loop
|
223
|
+
function = nil
|
224
|
+
JIT::Context.build do |context|
|
225
|
+
signature = JIT::Type.create_signature(
|
226
|
+
JIT::ABI::CDECL,
|
227
|
+
JIT::Type::INT,
|
228
|
+
[ ])
|
229
|
+
function = JIT::Function.compile(context, signature) do |f|
|
230
|
+
true_value = f.const(JIT::Type::INT, 1)
|
231
|
+
false_value = f.const(JIT::Type::INT, 0)
|
232
|
+
f.until(proc { false_value }) {
|
233
|
+
f.insn_return true_value
|
234
|
+
}.end
|
235
|
+
f.insn_return false_value
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
assert_equal(1, function.apply)
|
240
|
+
end
|
241
|
+
|
242
|
+
def test_until_false_reenters_loop
|
243
|
+
function = nil
|
244
|
+
JIT::Context.build do |context|
|
245
|
+
signature = JIT::Type.create_signature(
|
246
|
+
JIT::ABI::CDECL,
|
247
|
+
JIT::Type::INT,
|
248
|
+
[ ])
|
249
|
+
function = JIT::Function.compile(context, signature) do |f|
|
250
|
+
value = f.value(JIT::Type::INT)
|
251
|
+
value.store(f.const(JIT::Type::INT, 0))
|
252
|
+
f.until(proc { value == f.const(JIT::Type::INT, 2) }) {
|
253
|
+
value.store(value + f.const(JIT::Type::INT, 1))
|
254
|
+
}.end
|
255
|
+
f.insn_return value
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
259
|
+
assert_equal(2, function.apply)
|
260
|
+
end
|
261
|
+
|
262
|
+
def test_until_true_does_not_enter_loop
|
263
|
+
function = nil
|
264
|
+
JIT::Context.build do |context|
|
265
|
+
signature = JIT::Type.create_signature(
|
266
|
+
JIT::ABI::CDECL,
|
267
|
+
JIT::Type::INT,
|
268
|
+
[ ])
|
269
|
+
function = JIT::Function.compile(context, signature) do |f|
|
270
|
+
true_value = f.const(JIT::Type::INT, 1)
|
271
|
+
false_value = f.const(JIT::Type::INT, 0)
|
272
|
+
f.until(proc { true_value }) {
|
273
|
+
f.insn_return true_value
|
274
|
+
}.end
|
275
|
+
f.insn_return false_value
|
276
|
+
end
|
277
|
+
end
|
278
|
+
|
279
|
+
assert_equal(0, function.apply)
|
280
|
+
end
|
281
|
+
|
282
|
+
# TODO: while/break
|
283
|
+
# TODO: while/redo
|
284
|
+
# TODO: until/break
|
285
|
+
# TODO: until/redo
|
286
|
+
# TODO: unless
|
287
|
+
# TODO: elsunless
|
288
|
+
|
289
|
+
def test_define_jit_method
|
290
|
+
function = nil
|
291
|
+
JIT::Context.build do |context|
|
292
|
+
signature = JIT::Type.create_signature(
|
293
|
+
JIT::ABI::CDECL,
|
294
|
+
JIT::Type::OBJECT,
|
295
|
+
[ JIT::Type::OBJECT ])
|
296
|
+
function = JIT::Function.compile(context, signature) do |f|
|
297
|
+
f.insn_return(f.const(JIT::Type::OBJECT, 42))
|
298
|
+
end
|
299
|
+
end
|
300
|
+
|
301
|
+
c = Class.new
|
302
|
+
c.instance_eval do
|
303
|
+
define_jit_method('foo', function)
|
304
|
+
end
|
305
|
+
|
306
|
+
o = c.new
|
307
|
+
assert_equal 42, o.foo
|
308
|
+
end
|
309
|
+
|
310
|
+
def test_define_jit_method_non_object_param
|
311
|
+
# TODO: should raise an exception
|
312
|
+
end
|
313
|
+
|
314
|
+
# TODO: get_param
|
315
|
+
# TODO: insn_call
|
316
|
+
# TODO: insn_call_native
|
317
|
+
# TODO: insn_return
|
318
|
+
# TODO: apply
|
319
|
+
# TODO: value
|
320
|
+
# TODO: const
|
321
|
+
# TODO: optimization_level
|
322
|
+
# TODO: optimization_level=
|
323
|
+
# TODO: max_optimization_level
|
324
|
+
# TODO: dump
|
325
|
+
# TODO: to_closure
|
326
|
+
# TODO: context
|
327
|
+
# TODO: compiled?
|
328
|
+
end
|
329
|
+
|
@@ -0,0 +1,111 @@
|
|
1
|
+
require 'jit/array'
|
2
|
+
require 'jit/function'
|
3
|
+
require 'test/unit'
|
4
|
+
require 'assertions'
|
5
|
+
|
6
|
+
class TestJitStruct < Test::Unit::TestCase
|
7
|
+
include JitAssertions
|
8
|
+
|
9
|
+
def test_new_struct
|
10
|
+
s_type = JIT::Struct.new(
|
11
|
+
[ :foo, JIT::Type::INT ],
|
12
|
+
[ :bar, JIT::Type::VOID_PTR ],
|
13
|
+
[ :baz, JIT::Type::FLOAT32 ])
|
14
|
+
assert_equal [ :foo, :bar, :baz ], s_type.members
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_create
|
18
|
+
p = proc { |f|
|
19
|
+
s_type = JIT::Struct.new(
|
20
|
+
[ :foo, JIT::Type::INT ],
|
21
|
+
[ :bar, JIT::Type::VOID_PTR ],
|
22
|
+
[ :baz, JIT::Type::FLOAT32 ])
|
23
|
+
s = s_type.create(f)
|
24
|
+
f.return f.const(JIT::Type::INT, 0)
|
25
|
+
}
|
26
|
+
assert_function_result(
|
27
|
+
:result => [ JIT::Type::INT, 0 ],
|
28
|
+
&p)
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_offset_of
|
32
|
+
s_type = JIT::Struct.new(
|
33
|
+
[ :foo, JIT::Type::INT ],
|
34
|
+
[ :bar, JIT::Type::FLOAT64 ],
|
35
|
+
[ :baz, JIT::Type::VOID_PTR ])
|
36
|
+
assert_equal 0, s_type.offset_of(:foo)
|
37
|
+
assert_equal 4, s_type.offset_of(:bar)
|
38
|
+
assert_equal 12, s_type.offset_of(:baz)
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_type_of
|
42
|
+
s_type = JIT::Struct.new(
|
43
|
+
[ :foo, JIT::Type::INT ],
|
44
|
+
[ :bar, JIT::Type::FLOAT64 ],
|
45
|
+
[ :baz, JIT::Type::VOID_PTR ])
|
46
|
+
assert_equal JIT::Type::INT, s_type.type_of(:foo)
|
47
|
+
assert_equal JIT::Type::FLOAT64, s_type.type_of(:bar)
|
48
|
+
assert_equal JIT::Type::VOID_PTR, s_type.type_of(:baz)
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_instance_bracket
|
52
|
+
p = proc { |f|
|
53
|
+
s_type = JIT::Struct.new(
|
54
|
+
[ :foo, JIT::Type::INT ],
|
55
|
+
[ :bar, JIT::Type::FLOAT64 ],
|
56
|
+
[ :baz, JIT::Type::VOID_PTR ])
|
57
|
+
s = s_type.create(f)
|
58
|
+
f.insn_store_relative(s.ptr, 4, f.const(JIT::Type::FLOAT64, 42.0))
|
59
|
+
f.return s[:bar]
|
60
|
+
}
|
61
|
+
assert_function_result(
|
62
|
+
:result => [ JIT::Type::FLOAT64, 42.0 ],
|
63
|
+
&p)
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_instance_attrget
|
67
|
+
p = proc { |f|
|
68
|
+
s_type = JIT::Struct.new(
|
69
|
+
[ :foo, JIT::Type::INT ],
|
70
|
+
[ :bar, JIT::Type::FLOAT64 ],
|
71
|
+
[ :baz, JIT::Type::VOID_PTR ])
|
72
|
+
s = s_type.create(f)
|
73
|
+
f.insn_store_relative(s.ptr, 4, f.const(JIT::Type::FLOAT64, 42.0))
|
74
|
+
f.return s.bar
|
75
|
+
}
|
76
|
+
assert_function_result(
|
77
|
+
:result => [ JIT::Type::FLOAT64, 42.0 ],
|
78
|
+
&p)
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_instance_bracket_eq
|
82
|
+
p = proc { |f|
|
83
|
+
s_type = JIT::Struct.new(
|
84
|
+
[ :foo, JIT::Type::INT ],
|
85
|
+
[ :bar, JIT::Type::FLOAT64 ],
|
86
|
+
[ :baz, JIT::Type::VOID_PTR ])
|
87
|
+
s = s_type.create(f)
|
88
|
+
s[:bar] = f.const(JIT::Type::FLOAT64, 42.0)
|
89
|
+
f.return s[:bar]
|
90
|
+
}
|
91
|
+
assert_function_result(
|
92
|
+
:result => [ JIT::Type::FLOAT64, 42.0 ],
|
93
|
+
&p)
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_instance_attrset
|
97
|
+
p = proc { |f|
|
98
|
+
s_type = JIT::Struct.new(
|
99
|
+
[ :foo, JIT::Type::INT ],
|
100
|
+
[ :bar, JIT::Type::FLOAT64 ],
|
101
|
+
[ :baz, JIT::Type::VOID_PTR ])
|
102
|
+
s = s_type.create(f)
|
103
|
+
s.bar = f.const(JIT::Type::FLOAT64, 42.0)
|
104
|
+
f.return s.bar
|
105
|
+
}
|
106
|
+
assert_function_result(
|
107
|
+
:result => [ JIT::Type::FLOAT64, 42.0 ],
|
108
|
+
&p)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
@@ -0,0 +1,258 @@
|
|
1
|
+
require 'jit/value'
|
2
|
+
require 'jit/function'
|
3
|
+
require 'test/unit'
|
4
|
+
require 'assertions'
|
5
|
+
|
6
|
+
class TestJitValue < Test::Unit::TestCase
|
7
|
+
include JitAssertions
|
8
|
+
|
9
|
+
def test_store
|
10
|
+
p = proc { |f|
|
11
|
+
v = f.value(JIT::Type::INT)
|
12
|
+
v.store(f.const(JIT::Type::INT, 42))
|
13
|
+
f.return v
|
14
|
+
}
|
15
|
+
assert_function_result(
|
16
|
+
:result => [ JIT::Type::INT, 42 ],
|
17
|
+
&p)
|
18
|
+
end
|
19
|
+
|
20
|
+
# TODO: address
|
21
|
+
|
22
|
+
def test_int_plus
|
23
|
+
p = proc { |f|
|
24
|
+
v1 = f.get_param(0)
|
25
|
+
v2 = f.get_param(1)
|
26
|
+
f.return v1 + v2
|
27
|
+
}
|
28
|
+
assert_function_result(
|
29
|
+
:arg0 => [ JIT::Type::INT, 1 ],
|
30
|
+
:arg1 => [ JIT::Type::INT, 2 ],
|
31
|
+
:result => [ JIT::Type::INT, 3 ],
|
32
|
+
&p)
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_int_minus
|
36
|
+
p = proc { |f|
|
37
|
+
v1 = f.get_param(0)
|
38
|
+
v2 = f.get_param(1)
|
39
|
+
f.return v1 - v2
|
40
|
+
}
|
41
|
+
assert_function_result(
|
42
|
+
:arg0 => [ JIT::Type::INT, 3 ],
|
43
|
+
:arg1 => [ JIT::Type::INT, 2 ],
|
44
|
+
:result => [ JIT::Type::INT, 1 ],
|
45
|
+
&p)
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_int_mult
|
49
|
+
p = proc { |f|
|
50
|
+
v1 = f.get_param(0)
|
51
|
+
v2 = f.get_param(1)
|
52
|
+
f.return v1 * v2
|
53
|
+
}
|
54
|
+
assert_function_result(
|
55
|
+
:arg0 => [ JIT::Type::INT, 3 ],
|
56
|
+
:arg1 => [ JIT::Type::INT, 2 ],
|
57
|
+
:result => [ JIT::Type::INT, 6 ],
|
58
|
+
&p)
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_int_div
|
62
|
+
p = proc { |f|
|
63
|
+
v1 = f.get_param(0)
|
64
|
+
v2 = f.get_param(1)
|
65
|
+
f.return v1 / v2
|
66
|
+
}
|
67
|
+
assert_function_result(
|
68
|
+
:arg0 => [ JIT::Type::INT, 6 ],
|
69
|
+
:arg1 => [ JIT::Type::INT, 2 ],
|
70
|
+
:result => [ JIT::Type::INT, 3 ],
|
71
|
+
&p)
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_int_mod
|
75
|
+
p = proc { |f|
|
76
|
+
v1 = f.get_param(0)
|
77
|
+
v2 = f.get_param(1)
|
78
|
+
f.return v1 % v2
|
79
|
+
}
|
80
|
+
assert_function_result(
|
81
|
+
:arg0 => [ JIT::Type::INT, 20 ],
|
82
|
+
:arg1 => [ JIT::Type::INT, 6 ],
|
83
|
+
:result => [ JIT::Type::INT, 2 ],
|
84
|
+
&p)
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_int_and
|
88
|
+
p = proc { |f|
|
89
|
+
v1 = f.get_param(0)
|
90
|
+
v2 = f.get_param(1)
|
91
|
+
f.return v1 & v2
|
92
|
+
}
|
93
|
+
assert_function_result(
|
94
|
+
:arg0 => [ JIT::Type::INT, 11 ],
|
95
|
+
:arg1 => [ JIT::Type::INT, 3 ],
|
96
|
+
:result => [ JIT::Type::INT, 3 ],
|
97
|
+
&p)
|
98
|
+
assert_function_result(
|
99
|
+
:arg0 => [ JIT::Type::INT, 8 ],
|
100
|
+
:arg1 => [ JIT::Type::INT, 3 ],
|
101
|
+
:result => [ JIT::Type::INT, 0 ],
|
102
|
+
&p)
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_int_or
|
106
|
+
p = proc { |f|
|
107
|
+
v1 = f.get_param(0)
|
108
|
+
v2 = f.get_param(1)
|
109
|
+
f.return v1 | v2
|
110
|
+
}
|
111
|
+
assert_function_result(
|
112
|
+
:arg0 => [ JIT::Type::INT, 10 ],
|
113
|
+
:arg1 => [ JIT::Type::INT, 3 ],
|
114
|
+
:result => [ JIT::Type::INT, 11 ],
|
115
|
+
&p)
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_int_xor
|
119
|
+
p = proc { |f|
|
120
|
+
v1 = f.get_param(0)
|
121
|
+
v2 = f.get_param(1)
|
122
|
+
f.return v1 ^ v2
|
123
|
+
}
|
124
|
+
assert_function_result(
|
125
|
+
:arg0 => [ JIT::Type::INT, 10 ],
|
126
|
+
:arg1 => [ JIT::Type::INT, 3 ],
|
127
|
+
:result => [ JIT::Type::INT, 9 ],
|
128
|
+
&p)
|
129
|
+
end
|
130
|
+
|
131
|
+
def test_int_lt
|
132
|
+
p = proc { |f|
|
133
|
+
v1 = f.get_param(0)
|
134
|
+
v2 = f.get_param(1)
|
135
|
+
f.return v1 < v2
|
136
|
+
}
|
137
|
+
assert_function_result(
|
138
|
+
:arg0 => [ JIT::Type::INT, 1 ],
|
139
|
+
:arg1 => [ JIT::Type::INT, 2 ],
|
140
|
+
:result => [ JIT::Type::INT, 1 ],
|
141
|
+
&p)
|
142
|
+
assert_function_result(
|
143
|
+
:arg0 => [ JIT::Type::INT, 2 ],
|
144
|
+
:arg1 => [ JIT::Type::INT, 1 ],
|
145
|
+
:result => [ JIT::Type::INT, 0 ],
|
146
|
+
&p)
|
147
|
+
end
|
148
|
+
|
149
|
+
def test_int_gt
|
150
|
+
p = proc { |f|
|
151
|
+
v1 = f.get_param(0)
|
152
|
+
v2 = f.get_param(1)
|
153
|
+
f.return v1 > v2
|
154
|
+
}
|
155
|
+
assert_function_result(
|
156
|
+
:arg0 => [ JIT::Type::INT, 1 ],
|
157
|
+
:arg1 => [ JIT::Type::INT, 2 ],
|
158
|
+
:result => [ JIT::Type::INT, 0 ],
|
159
|
+
&p)
|
160
|
+
assert_function_result(
|
161
|
+
:arg0 => [ JIT::Type::INT, 2 ],
|
162
|
+
:arg1 => [ JIT::Type::INT, 1 ],
|
163
|
+
:result => [ JIT::Type::INT, 1 ],
|
164
|
+
&p)
|
165
|
+
end
|
166
|
+
|
167
|
+
def test_int_eq
|
168
|
+
p = proc { |f|
|
169
|
+
v1 = f.get_param(0)
|
170
|
+
v2 = f.get_param(1)
|
171
|
+
f.return v1 == v2
|
172
|
+
}
|
173
|
+
assert_function_result(
|
174
|
+
:arg0 => [ JIT::Type::INT, 1 ],
|
175
|
+
:arg1 => [ JIT::Type::INT, 2 ],
|
176
|
+
:result => [ JIT::Type::INT, 0 ],
|
177
|
+
&p)
|
178
|
+
assert_function_result(
|
179
|
+
:arg0 => [ JIT::Type::INT, 1 ],
|
180
|
+
:arg1 => [ JIT::Type::INT, 1 ],
|
181
|
+
:result => [ JIT::Type::INT, 1 ],
|
182
|
+
&p)
|
183
|
+
end
|
184
|
+
|
185
|
+
def test_int_le
|
186
|
+
p = proc { |f|
|
187
|
+
v1 = f.get_param(0)
|
188
|
+
v2 = f.get_param(1)
|
189
|
+
f.return v1 <= v2
|
190
|
+
}
|
191
|
+
assert_function_result(
|
192
|
+
:arg0 => [ JIT::Type::INT, 1 ],
|
193
|
+
:arg1 => [ JIT::Type::INT, 2 ],
|
194
|
+
:result => [ JIT::Type::INT, 1 ],
|
195
|
+
&p)
|
196
|
+
assert_function_result(
|
197
|
+
:arg0 => [ JIT::Type::INT, 2 ],
|
198
|
+
:arg1 => [ JIT::Type::INT, 1 ],
|
199
|
+
:result => [ JIT::Type::INT, 0 ],
|
200
|
+
&p)
|
201
|
+
assert_function_result(
|
202
|
+
:arg0 => [ JIT::Type::INT, 1 ],
|
203
|
+
:arg1 => [ JIT::Type::INT, 1 ],
|
204
|
+
:result => [ JIT::Type::INT, 1 ],
|
205
|
+
&p)
|
206
|
+
end
|
207
|
+
|
208
|
+
def test_int_ge
|
209
|
+
p = proc { |f|
|
210
|
+
v1 = f.get_param(0)
|
211
|
+
v2 = f.get_param(1)
|
212
|
+
f.return v1 >= v2
|
213
|
+
}
|
214
|
+
assert_function_result(
|
215
|
+
:arg0 => [ JIT::Type::INT, 1 ],
|
216
|
+
:arg1 => [ JIT::Type::INT, 2 ],
|
217
|
+
:result => [ JIT::Type::INT, 0 ],
|
218
|
+
&p)
|
219
|
+
assert_function_result(
|
220
|
+
:arg0 => [ JIT::Type::INT, 2 ],
|
221
|
+
:arg1 => [ JIT::Type::INT, 1 ],
|
222
|
+
:result => [ JIT::Type::INT, 1 ],
|
223
|
+
&p)
|
224
|
+
assert_function_result(
|
225
|
+
:arg0 => [ JIT::Type::INT, 1 ],
|
226
|
+
:arg1 => [ JIT::Type::INT, 1 ],
|
227
|
+
:result => [ JIT::Type::INT, 1 ],
|
228
|
+
&p)
|
229
|
+
end
|
230
|
+
|
231
|
+
def test_int_lshift
|
232
|
+
p = proc { |f|
|
233
|
+
v1 = f.get_param(0)
|
234
|
+
v2 = f.get_param(1)
|
235
|
+
f.return v1 << v2
|
236
|
+
}
|
237
|
+
assert_function_result(
|
238
|
+
:arg0 => [ JIT::Type::INT, 31 ],
|
239
|
+
:arg1 => [ JIT::Type::INT, 2 ],
|
240
|
+
:result => [ JIT::Type::INT, 124 ],
|
241
|
+
&p)
|
242
|
+
end
|
243
|
+
|
244
|
+
def test_int_rshift
|
245
|
+
p = proc { |f|
|
246
|
+
v1 = f.get_param(0)
|
247
|
+
v2 = f.get_param(1)
|
248
|
+
f.return v1 >> v2
|
249
|
+
}
|
250
|
+
assert_function_result(
|
251
|
+
:arg0 => [ JIT::Type::INT, 31 ],
|
252
|
+
:arg1 => [ JIT::Type::INT, 2 ],
|
253
|
+
:result => [ JIT::Type::INT, 7 ],
|
254
|
+
&p)
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
|