rucy 0.1.12 → 0.1.18
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.doc/ext/rucy/class.cpp +12 -75
- data/.doc/ext/rucy/tester.cpp +2 -2
- data/LICENSE +21 -0
- data/README.md +2 -2
- data/Rakefile +10 -15
- data/VERSION +1 -1
- data/ext/rucy/class.cpp +19 -86
- data/ext/rucy/class.h +0 -10
- data/ext/rucy/extconf.rb +2 -3
- data/ext/rucy/tester.cpp +2 -2
- data/include/rucy.h +4 -1
- data/include/rucy/debug.h +22 -0
- data/include/rucy/exception.h +29 -9
- data/include/rucy/extension.h.erb +97 -172
- data/include/rucy/module.h.erb +1 -1
- data/include/rucy/ruby.h +0 -1
- data/include/rucy/value.h.erb +30 -15
- data/lib/rucy/module.rb +4 -19
- data/lib/rucy/rake.rb +62 -0
- data/rucy.gemspec +4 -6
- data/src/module.cpp.erb +1 -1
- data/src/value.cpp.erb +53 -43
- data/test/test_class.rb +2 -34
- metadata +24 -50
data/include/rucy/module.h.erb
CHANGED
data/include/rucy/ruby.h
CHANGED
data/include/rucy/value.h.erb
CHANGED
@@ -41,6 +41,8 @@ namespace Rucy
|
|
41
41
|
|
42
42
|
bool is_f () const;
|
43
43
|
|
44
|
+
bool is_num () const;
|
45
|
+
|
44
46
|
bool is_s () const;
|
45
47
|
|
46
48
|
bool is_sym () const;
|
@@ -120,9 +122,9 @@ namespace Rucy
|
|
120
122
|
|
121
123
|
Value unshift (Value obj);
|
122
124
|
|
123
|
-
Value& operator [] (
|
125
|
+
Value& operator [] (size_t i);
|
124
126
|
|
125
|
-
const Value& operator [] (
|
127
|
+
const Value& operator [] (size_t i) const;
|
126
128
|
|
127
129
|
// String
|
128
130
|
|
@@ -134,6 +136,8 @@ namespace Rucy
|
|
134
136
|
|
135
137
|
int size () const;
|
136
138
|
|
139
|
+
bool empty () const;
|
140
|
+
|
137
141
|
protected:
|
138
142
|
|
139
143
|
RubyValue val;
|
@@ -144,7 +148,9 @@ namespace Rucy
|
|
144
148
|
class GlobalValue : public Value
|
145
149
|
{
|
146
150
|
|
147
|
-
typedef
|
151
|
+
typedef Value Super;
|
152
|
+
|
153
|
+
typedef GlobalValue This;
|
148
154
|
|
149
155
|
public:
|
150
156
|
|
@@ -170,24 +176,24 @@ namespace Rucy
|
|
170
176
|
|
171
177
|
GlobalValue (const Value& v, bool gc = false);
|
172
178
|
|
173
|
-
GlobalValue (const
|
179
|
+
GlobalValue (const This& obj, bool gc = false);
|
174
180
|
|
175
181
|
GlobalValue& operator = (const Value& v);
|
176
182
|
|
183
|
+
GlobalValue& operator = (const This& obj);
|
184
|
+
|
177
185
|
~GlobalValue ();
|
178
186
|
|
179
|
-
void
|
187
|
+
void enable_gc () const;
|
180
188
|
|
181
|
-
|
189
|
+
void disable_gc () const;
|
182
190
|
|
183
|
-
|
191
|
+
private:
|
184
192
|
|
185
|
-
mutable
|
193
|
+
mutable int gc_disable_count;
|
186
194
|
|
187
195
|
void init (bool gc);
|
188
196
|
|
189
|
-
void update_guard () const;
|
190
|
-
|
191
197
|
};// GlobalValue
|
192
198
|
|
193
199
|
|
@@ -224,21 +230,30 @@ namespace Rucy
|
|
224
230
|
Value value (const char* s, size_t len);
|
225
231
|
|
226
232
|
Value value (size_t size, const Value* array);
|
227
|
-
|
228
|
-
Value value (void* ptr);
|
229
|
-
% (1..10).each do |n|
|
233
|
+
% (1..16).each do |n|
|
230
234
|
|
231
235
|
Value array (<%= params(n, ', ') {|i| "Value v#{i}"} %>);
|
232
236
|
% end
|
233
237
|
|
234
238
|
|
235
|
-
template <typename T>
|
239
|
+
template <typename T> T
|
240
|
+
value_to (Value obj, bool convert = true);
|
236
241
|
|
237
|
-
template <typename T> inline T
|
242
|
+
template <typename T> inline T
|
243
|
+
to (Value obj, bool convert = true)
|
238
244
|
{
|
239
245
|
return value_to<T>(obj, convert);
|
240
246
|
}
|
241
247
|
|
248
|
+
template <typename T> T
|
249
|
+
value_to (int argc, const Value* argv, bool convert = true);
|
250
|
+
|
251
|
+
template <typename T> inline T
|
252
|
+
to (int argc, const Value* argv, bool convert = true)
|
253
|
+
{
|
254
|
+
return value_to<T>(argc, argv, convert);
|
255
|
+
}
|
256
|
+
|
242
257
|
template <typename T> inline T Value::as (bool convert) const
|
243
258
|
{
|
244
259
|
return value_to<T>(*this, convert);
|
data/lib/rucy/module.rb
CHANGED
@@ -6,6 +6,8 @@ module Rucy
|
|
6
6
|
|
7
7
|
module Module
|
8
8
|
|
9
|
+
module_function
|
10
|
+
|
9
11
|
def name ()
|
10
12
|
super.split('::')[-2]
|
11
13
|
end
|
@@ -15,10 +17,10 @@ module Rucy
|
|
15
17
|
end
|
16
18
|
|
17
19
|
def root_dir (path = '')
|
18
|
-
File.expand_path "
|
20
|
+
File.expand_path "../../#{path}", __dir__
|
19
21
|
end
|
20
22
|
|
21
|
-
def
|
23
|
+
def inc_dir ()
|
22
24
|
root_dir 'include'
|
23
25
|
end
|
24
26
|
|
@@ -26,23 +28,6 @@ module Rucy
|
|
26
28
|
root_dir 'lib'
|
27
29
|
end
|
28
30
|
|
29
|
-
def task_dir ()
|
30
|
-
root_dir 'task'
|
31
|
-
end
|
32
|
-
|
33
|
-
def load_tasks (*names)
|
34
|
-
if names.empty?
|
35
|
-
Dir["#{task_dir}/**/*.rake"].each {|path| load path}
|
36
|
-
else
|
37
|
-
names.each do |name|
|
38
|
-
path = "#{task_dir}/#{name}.rake"
|
39
|
-
load path if File.exist? path
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
extend self
|
45
|
-
|
46
31
|
end# Module
|
47
32
|
|
48
33
|
|
data/lib/rucy/rake.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
|
4
|
+
require 'xot/rake'
|
5
|
+
|
6
|
+
|
7
|
+
module Rucy
|
8
|
+
|
9
|
+
|
10
|
+
module Rake
|
11
|
+
|
12
|
+
|
13
|
+
def rdoc ()
|
14
|
+
env :RDOC, 'rdoc'# 'yardoc'
|
15
|
+
end
|
16
|
+
|
17
|
+
def rucy2rdoc ()
|
18
|
+
env :RUCY2RDOC, 'rucy2rdoc'
|
19
|
+
end
|
20
|
+
|
21
|
+
def generate_documents ()
|
22
|
+
rdocdir = ".doc/#{ext_dir}"
|
23
|
+
srcs = FileList["#{ext_dir}/**/*.{#{src_exts.join ','}}"]
|
24
|
+
rdocs = Hash[srcs.map{|path| [path, "#{rdocdir}/#{File.basename path}"]}]
|
25
|
+
out = "#{doc_dir}/index.html"
|
26
|
+
|
27
|
+
alias_task :doc => out
|
28
|
+
alias_task :clean => 'doc:clean'
|
29
|
+
|
30
|
+
namespace :doc do
|
31
|
+
desc "build documents"
|
32
|
+
file out => rdocs.values do
|
33
|
+
sh %( #{rdoc} #{rdocs.values.join ' '} )
|
34
|
+
end
|
35
|
+
|
36
|
+
rdocs.each do |(src, rdoc)|
|
37
|
+
file rdoc => [src, rdocdir] do
|
38
|
+
sh %( #{rucy2rdoc} #{src} > #{rdoc} )
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
directory rdocdir
|
43
|
+
|
44
|
+
task :clean do
|
45
|
+
sh %( rm -rf #{rdocdir} #{rdocs.values.join ' '} )
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
end# Rake
|
52
|
+
|
53
|
+
|
54
|
+
end# Rucy
|
55
|
+
|
56
|
+
|
57
|
+
include Rucy::Rake
|
58
|
+
|
59
|
+
|
60
|
+
File.expand_path('../../bin', __dir__).tap do |path|
|
61
|
+
ENV['PATH'] += ":#{path}" unless ENV['PATH'].split(':').include?(path)
|
62
|
+
end
|
data/rucy.gemspec
CHANGED
@@ -21,16 +21,14 @@ Gem::Specification.new do |s|
|
|
21
21
|
s.description = 'This library helps you to develop Ruby Extension by C++.'
|
22
22
|
s.version = mod.version
|
23
23
|
|
24
|
-
s.authors = %w[
|
25
|
-
s.email = '
|
24
|
+
s.authors = %w[xordog]
|
25
|
+
s.email = 'xordog@gmail.com'
|
26
26
|
s.homepage = "https://github.com/xord/rucy"
|
27
27
|
|
28
28
|
s.platform = Gem::Platform::RUBY
|
29
|
-
s.required_ruby_version = '
|
29
|
+
s.required_ruby_version = '~> 2'
|
30
30
|
|
31
|
-
s.add_runtime_dependency '
|
32
|
-
s.add_runtime_dependency 'xot'
|
33
|
-
s.add_development_dependency 'gemcutter'
|
31
|
+
s.add_runtime_dependency 'xot', '~> 0.1.16'
|
34
32
|
|
35
33
|
s.files = `git ls-files`.split $/
|
36
34
|
s.executables = s.files.grep(%r{^bin/}) {|f| File.basename f}
|
data/src/module.cpp.erb
CHANGED
@@ -58,7 +58,7 @@ namespace Rucy
|
|
58
58
|
}
|
59
59
|
|
60
60
|
% [
|
61
|
-
% ['
|
61
|
+
% ['define_module_function', 'rb_define_module_function'],
|
62
62
|
% ['define_method', 'rb_define_method'],
|
63
63
|
% ['define_private_method', 'rb_define_private_method'],
|
64
64
|
% ['define_singleton_method', 'rb_define_singleton_method']
|
data/src/value.cpp.erb
CHANGED
@@ -3,8 +3,10 @@
|
|
3
3
|
|
4
4
|
|
5
5
|
#include <assert.h>
|
6
|
+
#include <ruby/encoding.h>
|
6
7
|
#include "rucy/function.h"
|
7
8
|
#include "rucy/exception.h"
|
9
|
+
#include "rucy/debug.h"
|
8
10
|
|
9
11
|
|
10
12
|
namespace Rucy
|
@@ -54,15 +56,29 @@ namespace Rucy
|
|
54
56
|
{
|
55
57
|
}
|
56
58
|
|
59
|
+
static VALUE
|
60
|
+
str_new (const char* s)
|
61
|
+
{
|
62
|
+
rb_encoding* e = rb_default_internal_encoding();
|
63
|
+
return e ? rb_enc_str_new_cstr(s, e) : rb_str_new_cstr(s);
|
64
|
+
}
|
65
|
+
|
66
|
+
static VALUE
|
67
|
+
str_new (const char* s, size_t len)
|
68
|
+
{
|
69
|
+
rb_encoding* e = rb_default_internal_encoding();
|
70
|
+
return e ? rb_enc_str_new(s, len, e) : rb_str_new(s, len);
|
71
|
+
}
|
72
|
+
|
57
73
|
Value::Value (const char* s)
|
58
|
-
: val(s ?
|
74
|
+
: val(s ? str_new(s) : Qnil)
|
59
75
|
{
|
60
76
|
if (!s)
|
61
77
|
argument_error(__FILE__, __LINE__);
|
62
78
|
}
|
63
79
|
|
64
80
|
Value::Value (const char* s, size_t len)
|
65
|
-
: val(s ?
|
81
|
+
: val(s ? str_new(s, len) : Qnil)
|
66
82
|
{
|
67
83
|
if (!s)
|
68
84
|
argument_error(__FILE__, __LINE__);
|
@@ -101,6 +117,12 @@ namespace Rucy
|
|
101
117
|
return RB_FLOAT_TYPE_P(val) || is_kind_of(rb_cFloat);
|
102
118
|
}
|
103
119
|
|
120
|
+
bool
|
121
|
+
Value::is_num () const
|
122
|
+
{
|
123
|
+
return is_i() || is_f();
|
124
|
+
}
|
125
|
+
|
104
126
|
bool
|
105
127
|
Value::is_s () const
|
106
128
|
{
|
@@ -325,13 +347,13 @@ namespace Rucy
|
|
325
347
|
}
|
326
348
|
|
327
349
|
Value&
|
328
|
-
Value::operator [] (
|
350
|
+
Value::operator [] (size_t i)
|
329
351
|
{
|
330
352
|
return as_array()[i];
|
331
353
|
}
|
332
354
|
|
333
355
|
const Value&
|
334
|
-
Value::operator [] (
|
356
|
+
Value::operator [] (size_t i) const
|
335
357
|
{
|
336
358
|
return const_cast<Value*>(this)->operator[](i);
|
337
359
|
}
|
@@ -339,7 +361,7 @@ namespace Rucy
|
|
339
361
|
const char*
|
340
362
|
Value::c_str () const
|
341
363
|
{
|
342
|
-
return
|
364
|
+
return as_s(true);
|
343
365
|
}
|
344
366
|
|
345
367
|
static int
|
@@ -367,6 +389,12 @@ namespace Rucy
|
|
367
389
|
return get_length(*this, size);
|
368
390
|
}
|
369
391
|
|
392
|
+
bool
|
393
|
+
Value::empty () const
|
394
|
+
{
|
395
|
+
return size() <= 0;
|
396
|
+
}
|
397
|
+
|
370
398
|
|
371
399
|
GlobalValue::GlobalValue ()
|
372
400
|
{
|
@@ -433,7 +461,7 @@ namespace Rucy
|
|
433
461
|
init(gc_);
|
434
462
|
}
|
435
463
|
|
436
|
-
GlobalValue::GlobalValue (const
|
464
|
+
GlobalValue::GlobalValue (const This& obj, bool gc_)
|
437
465
|
: Super(obj)
|
438
466
|
{
|
439
467
|
init(gc_);
|
@@ -443,50 +471,41 @@ namespace Rucy
|
|
443
471
|
GlobalValue::operator = (const Value& v)
|
444
472
|
{
|
445
473
|
Super::operator=(v);
|
446
|
-
|
474
|
+
return *this;
|
475
|
+
}
|
476
|
+
|
477
|
+
GlobalValue&
|
478
|
+
GlobalValue::operator = (const This& obj)
|
479
|
+
{
|
480
|
+
Super::operator=(obj);
|
447
481
|
return *this;
|
448
482
|
}
|
449
483
|
|
450
484
|
GlobalValue::~GlobalValue ()
|
451
485
|
{
|
452
|
-
|
486
|
+
if (gc_disable_count > 0)
|
487
|
+
rb_gc_unregister_address(&val);
|
453
488
|
}
|
454
489
|
|
455
490
|
void
|
456
|
-
GlobalValue::
|
491
|
+
GlobalValue::enable_gc () const
|
457
492
|
{
|
458
|
-
gc_disable_count
|
459
|
-
|
493
|
+
if (--gc_disable_count == 0)
|
494
|
+
rb_gc_unregister_address(const_cast<RubyValue*>(&val));
|
460
495
|
}
|
461
496
|
|
462
497
|
void
|
463
|
-
GlobalValue::
|
498
|
+
GlobalValue::disable_gc () const
|
464
499
|
{
|
465
|
-
gc_disable_count
|
466
|
-
|
467
|
-
if (!gc_) gc(false);
|
500
|
+
if (++gc_disable_count == 1)
|
501
|
+
rb_gc_register_address(const_cast<RubyValue*>(&val));
|
468
502
|
}
|
469
503
|
|
470
504
|
void
|
471
|
-
GlobalValue::
|
505
|
+
GlobalValue::init (bool gc_)
|
472
506
|
{
|
473
|
-
|
474
|
-
|
475
|
-
if (IMMEDIATE_P(val))
|
476
|
-
{
|
477
|
-
if (gc_guarded) rb_gc_unregister_address((RubyValue*) &val);
|
478
|
-
gc_guarded = false;
|
479
|
-
}
|
480
|
-
else if (gc_disable_count > 0)
|
481
|
-
{
|
482
|
-
if (!gc_guarded) rb_gc_register_address((RubyValue*) &val);
|
483
|
-
gc_guarded = true;
|
484
|
-
}
|
485
|
-
else
|
486
|
-
{
|
487
|
-
if (gc_guarded) rb_gc_unregister_address((RubyValue*) &val);
|
488
|
-
gc_guarded = false;
|
489
|
-
}
|
507
|
+
gc_disable_count = 0;
|
508
|
+
if (!gc_) disable_gc();
|
490
509
|
}
|
491
510
|
|
492
511
|
|
@@ -591,16 +610,7 @@ namespace Rucy
|
|
591
610
|
{
|
592
611
|
return Value(size, array);
|
593
612
|
}
|
594
|
-
|
595
|
-
Value
|
596
|
-
value (void* ptr)
|
597
|
-
{
|
598
|
-
if (ptr)
|
599
|
-
argument_error(__FILE__, __LINE__, "Rucy::value(void*) can take only (void*) NULL.");
|
600
|
-
|
601
|
-
return nil();
|
602
|
-
}
|
603
|
-
% (1..10).each do |n|
|
613
|
+
% (1..16).each do |n|
|
604
614
|
|
605
615
|
Value
|
606
616
|
array (<%= params(n, ', ') {|i| "Value v#{i}"} %>)
|