ruby-libjit 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +10 -19
- data/ext/extconf.rb +9 -1
- data/ext/insns.inc.rpp +0 -1
- data/ext/jit.c +42 -11
- data/lib/jit/array.rb +4 -4
- data/lib/jit/function.rb +17 -18
- data/lib/jit/pointer.rb +98 -0
- data/lib/jit/struct.rb +0 -5
- data/sample/fib.rb +8 -8
- data/test/test_jit_function.rb +6 -6
- data/test/test_jit_pointer.rb +63 -0
- metadata +23 -14
data/README
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Ruby-libjit 0.
|
1
|
+
Ruby-libjit 0.2.0
|
2
2
|
Copyright (C) 2008 Paul Brannan
|
3
3
|
|
4
4
|
Ruby-libjit is a wrapper for the libjit library. It provides basic
|
@@ -8,6 +8,12 @@ provided so that jit code may be written in a ruby-like manner.
|
|
8
8
|
|
9
9
|
Please see the file COPYING for license information.
|
10
10
|
|
11
|
+
To install it:
|
12
|
+
|
13
|
+
gem install ruby-libjit
|
14
|
+
|
15
|
+
but you'll probably need to install libjit itself first (see below).
|
16
|
+
|
11
17
|
A simple example:
|
12
18
|
|
13
19
|
:include: sample/simple.rb
|
@@ -21,28 +27,13 @@ To build ruby-libjit, you will need to install libjit. If it is not
|
|
21
27
|
available pre-compiled for your platform, you may build the latest
|
22
28
|
release like this:
|
23
29
|
|
24
|
-
$ wget ftp://ftp.gnu.org/gnu/dotgnu/
|
25
|
-
$ tar xvfz libjit-0.1.
|
26
|
-
$ cd libjit-0.1.
|
27
|
-
$ ./configure
|
28
|
-
$ make
|
29
|
-
$ sudo make install
|
30
|
-
|
31
|
-
Or the latest development version like this:
|
32
|
-
|
33
|
-
$ cvs -z3 -d:pserver:anonymous@cvs.sv.gnu.org:/sources/dotgnu-pnet co libjit
|
34
|
-
$ cd libjit
|
35
|
-
$ ./auto_gen.sh
|
30
|
+
$ wget ftp://ftp.gnu.org/gnu/dotgnu/libjit/libjit-0.1.2.tar.gz
|
31
|
+
$ tar xvfz libjit-0.1.2.tar.gz
|
32
|
+
$ cd libjit-0.1.2
|
36
33
|
$ ./configure
|
37
34
|
$ make
|
38
35
|
$ sudo make install
|
39
36
|
|
40
|
-
To build ruby-libjit, run setup.rb:
|
41
|
-
|
42
|
-
$ ruby setup.rb config
|
43
|
-
$ ruby setup.rb setup
|
44
|
-
$ sudo ruby setup.rb install
|
45
|
-
|
46
37
|
For a more complete JIT framework and compiler for Ruby code, please
|
47
38
|
take a look at Ludicrous:
|
48
39
|
|
data/ext/extconf.rb
CHANGED
@@ -1,6 +1,14 @@
|
|
1
1
|
require 'mkmf'
|
2
|
+
require 'rbconfig'
|
2
3
|
|
3
|
-
if
|
4
|
+
if Config::CONFIG['host_os'] =~ /cygwin|win32|windows/ then
|
5
|
+
need_windows_h = [ 'windows.h' ]
|
6
|
+
$defs << ' -DNEED_WINDOWS_H'
|
7
|
+
else
|
8
|
+
need_windows_h = [ ]
|
9
|
+
end
|
10
|
+
|
11
|
+
if not have_library('jit', 'jit_init', need_windows_h + ["jit/jit.h"]) then
|
4
12
|
$stderr.puts "libjit not found"
|
5
13
|
exit 1
|
6
14
|
end
|
data/ext/insns.inc.rpp
CHANGED
data/ext/jit.c
CHANGED
@@ -2,6 +2,10 @@
|
|
2
2
|
#define _GNU_SOURCE
|
3
3
|
#endif
|
4
4
|
|
5
|
+
#ifdef NEED_WINDOWS_H
|
6
|
+
#include <windows.h>
|
7
|
+
#endif
|
8
|
+
|
5
9
|
#include <ruby.h>
|
6
10
|
|
7
11
|
#include <stdio.h>
|
@@ -16,6 +20,14 @@
|
|
16
20
|
#include "minimal_node.h"
|
17
21
|
#endif
|
18
22
|
|
23
|
+
#ifndef RARRAY_LEN
|
24
|
+
#define RARRAY_LEN(a) RARRAY(a)->len
|
25
|
+
#endif
|
26
|
+
|
27
|
+
#ifndef RARRAY_PTR
|
28
|
+
#define RARRAY_PTR(a) RARRAY(a)->ptr
|
29
|
+
#endif
|
30
|
+
|
19
31
|
static VALUE rb_mJIT;
|
20
32
|
static VALUE rb_cContext;
|
21
33
|
static VALUE rb_cFunction;
|
@@ -89,6 +101,18 @@ typedef jit_ptr jit_Function_Ptr;
|
|
89
101
|
* ---------------------------------------------------------------------------
|
90
102
|
*/
|
91
103
|
|
104
|
+
static VALUE lookup_const(VALUE module, VALUE symbol)
|
105
|
+
{
|
106
|
+
if(SYMBOL_P(symbol))
|
107
|
+
{
|
108
|
+
return rb_const_get(module, SYM2ID(symbol));
|
109
|
+
}
|
110
|
+
else
|
111
|
+
{
|
112
|
+
return symbol;
|
113
|
+
}
|
114
|
+
}
|
115
|
+
|
92
116
|
static void check_type(char const * param_name, VALUE expected_klass, VALUE val)
|
93
117
|
{
|
94
118
|
if(!rb_obj_is_kind_of(val, expected_klass))
|
@@ -381,6 +405,7 @@ static VALUE function_value_klass(VALUE self, VALUE type_v, VALUE klass)
|
|
381
405
|
|
382
406
|
Data_Get_Struct(self, struct _jit_function, function);
|
383
407
|
|
408
|
+
type_v = lookup_const(rb_cType, type_v);
|
384
409
|
check_type("type", rb_cType, type_v);
|
385
410
|
Data_Get_Struct(type_v, struct _jit_type, type);
|
386
411
|
|
@@ -514,6 +539,7 @@ static VALUE function_const(VALUE self, VALUE type_v, VALUE constant)
|
|
514
539
|
|
515
540
|
Data_Get_Struct(self, struct _jit_function, function);
|
516
541
|
|
542
|
+
type_v = lookup_const(rb_cType, type_v);
|
517
543
|
check_type("type", rb_cType, type_v);
|
518
544
|
Data_Get_Struct(type_v, struct _jit_type, type);
|
519
545
|
|
@@ -537,9 +563,9 @@ static void convert_call_args(jit_function_t function, jit_value_t * args, VALUE
|
|
537
563
|
{
|
538
564
|
int j;
|
539
565
|
|
540
|
-
for(j = 0; j <
|
566
|
+
for(j = 0; j < RARRAY_LEN(args_v); ++j)
|
541
567
|
{
|
542
|
-
VALUE value =
|
568
|
+
VALUE value = RARRAY_PTR(args_v)[j];
|
543
569
|
jit_value_t arg;
|
544
570
|
|
545
571
|
jit_type_t type = jit_type_get_param(signature, j);
|
@@ -596,7 +622,7 @@ static VALUE function_insn_call(int argc, VALUE * argv, VALUE self)
|
|
596
622
|
check_type("called function", rb_cFunction, called_function_v);
|
597
623
|
Data_Get_Struct(called_function_v, struct _jit_function, called_function);
|
598
624
|
|
599
|
-
num_args =
|
625
|
+
num_args = RARRAY_LEN(args_v);
|
600
626
|
args = ALLOCA_N(jit_value_t, num_args);
|
601
627
|
|
602
628
|
signature = jit_function_get_signature(function);
|
@@ -650,7 +676,7 @@ static VALUE function_insn_call_native(int argc, VALUE * argv, VALUE self)
|
|
650
676
|
|
651
677
|
Data_Get_Struct(signature_v, struct _jit_type, signature);
|
652
678
|
|
653
|
-
num_args =
|
679
|
+
num_args = RARRAY_LEN(args_v);
|
654
680
|
args = ALLOCA_N(jit_value_t, num_args);
|
655
681
|
|
656
682
|
if(num_args != jit_type_num_params(signature))
|
@@ -989,27 +1015,31 @@ static VALUE wrap_type(jit_type_t type)
|
|
989
1015
|
static VALUE type_s_create_signature(
|
990
1016
|
VALUE klass, VALUE abi_v, VALUE return_type_v, VALUE params_v)
|
991
1017
|
{
|
992
|
-
jit_abi_t abi
|
1018
|
+
jit_abi_t abi;
|
993
1019
|
jit_type_t return_type;
|
994
1020
|
jit_type_t * params;
|
995
1021
|
jit_type_t signature;
|
996
1022
|
int j;
|
997
1023
|
int len;
|
998
1024
|
|
1025
|
+
return_type_v = lookup_const(rb_cType, return_type_v);
|
999
1026
|
check_type("return type", rb_cType, return_type_v);
|
1000
|
-
|
1001
1027
|
Data_Get_Struct(return_type_v, struct _jit_type, return_type);
|
1002
1028
|
|
1003
1029
|
Check_Type(params_v, T_ARRAY);
|
1004
|
-
len =
|
1030
|
+
len = RARRAY_LEN(params_v);
|
1005
1031
|
params = ALLOCA_N(jit_type_t, len);
|
1006
1032
|
for(j = 0; j < len; ++j)
|
1007
1033
|
{
|
1008
|
-
VALUE param =
|
1034
|
+
VALUE param = RARRAY_PTR(params_v)[j];
|
1035
|
+
param = lookup_const(rb_cType, param);
|
1009
1036
|
check_type("param", rb_cType, param);
|
1010
1037
|
Data_Get_Struct(param, struct _jit_type, params[j]);
|
1011
1038
|
}
|
1012
1039
|
|
1040
|
+
abi_v = lookup_const(rb_mABI, abi_v);
|
1041
|
+
abi = NUM2INT(abi_v);
|
1042
|
+
|
1013
1043
|
signature = jit_type_create_signature(abi, return_type, params, len, 1);
|
1014
1044
|
return wrap_type(signature);
|
1015
1045
|
}
|
@@ -1029,16 +1059,16 @@ static VALUE type_s_create_struct(
|
|
1029
1059
|
int j;
|
1030
1060
|
|
1031
1061
|
Check_Type(fields_v, T_ARRAY);
|
1032
|
-
len =
|
1062
|
+
len = RARRAY_LEN(fields_v);
|
1033
1063
|
fields = ALLOCA_N(jit_type_t, len);
|
1034
1064
|
for(j = 0; j < len; ++j)
|
1035
1065
|
{
|
1036
|
-
VALUE field =
|
1066
|
+
VALUE field = RARRAY_PTR(fields_v)[j];
|
1037
1067
|
check_type("field", rb_cType, field);
|
1038
1068
|
Data_Get_Struct(field, struct _jit_type, fields[j]);
|
1039
1069
|
}
|
1040
1070
|
|
1041
|
-
struct_type = jit_type_create_struct(fields,
|
1071
|
+
struct_type = jit_type_create_struct(fields, RARRAY_LEN(fields_v), 1);
|
1042
1072
|
return wrap_type_with_klass(struct_type, klass);
|
1043
1073
|
}
|
1044
1074
|
|
@@ -1293,6 +1323,7 @@ static VALUE value_type(VALUE self)
|
|
1293
1323
|
jit_type_t type;
|
1294
1324
|
Data_Get_Struct(self, struct _jit_value, value);
|
1295
1325
|
type = jit_value_get_type(value);
|
1326
|
+
type = jit_type_copy(type);
|
1296
1327
|
return wrap_type(type);
|
1297
1328
|
}
|
1298
1329
|
|
data/lib/jit/array.rb
CHANGED
@@ -78,6 +78,10 @@ module JIT
|
|
78
78
|
class Instance < JIT::Value
|
79
79
|
attr_reader :array_type
|
80
80
|
attr_reader :type
|
81
|
+
|
82
|
+
# A pointer to the first element of the array. Note that this
|
83
|
+
# differs from +address+, which returns the address of a pointer
|
84
|
+
# to the array.
|
81
85
|
attr_reader :ptr
|
82
86
|
|
83
87
|
# TODO: This breaks code below?
|
@@ -129,7 +133,3 @@ module JIT
|
|
129
133
|
end
|
130
134
|
end
|
131
135
|
|
132
|
-
if __FILE__ == $0 then
|
133
|
-
a = JIT::Array.new()
|
134
|
-
end
|
135
|
-
|
data/lib/jit/function.rb
CHANGED
@@ -48,8 +48,7 @@ module JIT
|
|
48
48
|
return If.new(self, end_label)
|
49
49
|
end
|
50
50
|
|
51
|
-
# :nodoc:
|
52
|
-
class If
|
51
|
+
class If # :nodoc:
|
53
52
|
def initialize(function, end_label)
|
54
53
|
@function = function
|
55
54
|
@end_label = end_label
|
@@ -92,8 +91,7 @@ module JIT
|
|
92
91
|
return Case.new(self, value)
|
93
92
|
end
|
94
93
|
|
95
|
-
# :nodoc:
|
96
|
-
class Case
|
94
|
+
class Case # :nodoc:
|
97
95
|
def initialize(function, value)
|
98
96
|
@function = function
|
99
97
|
@value = value
|
@@ -120,49 +118,50 @@ module JIT
|
|
120
118
|
|
121
119
|
# Usage:
|
122
120
|
#
|
123
|
-
# until
|
121
|
+
# until { <condition> }.do {
|
124
122
|
# # loop body
|
125
123
|
# } .end
|
126
124
|
#
|
127
|
-
def until(
|
125
|
+
def until(&block)
|
128
126
|
start_label = Label.new
|
129
127
|
done_label = Label.new
|
130
128
|
insn_label(start_label)
|
131
|
-
insn_branch_if(
|
129
|
+
insn_branch_if(block.call, done_label)
|
132
130
|
loop = Loop.new(self, start_label, done_label)
|
133
|
-
block.call(loop)
|
134
|
-
insn_branch(start_label)
|
135
|
-
insn_label(done_label)
|
136
131
|
return loop
|
137
132
|
end
|
138
133
|
|
139
134
|
# Usage:
|
140
135
|
#
|
141
|
-
# while
|
136
|
+
# while { <condition> }.do {
|
142
137
|
# # loop body
|
143
138
|
# } .end
|
144
139
|
#
|
145
|
-
def while(
|
140
|
+
def while(&block)
|
146
141
|
start_label = Label.new
|
147
142
|
done_label = Label.new
|
148
143
|
insn_label(start_label)
|
149
|
-
insn_branch_if_not(
|
144
|
+
insn_branch_if_not(block.call, done_label)
|
150
145
|
loop = Loop.new(self, start_label, done_label)
|
151
|
-
block.call(loop)
|
152
|
-
insn_branch(start_label)
|
153
|
-
insn_label(done_label)
|
154
146
|
return loop
|
155
147
|
end
|
156
148
|
|
157
|
-
# :nodoc:
|
158
|
-
class Loop
|
149
|
+
class Loop # :nodoc:
|
159
150
|
def initialize(function, start_label, done_label)
|
160
151
|
@function = function
|
152
|
+
@start_label = start_label
|
161
153
|
@redo_label = start_label
|
162
154
|
@done_label = done_label
|
163
155
|
end
|
164
156
|
|
157
|
+
def do(&block)
|
158
|
+
block.call(self)
|
159
|
+
return self
|
160
|
+
end
|
161
|
+
|
165
162
|
def end
|
163
|
+
@function.insn_branch(@start_label)
|
164
|
+
@function.insn_label(@done_label)
|
166
165
|
end
|
167
166
|
|
168
167
|
def break
|
data/lib/jit/pointer.rb
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
require 'jit'
|
2
|
+
require 'jit/value'
|
3
|
+
|
4
|
+
module JIT
|
5
|
+
|
6
|
+
# An abstraction for a pointer to a non-void type.
|
7
|
+
#
|
8
|
+
# Example usage:
|
9
|
+
#
|
10
|
+
# TODO
|
11
|
+
#
|
12
|
+
class Pointer < JIT::Type
|
13
|
+
attr_reader :type
|
14
|
+
|
15
|
+
# Create a new JIT pointer type.
|
16
|
+
#
|
17
|
+
# +type+:: The pointed-to type.
|
18
|
+
#
|
19
|
+
def self.new(type)
|
20
|
+
pointer_type = self.create_pointer(type)
|
21
|
+
pointer_type.instance_eval do
|
22
|
+
@type = type
|
23
|
+
end
|
24
|
+
return pointer_type
|
25
|
+
end
|
26
|
+
|
27
|
+
# Wrap an existing void pointer.
|
28
|
+
#
|
29
|
+
# +ptr+:: The pointer to wrap.
|
30
|
+
#
|
31
|
+
def wrap(ptr)
|
32
|
+
return Instance.wrap(self, ptr)
|
33
|
+
end
|
34
|
+
|
35
|
+
# Return the offset (in bytes) of the element at the given +index+.
|
36
|
+
#
|
37
|
+
# +index+:: The index of the desired element.
|
38
|
+
#
|
39
|
+
def offset_of(index)
|
40
|
+
return index * @type.size
|
41
|
+
end
|
42
|
+
|
43
|
+
# Return the type of the element at the given +index+.
|
44
|
+
#
|
45
|
+
# +index+:: The index of the desired element.
|
46
|
+
#
|
47
|
+
def type_of(index)
|
48
|
+
return @type
|
49
|
+
end
|
50
|
+
|
51
|
+
# An abstraction for a pointer object.
|
52
|
+
#
|
53
|
+
class Instance < JIT::Value
|
54
|
+
# Wrap an existing void pointer.
|
55
|
+
#
|
56
|
+
# +array_type+:: The JIT::Array type to wrap.
|
57
|
+
# +ptr+:: A pointer to the first element in the array.
|
58
|
+
#
|
59
|
+
def self.wrap(pointer_type, ptr)
|
60
|
+
value = self.new_value(ptr.function, pointer_type)
|
61
|
+
value.store(ptr)
|
62
|
+
value.instance_eval do
|
63
|
+
@pointer_type = pointer_type
|
64
|
+
@pointed_type = pointer_type.type
|
65
|
+
@function = ptr.function
|
66
|
+
@ptr = ptr
|
67
|
+
end
|
68
|
+
return value
|
69
|
+
end
|
70
|
+
|
71
|
+
# Generate JIT code to retrieve the element at the given +index+.
|
72
|
+
#
|
73
|
+
# +index+:: The index of the desired element. The value of the
|
74
|
+
# index must be known at compile-time.
|
75
|
+
#
|
76
|
+
def [](index)
|
77
|
+
@function.insn_load_relative(
|
78
|
+
@ptr,
|
79
|
+
@pointer_type.offset_of(index),
|
80
|
+
@pointer_type.type_of(index))
|
81
|
+
end
|
82
|
+
|
83
|
+
# Generate JIT code to assign to the element at the given +index+.
|
84
|
+
#
|
85
|
+
# +index+:: The index of the desired element. The value of the
|
86
|
+
# index must be known at compile-time.
|
87
|
+
# +value+:: The JIT::Value to assign to the element.
|
88
|
+
#
|
89
|
+
def []=(index, value)
|
90
|
+
@function.insn_store_relative(
|
91
|
+
@ptr,
|
92
|
+
@pointer_type.offset_of(index),
|
93
|
+
value)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
data/lib/jit/struct.rb
CHANGED
data/sample/fib.rb
CHANGED
@@ -2,19 +2,19 @@ require 'jit'
|
|
2
2
|
|
3
3
|
fib = nil
|
4
4
|
signature = JIT::Type.create_signature(
|
5
|
-
|
6
|
-
|
7
|
-
[
|
5
|
+
:CDECL,
|
6
|
+
:INT,
|
7
|
+
[ :INT ])
|
8
8
|
fib = JIT::Function.build(signature) do |f|
|
9
9
|
n = f.param(0)
|
10
10
|
|
11
|
-
a = f.value(
|
12
|
-
b = f.value(
|
13
|
-
c = f.value(
|
11
|
+
a = f.value(:INT, 0)
|
12
|
+
b = f.value(:INT, 1)
|
13
|
+
c = f.value(:INT, 1)
|
14
14
|
|
15
|
-
i = f.value(
|
15
|
+
i = f.value(:INT, 0)
|
16
16
|
|
17
|
-
f.while
|
17
|
+
f.while{ i < n }.do {
|
18
18
|
c.store(a + b)
|
19
19
|
a.store(b)
|
20
20
|
b.store(c)
|
data/test/test_jit_function.rb
CHANGED
@@ -169,7 +169,7 @@ class TestJitFunction < Test::Unit::TestCase
|
|
169
169
|
function = JIT::Function.compile(context, signature) do |f|
|
170
170
|
true_value = f.const(JIT::Type::INT, 1)
|
171
171
|
false_value = f.const(JIT::Type::INT, 0)
|
172
|
-
f.while
|
172
|
+
f.while{ true_value }.do {
|
173
173
|
f.insn_return true_value
|
174
174
|
}.end
|
175
175
|
f.insn_return false_value
|
@@ -189,7 +189,7 @@ class TestJitFunction < Test::Unit::TestCase
|
|
189
189
|
function = JIT::Function.compile(context, signature) do |f|
|
190
190
|
value = f.value(JIT::Type::INT)
|
191
191
|
value.store(f.const(JIT::Type::INT, 0))
|
192
|
-
f.while
|
192
|
+
f.while{ value < f.const(JIT::Type::INT, 2) }.do {
|
193
193
|
value.store(value + f.const(JIT::Type::INT, 1))
|
194
194
|
}.end
|
195
195
|
f.insn_return value
|
@@ -209,7 +209,7 @@ class TestJitFunction < Test::Unit::TestCase
|
|
209
209
|
function = JIT::Function.compile(context, signature) do |f|
|
210
210
|
true_value = f.const(JIT::Type::INT, 1)
|
211
211
|
false_value = f.const(JIT::Type::INT, 0)
|
212
|
-
f.while
|
212
|
+
f.while{ false_value }.do {
|
213
213
|
f.insn_return true_value
|
214
214
|
}.end
|
215
215
|
f.insn_return false_value
|
@@ -229,7 +229,7 @@ class TestJitFunction < Test::Unit::TestCase
|
|
229
229
|
function = JIT::Function.compile(context, signature) do |f|
|
230
230
|
true_value = f.const(JIT::Type::INT, 1)
|
231
231
|
false_value = f.const(JIT::Type::INT, 0)
|
232
|
-
f.until
|
232
|
+
f.until{ false_value }.do {
|
233
233
|
f.insn_return true_value
|
234
234
|
}.end
|
235
235
|
f.insn_return false_value
|
@@ -249,7 +249,7 @@ class TestJitFunction < Test::Unit::TestCase
|
|
249
249
|
function = JIT::Function.compile(context, signature) do |f|
|
250
250
|
value = f.value(JIT::Type::INT)
|
251
251
|
value.store(f.const(JIT::Type::INT, 0))
|
252
|
-
f.until
|
252
|
+
f.until{ value == f.const(JIT::Type::INT, 2) }.do {
|
253
253
|
value.store(value + f.const(JIT::Type::INT, 1))
|
254
254
|
}.end
|
255
255
|
f.insn_return value
|
@@ -269,7 +269,7 @@ class TestJitFunction < Test::Unit::TestCase
|
|
269
269
|
function = JIT::Function.compile(context, signature) do |f|
|
270
270
|
true_value = f.const(JIT::Type::INT, 1)
|
271
271
|
false_value = f.const(JIT::Type::INT, 0)
|
272
|
-
f.until
|
272
|
+
f.until{ true_value }.do {
|
273
273
|
f.insn_return true_value
|
274
274
|
}.end
|
275
275
|
f.insn_return false_value
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'jit/pointer'
|
2
|
+
require 'jit/array'
|
3
|
+
require 'jit/function'
|
4
|
+
require 'test/unit'
|
5
|
+
require 'assertions'
|
6
|
+
|
7
|
+
class TestJitArray < Test::Unit::TestCase
|
8
|
+
include JitAssertions
|
9
|
+
|
10
|
+
def test_new_pointer
|
11
|
+
p_type = JIT::Pointer.new(JIT::Type::INT)
|
12
|
+
assert_equal JIT::Type::INT, p_type.type
|
13
|
+
end
|
14
|
+
|
15
|
+
# TODO: wrap
|
16
|
+
|
17
|
+
def test_offset_of
|
18
|
+
p_type = JIT::Pointer.new(JIT::Type::INT)
|
19
|
+
assert_equal 0, p_type.offset_of(0)
|
20
|
+
assert_equal 4, p_type.offset_of(1)
|
21
|
+
assert_equal 8, p_type.offset_of(2)
|
22
|
+
assert_equal 12, p_type.offset_of(3)
|
23
|
+
# TODO: check out of bounds
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_type_of
|
27
|
+
p_type = JIT::Pointer.new(JIT::Type::INT)
|
28
|
+
assert_equal JIT::Type::INT, p_type.type_of(0)
|
29
|
+
assert_equal JIT::Type::INT, p_type.type_of(1)
|
30
|
+
assert_equal JIT::Type::INT, p_type.type_of(2)
|
31
|
+
assert_equal JIT::Type::INT, p_type.type_of(3)
|
32
|
+
# TODO: check out of bounds
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_instance_bracket
|
36
|
+
p = proc { |f|
|
37
|
+
a_type = JIT::Array.new(JIT::Type::INT, 4)
|
38
|
+
p_type = JIT::Pointer.new(JIT::Type::INT)
|
39
|
+
a = a_type.create(f)
|
40
|
+
ptr = p_type.wrap(a.ptr)
|
41
|
+
f.insn_store_relative(a.ptr, 4, f.const(JIT::Type::INT, 42))
|
42
|
+
f.return ptr[1]
|
43
|
+
}
|
44
|
+
assert_function_result(
|
45
|
+
:result => [ JIT::Type::INT, 42 ],
|
46
|
+
&p)
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_instance_bracket_eq
|
50
|
+
p = proc { |f|
|
51
|
+
a_type = JIT::Array.new(JIT::Type::INT, 4)
|
52
|
+
p_type = JIT::Pointer.new(JIT::Type::INT)
|
53
|
+
a = a_type.create(f)
|
54
|
+
ptr = p_type.wrap(a.ptr)
|
55
|
+
ptr[1] = f.const(JIT::Type::INT, 42)
|
56
|
+
f.return a[1]
|
57
|
+
}
|
58
|
+
assert_function_result(
|
59
|
+
:result => [ JIT::Type::INT, 42 ],
|
60
|
+
&p)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-libjit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Brannan
|
@@ -9,11 +9,16 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2009-12-02 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
16
|
-
description:
|
16
|
+
description: |
|
17
|
+
Ruby-libjit is a wrapper for the libjit library. Libjit is a
|
18
|
+
lightweight library for building just-in-time compilers. Ruby-libjit
|
19
|
+
includes both a wrapper for libjit and a minimal DSL for building loops
|
20
|
+
and control structures.
|
21
|
+
|
17
22
|
email: curlypaul924@gmail.com
|
18
23
|
executables: []
|
19
24
|
|
@@ -30,22 +35,25 @@ files:
|
|
30
35
|
- lib/jit/array.rb
|
31
36
|
- lib/jit/function.rb
|
32
37
|
- lib/jit/struct.rb
|
38
|
+
- lib/jit/pointer.rb
|
33
39
|
- lib/jit/value.rb
|
34
|
-
- ext/rubypp.rb
|
35
40
|
- ext/extconf.rb
|
36
|
-
- ext/
|
37
|
-
- ext/minimal_node.c
|
41
|
+
- ext/rubypp.rb
|
38
42
|
- ext/jit.c
|
39
|
-
- ext/
|
43
|
+
- ext/minimal_node.c
|
44
|
+
- ext/method_data.c
|
40
45
|
- ext/minimal_node.h
|
46
|
+
- ext/method_data.h
|
41
47
|
- ext/rubyjit.h
|
42
|
-
- ext/insns.inc.rpp
|
43
48
|
- ext/method_data.c.rpp
|
49
|
+
- ext/insns.inc.rpp
|
44
50
|
- sample/gcd_benchmark.rb
|
45
|
-
- sample/fib.rb
|
46
51
|
- sample/simple.rb
|
52
|
+
- sample/fib.rb
|
47
53
|
has_rdoc: true
|
48
54
|
homepage: http://ruby-libjit.rubyforge.org
|
55
|
+
licenses: []
|
56
|
+
|
49
57
|
post_install_message:
|
50
58
|
rdoc_options: []
|
51
59
|
|
@@ -66,12 +74,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
66
74
|
requirements: []
|
67
75
|
|
68
76
|
rubyforge_project: ruby-libjit
|
69
|
-
rubygems_version: 1.3.
|
77
|
+
rubygems_version: 1.3.5
|
70
78
|
signing_key:
|
71
|
-
specification_version:
|
79
|
+
specification_version: 3
|
72
80
|
summary: A wrapper for the libjit library
|
73
81
|
test_files:
|
74
|
-
- test/test_jit_array.rb
|
75
|
-
- test/test_jit_function.rb
|
76
|
-
- test/test_jit_value.rb
|
77
82
|
- test/test_jit_struct.rb
|
83
|
+
- test/test_jit_value.rb
|
84
|
+
- test/test_jit_function.rb
|
85
|
+
- test/test_jit_array.rb
|
86
|
+
- test/test_jit_pointer.rb
|