rice 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Doxyfile +1 -1
- data/Makefile.in +130 -52
- data/README +45 -79
- data/Rakefile +1 -36
- data/aclocal.m4 +133 -61
- data/config.guess +43 -8
- data/config.sub +41 -13
- data/configure +1370 -1898
- data/configure.ac +2 -2
- data/doxygen.ac +1 -1
- data/extconf.rb +3 -1
- data/rice/Arg_impl.hpp +2 -2
- data/rice/Data_Type.cpp +34 -1
- data/rice/Data_Type.ipp +14 -5
- data/rice/Data_Type_defn.hpp +28 -1
- data/rice/Director.cpp +0 -6
- data/rice/Director.hpp +0 -8
- data/rice/Hash.hpp +1 -1
- data/rice/Makefile.am +2 -12
- data/rice/Makefile.in +111 -88
- data/rice/Object.cpp +8 -1
- data/rice/Object.ipp +1 -1
- data/rice/Object_defn.hpp +8 -0
- data/rice/config.hpp +3 -0
- data/rice/config.hpp.in +3 -0
- data/rice/detail/Auto_Function_Wrapper.ipp +1025 -512
- data/rice/detail/Auto_Member_Function_Wrapper.ipp +545 -272
- data/rice/detail/cfp.hpp +24 -0
- data/rice/detail/cfp.ipp +51 -0
- data/rice/detail/method_data.cpp +107 -336
- data/rice/detail/node.hpp +13 -13
- data/rice/detail/ruby.hpp +4 -0
- data/rice/detail/rubysig.hpp +19 -19
- data/rice/detail/traits.hpp +43 -0
- data/rice/generate_code.rb +37 -16
- data/rice/protect.hpp +1 -1
- data/rice/protect.ipp +448 -192
- data/rice/to_from_ruby.ipp +4 -12
- data/rice/to_from_ruby_defn.hpp +2 -2
- data/ruby/Makefile.in +99 -32
- data/ruby/lib/Makefile.in +61 -21
- data/ruby/lib/mkmf-rice.rb.in +9 -2
- data/ruby/lib/version.rb +1 -1
- data/sample/Makefile.in +33 -10
- data/test/Makefile.am +27 -0
- data/test/Makefile.in +270 -59
- data/test/ext/Makefile.am +43 -0
- data/test/ext/Makefile.in +399 -0
- data/test/ext/t1/Foo.hpp +10 -0
- data/test/ext/t1/extconf.rb +2 -0
- data/test/ext/t1/t1.cpp +15 -0
- data/test/ext/t2/extconf.rb +2 -0
- data/test/ext/t2/t2.cpp +11 -0
- data/test/test_Allocation_Strategies.cpp +1 -1
- data/test/test_Class.cpp +79 -0
- data/test/test_Data_Type.cpp +2 -2
- data/test/test_Director.cpp +114 -38
- data/test/test_Module.cpp +27 -2
- data/test/test_To_From_Ruby.cpp +4 -4
- data/test/test_rice.rb +9 -1
- metadata +23 -8
- data/rice/detail/method_data.cpp.rpp +0 -301
- data/rice/detail/mininode.cpp.rpp +0 -62
- data/rice/detail/mininode.hpp.rpp +0 -119
- data/rice/detail/remove_const.hpp +0 -21
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rice
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Brannan
|
@@ -10,10 +10,19 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2009-
|
13
|
+
date: 2009-12-14 00:00:00 -05:00
|
14
14
|
default_executable:
|
15
|
-
dependencies:
|
16
|
-
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: rubyforge
|
18
|
+
type: :development
|
19
|
+
version_requirement:
|
20
|
+
version_requirements: !ruby/object:Gem::Requirement
|
21
|
+
requirements:
|
22
|
+
- - ">="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: "0"
|
25
|
+
version:
|
17
26
|
description: |
|
18
27
|
Rice is a C++ interface to Ruby's C API. It provides a type-safe and
|
19
28
|
exception-safe interface in order to make embedding Ruby and writing
|
@@ -154,9 +163,9 @@ files:
|
|
154
163
|
- rice/detail/node.hpp
|
155
164
|
- rice/detail/Wrapped_Function.hpp
|
156
165
|
- rice/detail/protect.hpp
|
157
|
-
- rice/detail/mininode.cpp.rpp
|
158
166
|
- rice/detail/demangle.hpp
|
159
167
|
- rice/detail/define_method_and_auto_wrap.hpp
|
168
|
+
- rice/detail/traits.hpp
|
160
169
|
- rice/detail/default_allocation_func.ipp
|
161
170
|
- rice/detail/wrap_function.hpp
|
162
171
|
- rice/detail/Caster.hpp
|
@@ -166,13 +175,11 @@ files:
|
|
166
175
|
- rice/detail/st.hpp
|
167
176
|
- rice/detail/from_ruby.hpp
|
168
177
|
- rice/detail/win32.hpp
|
169
|
-
- rice/detail/mininode.hpp.rpp
|
170
178
|
- rice/detail/creation_funcs.ipp
|
171
179
|
- rice/detail/to_ruby.hpp
|
172
|
-
- rice/detail/remove_const.hpp
|
173
180
|
- rice/detail/Auto_Function_Wrapper.hpp
|
181
|
+
- rice/detail/cfp.hpp
|
174
182
|
- rice/detail/env.hpp
|
175
|
-
- rice/detail/method_data.cpp.rpp
|
176
183
|
- rice/detail/to_ruby.ipp
|
177
184
|
- rice/detail/method_data.hpp
|
178
185
|
- rice/detail/Exception_Handler.hpp
|
@@ -184,6 +191,7 @@ files:
|
|
184
191
|
- rice/detail/Iterator.hpp
|
185
192
|
- rice/detail/Not_Copyable.hpp
|
186
193
|
- rice/detail/Exception_Handler_defn.hpp
|
194
|
+
- rice/detail/cfp.ipp
|
187
195
|
- rice/detail/define_method_and_auto_wrap.ipp
|
188
196
|
- rice/detail/Auto_Function_Wrapper.ipp
|
189
197
|
- rice/detail/Exception_Handler.ipp
|
@@ -225,6 +233,13 @@ files:
|
|
225
233
|
- test/test_Enum.cpp
|
226
234
|
- test/test_Address_Registration_Guard.cpp
|
227
235
|
- test/test_Director.cpp
|
236
|
+
- test/ext/Makefile.am
|
237
|
+
- test/ext/Makefile.in
|
238
|
+
- test/ext/t1/extconf.rb
|
239
|
+
- test/ext/t1/Foo.hpp
|
240
|
+
- test/ext/t1/t1.cpp
|
241
|
+
- test/ext/t2/extconf.rb
|
242
|
+
- test/ext/t2/t2.cpp
|
228
243
|
has_rdoc: true
|
229
244
|
homepage: http://rice.rubyforge.org/
|
230
245
|
licenses: []
|
@@ -1,301 +0,0 @@
|
|
1
|
-
#include "method_data.hpp"
|
2
|
-
|
3
|
-
// TODO: This is silly, autoconf...
|
4
|
-
#undef PACKAGE_NAME
|
5
|
-
#undef PACKAGE_STRING
|
6
|
-
#undef PACKAGE_TARNAME
|
7
|
-
#undef PACKAGE_VERSION
|
8
|
-
|
9
|
-
#include "../config.hpp"
|
10
|
-
|
11
|
-
#ruby <<END
|
12
|
-
MAX_ARGS = 15
|
13
|
-
nil
|
14
|
-
END
|
15
|
-
|
16
|
-
#if defined(HAVE_NODE_H)
|
17
|
-
/* pre-YARV */
|
18
|
-
#include <node.h>
|
19
|
-
#elif defined(REALLY_HAVE_RUBY_NODE_H)
|
20
|
-
/* YARV */
|
21
|
-
#include <ruby/node.h>
|
22
|
-
#else
|
23
|
-
/* YARV without node.h */
|
24
|
-
#include "mininode.hpp"
|
25
|
-
using namespace Rice::detail::Mininode;
|
26
|
-
#endif
|
27
|
-
|
28
|
-
#include "env.hpp"
|
29
|
-
|
30
|
-
#ifdef RUBY_VM
|
31
|
-
|
32
|
-
/* YARV */
|
33
|
-
|
34
|
-
namespace
|
35
|
-
{
|
36
|
-
|
37
|
-
struct rb_thread_struct
|
38
|
-
{
|
39
|
-
VALUE self;
|
40
|
-
void *vm;
|
41
|
-
VALUE *stack;
|
42
|
-
unsigned long stack_size;
|
43
|
-
VALUE *cfp;
|
44
|
-
/* ... */
|
45
|
-
};
|
46
|
-
|
47
|
-
typedef struct rb_thread_struct rb_thread_t;
|
48
|
-
|
49
|
-
} // namespace
|
50
|
-
|
51
|
-
extern "C" rb_thread_t * ruby_current_thread;
|
52
|
-
|
53
|
-
#endif
|
54
|
-
|
55
|
-
namespace
|
56
|
-
{
|
57
|
-
|
58
|
-
#ifdef RUBY_VM
|
59
|
-
|
60
|
-
/* YARV */
|
61
|
-
|
62
|
-
#define CFP_DATA_MEMO_NODE_AND_PC cfp[0]
|
63
|
-
#define CFP_METHOD_CLASS cfp[11]
|
64
|
-
|
65
|
-
/* On YARV, we store the method data on the stack. We don't have to pop
|
66
|
-
* it off the stack, because the stack pointer will be reset to the
|
67
|
-
* previous frame's stack pointer when the function returns.
|
68
|
-
*/
|
69
|
-
static void fix_frame()
|
70
|
-
{
|
71
|
-
do {
|
72
|
-
VALUE * cfp = ruby_current_thread->cfp;
|
73
|
-
CFP_DATA_MEMO_NODE_AND_PC = RBASIC(CFP_METHOD_CLASS)->klass;
|
74
|
-
|
75
|
-
if(rb_type(CFP_DATA_MEMO_NODE_AND_PC) != T_NODE)
|
76
|
-
{
|
77
|
-
/* This can happen for module functions that are created after
|
78
|
-
* the stub function */
|
79
|
-
rb_raise(
|
80
|
-
rb_eRuntimeError,
|
81
|
-
"Cannot find method data for module function");
|
82
|
-
}
|
83
|
-
else
|
84
|
-
{
|
85
|
-
CFP_METHOD_CLASS = RCLASS_SUPER(CFP_METHOD_CLASS);
|
86
|
-
}
|
87
|
-
} while(0);
|
88
|
-
}
|
89
|
-
|
90
|
-
#define FIX_FRAME() \
|
91
|
-
fix_frame()
|
92
|
-
|
93
|
-
static NODE * data_memo_node()
|
94
|
-
{
|
95
|
-
VALUE * cfp = ruby_current_thread->cfp;
|
96
|
-
return (NODE *)CFP_DATA_MEMO_NODE_AND_PC;
|
97
|
-
}
|
98
|
-
|
99
|
-
#else
|
100
|
-
|
101
|
-
/* pre-YARV */
|
102
|
-
|
103
|
-
/* Okay to not pop this temporary frame, since it will be popped by the
|
104
|
-
* caller
|
105
|
-
*/
|
106
|
-
#define FIX_FRAME() \
|
107
|
-
struct FRAME _frame = *ruby_frame; \
|
108
|
-
_frame.last_class = RCLASS(ruby_frame->last_class)->super; \
|
109
|
-
_frame.prev = ruby_frame; \
|
110
|
-
ruby_frame = &_frame; \
|
111
|
-
|
112
|
-
static NODE * data_memo_node()
|
113
|
-
{
|
114
|
-
return (NODE *)(RBASIC(ruby_frame->prev->last_class)->klass);
|
115
|
-
}
|
116
|
-
|
117
|
-
#endif
|
118
|
-
|
119
|
-
typedef VALUE (*Method_Func)(ANYARGS);
|
120
|
-
|
121
|
-
static Method_Func actual_cfunc()
|
122
|
-
{
|
123
|
-
return data_memo_node()->nd_cfnc;
|
124
|
-
}
|
125
|
-
|
126
|
-
static VALUE data_wrapper_m1(int argc, VALUE * argv, VALUE self)
|
127
|
-
{
|
128
|
-
VALUE result;
|
129
|
-
FIX_FRAME();
|
130
|
-
result = (*actual_cfunc())(argc, argv, self);
|
131
|
-
return result;
|
132
|
-
}
|
133
|
-
|
134
|
-
static VALUE data_wrapper_0(VALUE self)
|
135
|
-
{
|
136
|
-
VALUE result;
|
137
|
-
FIX_FRAME();
|
138
|
-
result = (*actual_cfunc())(self);
|
139
|
-
return result;
|
140
|
-
}
|
141
|
-
|
142
|
-
#ruby <<END
|
143
|
-
(1..MAX_ARGS).each do |i|
|
144
|
-
params = (1..i).map { |j| "VALUE arg#{j}" }.join(', ')
|
145
|
-
args = (1..i).map { |j| "arg#{j}" }.join(', ')
|
146
|
-
|
147
|
-
puts <<-END
|
148
|
-
static VALUE data_wrapper_#{i}(VALUE self, #{params})
|
149
|
-
{
|
150
|
-
VALUE result;
|
151
|
-
FIX_FRAME();
|
152
|
-
result = (*actual_cfunc())(self, #{args});
|
153
|
-
return result;
|
154
|
-
}
|
155
|
-
END
|
156
|
-
end
|
157
|
-
|
158
|
-
nil
|
159
|
-
END
|
160
|
-
|
161
|
-
} // namespace
|
162
|
-
|
163
|
-
/* Define a method and attach data to it.
|
164
|
-
*
|
165
|
-
* The method looks to ruby like a normal aliased CFUNC, with a modified
|
166
|
-
* origin class:
|
167
|
-
*
|
168
|
-
* NODE_FBODY
|
169
|
-
* |- (u1) orig - origin class
|
170
|
-
* | |- basic
|
171
|
-
* | | |- flags - origin class flags + FL_SINGLETON
|
172
|
-
* | | +- klass - NODE_MEMO
|
173
|
-
* | | |- (u1) cfnc - actual C function to call
|
174
|
-
* | | |- (u2) rval - stored data
|
175
|
-
* | | +- (u3) 0
|
176
|
-
* | |- iv_tbl - 0
|
177
|
-
* | |- m_tbl - 0
|
178
|
-
* | +- super - actual origin class
|
179
|
-
* |- (u2) mid - name of the method
|
180
|
-
* +- (u3) head - NODE_CFUNC
|
181
|
-
* |- (u1) cfnc - wrapper function to call
|
182
|
-
* +- (u2) argc - function arity
|
183
|
-
*
|
184
|
-
* Or, on YARV:
|
185
|
-
*
|
186
|
-
* NODE_FBODY
|
187
|
-
* |- (u1) oid - name of the method
|
188
|
-
* +- (u2) body - NODE_METHOD
|
189
|
-
* |- (u1) clss - origin class
|
190
|
-
* | |- basic
|
191
|
-
* | | |- flags - origin class flags + FL_SINGLETON
|
192
|
-
* | | +- klass - NODE_MEMO
|
193
|
-
* | | |- (u1) cfnc - actual C function to call
|
194
|
-
* | | |- (u2) rval - stored data
|
195
|
-
* | | +- (u3) 0
|
196
|
-
* | |- ptr - rb_classext_t
|
197
|
-
* | | |- super - actual origin class
|
198
|
-
* | | +- iv_tbl - 0
|
199
|
-
* | |- m_tbl - 0
|
200
|
-
* | +- iv_index_tbl - 0?
|
201
|
-
* |- (u2) body - NODE_CFUNC
|
202
|
-
* | |- (u1) cfnc - wrapper function to call
|
203
|
-
* | |- (u2) argc - function arity
|
204
|
-
* +- (u3) noex - NOEX_PUBLIC
|
205
|
-
*
|
206
|
-
* When the wrapper function is called, last_class is set to the origin
|
207
|
-
* class found in the FBODY node. So that the method data will be
|
208
|
-
* accessible, and so last_class will point to klass and not to our MEMO
|
209
|
-
* node, it is necessary to "fix" the current frame.
|
210
|
-
*
|
211
|
-
* Pre-YARV, this means we duplicate the current frame and set last_class:
|
212
|
-
*
|
213
|
-
* ruby_frame
|
214
|
-
* |- last_class - klass
|
215
|
-
* |- prev
|
216
|
-
* | |- last_class - NODE_MEMO
|
217
|
-
* | | |- (u1) cfnc - actual C function to call
|
218
|
-
* | | |- (u2) rval - stored data
|
219
|
-
* | | +- (u3) 0
|
220
|
-
* | |- prev - the real previous frame
|
221
|
-
* | +- ...
|
222
|
-
* +- ...
|
223
|
-
*
|
224
|
-
* The method data is then accessible via
|
225
|
-
* ruby_frame->prev->last_class->rval.
|
226
|
-
*
|
227
|
-
* On YARV, the current frame is not duplicated; rather, the method data
|
228
|
-
* is placed on the stack and is referenced by one of the unused members
|
229
|
-
* of the control frame (the program counter):
|
230
|
-
*
|
231
|
-
* ruby_current_thread->cfp
|
232
|
-
* |- pc - NODE_MEMO
|
233
|
-
* | |- (u1) cfnc - actual C function to call
|
234
|
-
* | |- (u2) rval - stored data
|
235
|
-
* | +- (u3) 0
|
236
|
-
* |- method_class - klass
|
237
|
-
* +- ...
|
238
|
-
*
|
239
|
-
*/
|
240
|
-
VALUE
|
241
|
-
Rice::detail::
|
242
|
-
define_method_with_data(
|
243
|
-
VALUE klass, ID id, VALUE (*cfunc)(ANYARGS), int arity, VALUE data)
|
244
|
-
{
|
245
|
-
/* TODO: origin should have #to_s and #inspect methods defined */
|
246
|
-
#ifdef HAVE_RB_CLASS_BOOT
|
247
|
-
VALUE origin = rb_class_boot(klass);
|
248
|
-
#else
|
249
|
-
VALUE origin = rb_class_new(klass);
|
250
|
-
#endif
|
251
|
-
NODE * node;
|
252
|
-
|
253
|
-
VALUE (*data_wrapper)(ANYARGS);
|
254
|
-
switch(arity)
|
255
|
-
{
|
256
|
-
#ruby <<END
|
257
|
-
(0..MAX_ARGS).each do |i|
|
258
|
-
puts <<-END
|
259
|
-
case #{i}: data_wrapper = RUBY_METHOD_FUNC(data_wrapper_#{i}); break;
|
260
|
-
END
|
261
|
-
end
|
262
|
-
nil
|
263
|
-
END
|
264
|
-
case -1: data_wrapper = RUBY_METHOD_FUNC(data_wrapper_m1); break;
|
265
|
-
default: rb_raise(rb_eArgError, "unsupported arity %d", arity);
|
266
|
-
}
|
267
|
-
|
268
|
-
FL_SET(origin, FL_SINGLETON);
|
269
|
-
rb_singleton_class_attached(origin, klass);
|
270
|
-
rb_name_class(origin, SYM2ID(rb_class_name(klass)));
|
271
|
-
|
272
|
-
RBASIC(origin)->klass = (VALUE)NEW_NODE(NODE_MEMO, cfunc, data, 0);
|
273
|
-
|
274
|
-
#ifdef RUBY_VM
|
275
|
-
/* YARV */
|
276
|
-
node = NEW_FBODY(
|
277
|
-
NEW_METHOD(
|
278
|
-
NEW_CFUNC(data_wrapper, arity),
|
279
|
-
origin,
|
280
|
-
NOEX_PUBLIC),
|
281
|
-
id);
|
282
|
-
st_insert(RCLASS_M_TBL(klass), id, (st_data_t)node);
|
283
|
-
#else
|
284
|
-
/* pre-YARV */
|
285
|
-
node = NEW_FBODY(
|
286
|
-
NEW_CFUNC(data_wrapper, arity),
|
287
|
-
id,
|
288
|
-
origin);
|
289
|
-
rb_add_method(klass, id, node, NOEX_PUBLIC);
|
290
|
-
#endif
|
291
|
-
|
292
|
-
return Qnil;
|
293
|
-
}
|
294
|
-
|
295
|
-
VALUE
|
296
|
-
Rice::detail::
|
297
|
-
method_data()
|
298
|
-
{
|
299
|
-
return data_memo_node()->nd_rval;
|
300
|
-
}
|
301
|
-
|
@@ -1,62 +0,0 @@
|
|
1
|
-
// TODO: This is silly, autoconf...
|
2
|
-
#undef PACKAGE_NAME
|
3
|
-
#undef PACKAGE_STRING
|
4
|
-
#undef PACKAGE_TARNAME
|
5
|
-
#undef PACKAGE_VERSION
|
6
|
-
|
7
|
-
#include "../config.hpp"
|
8
|
-
|
9
|
-
// TODO: This is silly, autoconf...
|
10
|
-
#undef PACKAGE_NAME
|
11
|
-
#undef PACKAGE_STRING
|
12
|
-
#undef PACKAGE_TARNAME
|
13
|
-
#undef PACKAGE_VERSION
|
14
|
-
|
15
|
-
#if !defined(HAVE_NODE_H) && !defined(REALLY_HAVE_RUBY_NODE_H)
|
16
|
-
|
17
|
-
#include "mininode.hpp"
|
18
|
-
#include <cstring>
|
19
|
-
|
20
|
-
extern "C"
|
21
|
-
char const * ruby_node_name(int node);
|
22
|
-
|
23
|
-
namespace
|
24
|
-
{
|
25
|
-
|
26
|
-
int node_value(char const * name)
|
27
|
-
{
|
28
|
-
/* TODO: any way to end the block? */
|
29
|
-
int j;
|
30
|
-
for(j = 0; ; ++j)
|
31
|
-
{
|
32
|
-
if(!std::strcmp(name, ruby_node_name(j)))
|
33
|
-
{
|
34
|
-
return j;
|
35
|
-
}
|
36
|
-
}
|
37
|
-
}
|
38
|
-
|
39
|
-
} // namespace
|
40
|
-
|
41
|
-
#ruby <<END
|
42
|
-
require 'node_names'
|
43
|
-
NODE_NAMES.each do |name|
|
44
|
-
puts <<-END
|
45
|
-
static int NODE_#{name}_ = -1;
|
46
|
-
|
47
|
-
int Rice::detail::Mininode::get_NODE_#{name}()
|
48
|
-
{
|
49
|
-
if(NODE_#{name}_ == -1)
|
50
|
-
{
|
51
|
-
NODE_#{name}_ = node_value("NODE_#{name}");
|
52
|
-
}
|
53
|
-
|
54
|
-
return NODE_#{name}_;
|
55
|
-
}
|
56
|
-
END
|
57
|
-
end
|
58
|
-
nil
|
59
|
-
END
|
60
|
-
|
61
|
-
#endif
|
62
|
-
|
@@ -1,119 +0,0 @@
|
|
1
|
-
#ifndef Rice__detail__mininode__hpp
|
2
|
-
#define Rice__detail__mininode__hpp
|
3
|
-
|
4
|
-
#include "ruby.hpp"
|
5
|
-
|
6
|
-
// TODO: This is silly, autoconf...
|
7
|
-
#undef PACKAGE_NAME
|
8
|
-
#undef PACKAGE_STRING
|
9
|
-
#undef PACKAGE_TARNAME
|
10
|
-
#undef PACKAGE_VERSION
|
11
|
-
|
12
|
-
#include "../config.hpp"
|
13
|
-
|
14
|
-
// TODO: This is silly, autoconf...
|
15
|
-
#undef PACKAGE_NAME
|
16
|
-
#undef PACKAGE_STRING
|
17
|
-
#undef PACKAGE_TARNAME
|
18
|
-
#undef PACKAGE_VERSION
|
19
|
-
|
20
|
-
#if !defined(HAVE_NODE_H) && !defined(REALLY_HAVE_RUBY_NODE_H)
|
21
|
-
|
22
|
-
namespace Rice
|
23
|
-
{
|
24
|
-
|
25
|
-
namespace detail
|
26
|
-
{
|
27
|
-
|
28
|
-
namespace Mininode
|
29
|
-
{
|
30
|
-
|
31
|
-
typedef struct RNode {
|
32
|
-
unsigned long flags;
|
33
|
-
void * reserved;
|
34
|
-
union {
|
35
|
-
struct RNode * node;
|
36
|
-
VALUE (*cfunc)(ANYARGS);
|
37
|
-
} u1;
|
38
|
-
union {
|
39
|
-
struct RNode * node;
|
40
|
-
VALUE value;
|
41
|
-
} u2;
|
42
|
-
union {
|
43
|
-
struct RNode * node;
|
44
|
-
} u3;
|
45
|
-
} NODE;
|
46
|
-
|
47
|
-
#define nd_cfnc u1.cfunc
|
48
|
-
#define nd_rval u2.value
|
49
|
-
|
50
|
-
/* TODO: No way to know the correct size of node_type */
|
51
|
-
enum node_type {
|
52
|
-
NODE_FOO,
|
53
|
-
};
|
54
|
-
|
55
|
-
extern "C"
|
56
|
-
void rb_add_method(VALUE, ID, NODE *, int);
|
57
|
-
|
58
|
-
extern "C"
|
59
|
-
NODE *rb_node_newnode(enum node_type, VALUE, VALUE, VALUE);
|
60
|
-
|
61
|
-
template<typename T, typename A0, typename A1, typename A2>
|
62
|
-
inline NODE * NEW_NODE(T t, A0 a0, A1 a1, A2 a2)
|
63
|
-
{
|
64
|
-
return rb_node_newnode((node_type)t, (VALUE)a0, (VALUE)a1, (VALUE)a2);
|
65
|
-
}
|
66
|
-
|
67
|
-
#ruby <<END
|
68
|
-
require 'node_names'
|
69
|
-
|
70
|
-
NODE_NAMES.each do |name|
|
71
|
-
puts "#define NODE_#{name} Rice::detail::Mininode::get_NODE_#{name}()"
|
72
|
-
end
|
73
|
-
|
74
|
-
puts
|
75
|
-
|
76
|
-
NODE_NAMES.each do |name|
|
77
|
-
puts "int get_NODE_#{name}();"
|
78
|
-
end
|
79
|
-
nil
|
80
|
-
END
|
81
|
-
|
82
|
-
static const int NOEX_PUBLIC = 0x0;
|
83
|
-
|
84
|
-
inline NODE * NEW_METHOD(NODE * body, VALUE origin, int noex)
|
85
|
-
{
|
86
|
-
return NEW_NODE(NODE_METHOD, origin, body, noex);
|
87
|
-
}
|
88
|
-
|
89
|
-
#ifdef RUBY_VM
|
90
|
-
|
91
|
-
inline NODE * NEW_FBODY(NODE * body, ID id)
|
92
|
-
{
|
93
|
-
return NEW_NODE(NODE_FBODY, id, body, 0);
|
94
|
-
}
|
95
|
-
|
96
|
-
#else
|
97
|
-
|
98
|
-
inline NODE * NEW_FBODY(NODE * body, ID id, VALUE origin)
|
99
|
-
{
|
100
|
-
return NEW_NODE(NODE_FBODY, body, id, origin);
|
101
|
-
}
|
102
|
-
|
103
|
-
#endif // RUBY_VM
|
104
|
-
|
105
|
-
inline NODE * NEW_CFUNC(RUBY_METHOD_FUNC cfunc, int arity)
|
106
|
-
{
|
107
|
-
return NEW_NODE(NODE_CFUNC, cfunc, arity, 0);
|
108
|
-
}
|
109
|
-
|
110
|
-
} // namespace Mininode
|
111
|
-
|
112
|
-
} // namespace detail
|
113
|
-
|
114
|
-
} // namespace Rice
|
115
|
-
|
116
|
-
#endif
|
117
|
-
|
118
|
-
#endif // Rice__detail__mininode__hpp
|
119
|
-
|