rucy 0.1.11 → 0.1.16

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.
@@ -41,7 +41,7 @@ namespace Rucy
41
41
  void extend_module (Value module);
42
42
 
43
43
  % [
44
- % 'define_function',
44
+ % 'define_module_function',
45
45
  % 'define_method',
46
46
  % 'define_private_method',
47
47
  % 'define_singleton_method',
@@ -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 [] (int i);
125
+ Value& operator [] (size_t i);
124
126
 
125
- const Value& operator [] (int i) const;
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 Value Super;
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 GlobalValue& obj, bool gc = false);
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 gc (bool enable) const;
187
+ void enable_gc () const;
180
188
 
181
- private:
189
+ void disable_gc () const;
182
190
 
183
- mutable short gc_disable_count;
191
+ private:
184
192
 
185
- mutable bool gc_guarded;
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> T value_to (Value obj, bool convert = true);
239
+ template <typename T> T
240
+ value_to (Value obj, bool convert = true);
236
241
 
237
- template <typename T> inline T to (Value obj, bool convert = true)
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);
@@ -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 "../../../#{path}", __FILE__
20
+ File.expand_path "../../#{path}", __dir__
19
21
  end
20
22
 
21
- def include_dir ()
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
 
@@ -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
@@ -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[snori]
25
- s.email = 'snori@xord.org'
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 = '>=1.9.0'
29
+ s.required_ruby_version = '~> 2'
30
30
 
31
- s.add_runtime_dependency 'rake'
32
- s.add_runtime_dependency 'xot'
33
- s.add_development_dependency 'gemcutter'
31
+ s.add_runtime_dependency 'xot', '~> 0.1'
34
32
 
35
33
  s.files = `git ls-files`.split $/
36
34
  s.executables = s.files.grep(%r{^bin/}) {|f| File.basename f}
@@ -58,7 +58,7 @@ namespace Rucy
58
58
  }
59
59
 
60
60
  % [
61
- % ['define_function', 'rb_define_module_function'],
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']
@@ -5,6 +5,7 @@
5
5
  #include <assert.h>
6
6
  #include "rucy/function.h"
7
7
  #include "rucy/exception.h"
8
+ #include "rucy/debug.h"
8
9
 
9
10
 
10
11
  namespace Rucy
@@ -101,6 +102,12 @@ namespace Rucy
101
102
  return RB_FLOAT_TYPE_P(val) || is_kind_of(rb_cFloat);
102
103
  }
103
104
 
105
+ bool
106
+ Value::is_num () const
107
+ {
108
+ return is_i() || is_f();
109
+ }
110
+
104
111
  bool
105
112
  Value::is_s () const
106
113
  {
@@ -325,13 +332,13 @@ namespace Rucy
325
332
  }
326
333
 
327
334
  Value&
328
- Value::operator [] (int i)
335
+ Value::operator [] (size_t i)
329
336
  {
330
337
  return as_array()[i];
331
338
  }
332
339
 
333
340
  const Value&
334
- Value::operator [] (int i) const
341
+ Value::operator [] (size_t i) const
335
342
  {
336
343
  return const_cast<Value*>(this)->operator[](i);
337
344
  }
@@ -339,7 +346,7 @@ namespace Rucy
339
346
  const char*
340
347
  Value::c_str () const
341
348
  {
342
- return as<const char*>(true);
349
+ return as_s(true);
343
350
  }
344
351
 
345
352
  static int
@@ -367,6 +374,12 @@ namespace Rucy
367
374
  return get_length(*this, size);
368
375
  }
369
376
 
377
+ bool
378
+ Value::empty () const
379
+ {
380
+ return size() <= 0;
381
+ }
382
+
370
383
 
371
384
  GlobalValue::GlobalValue ()
372
385
  {
@@ -433,7 +446,7 @@ namespace Rucy
433
446
  init(gc_);
434
447
  }
435
448
 
436
- GlobalValue::GlobalValue (const GlobalValue& obj, bool gc_)
449
+ GlobalValue::GlobalValue (const This& obj, bool gc_)
437
450
  : Super(obj)
438
451
  {
439
452
  init(gc_);
@@ -443,50 +456,41 @@ namespace Rucy
443
456
  GlobalValue::operator = (const Value& v)
444
457
  {
445
458
  Super::operator=(v);
446
- update_guard();
459
+ return *this;
460
+ }
461
+
462
+ GlobalValue&
463
+ GlobalValue::operator = (const This& obj)
464
+ {
465
+ Super::operator=(obj);
447
466
  return *this;
448
467
  }
449
468
 
450
469
  GlobalValue::~GlobalValue ()
451
470
  {
452
- while (gc_guarded) gc(true);
471
+ if (gc_disable_count > 0)
472
+ rb_gc_unregister_address(&val);
453
473
  }
454
474
 
455
475
  void
456
- GlobalValue::gc (bool enable) const
476
+ GlobalValue::enable_gc () const
457
477
  {
458
- gc_disable_count += enable ? -1 : +1;
459
- update_guard();
478
+ if (--gc_disable_count == 0)
479
+ rb_gc_unregister_address(const_cast<RubyValue*>(&val));
460
480
  }
461
481
 
462
482
  void
463
- GlobalValue::init (bool gc_)
483
+ GlobalValue::disable_gc () const
464
484
  {
465
- gc_disable_count = 0;
466
- gc_guarded = false;
467
- if (!gc_) gc(false);
485
+ if (++gc_disable_count == 1)
486
+ rb_gc_register_address(const_cast<RubyValue*>(&val));
468
487
  }
469
488
 
470
489
  void
471
- GlobalValue::update_guard () const
490
+ GlobalValue::init (bool gc_)
472
491
  {
473
- assert(gc_disable_count >= 0);
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
- }
492
+ gc_disable_count = 0;
493
+ if (!gc_) disable_gc();
490
494
  }
491
495
 
492
496
 
@@ -591,16 +595,7 @@ namespace Rucy
591
595
  {
592
596
  return Value(size, array);
593
597
  }
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|
598
+ % (1..16).each do |n|
604
599
 
605
600
  Value
606
601
  array (<%= params(n, ', ') {|i| "Value v#{i}"} %>)
@@ -14,10 +14,6 @@ class Temp < Rucy::Tester::Sub
14
14
  "Temp::name_overridable"
15
15
  end
16
16
 
17
- def name_overridable_faster ()
18
- "Temp::name_overridable_faster"
19
- end
20
-
21
17
  end# Temp
22
18
 
23
19
 
@@ -94,7 +90,7 @@ class TestClass < Test::Unit::TestCase
94
90
  assert_equal "Base::name", base_raw.call_name
95
91
  assert_equal "Sub::name", sub .call_name
96
92
  assert_equal "Sub::name", sub_raw .call_name
97
- assert_equal "Sub::name", temp .call_name # returns "Sub" not "Temp"!
93
+ assert_equal "Sub::name", temp .call_name# "Sub" instead of "Temp"!
98
94
  end
99
95
 
100
96
  def test_call_name_overridable ()
@@ -105,37 +101,9 @@ class TestClass < Test::Unit::TestCase
105
101
  assert_equal "Temp::name_overridable", temp .call_name_overridable
106
102
  end
107
103
 
108
- class X < Sub; end
109
-
110
- def test_is_overridden ()
111
- m = :name_overridable_faster
112
- def is_overridden (o) o.is_name_overridable_faster_overridden; end
113
-
114
- assert_equal true, is_overridden(temp)
115
-
116
- o = X.new
117
- assert_equal false, is_overridden(o)
118
- def o.name_overridable_faster () end
119
- assert_equal true, is_overridden(o)
120
-
121
- o = X.new
122
- assert_equal false, is_overridden(o)
123
- eval "class X; def #{m}; end; end"
124
- assert_equal true, is_overridden(o)
125
- eval "class X; remove_method :#{m}; end"
126
- assert_equal false, is_overridden(o)
127
-
128
- o = X.new
129
- assert_equal false, is_overridden(o)
130
- X.send(:define_method, m) {}
131
- assert_equal true, is_overridden(o)
132
- X.send :remove_method, m
133
- assert_equal false, is_overridden(o)
134
- end
135
-
136
104
  def test_gc ()
137
105
  def simple_objs (name, n = 10) ([nil] * n).map {SimpleObj.new name} end
138
- def gc (n = 10) n.times {GC.start}; print '' end
106
+ def gc () GC.start end
139
107
  rt = Rucy::Tester
140
108
 
141
109
  gc