rucy 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.doc/ext/rucy/class.cpp +48 -56
- data/.doc/ext/rucy/exception.cpp +1 -1
- data/.doc/ext/rucy/function.cpp +14 -2
- data/.doc/ext/rucy/struct.cpp +2 -20
- data/.doc/ext/rucy/tester.cpp +7 -19
- data/.doc/ext/rucy/value.cpp +23 -1
- data/{README → README.md} +0 -0
- data/Rakefile +7 -5
- data/VERSION +1 -1
- data/bin/rucy2rdoc +8 -5
- data/ext/rucy/class.cpp +78 -87
- data/ext/rucy/class.h +12 -6
- data/ext/rucy/exception.cpp +17 -17
- data/ext/rucy/extconf.rb +11 -52
- data/ext/rucy/function.cpp +25 -12
- data/ext/rucy/struct.cpp +8 -26
- data/ext/rucy/tester.cpp +11 -24
- data/ext/rucy/value.cpp +32 -9
- data/include/rucy/class.h +5 -3
- data/include/rucy/exception.h +17 -71
- data/include/rucy/extension.h.erb +489 -0
- data/include/rucy/function.h.erb +20 -34
- data/include/rucy/module.h.erb +20 -14
- data/include/rucy/ruby.h +23 -0
- data/include/rucy/rucy.h +7 -66
- data/include/rucy/symbol.h +11 -11
- data/include/rucy/value.h.erb +98 -176
- data/include/rucy.h +9 -1
- data/lib/rucy/module.rb +11 -7
- data/rucy.gemspec +3 -4
- data/src/class.cpp +34 -6
- data/src/exception.cpp +69 -54
- data/src/extension.cpp +59 -0
- data/src/function.cpp.erb +17 -25
- data/src/module.cpp.erb +25 -16
- data/src/rucy.cpp +15 -25
- data/src/symbol.cpp +18 -17
- data/src/value.cpp.erb +374 -175
- data/task/doc.rake +5 -0
- data/test/helper.rb +6 -2
- data/test/test_class.rb +27 -20
- data/test/test_function.rb +6 -0
- data/test/test_value.rb +4 -0
- metadata +29 -39
- data/.gitignore +0 -22
- data/ChangeLog +0 -13
- data/include/rucy/defs.h.erb +0 -76
- data/include/rucy/extension.h +0 -206
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 67f71a7e93376401c6cc03e60b6c52edebb27ec7
|
4
|
+
data.tar.gz: ac0cd48435e3134dc6ab318a442caae40fe7c16c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 99a2a7c5f8c14eb83bd69a6b9876769fbab447571869171a8453bc13715c4bb12e11d2ceaf5f43129d6c555801fef06a9bfef52a3b0db881325de002207abf75
|
7
|
+
data.tar.gz: 6e03ed8138bf76df496a2b734ee57f36a4663cb73345220c82f0ae6937c7b9cb906f3fc66a895a743b818ab02146fef27be2ac6b631631b7722938069fcf4cf7
|
data/.doc/ext/rucy/class.cpp
CHANGED
@@ -1,19 +1,17 @@
|
|
1
1
|
#include "class.h"
|
2
2
|
|
3
3
|
|
4
|
-
#include
|
4
|
+
#include "rucy.h"
|
5
5
|
|
6
6
|
|
7
7
|
using namespace Rucy;
|
8
8
|
|
9
9
|
|
10
|
-
static Class cBase, cSub,
|
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)
|
10
|
+
static Class cBase, cSub, cSimpleObj;
|
16
11
|
|
12
|
+
RUCY_WRAPPER_VALUE_FROM_TO(Base, cBase)
|
13
|
+
RUCY_WRAPPER_VALUE_FROM_TO(Sub, cSub)
|
14
|
+
RUCY_WRAPPER_VALUE_FROM_TO(SimpleObj, cSimpleObj)
|
17
15
|
|
18
16
|
template <typename T> Class get_class ();
|
19
17
|
|
@@ -26,26 +24,32 @@ template <typename T>
|
|
26
24
|
class RubyBase : public ClassWrapper<T>
|
27
25
|
{
|
28
26
|
|
29
|
-
|
27
|
+
public:
|
30
28
|
|
31
|
-
|
32
|
-
RUCY_OVERRIDE_ID_LAST
|
29
|
+
RUCY_OVERRIDE_BEGIN(ClassWrapper<T>)
|
33
30
|
|
34
|
-
|
31
|
+
RUCY_OVERRIDE_ID(name_overridable_faster)
|
32
|
+
|
33
|
+
RUCY_OVERRIDE_END
|
35
34
|
|
36
35
|
virtual const char* name_overridable () const
|
37
36
|
{
|
38
|
-
|
37
|
+
RUCY_SYM(name_overridable);
|
38
|
+
return this->value.call(name_overridable).c_str();
|
39
39
|
}
|
40
40
|
|
41
41
|
virtual const char* name_overridable_faster () const
|
42
42
|
{
|
43
|
-
|
43
|
+
RUCY_SYM(name_overridable_faster);
|
44
|
+
if (RUCY_IS_OVERRIDDEN(name_overridable_faster, get_class<T>()))
|
45
|
+
return this->value.call(name_overridable_faster).c_str();
|
46
|
+
else
|
47
|
+
return Super::name_overridable_faster();
|
44
48
|
}
|
45
49
|
|
46
50
|
bool is_name_overridable_faster_overridden () const
|
47
51
|
{
|
48
|
-
|
52
|
+
RUCY_SYM(name_overridable_faster);
|
49
53
|
return RUCY_IS_OVERRIDDEN(name_overridable_faster, get_class<T>());
|
50
54
|
}
|
51
55
|
|
@@ -54,9 +58,9 @@ class RubyBase : public ClassWrapper<T>
|
|
54
58
|
|
55
59
|
#define THIS(type) to<type*>(self)
|
56
60
|
|
57
|
-
#define CHECK(type) RUCY_CHECK_OBJ(
|
61
|
+
#define CHECK(type) RUCY_CHECK_OBJ(type, c##type, self)
|
58
62
|
|
59
|
-
#define CALL(type, obj, fun) RUCY_WRAPPER_CALL(
|
63
|
+
#define CALL(type, obj, fun) RUCY_WRAPPER_CALL(type, obj, fun)
|
60
64
|
|
61
65
|
|
62
66
|
/*
|
@@ -114,32 +118,14 @@ template <typename T>
|
|
114
118
|
static
|
115
119
|
VALUE is_name_overridable_faster_overridden(VALUE self)
|
116
120
|
{
|
117
|
-
RUCY_CHECK_OBJ(
|
121
|
+
RUCY_CHECK_OBJ(T, get_class<T>(), self);
|
118
122
|
RubyBase<T>* obj = dynamic_cast<RubyBase<T>*>(THIS(T));
|
119
|
-
if (!obj) invalid_object_error("dynamic_cast() failed.");
|
123
|
+
if (!obj) invalid_object_error(__FILE__, __LINE__, "dynamic_cast() failed.");
|
120
124
|
return value(obj->is_name_overridable_faster_overridden());
|
121
125
|
}
|
122
126
|
|
123
|
-
|
124
|
-
static
|
125
|
-
VALUE clear_override_flags(VALUE self)
|
126
|
-
{
|
127
|
-
RUCY_CHECK_OBJ(self, T, get_class<T>());
|
128
|
-
ClassWrapper<T>* obj = dynamic_cast<ClassWrapper<T>*>(THIS(T));
|
129
|
-
if (obj) obj->clear_override_flags();
|
130
|
-
}
|
131
|
-
|
132
|
-
template <bool singleton>
|
133
|
-
static
|
134
|
-
VALUE method_added_or_removed(VALUE self, VALUE method_name)
|
135
|
-
{
|
136
|
-
SYMBOL(klass, "class");
|
137
|
-
SYM(name);
|
138
|
-
eval(
|
139
|
-
Xot::stringf(
|
140
|
-
"ObjectSpace.each_object(%s) {|o| o.clear_override_flags}",
|
141
|
-
(singleton ? self(klass) : self)(name).c_str()).c_str());
|
142
|
-
}
|
127
|
+
static RUCY_DEF_clear_override_flags(Base_clear_override_flags, Base, cBase);
|
128
|
+
static RUCY_DEF_clear_override_flags(Sub_clear_override_flags, Sub, cSub);
|
143
129
|
|
144
130
|
static
|
145
131
|
VALUE base_new_raw(VALUE self)
|
@@ -182,24 +168,33 @@ VALUE sub_new_raw(VALUE self)
|
|
182
168
|
alloc function.
|
183
169
|
*/
|
184
170
|
static
|
185
|
-
VALUE
|
171
|
+
VALUE simpleobj_alloc(VALUE klass)
|
172
|
+
{
|
173
|
+
return value(new ClassWrapper<SimpleObj>, klass);
|
174
|
+
}
|
175
|
+
|
176
|
+
static
|
177
|
+
VALUE simpleobj_initialize(VALUE self, VALUE name)
|
186
178
|
{
|
187
|
-
|
179
|
+
CHECK(SimpleObj);
|
180
|
+
THIS(SimpleObj)->init(name.c_str());
|
188
181
|
}
|
189
182
|
|
190
|
-
static Xot::Ref<
|
183
|
+
static std::vector<Xot::Ref<SimpleObj> > simpleobj_refs;
|
191
184
|
|
192
185
|
static
|
193
|
-
VALUE
|
186
|
+
VALUE simpleobj_set_refs(VALUE self, VALUE objs)
|
194
187
|
{
|
195
|
-
|
196
|
-
|
188
|
+
int size = objs.size();
|
189
|
+
for (int i = 0; i < size; ++i)
|
190
|
+
simpleobj_refs.push_back(to<SimpleObj*>(objs[i]));
|
191
|
+
return objs;
|
197
192
|
}
|
198
193
|
|
199
194
|
static
|
200
|
-
VALUE
|
195
|
+
VALUE simpleobj_clear_refs(VALUE self)
|
201
196
|
{
|
202
|
-
|
197
|
+
simpleobj_refs.clear();
|
203
198
|
}
|
204
199
|
|
205
200
|
|
@@ -220,12 +215,8 @@ Init_class ()
|
|
220
215
|
cBase.define_method(
|
221
216
|
"is_name_overridable_faster_overridden",
|
222
217
|
is_name_overridable_faster_overridden<Base>);
|
223
|
-
cBase.define_method("clear_override_flags", clear_override_flags<Base>);
|
224
|
-
cBase.define_method("singleton_method_added", method_added_or_removed<true>);
|
225
|
-
cBase.define_method("singleton_method_removed", method_added_or_removed<true>);
|
226
|
-
cBase.define_singleton_method("method_added", method_added_or_removed<false>);
|
227
|
-
cBase.define_singleton_method("method_removed", method_added_or_removed<false>);
|
228
218
|
rb_define_singleton_method(cBase, "new_raw", RUBY_METHOD_FUNC(base_new_raw), 0);
|
219
|
+
|
229
220
|
|
230
221
|
cSub = rb_define_class_under(mTester, "Sub", cBase);
|
231
222
|
rb_define_alloc_func(cSub, sub_alloc);
|
@@ -234,11 +225,12 @@ Init_class ()
|
|
234
225
|
cSub.define_method(
|
235
226
|
"is_name_overridable_faster_overridden",
|
236
227
|
is_name_overridable_faster_overridden<Sub>);
|
237
|
-
cSub.define_method("clear_override_flags", clear_override_flags<Sub>);
|
238
228
|
rb_define_singleton_method(cSub, "new_raw", RUBY_METHOD_FUNC(sub_new_raw), 0);
|
229
|
+
|
239
230
|
|
240
|
-
|
241
|
-
rb_define_alloc_func(
|
242
|
-
|
243
|
-
rb_define_function(
|
231
|
+
cSimpleObj = rb_define_class_under(mTester, "SimpleObj", rb_cObject);
|
232
|
+
rb_define_alloc_func(cSimpleObj, simpleobj_alloc);
|
233
|
+
rb_define_private_method(cSimpleObj, "initialize", RUBY_METHOD_FUNC(simpleobj_initialize), 1);
|
234
|
+
rb_define_function(cSimpleObj, "set_refs", RUBY_METHOD_FUNC(simpleobj_set_refs), 1);
|
235
|
+
rb_define_function(cSimpleObj, "clear_refs", RUBY_METHOD_FUNC(simpleobj_clear_refs), 0);
|
244
236
|
}
|
data/.doc/ext/rucy/exception.cpp
CHANGED
data/.doc/ext/rucy/function.cpp
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#include
|
1
|
+
#include "rucy.h"
|
2
2
|
|
3
3
|
|
4
4
|
using namespace Rucy;
|
@@ -18,7 +18,7 @@ VALUE do_nothing(VALUE self)
|
|
18
18
|
static
|
19
19
|
VALUE return_nil(VALUE self)
|
20
20
|
{
|
21
|
-
return
|
21
|
+
return nil();
|
22
22
|
}
|
23
23
|
|
24
24
|
/*
|
@@ -48,6 +48,17 @@ VALUE return_string(VALUE self)
|
|
48
48
|
return value("");
|
49
49
|
}
|
50
50
|
|
51
|
+
/*
|
52
|
+
check_arg_count
|
53
|
+
*/
|
54
|
+
static
|
55
|
+
VALUE arg_count_must_1(VALUE self)
|
56
|
+
{
|
57
|
+
check_arg_count(__FILE__, __LINE__, "arg_count_must_1", argc, 1);
|
58
|
+
RUCY_SYM(ok);
|
59
|
+
return ok.value();
|
60
|
+
}
|
61
|
+
|
51
62
|
|
52
63
|
void
|
53
64
|
Init_function ()
|
@@ -60,4 +71,5 @@ Init_function ()
|
|
60
71
|
rb_define_method(mTester, "return_int", RUBY_METHOD_FUNC(return_int), 0);
|
61
72
|
rb_define_method(mTester, "return_float", RUBY_METHOD_FUNC(return_float), 0);
|
62
73
|
rb_define_method(mTester, "return_string", RUBY_METHOD_FUNC(return_string), 0);
|
74
|
+
rb_define_method(mTester, "arg_count_must_1", RUBY_METHOD_FUNC(arg_count_must_1), -1);
|
63
75
|
}
|
data/.doc/ext/rucy/struct.cpp
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#include
|
1
|
+
#include "rucy.h"
|
2
2
|
|
3
3
|
|
4
4
|
using namespace Rucy;
|
@@ -16,25 +16,7 @@ struct Struct
|
|
16
16
|
|
17
17
|
static Class cStruct;
|
18
18
|
|
19
|
-
|
20
|
-
namespace Rucy
|
21
|
-
{
|
22
|
-
|
23
|
-
|
24
|
-
static Value
|
25
|
-
value (const Struct& obj)
|
26
|
-
{
|
27
|
-
return new_type(cStruct, new Struct(obj));
|
28
|
-
}
|
29
|
-
|
30
|
-
template <> inline Struct*
|
31
|
-
value_to<Struct*> (Value val, bool)
|
32
|
-
{
|
33
|
-
return get_type_ptr<Struct>(val, cStruct);
|
34
|
-
}
|
35
|
-
|
36
|
-
|
37
|
-
}// Rucy
|
19
|
+
RUCY_VALUE_FROM_TO(Struct, cStruct)
|
38
20
|
|
39
21
|
|
40
22
|
/*
|
data/.doc/ext/rucy/tester.cpp
CHANGED
@@ -2,13 +2,13 @@
|
|
2
2
|
|
3
3
|
|
4
4
|
#include <vector>
|
5
|
-
#include
|
5
|
+
#include "rucy.h"
|
6
6
|
|
7
7
|
|
8
8
|
using namespace Rucy;
|
9
9
|
|
10
10
|
|
11
|
-
static std::vector<String> logs;
|
11
|
+
static std::vector<Xot::String> logs;
|
12
12
|
|
13
13
|
|
14
14
|
void
|
@@ -18,21 +18,6 @@ log (const char* str)
|
|
18
18
|
}
|
19
19
|
|
20
20
|
|
21
|
-
/*
|
22
|
-
return last log.
|
23
|
-
*/
|
24
|
-
VALUE last_log(VALUE self)
|
25
|
-
{
|
26
|
-
if (argc > 1)
|
27
|
-
arg_count_error("#last_log", argc, 0, 1);
|
28
|
-
|
29
|
-
size_t index = (argc >= 1) ? to<size_t>(argv[0]) : logs.size() - 1;
|
30
|
-
if (index >= logs.size())
|
31
|
-
index_error();
|
32
|
-
|
33
|
-
return value(logs[index].c_str());
|
34
|
-
}
|
35
|
-
|
36
21
|
/*
|
37
22
|
return all logs.
|
38
23
|
*/
|
@@ -62,12 +47,13 @@ void Init_class ();
|
|
62
47
|
extern "C" void
|
63
48
|
Init_tester ()
|
64
49
|
{
|
65
|
-
|
50
|
+
RUCY_TRY
|
51
|
+
|
52
|
+
init();
|
66
53
|
|
67
54
|
Module mRucy = rb_define_module("Rucy");
|
68
55
|
Module mTester = rb_define_module_under(mRucy, "Tester");
|
69
56
|
|
70
|
-
rb_define_function(mTester, "last_log", RUBY_METHOD_FUNC(last_log), -1);
|
71
57
|
rb_define_function(mTester, "all_logs", RUBY_METHOD_FUNC(all_logs), 0);
|
72
58
|
rb_define_function(mTester, "clear_logs", RUBY_METHOD_FUNC(clear_logs), 0);
|
73
59
|
|
@@ -76,4 +62,6 @@ Init_tester ()
|
|
76
62
|
Init_function();
|
77
63
|
Init_struct ();
|
78
64
|
Init_class ();
|
65
|
+
|
66
|
+
RUCY_CATCH
|
79
67
|
}
|
data/.doc/ext/rucy/value.cpp
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#include
|
1
|
+
#include "rucy.h"
|
2
2
|
|
3
3
|
|
4
4
|
using namespace Rucy;
|
@@ -28,6 +28,27 @@ VALUE nil_value(VALUE self)
|
|
28
28
|
return nil();
|
29
29
|
}
|
30
30
|
|
31
|
+
static
|
32
|
+
VALUE array_value(VALUE self)
|
33
|
+
{
|
34
|
+
const Value* a = argv;
|
35
|
+
switch (argc)
|
36
|
+
{
|
37
|
+
case 1: return array(a[0]);
|
38
|
+
case 2: return array(a[0], a[1]);
|
39
|
+
case 3: return array(a[0], a[1], a[2]);
|
40
|
+
case 4: return array(a[0], a[1], a[2], a[3]);
|
41
|
+
case 5: return array(a[0], a[1], a[2], a[3], a[4]);
|
42
|
+
case 6: return array(a[0], a[1], a[2], a[3], a[4], a[5]);
|
43
|
+
case 7: return array(a[0], a[1], a[2], a[3], a[4], a[5], a[6]);
|
44
|
+
case 8: return array(a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7]);
|
45
|
+
case 9: return array(a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8]);
|
46
|
+
case 10: return array(a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9]);
|
47
|
+
case 0:
|
48
|
+
default: argument_error(__FILE__, __LINE__);
|
49
|
+
}
|
50
|
+
}
|
51
|
+
|
31
52
|
|
32
53
|
void
|
33
54
|
Init_value ()
|
@@ -39,4 +60,5 @@ Init_value ()
|
|
39
60
|
rb_define_method(mTester, "false_to_value", RUBY_METHOD_FUNC(false_to_value), -1);
|
40
61
|
rb_define_method(mTester, "null_to_value", RUBY_METHOD_FUNC(NULL_to_value), -1);
|
41
62
|
rb_define_method(mTester, "nil_value", RUBY_METHOD_FUNC(nil_value), -1);
|
63
|
+
rb_define_method(mTester, "array_value", RUBY_METHOD_FUNC(array_value), -1);
|
42
64
|
}
|
data/{README → README.md}
RENAMED
File without changes
|
data/Rakefile
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
# -*- mode: ruby; coding: utf-8 -*-
|
2
2
|
|
3
3
|
|
4
|
-
|
5
|
-
|
4
|
+
%w[../xot .]
|
5
|
+
.map {|s| File.expand_path "../#{s}/lib", __FILE__}
|
6
|
+
.each {|s| $:.unshift s if !$:.include?(s) && File.directory?(s)}
|
6
7
|
|
7
8
|
require 'xot/rake'
|
8
9
|
require 'xot/module'
|
@@ -11,9 +12,10 @@ require 'rucy/module'
|
|
11
12
|
include Xot::Rake
|
12
13
|
|
13
14
|
|
14
|
-
|
15
|
+
MODULES = [Xot, Rucy].map {|m| m.const_get :Module}
|
16
|
+
MODULE = MODULES.last
|
15
17
|
DLNAME = 'tester'
|
16
|
-
INCDIRS =
|
18
|
+
INCDIRS = ruby_incdirs
|
17
19
|
RUCY2RDOC = 'bin/rucy2rdoc'
|
18
20
|
NPARAM_MAX = 8
|
19
21
|
NTIMES = (0..NPARAM_MAX)
|
@@ -24,4 +26,4 @@ task :default => :build
|
|
24
26
|
task :build => :lib
|
25
27
|
|
26
28
|
|
27
|
-
|
29
|
+
MODULES.each {|m| m.load_tasks :lib, :ext, :test, :doc, :gem}
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.7
|
data/bin/rucy2rdoc
CHANGED
@@ -26,11 +26,11 @@ class Parser
|
|
26
26
|
|
27
27
|
def parse_functions (lines)
|
28
28
|
re = %r{
|
29
|
-
(?:
|
29
|
+
(?:RUCY_)?DEF(\d+|N|_ALLOC)\( (\w+) \s* ((?:\, \s* \w+)*) \s* \) \s*
|
30
30
|
(\{ \s*
|
31
31
|
.*?
|
32
32
|
\}) \s*
|
33
|
-
(?:
|
33
|
+
(?:RUCY_)?END
|
34
34
|
}mx
|
35
35
|
process_lines lines, re do |all, type, name, params, body|
|
36
36
|
type = '-1' if type == 'N'
|
@@ -42,7 +42,7 @@ class Parser
|
|
42
42
|
params = 'VALUE self' + params
|
43
43
|
end
|
44
44
|
@funs[name] = {
|
45
|
-
:type
|
45
|
+
:type => type,
|
46
46
|
:params => params,
|
47
47
|
:body => body
|
48
48
|
}
|
@@ -72,7 +72,7 @@ class Parser
|
|
72
72
|
}mx
|
73
73
|
process_lines lines, re do |all, var, recv, define, name, super_|
|
74
74
|
define += '_under' if recv
|
75
|
-
recv +=
|
75
|
+
recv += ', ' if recv
|
76
76
|
super_ = 'rb_cObject' if !super_ && define =~ /class/
|
77
77
|
super_ = ', ' + super_ if super_
|
78
78
|
"#{var} = rb_#{define}(#{recv}#{name}#{super_});"
|
@@ -85,7 +85,10 @@ class Parser
|
|
85
85
|
\( \s* (?: (\"\w+(?:\=|\?\!)?\") \s* \, \s* )? (\w+) \s* \) \s* ;
|
86
86
|
}mx
|
87
87
|
process_lines lines, re do |all, obj, define, symbol, name|
|
88
|
-
|
88
|
+
fun = @funs[name]
|
89
|
+
next unless fun
|
90
|
+
|
91
|
+
type = fun[:type]
|
89
92
|
if type == '_ALLOC'
|
90
93
|
"rb_#{define}(#{obj}, #{name});"
|
91
94
|
else
|