rucy 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +3 -0
- data/Gemfile.lock +12 -0
- data/README +4 -0
- data/Rakefile +58 -0
- data/VERSION +1 -0
- data/ext/rucy/extconf.rb +50 -0
- data/ext/rucy/tester.cpp +102 -0
- data/include/rucy/class.h +37 -0
- data/include/rucy/defs.h +97 -0
- data/include/rucy/defs.h.erb +56 -0
- data/include/rucy/exception.h +124 -0
- data/include/rucy/function.h +245 -0
- data/include/rucy/function.h.erb +73 -0
- data/include/rucy/gc.h +59 -0
- data/include/rucy/module.h +96 -0
- data/include/rucy/module.h.erb +68 -0
- data/include/rucy/rucy.h +64 -0
- data/include/rucy/string.h +28 -0
- data/include/rucy/symbol.h +50 -0
- data/include/rucy/value.h +291 -0
- data/include/rucy/value.h.erb +278 -0
- data/include/rucy.h +10 -0
- data/lib/rucy.rb +24 -0
- data/rucy.gemspec +50 -0
- data/src/class.cpp +35 -0
- data/src/exception.cpp +124 -0
- data/src/function.cpp +157 -0
- data/src/function.cpp.erb +74 -0
- data/src/gc.cpp +63 -0
- data/src/module.cpp +321 -0
- data/src/module.cpp.erb +103 -0
- data/src/rucy.cpp +56 -0
- data/src/string.cpp +78 -0
- data/src/symbol.cpp +51 -0
- data/src/value.cpp +511 -0
- data/src/value.cpp.erb +409 -0
- data/support.rb +58 -0
- data/task/ext.rake +36 -0
- data/task/gem.rake +33 -0
- data/task/lib.rake +47 -0
- data/test/test_rucy.rb +57 -0
- metadata +116 -0
@@ -0,0 +1,245 @@
|
|
1
|
+
// -*- c++ -*-
|
2
|
+
#pragma once
|
3
|
+
#ifndef __RUCY_FUNCTION_H__
|
4
|
+
#define __RUCY_FUNCTION_H__
|
5
|
+
|
6
|
+
|
7
|
+
#include <ruby.h>
|
8
|
+
#include <rucy/defs.h>
|
9
|
+
#include <rucy/value.h>
|
10
|
+
|
11
|
+
|
12
|
+
namespace Rucy
|
13
|
+
{
|
14
|
+
|
15
|
+
|
16
|
+
void define_function (const char* name, RubyFunctionN fun);
|
17
|
+
void define_function (const char* name, RubyFunction0 fun);
|
18
|
+
void define_function (const char* name, RubyFunction1 fun);
|
19
|
+
void define_function (const char* name, RubyFunction2 fun);
|
20
|
+
void define_function (const char* name, RubyFunction3 fun);
|
21
|
+
void define_function (const char* name, RubyFunction4 fun);
|
22
|
+
void define_function (const char* name, RubyFunction5 fun);
|
23
|
+
void define_function (const char* name, RubyFunction6 fun);
|
24
|
+
void define_function (const char* name, RubyFunction7 fun);
|
25
|
+
void define_function (const char* name, RubyFunction8 fun);
|
26
|
+
|
27
|
+
Value call (Symbol name, int argc, const Value* argv);
|
28
|
+
Value call (Symbol name);
|
29
|
+
Value call (Symbol name, Value v1);
|
30
|
+
Value call (Symbol name, Value v1, Value v2);
|
31
|
+
Value call (Symbol name, Value v1, Value v2, Value v3);
|
32
|
+
Value call (Symbol name, Value v1, Value v2, Value v3, Value v4);
|
33
|
+
Value call (Symbol name, Value v1, Value v2, Value v3, Value v4, Value v5);
|
34
|
+
Value call (Symbol name, Value v1, Value v2, Value v3, Value v4, Value v5, Value v6);
|
35
|
+
Value call (Symbol name, Value v1, Value v2, Value v3, Value v4, Value v5, Value v6, Value v7);
|
36
|
+
Value call (Symbol name, Value v1, Value v2, Value v3, Value v4, Value v5, Value v6, Value v7, Value v8);
|
37
|
+
|
38
|
+
Value eval (const char* str);
|
39
|
+
|
40
|
+
|
41
|
+
template <typename F> class Fun0
|
42
|
+
{
|
43
|
+
public:
|
44
|
+
Fun0 (F f) : f(f) {}
|
45
|
+
static VALUE function (Fun0* fun) {return (*fun->f)();}
|
46
|
+
private:
|
47
|
+
F f;
|
48
|
+
};// Fun0
|
49
|
+
template <typename F, typename P1> class Fun1
|
50
|
+
{
|
51
|
+
public:
|
52
|
+
Fun1 (F f, P1 p1) : f(f), p1(p1) {}
|
53
|
+
static VALUE function (Fun1* fun) {return (*fun->f)(fun->p1);}
|
54
|
+
private:
|
55
|
+
F f; P1 p1;
|
56
|
+
};// Fun1
|
57
|
+
template <typename F, typename P1, typename P2> class Fun2
|
58
|
+
{
|
59
|
+
public:
|
60
|
+
Fun2 (F f, P1 p1, P2 p2) : f(f), p1(p1), p2(p2) {}
|
61
|
+
static VALUE function (Fun2* fun) {return (*fun->f)(fun->p1, fun->p2);}
|
62
|
+
private:
|
63
|
+
F f; P1 p1; P2 p2;
|
64
|
+
};// Fun2
|
65
|
+
template <typename F, typename P1, typename P2, typename P3> class Fun3
|
66
|
+
{
|
67
|
+
public:
|
68
|
+
Fun3 (F f, P1 p1, P2 p2, P3 p3) : f(f), p1(p1), p2(p2), p3(p3) {}
|
69
|
+
static VALUE function (Fun3* fun) {return (*fun->f)(fun->p1, fun->p2, fun->p3);}
|
70
|
+
private:
|
71
|
+
F f; P1 p1; P2 p2; P3 p3;
|
72
|
+
};// Fun3
|
73
|
+
template <typename F, typename P1, typename P2, typename P3, typename P4> class Fun4
|
74
|
+
{
|
75
|
+
public:
|
76
|
+
Fun4 (F f, P1 p1, P2 p2, P3 p3, P4 p4) : f(f), p1(p1), p2(p2), p3(p3), p4(p4) {}
|
77
|
+
static VALUE function (Fun4* fun) {return (*fun->f)(fun->p1, fun->p2, fun->p3, fun->p4);}
|
78
|
+
private:
|
79
|
+
F f; P1 p1; P2 p2; P3 p3; P4 p4;
|
80
|
+
};// Fun4
|
81
|
+
template <typename F, typename P1, typename P2, typename P3, typename P4, typename P5> class Fun5
|
82
|
+
{
|
83
|
+
public:
|
84
|
+
Fun5 (F f, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) : f(f), p1(p1), p2(p2), p3(p3), p4(p4), p5(p5) {}
|
85
|
+
static VALUE function (Fun5* fun) {return (*fun->f)(fun->p1, fun->p2, fun->p3, fun->p4, fun->p5);}
|
86
|
+
private:
|
87
|
+
F f; P1 p1; P2 p2; P3 p3; P4 p4; P5 p5;
|
88
|
+
};// Fun5
|
89
|
+
template <typename F, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6> class Fun6
|
90
|
+
{
|
91
|
+
public:
|
92
|
+
Fun6 (F f, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6) : f(f), p1(p1), p2(p2), p3(p3), p4(p4), p5(p5), p6(p6) {}
|
93
|
+
static VALUE function (Fun6* fun) {return (*fun->f)(fun->p1, fun->p2, fun->p3, fun->p4, fun->p5, fun->p6);}
|
94
|
+
private:
|
95
|
+
F f; P1 p1; P2 p2; P3 p3; P4 p4; P5 p5; P6 p6;
|
96
|
+
};// Fun6
|
97
|
+
template <typename F, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7> class Fun7
|
98
|
+
{
|
99
|
+
public:
|
100
|
+
Fun7 (F f, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7) : f(f), p1(p1), p2(p2), p3(p3), p4(p4), p5(p5), p6(p6), p7(p7) {}
|
101
|
+
static VALUE function (Fun7* fun) {return (*fun->f)(fun->p1, fun->p2, fun->p3, fun->p4, fun->p5, fun->p6, fun->p7);}
|
102
|
+
private:
|
103
|
+
F f; P1 p1; P2 p2; P3 p3; P4 p4; P5 p5; P6 p6; P7 p7;
|
104
|
+
};// Fun7
|
105
|
+
template <typename F, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8> class Fun8
|
106
|
+
{
|
107
|
+
public:
|
108
|
+
Fun8 (F f, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8) : f(f), p1(p1), p2(p2), p3(p3), p4(p4), p5(p5), p6(p6), p7(p7), p8(p8) {}
|
109
|
+
static VALUE function (Fun8* fun) {return (*fun->f)(fun->p1, fun->p2, fun->p3, fun->p4, fun->p5, fun->p6, fun->p7, fun->p8);}
|
110
|
+
private:
|
111
|
+
F f; P1 p1; P2 p2; P3 p3; P4 p4; P5 p5; P6 p6; P7 p7; P8 p8;
|
112
|
+
};// Fun8
|
113
|
+
|
114
|
+
Value call_protect (VALUE (*fun)(VALUE), VALUE arg);
|
115
|
+
|
116
|
+
template <typename F>
|
117
|
+
inline Value protect (F f)
|
118
|
+
{
|
119
|
+
typedef Fun0<F> FunT;
|
120
|
+
FunT fun(f);
|
121
|
+
return call_protect((VALUE(*)(VALUE)) FunT::function, (VALUE) &fun);
|
122
|
+
}
|
123
|
+
template <typename F, typename P1>
|
124
|
+
inline Value protect (F f, P1 p1)
|
125
|
+
{
|
126
|
+
typedef Fun1<F, P1> FunT;
|
127
|
+
FunT fun(f, p1);
|
128
|
+
return call_protect((VALUE(*)(VALUE)) FunT::function, (VALUE) &fun);
|
129
|
+
}
|
130
|
+
template <typename F, typename P1, typename P2>
|
131
|
+
inline Value protect (F f, P1 p1, P2 p2)
|
132
|
+
{
|
133
|
+
typedef Fun2<F, P1, P2> FunT;
|
134
|
+
FunT fun(f, p1, p2);
|
135
|
+
return call_protect((VALUE(*)(VALUE)) FunT::function, (VALUE) &fun);
|
136
|
+
}
|
137
|
+
template <typename F, typename P1, typename P2, typename P3>
|
138
|
+
inline Value protect (F f, P1 p1, P2 p2, P3 p3)
|
139
|
+
{
|
140
|
+
typedef Fun3<F, P1, P2, P3> FunT;
|
141
|
+
FunT fun(f, p1, p2, p3);
|
142
|
+
return call_protect((VALUE(*)(VALUE)) FunT::function, (VALUE) &fun);
|
143
|
+
}
|
144
|
+
template <typename F, typename P1, typename P2, typename P3, typename P4>
|
145
|
+
inline Value protect (F f, P1 p1, P2 p2, P3 p3, P4 p4)
|
146
|
+
{
|
147
|
+
typedef Fun4<F, P1, P2, P3, P4> FunT;
|
148
|
+
FunT fun(f, p1, p2, p3, p4);
|
149
|
+
return call_protect((VALUE(*)(VALUE)) FunT::function, (VALUE) &fun);
|
150
|
+
}
|
151
|
+
template <typename F, typename P1, typename P2, typename P3, typename P4, typename P5>
|
152
|
+
inline Value protect (F f, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5)
|
153
|
+
{
|
154
|
+
typedef Fun5<F, P1, P2, P3, P4, P5> FunT;
|
155
|
+
FunT fun(f, p1, p2, p3, p4, p5);
|
156
|
+
return call_protect((VALUE(*)(VALUE)) FunT::function, (VALUE) &fun);
|
157
|
+
}
|
158
|
+
template <typename F, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6>
|
159
|
+
inline Value protect (F f, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6)
|
160
|
+
{
|
161
|
+
typedef Fun6<F, P1, P2, P3, P4, P5, P6> FunT;
|
162
|
+
FunT fun(f, p1, p2, p3, p4, p5, p6);
|
163
|
+
return call_protect((VALUE(*)(VALUE)) FunT::function, (VALUE) &fun);
|
164
|
+
}
|
165
|
+
template <typename F, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7>
|
166
|
+
inline Value protect (F f, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7)
|
167
|
+
{
|
168
|
+
typedef Fun7<F, P1, P2, P3, P4, P5, P6, P7> FunT;
|
169
|
+
FunT fun(f, p1, p2, p3, p4, p5, p6, p7);
|
170
|
+
return call_protect((VALUE(*)(VALUE)) FunT::function, (VALUE) &fun);
|
171
|
+
}
|
172
|
+
template <typename F, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8>
|
173
|
+
inline Value protect (F f, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8)
|
174
|
+
{
|
175
|
+
typedef Fun8<F, P1, P2, P3, P4, P5, P6, P7, P8> FunT;
|
176
|
+
FunT fun(f, p1, p2, p3, p4, p5, p6, p7, p8);
|
177
|
+
return call_protect((VALUE(*)(VALUE)) FunT::function, (VALUE) &fun);
|
178
|
+
}
|
179
|
+
|
180
|
+
inline Value protect (const char* method)
|
181
|
+
{
|
182
|
+
return protect(rb_eval_string, method);
|
183
|
+
}
|
184
|
+
template <typename P1>
|
185
|
+
inline Value protect (const char* method, P1 p1)
|
186
|
+
{
|
187
|
+
return protect(rb_eval_string, stringf(
|
188
|
+
"%s(%s)", method,
|
189
|
+
to_str(p1).c_str()).c_str());
|
190
|
+
}
|
191
|
+
template <typename P1, typename P2>
|
192
|
+
inline Value protect (const char* method, P1 p1, P2 p2)
|
193
|
+
{
|
194
|
+
return protect(rb_eval_string, stringf(
|
195
|
+
"%s(%s, %s)", method,
|
196
|
+
to_str(p1).c_str(), to_str(p2).c_str()).c_str());
|
197
|
+
}
|
198
|
+
template <typename P1, typename P2, typename P3>
|
199
|
+
inline Value protect (const char* method, P1 p1, P2 p2, P3 p3)
|
200
|
+
{
|
201
|
+
return protect(rb_eval_string, stringf(
|
202
|
+
"%s(%s, %s, %s)", method,
|
203
|
+
to_str(p1).c_str(), to_str(p2).c_str(), to_str(p3).c_str()).c_str());
|
204
|
+
}
|
205
|
+
template <typename P1, typename P2, typename P3, typename P4>
|
206
|
+
inline Value protect (const char* method, P1 p1, P2 p2, P3 p3, P4 p4)
|
207
|
+
{
|
208
|
+
return protect(rb_eval_string, stringf(
|
209
|
+
"%s(%s, %s, %s, %s)", method,
|
210
|
+
to_str(p1).c_str(), to_str(p2).c_str(), to_str(p3).c_str(), to_str(p4).c_str()).c_str());
|
211
|
+
}
|
212
|
+
template <typename P1, typename P2, typename P3, typename P4, typename P5>
|
213
|
+
inline Value protect (const char* method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5)
|
214
|
+
{
|
215
|
+
return protect(rb_eval_string, stringf(
|
216
|
+
"%s(%s, %s, %s, %s, %s)", method,
|
217
|
+
to_str(p1).c_str(), to_str(p2).c_str(), to_str(p3).c_str(), to_str(p4).c_str(), to_str(p5).c_str()).c_str());
|
218
|
+
}
|
219
|
+
template <typename P1, typename P2, typename P3, typename P4, typename P5, typename P6>
|
220
|
+
inline Value protect (const char* method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6)
|
221
|
+
{
|
222
|
+
return protect(rb_eval_string, stringf(
|
223
|
+
"%s(%s, %s, %s, %s, %s, %s)", method,
|
224
|
+
to_str(p1).c_str(), to_str(p2).c_str(), to_str(p3).c_str(), to_str(p4).c_str(), to_str(p5).c_str(), to_str(p6).c_str()).c_str());
|
225
|
+
}
|
226
|
+
template <typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7>
|
227
|
+
inline Value protect (const char* method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7)
|
228
|
+
{
|
229
|
+
return protect(rb_eval_string, stringf(
|
230
|
+
"%s(%s, %s, %s, %s, %s, %s, %s)", method,
|
231
|
+
to_str(p1).c_str(), to_str(p2).c_str(), to_str(p3).c_str(), to_str(p4).c_str(), to_str(p5).c_str(), to_str(p6).c_str(), to_str(p7).c_str()).c_str());
|
232
|
+
}
|
233
|
+
template <typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8>
|
234
|
+
inline Value protect (const char* method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8)
|
235
|
+
{
|
236
|
+
return protect(rb_eval_string, stringf(
|
237
|
+
"%s(%s, %s, %s, %s, %s, %s, %s, %s)", method,
|
238
|
+
to_str(p1).c_str(), to_str(p2).c_str(), to_str(p3).c_str(), to_str(p4).c_str(), to_str(p5).c_str(), to_str(p6).c_str(), to_str(p7).c_str(), to_str(p8).c_str()).c_str());
|
239
|
+
}
|
240
|
+
|
241
|
+
|
242
|
+
}// Rucy
|
243
|
+
|
244
|
+
|
245
|
+
#endif//EOH
|
@@ -0,0 +1,73 @@
|
|
1
|
+
// -*- c++ -*-
|
2
|
+
% require 'support'
|
3
|
+
#pragma once
|
4
|
+
#ifndef __RUCY_FUNCTION_H__
|
5
|
+
#define __RUCY_FUNCTION_H__
|
6
|
+
|
7
|
+
|
8
|
+
#include <ruby.h>
|
9
|
+
#include <rucy/defs.h>
|
10
|
+
#include <rucy/value.h>
|
11
|
+
|
12
|
+
|
13
|
+
namespace Rucy
|
14
|
+
{
|
15
|
+
|
16
|
+
|
17
|
+
void define_function (const char* name, RubyFunctionN fun);
|
18
|
+
% NTIMES.each do |n|
|
19
|
+
void define_function (const char* name, RubyFunction<%= n %> fun);
|
20
|
+
% end
|
21
|
+
|
22
|
+
Value call (Symbol name, int argc, const Value* argv);
|
23
|
+
% NTIMES.each do |n|
|
24
|
+
Value call (Symbol name<%= params(n) {|i| ", Value v#{i}"} %>);
|
25
|
+
% end
|
26
|
+
|
27
|
+
Value eval (const char* str);
|
28
|
+
|
29
|
+
|
30
|
+
% NTIMES.each do |n|
|
31
|
+
template <typename F<%= params(n) {|i| ", typename P#{i}"} %>> class Fun<%= n %>
|
32
|
+
{
|
33
|
+
public:
|
34
|
+
Fun<%= n %> (F f<%= params(n) {|i| ", P#{i} p#{i}"} %>) : f(f)<%= params(n) {|i| ", p#{i}(p#{i})"} %> {}
|
35
|
+
static VALUE function (Fun<%= n %>* fun) {return (*fun->f)(<%= params(n, ", ") {|i| "fun->p#{i}"} %>);}
|
36
|
+
private:
|
37
|
+
F f; <%= params(n, " ") {|i| "P#{i} p#{i};"} %>
|
38
|
+
};// Fun<%= n %>
|
39
|
+
% end
|
40
|
+
|
41
|
+
Value call_protect (VALUE (*fun)(VALUE), VALUE arg);
|
42
|
+
|
43
|
+
% NTIMES.each do |n|
|
44
|
+
template <typename F<%= params(n) {|i| ", typename P#{i}"} %>>
|
45
|
+
inline Value protect (F f<%= params(n) {|i| ", P#{i} p#{i}"} %>)
|
46
|
+
{
|
47
|
+
typedef Fun<%= n %><F<%= params(n) {|i| ", P#{i}"} %>> FunT;
|
48
|
+
FunT fun(f<%= params(n) {|i| ", p#{i}"} %>);
|
49
|
+
return call_protect((VALUE(*)(VALUE)) FunT::function, (VALUE) &fun);
|
50
|
+
}
|
51
|
+
% end
|
52
|
+
|
53
|
+
% NTIMES.each do |n|
|
54
|
+
% if n != 0
|
55
|
+
template <<%= params(n, ", ") {|i| "typename P#{i}"} %>>
|
56
|
+
% end
|
57
|
+
inline Value protect (const char* method<%= params(n) {|i| ", P#{i} p#{i}"} %>)
|
58
|
+
{
|
59
|
+
% if n == 0
|
60
|
+
return protect(rb_eval_string, method);
|
61
|
+
% else
|
62
|
+
return protect(rb_eval_string, stringf(
|
63
|
+
"%s(<%= params(n, ", ") {|i| "%s"} %>)", method,
|
64
|
+
<%= params(n, ", ") {|i| "to_str(p#{i}).c_str()"} %>).c_str());
|
65
|
+
% end
|
66
|
+
}
|
67
|
+
% end
|
68
|
+
|
69
|
+
|
70
|
+
}// Rucy
|
71
|
+
|
72
|
+
|
73
|
+
#endif//EOH
|
data/include/rucy/gc.h
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
// -*- c++ -*-
|
2
|
+
#pragma once
|
3
|
+
#ifndef __RUCY_GC_H__
|
4
|
+
#define __RUCY_GC_H__
|
5
|
+
|
6
|
+
|
7
|
+
#include <boost/noncopyable.hpp>
|
8
|
+
#include <ruby.h>
|
9
|
+
#include <rucy/value.h>
|
10
|
+
|
11
|
+
|
12
|
+
namespace Rucy
|
13
|
+
{
|
14
|
+
|
15
|
+
|
16
|
+
class GCGuard : public boost::noncopyable
|
17
|
+
{
|
18
|
+
|
19
|
+
public:
|
20
|
+
|
21
|
+
GCGuard (VALUE* v);
|
22
|
+
|
23
|
+
GCGuard (Value* v);
|
24
|
+
|
25
|
+
~GCGuard ();
|
26
|
+
|
27
|
+
private:
|
28
|
+
|
29
|
+
VALUE* pval;
|
30
|
+
|
31
|
+
};// GCGuard
|
32
|
+
|
33
|
+
|
34
|
+
class GlobalValue
|
35
|
+
{
|
36
|
+
|
37
|
+
public:
|
38
|
+
|
39
|
+
GlobalValue (Value v);
|
40
|
+
|
41
|
+
Value value () const;
|
42
|
+
|
43
|
+
operator VALUE () const;
|
44
|
+
|
45
|
+
operator Value () const;
|
46
|
+
|
47
|
+
private:
|
48
|
+
|
49
|
+
Value val;
|
50
|
+
|
51
|
+
GCGuard guard;
|
52
|
+
|
53
|
+
};// GlobalValue
|
54
|
+
|
55
|
+
|
56
|
+
}// Rucy
|
57
|
+
|
58
|
+
|
59
|
+
#endif//EOH
|
@@ -0,0 +1,96 @@
|
|
1
|
+
// -*- c++ -*-
|
2
|
+
#pragma once
|
3
|
+
#ifndef __RUCY_MODULE_H__
|
4
|
+
#define __RUCY_MODULE_H__
|
5
|
+
|
6
|
+
|
7
|
+
#include <ruby.h>
|
8
|
+
#include <rucy/defs.h>
|
9
|
+
#include <rucy/value.h>
|
10
|
+
|
11
|
+
|
12
|
+
namespace Rucy
|
13
|
+
{
|
14
|
+
|
15
|
+
|
16
|
+
class Class;
|
17
|
+
|
18
|
+
|
19
|
+
class Module : public Value
|
20
|
+
{
|
21
|
+
|
22
|
+
typedef Value Super;
|
23
|
+
|
24
|
+
public:
|
25
|
+
|
26
|
+
Module (VALUE v = Qnil);
|
27
|
+
|
28
|
+
Module define_module (const char* name);
|
29
|
+
|
30
|
+
Class define_class (const char* name, Value super = rb_cObject);
|
31
|
+
|
32
|
+
Module define_const (const char* name, Value val);
|
33
|
+
|
34
|
+
Module define_attr (const char* name, bool read = true, bool write = true);
|
35
|
+
|
36
|
+
Module define_alias (const char* new_, const char* old);
|
37
|
+
|
38
|
+
Module undef_method (const char* name);
|
39
|
+
|
40
|
+
Module include_module (Value module);
|
41
|
+
|
42
|
+
Module define_function (const char* name, RubyFunctionN fun);
|
43
|
+
Module define_function (const char* name, RubyFunction0 fun);
|
44
|
+
Module define_function (const char* name, RubyFunction1 fun);
|
45
|
+
Module define_function (const char* name, RubyFunction2 fun);
|
46
|
+
Module define_function (const char* name, RubyFunction3 fun);
|
47
|
+
Module define_function (const char* name, RubyFunction4 fun);
|
48
|
+
Module define_function (const char* name, RubyFunction5 fun);
|
49
|
+
Module define_function (const char* name, RubyFunction6 fun);
|
50
|
+
Module define_function (const char* name, RubyFunction7 fun);
|
51
|
+
Module define_function (const char* name, RubyFunction8 fun);
|
52
|
+
Module define_method (const char* name, RubyFunctionN fun);
|
53
|
+
Module define_method (const char* name, RubyFunction0 fun);
|
54
|
+
Module define_method (const char* name, RubyFunction1 fun);
|
55
|
+
Module define_method (const char* name, RubyFunction2 fun);
|
56
|
+
Module define_method (const char* name, RubyFunction3 fun);
|
57
|
+
Module define_method (const char* name, RubyFunction4 fun);
|
58
|
+
Module define_method (const char* name, RubyFunction5 fun);
|
59
|
+
Module define_method (const char* name, RubyFunction6 fun);
|
60
|
+
Module define_method (const char* name, RubyFunction7 fun);
|
61
|
+
Module define_method (const char* name, RubyFunction8 fun);
|
62
|
+
Module define_private_method (const char* name, RubyFunctionN fun);
|
63
|
+
Module define_private_method (const char* name, RubyFunction0 fun);
|
64
|
+
Module define_private_method (const char* name, RubyFunction1 fun);
|
65
|
+
Module define_private_method (const char* name, RubyFunction2 fun);
|
66
|
+
Module define_private_method (const char* name, RubyFunction3 fun);
|
67
|
+
Module define_private_method (const char* name, RubyFunction4 fun);
|
68
|
+
Module define_private_method (const char* name, RubyFunction5 fun);
|
69
|
+
Module define_private_method (const char* name, RubyFunction6 fun);
|
70
|
+
Module define_private_method (const char* name, RubyFunction7 fun);
|
71
|
+
Module define_private_method (const char* name, RubyFunction8 fun);
|
72
|
+
Module define_singleton_method (const char* name, RubyFunctionN fun);
|
73
|
+
Module define_singleton_method (const char* name, RubyFunction0 fun);
|
74
|
+
Module define_singleton_method (const char* name, RubyFunction1 fun);
|
75
|
+
Module define_singleton_method (const char* name, RubyFunction2 fun);
|
76
|
+
Module define_singleton_method (const char* name, RubyFunction3 fun);
|
77
|
+
Module define_singleton_method (const char* name, RubyFunction4 fun);
|
78
|
+
Module define_singleton_method (const char* name, RubyFunction5 fun);
|
79
|
+
Module define_singleton_method (const char* name, RubyFunction6 fun);
|
80
|
+
Module define_singleton_method (const char* name, RubyFunction7 fun);
|
81
|
+
Module define_singleton_method (const char* name, RubyFunction8 fun);
|
82
|
+
|
83
|
+
};// Module
|
84
|
+
|
85
|
+
|
86
|
+
Module define_module (const char* name);
|
87
|
+
|
88
|
+
|
89
|
+
Module rucy_module ();
|
90
|
+
// module Rucy
|
91
|
+
|
92
|
+
|
93
|
+
}// Rucy
|
94
|
+
|
95
|
+
|
96
|
+
#endif//EOH
|
@@ -0,0 +1,68 @@
|
|
1
|
+
// -*- c++ -*-
|
2
|
+
% require 'support'
|
3
|
+
#pragma once
|
4
|
+
#ifndef __RUCY_MODULE_H__
|
5
|
+
#define __RUCY_MODULE_H__
|
6
|
+
|
7
|
+
|
8
|
+
#include <ruby.h>
|
9
|
+
#include <rucy/defs.h>
|
10
|
+
#include <rucy/value.h>
|
11
|
+
|
12
|
+
|
13
|
+
namespace Rucy
|
14
|
+
{
|
15
|
+
|
16
|
+
|
17
|
+
class Class;
|
18
|
+
|
19
|
+
|
20
|
+
class Module : public Value
|
21
|
+
{
|
22
|
+
|
23
|
+
typedef Value Super;
|
24
|
+
|
25
|
+
public:
|
26
|
+
|
27
|
+
Module (VALUE v = Qnil);
|
28
|
+
|
29
|
+
Module define_module (const char* name);
|
30
|
+
|
31
|
+
Class define_class (const char* name, Value super = rb_cObject);
|
32
|
+
|
33
|
+
Module define_const (const char* name, Value val);
|
34
|
+
|
35
|
+
Module define_attr (const char* name, bool read = true, bool write = true);
|
36
|
+
|
37
|
+
Module define_alias (const char* new_, const char* old);
|
38
|
+
|
39
|
+
Module undef_method (const char* name);
|
40
|
+
|
41
|
+
Module include_module (Value module);
|
42
|
+
|
43
|
+
% [
|
44
|
+
% 'define_function',
|
45
|
+
% 'define_method',
|
46
|
+
% 'define_private_method',
|
47
|
+
% 'define_singleton_method',
|
48
|
+
% ].each do |op|
|
49
|
+
Module <%= op %> (const char* name, RubyFunctionN fun);
|
50
|
+
% NTIMES.each do |n|
|
51
|
+
Module <%= op %> (const char* name, RubyFunction<%= n %> fun);
|
52
|
+
% end
|
53
|
+
% end
|
54
|
+
|
55
|
+
};// Module
|
56
|
+
|
57
|
+
|
58
|
+
Module define_module (const char* name);
|
59
|
+
|
60
|
+
|
61
|
+
Module rucy_module ();
|
62
|
+
// module Rucy
|
63
|
+
|
64
|
+
|
65
|
+
}// Rucy
|
66
|
+
|
67
|
+
|
68
|
+
#endif//EOH
|
data/include/rucy/rucy.h
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
// -*- c++ -*-
|
2
|
+
#pragma once
|
3
|
+
#ifndef __RUCY_H__
|
4
|
+
#define __RUCY_H__
|
5
|
+
|
6
|
+
|
7
|
+
#include <ruby.h>
|
8
|
+
#include <rucy/value.h>
|
9
|
+
|
10
|
+
|
11
|
+
namespace Rucy
|
12
|
+
{
|
13
|
+
|
14
|
+
|
15
|
+
bool init ();
|
16
|
+
|
17
|
+
|
18
|
+
Value require (const char* name);
|
19
|
+
|
20
|
+
void define_const (const char* name, Value val);
|
21
|
+
|
22
|
+
|
23
|
+
bool check_class (Value obj, Value class_);
|
24
|
+
|
25
|
+
|
26
|
+
template <typename T> inline void mark_type (void* p)
|
27
|
+
{
|
28
|
+
((T*) p)->mark();
|
29
|
+
}
|
30
|
+
|
31
|
+
template <typename T> inline void delete_type (void* p)
|
32
|
+
{
|
33
|
+
delete (T*) p;
|
34
|
+
}
|
35
|
+
|
36
|
+
template <typename T> inline Value new_type (
|
37
|
+
Value klass, T* ptr,
|
38
|
+
RUBY_DATA_FUNC mark = NULL,
|
39
|
+
RUBY_DATA_FUNC free = delete_type<T>)
|
40
|
+
{
|
41
|
+
return Data_Wrap_Struct(klass, mark, free, ptr);
|
42
|
+
}
|
43
|
+
|
44
|
+
template <typename T> inline Value new_type (
|
45
|
+
Value klass,
|
46
|
+
RUBY_DATA_FUNC mark = NULL,
|
47
|
+
RUBY_DATA_FUNC free = delete_type<T>)
|
48
|
+
{
|
49
|
+
return new_type(klass, new T, mark, free);
|
50
|
+
}
|
51
|
+
|
52
|
+
template <typename T> inline T* get_type (Value obj, Value klass = Qnil)
|
53
|
+
{
|
54
|
+
if (klass && !check_class(obj, klass)) return NULL;
|
55
|
+
T* p = NULL;
|
56
|
+
Data_Get_Struct(obj.value(), T, p);
|
57
|
+
return p;
|
58
|
+
}
|
59
|
+
|
60
|
+
|
61
|
+
}// Rucy
|
62
|
+
|
63
|
+
|
64
|
+
#endif//EOH
|
@@ -0,0 +1,28 @@
|
|
1
|
+
// -*- c++ -*-
|
2
|
+
#pragma once
|
3
|
+
#ifndef __RUCY_STRING_H__
|
4
|
+
#define __RUCY_STRING_H__
|
5
|
+
|
6
|
+
|
7
|
+
#include <stdarg.h>
|
8
|
+
#include <string>
|
9
|
+
|
10
|
+
|
11
|
+
namespace Rucy
|
12
|
+
{
|
13
|
+
|
14
|
+
|
15
|
+
typedef std::string String;
|
16
|
+
|
17
|
+
|
18
|
+
String stringf (const char* format, ...);
|
19
|
+
|
20
|
+
String stringf (const char* format, va_list args);
|
21
|
+
|
22
|
+
template <typename T> String to_s (const T& val);
|
23
|
+
|
24
|
+
|
25
|
+
}// Rucy
|
26
|
+
|
27
|
+
|
28
|
+
#endif//EOH
|
@@ -0,0 +1,50 @@
|
|
1
|
+
// -*- c++ -*-
|
2
|
+
#pragma once
|
3
|
+
#ifndef __RUCY_SYMBOL_H__
|
4
|
+
#define __RUCY_SYMBOL_H__
|
5
|
+
|
6
|
+
|
7
|
+
#include <ruby.h>
|
8
|
+
|
9
|
+
|
10
|
+
#define SYMBOL(name, str) static const Rucy::Symbol name (str)
|
11
|
+
|
12
|
+
#define SYM(s) SYMBOL(s, #s)
|
13
|
+
#define SYM_Q(s) SYMBOL(s, #s "?")
|
14
|
+
#define SYM_B(s) SYMBOL(s, #s "!")
|
15
|
+
|
16
|
+
|
17
|
+
namespace Rucy
|
18
|
+
{
|
19
|
+
|
20
|
+
|
21
|
+
class Symbol
|
22
|
+
{
|
23
|
+
|
24
|
+
public:
|
25
|
+
|
26
|
+
Symbol ();
|
27
|
+
|
28
|
+
Symbol (ID id);
|
29
|
+
|
30
|
+
Symbol (const char* str);
|
31
|
+
|
32
|
+
ID id () const;
|
33
|
+
|
34
|
+
const char* c_str () const;
|
35
|
+
|
36
|
+
operator bool () const;
|
37
|
+
|
38
|
+
bool operator ! () const;
|
39
|
+
|
40
|
+
private:
|
41
|
+
|
42
|
+
ID id_;
|
43
|
+
|
44
|
+
};// Symbol
|
45
|
+
|
46
|
+
|
47
|
+
}// Rucy
|
48
|
+
|
49
|
+
|
50
|
+
#endif//EOH
|