rucy 0.1.3 → 0.1.4
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/.doc/ext/rucy/class.cpp +244 -0
- data/.doc/ext/rucy/exception.cpp +99 -0
- data/.doc/ext/rucy/function.cpp +63 -0
- data/.doc/ext/rucy/struct.cpp +80 -0
- data/.doc/ext/rucy/tester.cpp +41 -184
- data/.doc/ext/rucy/value.cpp +42 -0
- data/.gitignore +22 -0
- data/Rakefile +4 -29
- data/VERSION +1 -1
- data/ext/rucy/class.cpp +262 -0
- data/ext/rucy/class.h +96 -0
- data/ext/rucy/exception.cpp +107 -0
- data/ext/rucy/extconf.rb +9 -8
- data/ext/rucy/function.cpp +68 -0
- data/ext/rucy/struct.cpp +83 -0
- data/ext/rucy/tester.cpp +41 -197
- data/ext/rucy/tester.h +10 -0
- data/ext/rucy/value.cpp +46 -0
- data/include/rucy/defs.h.erb +17 -0
- data/include/rucy/exception.h +2 -0
- data/include/rucy/extension.h +206 -0
- data/include/rucy/rucy.h +25 -2
- data/include/rucy/symbol.h +11 -0
- data/include/rucy/value.h.erb +66 -14
- data/include/rucy.h +1 -1
- data/lib/rucy/module.rb +9 -2
- data/rucy.gemspec +16 -40
- data/src/exception.cpp +17 -25
- data/src/rucy.cpp +2 -2
- data/src/symbol.cpp +24 -0
- data/src/value.cpp.erb +161 -25
- data/task/doc.rake +50 -0
- data/test/helpers.rb +7 -0
- data/test/test_class.rb +161 -0
- data/test/test_exception.rb +39 -0
- data/test/test_function.rb +31 -0
- data/test/test_struct.rb +30 -0
- data/test/test_value.rb +18 -0
- metadata +123 -74
- data/include/rucy/defs.h +0 -101
- data/include/rucy/function.h +0 -245
- data/include/rucy/gc.h +0 -59
- data/include/rucy/module.h +0 -98
- data/include/rucy/value.h +0 -291
- data/src/function.cpp +0 -158
- data/src/gc.cpp +0 -63
- data/src/module.cpp +0 -325
- data/src/value.cpp +0 -511
- data/task/ext.rake +0 -96
- data/test/test_rucy.rb +0 -73
data/.doc/ext/rucy/tester.cpp
CHANGED
@@ -1,196 +1,62 @@
|
|
1
|
-
#include
|
2
|
-
|
3
|
-
|
4
|
-
using namespace Rucy;
|
5
|
-
|
6
|
-
|
7
|
-
struct Tester
|
8
|
-
{
|
9
|
-
|
10
|
-
int value;
|
11
|
-
|
12
|
-
};// Tester
|
13
|
-
|
14
|
-
|
15
|
-
static Class cTester;
|
16
|
-
|
17
|
-
|
18
|
-
Class
|
19
|
-
tester_class ()
|
20
|
-
{
|
21
|
-
return cTester;
|
22
|
-
}
|
23
|
-
|
24
|
-
|
25
|
-
namespace Rucy
|
26
|
-
{
|
27
|
-
|
28
|
-
|
29
|
-
static Value
|
30
|
-
value (const Tester& obj)
|
31
|
-
{
|
32
|
-
return new_type<Tester>(tester_class(), new Tester(obj));
|
33
|
-
}
|
1
|
+
#include "tester.h"
|
34
2
|
|
35
|
-
template <> inline Tester*
|
36
|
-
value_to<Tester*> (Value obj, bool)
|
37
|
-
{
|
38
|
-
return get_type<Tester>(obj, tester_class());
|
39
|
-
}
|
40
3
|
|
4
|
+
#include <vector>
|
5
|
+
#include <rucy.h>
|
41
6
|
|
42
|
-
}// Rucy
|
43
|
-
|
44
|
-
|
45
|
-
/*
|
46
|
-
alloc function.
|
47
|
-
*/
|
48
|
-
static
|
49
|
-
VALUE alloc(VALUE klass)
|
50
|
-
{
|
51
|
-
return new_type<Tester>(klass);
|
52
|
-
}
|
53
|
-
|
54
|
-
/*
|
55
|
-
get value.
|
56
|
-
*/
|
57
|
-
static
|
58
|
-
VALUE get_value(VALUE self)
|
59
|
-
{
|
60
|
-
Tester* t = to<Tester*>(self);
|
61
|
-
if (t) return value(t->value);
|
62
|
-
}
|
63
|
-
|
64
|
-
/*
|
65
|
-
set value.
|
66
|
-
*/
|
67
|
-
static
|
68
|
-
VALUE set_value(VALUE self, VALUE value)
|
69
|
-
{
|
70
|
-
Tester* t = to<Tester*>(self);
|
71
|
-
if (t) t->value = to<int>(value);
|
72
|
-
}
|
73
7
|
|
74
|
-
|
75
|
-
do nothing.
|
76
|
-
*/
|
77
|
-
static
|
78
|
-
VALUE do_nothing(VALUE self)
|
79
|
-
{
|
80
|
-
}
|
8
|
+
using namespace Rucy;
|
81
9
|
|
82
|
-
/*
|
83
|
-
return nil.
|
84
|
-
*/
|
85
|
-
static
|
86
|
-
VALUE return_nil(VALUE self)
|
87
|
-
{
|
88
|
-
return Qnil;
|
89
|
-
}
|
90
10
|
|
91
|
-
|
92
|
-
return int.
|
93
|
-
*/
|
94
|
-
static
|
95
|
-
VALUE return_int(VALUE self)
|
96
|
-
{
|
97
|
-
return value(1);
|
98
|
-
}
|
11
|
+
static std::vector<String> logs;
|
99
12
|
|
100
|
-
/*
|
101
|
-
return flaot.
|
102
|
-
*/
|
103
|
-
static
|
104
|
-
VALUE return_float(VALUE self)
|
105
|
-
{
|
106
|
-
return value(1.0f);
|
107
|
-
}
|
108
13
|
|
109
|
-
|
110
|
-
|
111
|
-
*/
|
112
|
-
static
|
113
|
-
VALUE return_string(VALUE self)
|
14
|
+
void
|
15
|
+
log (const char* str)
|
114
16
|
{
|
115
|
-
|
17
|
+
logs.push_back(str);
|
116
18
|
}
|
117
19
|
|
118
|
-
/*
|
119
|
-
raise ruby's exception.
|
120
|
-
*/
|
121
|
-
static
|
122
|
-
VALUE raise_ruby_exception(VALUE self)
|
123
|
-
{
|
124
|
-
throw RubyException(rb_eStandardError, "raise_ruby_exception");
|
125
|
-
}
|
126
20
|
|
127
21
|
/*
|
128
|
-
|
22
|
+
return last log.
|
129
23
|
*/
|
130
|
-
|
131
|
-
VALUE raise_in_eval(VALUE self)
|
24
|
+
VALUE last_log(VALUE self)
|
132
25
|
{
|
133
|
-
|
134
|
-
|
26
|
+
if (argc > 1)
|
27
|
+
arg_count_error("#last_log", argc, 0, 1);
|
135
28
|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
static
|
140
|
-
VALUE throw_nothing(VALUE self)
|
141
|
-
{
|
142
|
-
throw;
|
143
|
-
}
|
29
|
+
size_t index = (argc >= 1) ? to<size_t>(argv[0]) : logs.size() - 1;
|
30
|
+
if (index >= logs.size())
|
31
|
+
index_error();
|
144
32
|
|
145
|
-
|
146
|
-
throw std::exception.
|
147
|
-
*/
|
148
|
-
static
|
149
|
-
VALUE throw_std_exception(VALUE self)
|
150
|
-
{
|
151
|
-
throw std::exception();
|
33
|
+
return value(logs[index].c_str());
|
152
34
|
}
|
153
35
|
|
154
36
|
/*
|
155
|
-
|
37
|
+
return all logs.
|
156
38
|
*/
|
157
|
-
|
158
|
-
VALUE throw_std_runtime_error(VALUE self)
|
39
|
+
VALUE all_logs(VALUE self)
|
159
40
|
{
|
160
|
-
|
41
|
+
std::vector<Value> a;
|
42
|
+
for (size_t i = 0; i < logs.size(); ++i) a.push_back(logs[i].c_str());
|
43
|
+
return value(a.size(), &a[0]);
|
161
44
|
}
|
162
45
|
|
163
|
-
struct MyException : public std::runtime_error
|
164
|
-
{
|
165
|
-
MyException() : runtime_error("") {}
|
166
|
-
};
|
167
|
-
|
168
46
|
/*
|
169
|
-
|
47
|
+
clcear all logs.
|
170
48
|
*/
|
171
|
-
|
172
|
-
VALUE throw_custom_exception(VALUE self)
|
49
|
+
VALUE clear_logs(VALUE self)
|
173
50
|
{
|
174
|
-
|
51
|
+
logs.clear();
|
175
52
|
}
|
176
53
|
|
177
|
-
/*
|
178
|
-
throw std::string.
|
179
|
-
*/
|
180
|
-
static
|
181
|
-
VALUE throw_std_string(VALUE self)
|
182
|
-
{
|
183
|
-
throw std::string("std::string");
|
184
|
-
}
|
185
54
|
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
{
|
192
|
-
throw "cstring";
|
193
|
-
}
|
55
|
+
void Init_value ();
|
56
|
+
void Init_exception ();
|
57
|
+
void Init_function ();
|
58
|
+
void Init_struct ();
|
59
|
+
void Init_class ();
|
194
60
|
|
195
61
|
|
196
62
|
extern "C" void
|
@@ -198,25 +64,16 @@ Init_tester ()
|
|
198
64
|
{
|
199
65
|
if (!init()) return;
|
200
66
|
|
201
|
-
Module
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
rb_define_method(c, "return_string", RUBY_METHOD_FUNC(return_string), 0);
|
214
|
-
rb_define_method(c, "raise_ruby_exception", RUBY_METHOD_FUNC(raise_ruby_exception), 0);
|
215
|
-
rb_define_method(c, "raise_in_eval", RUBY_METHOD_FUNC(raise_in_eval), 0);
|
216
|
-
rb_define_method(c, "throw_nothing", RUBY_METHOD_FUNC(throw_nothing), 0);
|
217
|
-
rb_define_method(c, "throw_std_exception", RUBY_METHOD_FUNC(throw_std_exception), 0);
|
218
|
-
rb_define_method(c, "throw_std_runtime_error", RUBY_METHOD_FUNC(throw_std_runtime_error), 0);
|
219
|
-
rb_define_method(c, "throw_custom_exception", RUBY_METHOD_FUNC(throw_custom_exception), 0);
|
220
|
-
rb_define_method(c, "throw_std_string", RUBY_METHOD_FUNC(throw_std_string), 0);
|
221
|
-
rb_define_method(c, "throw_cstring", RUBY_METHOD_FUNC(throw_cstring), 0);
|
67
|
+
Module mRucy = rb_define_module("Rucy");
|
68
|
+
Module mTester = rb_define_module_under(mRucy, "Tester");
|
69
|
+
|
70
|
+
rb_define_function(mTester, "last_log", RUBY_METHOD_FUNC(last_log), -1);
|
71
|
+
rb_define_function(mTester, "all_logs", RUBY_METHOD_FUNC(all_logs), 0);
|
72
|
+
rb_define_function(mTester, "clear_logs", RUBY_METHOD_FUNC(clear_logs), 0);
|
73
|
+
|
74
|
+
Init_value();
|
75
|
+
Init_exception();
|
76
|
+
Init_function();
|
77
|
+
Init_struct ();
|
78
|
+
Init_class ();
|
222
79
|
}
|
@@ -0,0 +1,42 @@
|
|
1
|
+
#include <rucy.h>
|
2
|
+
|
3
|
+
|
4
|
+
using namespace Rucy;
|
5
|
+
|
6
|
+
|
7
|
+
static
|
8
|
+
VALUE true_to_value(VALUE self)
|
9
|
+
{
|
10
|
+
return value(true);
|
11
|
+
}
|
12
|
+
|
13
|
+
static
|
14
|
+
VALUE false_to_value(VALUE self)
|
15
|
+
{
|
16
|
+
return value(false);
|
17
|
+
}
|
18
|
+
|
19
|
+
static
|
20
|
+
VALUE NULL_to_value(VALUE self)
|
21
|
+
{
|
22
|
+
return nil();
|
23
|
+
}
|
24
|
+
|
25
|
+
static
|
26
|
+
VALUE nil_value(VALUE self)
|
27
|
+
{
|
28
|
+
return nil();
|
29
|
+
}
|
30
|
+
|
31
|
+
|
32
|
+
void
|
33
|
+
Init_value ()
|
34
|
+
{
|
35
|
+
Module mRucy = rb_define_module("Rucy");
|
36
|
+
Module mTester = rb_define_module_under(mRucy, "Tester");
|
37
|
+
|
38
|
+
rb_define_method(mTester, "true_to_value", RUBY_METHOD_FUNC(true_to_value), -1);
|
39
|
+
rb_define_method(mTester, "false_to_value", RUBY_METHOD_FUNC(false_to_value), -1);
|
40
|
+
rb_define_method(mTester, "null_to_value", RUBY_METHOD_FUNC(NULL_to_value), -1);
|
41
|
+
rb_define_method(mTester, "nil_value", RUBY_METHOD_FUNC(nil_value), -1);
|
42
|
+
}
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.o
|
2
|
+
*.so
|
3
|
+
*.bundle
|
4
|
+
*.dll.a
|
5
|
+
*.gem
|
6
|
+
*.log
|
7
|
+
*.rdoc.cpp
|
8
|
+
*~
|
9
|
+
lib/*.a
|
10
|
+
.doc
|
11
|
+
.yardoc
|
12
|
+
.DS_Store
|
13
|
+
Makefile
|
14
|
+
depend.mf
|
15
|
+
|
16
|
+
include/rucy/defs.h
|
17
|
+
include/rucy/function.h
|
18
|
+
include/rucy/module.h
|
19
|
+
include/rucy/value.h
|
20
|
+
src/function.cpp
|
21
|
+
src/module.cpp
|
22
|
+
src/value.cpp
|
data/Rakefile
CHANGED
@@ -1,12 +1,8 @@
|
|
1
1
|
# -*- mode: ruby; coding: utf-8 -*-
|
2
2
|
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
end
|
7
|
-
|
8
|
-
require 'rubygems'
|
9
|
-
require 'xot/rake/helpers'
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'xot/rake'
|
10
6
|
require 'xot/module'
|
11
7
|
require 'rucy/module'
|
12
8
|
|
@@ -14,7 +10,8 @@ include Xot::Rake
|
|
14
10
|
|
15
11
|
|
16
12
|
MODULE = Rucy
|
17
|
-
|
13
|
+
DLNAME = 'tester'
|
14
|
+
INCDIRS = [Rucy, Xot].map {|m| m.include_dirs}.flatten
|
18
15
|
RUCY2RDOC = 'bin/rucy2rdoc'
|
19
16
|
NPARAM_MAX = 8
|
20
17
|
NTIMES = (0..NPARAM_MAX)
|
@@ -24,27 +21,5 @@ task :default => :build
|
|
24
21
|
|
25
22
|
task :build => :lib
|
26
23
|
|
27
|
-
task :rebuild => [:clean, :build]
|
28
|
-
|
29
|
-
task :lib => 'lib:build'
|
30
|
-
|
31
|
-
task :ext => 'ext:build'
|
32
|
-
|
33
|
-
task :doc => 'ext:doc'
|
34
|
-
|
35
|
-
task :gem => 'gem:build'
|
36
|
-
|
37
|
-
task :install => 'gem:install'
|
38
|
-
|
39
|
-
task :uninstall => 'gem:uninstall'
|
40
|
-
|
41
|
-
task :clean => ['lib:clean', 'ext:clean', 'gem:clean']
|
42
|
-
|
43
|
-
task :test => :ext do
|
44
|
-
Dir['test/**/test_*.rb'].each do |rb|
|
45
|
-
sh %( ruby #{rb} )
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
24
|
|
50
25
|
[Xot, Rucy].each {|m| m.load_tasks}
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.4
|
data/ext/rucy/class.cpp
ADDED
@@ -0,0 +1,262 @@
|
|
1
|
+
#include "class.h"
|
2
|
+
|
3
|
+
|
4
|
+
#include <rucy.h>
|
5
|
+
|
6
|
+
|
7
|
+
using namespace Rucy;
|
8
|
+
|
9
|
+
|
10
|
+
static Class cBase, cSub, cRubyObj;
|
11
|
+
|
12
|
+
|
13
|
+
RUCY_WRAPPER_VALUE_FROM_TO(Base, cBase)
|
14
|
+
RUCY_WRAPPER_VALUE_FROM_TO(Sub, cSub)
|
15
|
+
RUCY_WRAPPER_VALUE_FROM_TO(RubyObj, cRubyObj)
|
16
|
+
|
17
|
+
|
18
|
+
template <typename T> Class get_class ();
|
19
|
+
|
20
|
+
template <> Class get_class<Base> () {return cBase;}
|
21
|
+
|
22
|
+
template <> Class get_class<Sub> () {return cSub;}
|
23
|
+
|
24
|
+
|
25
|
+
template <typename T>
|
26
|
+
class RubyBase : public ClassWrapper<T>
|
27
|
+
{
|
28
|
+
|
29
|
+
typedef ClassWrapper<T> Super;
|
30
|
+
|
31
|
+
RUCY_OVERRIDE_ID_START(name_overridable_faster)
|
32
|
+
RUCY_OVERRIDE_ID_LAST
|
33
|
+
|
34
|
+
public:
|
35
|
+
|
36
|
+
virtual const char* name_overridable () const
|
37
|
+
{
|
38
|
+
RUCY_OVERRIDABLE_METHOD(name_overridable, get_class<T>(), .c_str());
|
39
|
+
}
|
40
|
+
|
41
|
+
virtual const char* name_overridable_faster () const
|
42
|
+
{
|
43
|
+
RUCY_OVERRIDABLE_METHOD_FAST(name_overridable_faster, get_class<T>(), .c_str());
|
44
|
+
}
|
45
|
+
|
46
|
+
bool is_name_overridable_faster_overridden () const
|
47
|
+
{
|
48
|
+
SYM(name_overridable_faster);
|
49
|
+
return RUCY_IS_OVERRIDDEN(name_overridable_faster, get_class<T>());
|
50
|
+
}
|
51
|
+
|
52
|
+
};// RubyBase
|
53
|
+
|
54
|
+
|
55
|
+
#define THIS(type) to<type*>(self)
|
56
|
+
|
57
|
+
#define CHECK(type) RUCY_CHECK_OBJ(self, type, c##type)
|
58
|
+
|
59
|
+
#define CALL(type, obj, fun) RUCY_WRAPPER_CALL(ClassWrapper<type>, obj, fun)
|
60
|
+
|
61
|
+
|
62
|
+
/*
|
63
|
+
alloc function.
|
64
|
+
*/
|
65
|
+
static
|
66
|
+
RUBY_DEF_ALLOC(base_alloc, klass)
|
67
|
+
{
|
68
|
+
return value(new RubyBase<Base>, klass);
|
69
|
+
}
|
70
|
+
RUBY_END
|
71
|
+
|
72
|
+
static
|
73
|
+
RUBY_DEF0(name)
|
74
|
+
{
|
75
|
+
CHECK(Base);
|
76
|
+
return value(THIS(Base)->name());
|
77
|
+
}
|
78
|
+
RUBY_END
|
79
|
+
|
80
|
+
static
|
81
|
+
RUBY_DEF0(call_name)
|
82
|
+
{
|
83
|
+
CHECK(Base);
|
84
|
+
return value(THIS(Base)->name());
|
85
|
+
}
|
86
|
+
RUBY_END
|
87
|
+
|
88
|
+
static
|
89
|
+
RUBY_DEF0(base_name_overridable)
|
90
|
+
{
|
91
|
+
CHECK(Base);
|
92
|
+
return value(CALL(Base, THIS(Base), name_overridable()));
|
93
|
+
}
|
94
|
+
RUBY_END
|
95
|
+
|
96
|
+
static
|
97
|
+
RUBY_DEF0(call_name_overridable)
|
98
|
+
{
|
99
|
+
CHECK(Base);
|
100
|
+
return value(THIS(Base)->name_overridable());
|
101
|
+
}
|
102
|
+
RUBY_END
|
103
|
+
|
104
|
+
static
|
105
|
+
RUBY_DEF0(base_name_overridable_faster)
|
106
|
+
{
|
107
|
+
CHECK(Base);
|
108
|
+
return value(CALL(Base, THIS(Base), name_overridable_faster()));
|
109
|
+
}
|
110
|
+
RUBY_END
|
111
|
+
|
112
|
+
static
|
113
|
+
RUBY_DEF0(call_name_overridable_faster)
|
114
|
+
{
|
115
|
+
CHECK(Base);
|
116
|
+
return value(THIS(Base)->name_overridable_faster());
|
117
|
+
}
|
118
|
+
RUBY_END
|
119
|
+
|
120
|
+
template <typename T>
|
121
|
+
static
|
122
|
+
RUBY_DEF0(is_name_overridable_faster_overridden)
|
123
|
+
{
|
124
|
+
RUCY_CHECK_OBJ(self, T, get_class<T>());
|
125
|
+
RubyBase<T>* obj = dynamic_cast<RubyBase<T>*>(THIS(T));
|
126
|
+
if (!obj) invalid_object_error("dynamic_cast() failed.");
|
127
|
+
return value(obj->is_name_overridable_faster_overridden());
|
128
|
+
}
|
129
|
+
RUBY_END
|
130
|
+
|
131
|
+
template <typename T>
|
132
|
+
static
|
133
|
+
RUBY_DEF0(clear_override_flags)
|
134
|
+
{
|
135
|
+
RUCY_CHECK_OBJ(self, T, get_class<T>());
|
136
|
+
ClassWrapper<T>* obj = dynamic_cast<ClassWrapper<T>*>(THIS(T));
|
137
|
+
if (obj) obj->clear_override_flags();
|
138
|
+
}
|
139
|
+
RUBY_END
|
140
|
+
|
141
|
+
template <bool singleton>
|
142
|
+
static
|
143
|
+
RUBY_DEF1(method_added_or_removed, method_name)
|
144
|
+
{
|
145
|
+
SYMBOL(klass, "class");
|
146
|
+
SYM(name);
|
147
|
+
eval(
|
148
|
+
Xot::stringf(
|
149
|
+
"ObjectSpace.each_object(%s) {|o| o.clear_override_flags}",
|
150
|
+
(singleton ? self(klass) : self)(name).c_str()).c_str());
|
151
|
+
}
|
152
|
+
RUBY_END
|
153
|
+
|
154
|
+
static
|
155
|
+
RUBY_DEF0(base_new_raw)
|
156
|
+
{
|
157
|
+
return value(new Base);
|
158
|
+
}
|
159
|
+
RUBY_END
|
160
|
+
|
161
|
+
|
162
|
+
/*
|
163
|
+
alloc function.
|
164
|
+
*/
|
165
|
+
static
|
166
|
+
RUBY_DEF_ALLOC(sub_alloc, klass)
|
167
|
+
{
|
168
|
+
return value(new RubyBase<Sub>, klass);
|
169
|
+
}
|
170
|
+
RUBY_END
|
171
|
+
|
172
|
+
static
|
173
|
+
RUBY_DEF0(sub_name_overridable)
|
174
|
+
{
|
175
|
+
CHECK(Sub);
|
176
|
+
return value(CALL(Sub, THIS(Sub), name_overridable()));
|
177
|
+
}
|
178
|
+
RUBY_END
|
179
|
+
|
180
|
+
static
|
181
|
+
RUBY_DEF0(sub_name_overridable_faster)
|
182
|
+
{
|
183
|
+
CHECK(Sub);
|
184
|
+
return value(CALL(Sub, THIS(Sub), name_overridable_faster()));
|
185
|
+
}
|
186
|
+
RUBY_END
|
187
|
+
|
188
|
+
static
|
189
|
+
RUBY_DEF0(sub_new_raw)
|
190
|
+
{
|
191
|
+
return value(new Sub);
|
192
|
+
}
|
193
|
+
RUBY_END
|
194
|
+
|
195
|
+
|
196
|
+
/*
|
197
|
+
alloc function.
|
198
|
+
*/
|
199
|
+
static
|
200
|
+
RUBY_DEF_ALLOC(rubyobj_alloc, klass)
|
201
|
+
{
|
202
|
+
return value(new ClassWrapper<RubyObj>, klass);
|
203
|
+
}
|
204
|
+
RUBY_END
|
205
|
+
|
206
|
+
static Xot::Ref<RubyObj> rubyobj_ref;
|
207
|
+
|
208
|
+
static
|
209
|
+
RUBY_DEF1(rubyobj_set_ref, obj)
|
210
|
+
{
|
211
|
+
rubyobj_ref = to<RubyObj*>(obj);
|
212
|
+
return obj;
|
213
|
+
}
|
214
|
+
RUBY_END
|
215
|
+
|
216
|
+
static
|
217
|
+
RUBY_DEF0(rubyobj_clear_ref)
|
218
|
+
{
|
219
|
+
rubyobj_ref.reset();
|
220
|
+
}
|
221
|
+
RUBY_END
|
222
|
+
|
223
|
+
|
224
|
+
void
|
225
|
+
Init_class ()
|
226
|
+
{
|
227
|
+
Module mRucy = define_module("Rucy");
|
228
|
+
Module mTester = mRucy.define_module("Tester");
|
229
|
+
|
230
|
+
cBase = mTester.define_class("Base");
|
231
|
+
cBase.define_alloc_func(base_alloc);
|
232
|
+
cBase.define_method( "name", name);
|
233
|
+
cBase.define_method( "name_overridable", base_name_overridable);
|
234
|
+
cBase.define_method( "name_overridable_faster", base_name_overridable_faster);
|
235
|
+
cBase.define_method("call_name", call_name);
|
236
|
+
cBase.define_method("call_name_overridable", call_name_overridable);
|
237
|
+
cBase.define_method("call_name_overridable_faster", call_name_overridable_faster);
|
238
|
+
cBase.define_method(
|
239
|
+
"is_name_overridable_faster_overridden",
|
240
|
+
is_name_overridable_faster_overridden<Base>);
|
241
|
+
cBase.define_method("clear_override_flags", clear_override_flags<Base>);
|
242
|
+
cBase.define_method("singleton_method_added", method_added_or_removed<true>);
|
243
|
+
cBase.define_method("singleton_method_removed", method_added_or_removed<true>);
|
244
|
+
cBase.define_singleton_method("method_added", method_added_or_removed<false>);
|
245
|
+
cBase.define_singleton_method("method_removed", method_added_or_removed<false>);
|
246
|
+
cBase.define_singleton_method("new_raw", base_new_raw);
|
247
|
+
|
248
|
+
cSub = mTester.define_class("Sub", cBase);
|
249
|
+
cSub.define_alloc_func(sub_alloc);
|
250
|
+
cSub.define_method("name_overridable", sub_name_overridable);
|
251
|
+
cSub.define_method("name_overridable_faster", sub_name_overridable_faster);
|
252
|
+
cSub.define_method(
|
253
|
+
"is_name_overridable_faster_overridden",
|
254
|
+
is_name_overridable_faster_overridden<Sub>);
|
255
|
+
cSub.define_method("clear_override_flags", clear_override_flags<Sub>);
|
256
|
+
cSub.define_singleton_method("new_raw", sub_new_raw);
|
257
|
+
|
258
|
+
cRubyObj = mTester.define_class("RubyObj");
|
259
|
+
cRubyObj.define_alloc_func(rubyobj_alloc);
|
260
|
+
cRubyObj.define_function("set_ref", rubyobj_set_ref);
|
261
|
+
cRubyObj.define_function("clear_ref", rubyobj_clear_ref);
|
262
|
+
}
|