rucy 0.1.2 → 0.1.3

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/src/exception.cpp CHANGED
@@ -4,7 +4,6 @@
4
4
 
5
5
  #include <ruby.h>
6
6
  #include <rucy/rucy.h>
7
- #include <rucy/string.h>
8
7
 
9
8
  #ifdef WIN32
10
9
  #include <windows.h>
@@ -19,7 +18,7 @@
19
18
  { \
20
19
  va_list args; \
21
20
  va_start(args, format); \
22
- result = stringf(format, args); \
21
+ result = Xot::stringf(format, args); \
23
22
  va_end(args); \
24
23
  } \
25
24
  } \
@@ -30,34 +29,43 @@ namespace Rucy
30
29
  {
31
30
 
32
31
 
33
- Class
34
- native_error_class ()
32
+ RubyException::RubyException (Value exception)
33
+ : Super(""), val(exception)
34
+ {
35
+ }
36
+
37
+ RubyException::RubyException (Value type, const char* format, ...)
38
+ : Super(""), val(Qnil)
35
39
  {
36
- static Class c =
37
- rucy_module().define_class("NativeError", rb_eRuntimeError);
38
- return c;
40
+ VA_STRING(format, s);
41
+ val = rb_exc_new2(type, s.c_str());
42
+ }
43
+
44
+ const char*
45
+ RubyException::what () const throw()
46
+ {
47
+ SYM(message);
48
+ return value().call(message).c_str();
39
49
  }
40
50
 
41
- Class
42
- system_error_class ()
51
+ Value
52
+ RubyException::value () const
43
53
  {
44
- static Class c =
45
- rucy_module().define_class("SystemError", native_error_class());
46
- return c;
54
+ return val;
47
55
  }
48
56
 
49
- Class
50
- invalid_object_error_class ()
57
+
58
+ RubyJumptag::RubyJumptag (int tag)
59
+ : tag(tag)
51
60
  {
52
- static Class c =
53
- rucy_module().define_class("InvalidObjectError", native_error_class());
54
- return c;
55
61
  }
56
62
 
57
63
 
58
64
  void
59
- error (const char* format, ...)
65
+ raise (const char* format, ...)
60
66
  {
67
+ if (!format) throw;
68
+
61
69
  VA_STRING(format, message);
62
70
  throw message;
63
71
  }
@@ -90,13 +98,13 @@ namespace Rucy
90
98
  int n1, int n2, int n3, int n4, int n5,
91
99
  int n6, int n7, int n8, int n9, int n10)
92
100
  {
93
- String message = stringf(
101
+ String message = Xot::stringf(
94
102
  "wrong number of arguments for %s: %d for %d",
95
103
  method, nargs, nargs_expected);
96
104
 
97
105
  int n[10] = {n1, n2, n3, n4, n5, n6, n7, n8, n9, n10};
98
106
  for (int i = 0; i < 5 && n[i] >= 0; ++i)
99
- message += stringf(" or %d", n[i]);
107
+ message += Xot::stringf(" or %d", n[i]);
100
108
 
101
109
  message += ".";
102
110
  argument_error(message.c_str());
@@ -146,36 +154,4 @@ namespace Rucy
146
154
  }
147
155
 
148
156
 
149
- RubyException::RubyException (Value exception)
150
- : Super(""), val(exception)
151
- {
152
- }
153
-
154
- RubyException::RubyException (Value type, const char* format, ...)
155
- : Super(""), val(Qnil)
156
- {
157
- VA_STRING(format, message);
158
- val = rb_exc_new2(type, message.c_str());
159
- }
160
-
161
- const char*
162
- RubyException::what () const throw()
163
- {
164
- SYM(message);
165
- return value().call(message).c_str();
166
- }
167
-
168
- Value
169
- RubyException::value () const
170
- {
171
- return val;
172
- }
173
-
174
-
175
- RubyJumptag::RubyJumptag (int tag)
176
- : tag(tag)
177
- {
178
- }
179
-
180
-
181
157
  }// Rucy
data/src/function.cpp CHANGED
@@ -13,6 +13,7 @@
13
13
  namespace Rucy
14
14
  {
15
15
 
16
+
16
17
  void
17
18
  define_function (const char* name, RubyFunctionN fun)
18
19
  {
data/src/function.cpp.erb CHANGED
@@ -1,5 +1,4 @@
1
1
  // -*- c++ -*-
2
- % require 'support'
3
2
  #include "rucy/function.h"
4
3
 
5
4
 
@@ -14,6 +13,7 @@
14
13
  namespace Rucy
15
14
  {
16
15
 
16
+
17
17
  void
18
18
  define_function (const char* name, RubyFunctionN fun)
19
19
  {
data/src/module.cpp CHANGED
@@ -309,12 +309,16 @@ namespace Rucy
309
309
  return rb_define_module(name);
310
310
  }
311
311
 
312
+ Class
313
+ define_class (const char* name, Value super)
314
+ {
315
+ return rb_define_class(name, super);
316
+ }
312
317
 
313
- Module
314
- rucy_module ()
318
+ void
319
+ define_const (const char* name, Value val)
315
320
  {
316
- static Module m = define_module("Rucy");
317
- return m;
321
+ rb_define_global_const(name, val);
318
322
  }
319
323
 
320
324
 
data/src/module.cpp.erb CHANGED
@@ -1,5 +1,4 @@
1
1
  // -*- c++ -*-
2
- % require 'support'
3
2
  #include "rucy/module.h"
4
3
 
5
4
 
@@ -91,12 +90,16 @@ namespace Rucy
91
90
  return rb_define_module(name);
92
91
  }
93
92
 
93
+ Class
94
+ define_class (const char* name, Value super)
95
+ {
96
+ return rb_define_class(name, super);
97
+ }
94
98
 
95
- Module
96
- rucy_module ()
99
+ void
100
+ define_const (const char* name, Value val)
97
101
  {
98
- static Module m = define_module("Rucy");
99
- return m;
102
+ rb_define_global_const(name, val);
100
103
  }
101
104
 
102
105
 
data/src/rucy.cpp CHANGED
@@ -2,7 +2,6 @@
2
2
  #include "rucy/rucy.h"
3
3
 
4
4
 
5
- #include <rucy/module.h>
6
5
  #include <rucy/exception.h>
7
6
 
8
7
 
@@ -19,27 +18,16 @@ namespace Rucy
19
18
 
20
19
  rucy_module();
21
20
  native_error_class();
22
- return true;
23
- }
24
-
25
-
26
- Value
27
- require (const char* name)
28
- {
29
- return rb_require(name);
30
- }
21
+ system_error_class();
22
+ invalid_object_error_class();
31
23
 
32
- void
33
- define_const (const char* name, Value val)
34
- {
35
- rb_define_global_const(name, val);
24
+ return true;
36
25
  }
37
26
 
38
-
39
27
  bool
40
- check_class (Value obj, Value class_)
28
+ check_class (Value obj, Value klass)
41
29
  {
42
- return class_ && obj.is_kind_of(class_);
30
+ return klass && obj.is_kind_of(klass);
43
31
 
44
32
  #if 0
45
33
  SYMBOL(klass, "class");
@@ -53,4 +41,37 @@ namespace Rucy
53
41
  }
54
42
 
55
43
 
44
+ Module
45
+ rucy_module ()
46
+ {
47
+ static Module m = define_module("Rucy");
48
+ return m;
49
+ }
50
+
51
+
52
+ Class
53
+ native_error_class ()
54
+ {
55
+ static Class c =
56
+ rucy_module().define_class("NativeError", rb_eRuntimeError);
57
+ return c;
58
+ }
59
+
60
+ Class
61
+ system_error_class ()
62
+ {
63
+ static Class c =
64
+ rucy_module().define_class("SystemError", native_error_class());
65
+ return c;
66
+ }
67
+
68
+ Class
69
+ invalid_object_error_class ()
70
+ {
71
+ static Class c =
72
+ rucy_module().define_class("InvalidObjectError", native_error_class());
73
+ return c;
74
+ }
75
+
76
+
56
77
  }// Rucy
data/src/value.cpp.erb CHANGED
@@ -1,5 +1,4 @@
1
1
  // -*- c++ -*-
2
- % require 'support'
3
2
  #include "rucy/value.h"
4
3
 
5
4
 
data/task/ext.rake CHANGED
@@ -1,37 +1,96 @@
1
1
  # -*- mode: ruby; coding: utf-8 -*-
2
2
 
3
3
 
4
+ require 'rbconfig'
5
+ require 'rucy/module'
6
+
7
+
4
8
  namespace :ext do
5
9
 
6
- dir = "#{EXTDIR}/#{NAME}"
7
- name = "#{NAME}/tester"
8
- outname = "#{name}.#{EXTEXT}"
9
- out = File.join EXTDIR, outname
10
+
11
+ rbconf = RbConfig::CONFIG
12
+
13
+ mod = MODULE
14
+ name = env :NAME, MODULE.name.downcase
15
+ extdir = env :EXTDIR, 'ext'
16
+ docdir = env :DOCDIR, 'doc'
17
+ dlext = env :DLEXT, rbconf['DLEXT'] || 'so'
18
+ ruby = env :RUBY, 'ruby'
19
+ make = env :MAKE, 'make'
20
+ cc = env :CC, rbconf['CC'] || 'g++'
21
+ rdoc = env :RDOC, 'rdoc'# 'yardoc'
22
+ rucy2rdoc = env :RUCY2RDOC, 'rucy2rdoc'
23
+ defs = env :DEFS, []
24
+ incdirs = env(:INCDIRS) ? env(:INCDIRS) : []
25
+ cflags = env(:CFLAGS, '-Wall -O -g').dup
26
+
27
+ dir = "#{extdir}/#{name}"
28
+ modname = "#{name}/native"
29
+ outname = "#{name}.#{dlext}"
30
+ out = File.join extdir, outname
31
+
32
+ srcs = FileList["#{dir}/**/*.cpp"]
33
+
34
+ incroot = rbconf['rubyhdrdir']
35
+ incdirs.concat mod.include_dirs + Rucy.include_dirs + [
36
+ incroot,
37
+ "#{incroot}/#{RUBY_PLATFORM}",
38
+ '/opt/local/include',
39
+ '/opt/include'
40
+ ]
41
+ incdirs.uniq!
42
+
43
+ defs << 'WIN32' if win32?
44
+ defs << 'COCOA' if cocoa?
45
+ cflags << defs.map{|s| " -D#{s}"}.join
46
+ cflags << incdirs.map{|s| " -I#{s}"}.join
10
47
 
11
48
  extconf = File.join dir, "extconf.rb"
12
49
  makefile = File.join dir, "Makefile"
13
50
  depend = File.join dir, "depend"
14
51
 
15
- cpps = Dir.glob("#{dir}/**/*.cpp")
52
+ rdocdir = ".doc/#{dir}"
53
+ rdocs = Hash[srcs.map{|path| [path, "#{rdocdir}/#{File.basename path}"]}]
54
+ docindex = "#{docdir}/index.html"
16
55
 
17
- task :build => makefile do
18
- sh %( cd #{dir} && #{MAKE} )
19
- end
56
+
57
+ task :build => out
58
+
59
+ task :rdoc => rdocs.values
60
+
61
+ task :doc => docindex
20
62
 
21
63
  task :clean do
22
- sh %( cd #{dir} && #{MAKE} clean ) if File.exist? makefile
23
- sh %( rm -f #{makefile} #{depend} )
64
+ sh %( cd #{dir} && #{make} clean ) if File.exist? makefile
65
+ sh %( rm -rf #{makefile} #{depend} #{docdir} #{rdocs.values.join ' '} )
66
+ end
67
+
68
+ file out => makefile do
69
+ sh %( cd #{dir} && #{make} )
24
70
  end
25
71
 
26
72
  file makefile => [extconf, depend] do
27
- sh %( cd #{dir} && #{RUBY} #{File.basename extconf} )
73
+ sh %( cd #{dir} && #{ruby} #{File.basename extconf} )
28
74
  end
29
75
 
30
- file depend => ["lib:build"] + cpps do
31
- incdirs = INCDIRS.map{|s| " -I#{s}"}.join
32
- srcs = cpps.map{|cpp| File.basename cpp}.join ' '
76
+ file depend => ["lib:build"] + srcs do
77
+ inc = incdirs.map{|s| " -I#{s}"}.join
78
+ src = srcs.map{|cpp| File.basename cpp}.join ' '
33
79
  dep = File.basename depend
34
- sh %( cd #{dir} && #{CC} -M #{CFLAGS} #{incdirs} #{srcs} > #{dep} )
80
+ sh %( cd #{dir} && #{cc} -M #{cflags} #{inc} #{src} > #{dep} )
81
+ end
82
+
83
+ file docindex => "ext:rdoc" do
84
+ sh %( #{rdoc} #{rdocs.values.join ' '} )
85
+ end
86
+
87
+ rdocs.each do |(cpp, rdoc)|
88
+ file rdoc => [cpp, rdocdir] do
89
+ sh %( #{rucy2rdoc} #{cpp} > #{rdoc} )
90
+ end
35
91
  end
36
92
 
93
+ directory rdocdir
94
+
95
+
37
96
  end# :ext
data/test/test_rucy.rb CHANGED
@@ -17,6 +17,15 @@ class TestTester < Test::Unit::TestCase
17
17
  assert_equal nil, @t.do_nothing
18
18
  end
19
19
 
20
+ def test_set_get ()
21
+ @t.value = 100
22
+ assert_equal 100, @t.value
23
+ end
24
+
25
+ def test_no_return_returns_nil ()
26
+ assert_equal nil, @t.do_nothing
27
+ end
28
+
20
29
  def test_returns_nil ()
21
30
  assert_equal nil, @t.return_nil
22
31
  end
@@ -49,6 +58,10 @@ class TestTester < Test::Unit::TestCase
49
58
  assert_raise(Rucy::NativeError) {@t.throw_std_runtime_error}
50
59
  end
51
60
 
61
+ def test_throw_custom_exception ()
62
+ assert_raise(Rucy::NativeError) {@t.throw_custom_exception}
63
+ end
64
+
52
65
  def test_throw_std_string ()
53
66
  assert_raise(Rucy::NativeError) {@t.throw_std_string}
54
67
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: rucy
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.2
5
+ version: 0.1.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - snori
@@ -10,10 +10,10 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-08-29 00:00:00 Z
13
+ date: 2011-09-19 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
- name: rake
16
+ name: xot
17
17
  prerelease: false
18
18
  requirement: &id001 !ruby/object:Gem::Requirement
19
19
  none: false
@@ -21,10 +21,10 @@ dependencies:
21
21
  - - ">="
22
22
  - !ruby/object:Gem::Version
23
23
  version: "0"
24
- type: :development
24
+ type: :runtime
25
25
  version_requirements: *id001
26
26
  - !ruby/object:Gem::Dependency
27
- name: gemcutter
27
+ name: rake
28
28
  prerelease: false
29
29
  requirement: &id002 !ruby/object:Gem::Requirement
30
30
  none: false
@@ -34,27 +34,39 @@ dependencies:
34
34
  version: "0"
35
35
  type: :development
36
36
  version_requirements: *id002
37
+ - !ruby/object:Gem::Dependency
38
+ name: gemcutter
39
+ prerelease: false
40
+ requirement: &id003 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: "0"
46
+ type: :development
47
+ version_requirements: *id003
37
48
  description: This library helps you to develop Ruby Extension by C++.
38
49
  email: snori@xord.org
39
- executables: []
40
-
50
+ executables:
51
+ - rucy2rdoc
41
52
  extensions:
42
53
  - Rakefile
43
54
  extra_rdoc_files:
44
55
  - README
56
+ - .doc/ext/rucy/tester.cpp
45
57
  files:
46
58
  - README
47
59
  - ChangeLog
48
60
  - Rakefile
49
- - support.rb
50
61
  - rucy.gemspec
51
62
  - VERSION
52
63
  - task/ext.rake
53
- - task/gem.rake
54
- - task/git.rake
55
- - task/lib.rake
56
64
  - ext/rucy/extconf.rb
57
65
  - ext/rucy/tester.cpp
66
+ - include/rucy/defs.h.erb
67
+ - include/rucy/function.h.erb
68
+ - include/rucy/module.h.erb
69
+ - include/rucy/value.h.erb
58
70
  - include/rucy/class.h
59
71
  - include/rucy/defs.h
60
72
  - include/rucy/exception.h
@@ -62,29 +74,25 @@ files:
62
74
  - include/rucy/gc.h
63
75
  - include/rucy/module.h
64
76
  - include/rucy/rucy.h
65
- - include/rucy/string.h
66
77
  - include/rucy/symbol.h
67
78
  - include/rucy/value.h
68
79
  - include/rucy.h
69
- - include/rucy/defs.h.erb
70
- - include/rucy/function.h.erb
71
- - include/rucy/module.h.erb
72
- - include/rucy/value.h.erb
73
80
  - lib/rucy/module.rb
74
81
  - lib/rucy.rb
82
+ - src/function.cpp.erb
83
+ - src/module.cpp.erb
84
+ - src/value.cpp.erb
75
85
  - src/class.cpp
76
86
  - src/exception.cpp
77
87
  - src/function.cpp
78
88
  - src/gc.cpp
79
89
  - src/module.cpp
80
90
  - src/rucy.cpp
81
- - src/string.cpp
82
91
  - src/symbol.cpp
83
92
  - src/value.cpp
84
- - src/function.cpp.erb
85
- - src/module.cpp.erb
86
- - src/value.cpp.erb
87
93
  - test/test_rucy.rb
94
+ - .doc/ext/rucy/tester.cpp
95
+ - bin/rucy2rdoc
88
96
  homepage: http://github.com/xord/rucy
89
97
  licenses: []
90
98
 
@@ -1,28 +0,0 @@
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
data/src/string.cpp DELETED
@@ -1,78 +0,0 @@
1
- // -*- c++ -*-
2
- #include "rucy/string.h"
3
-
4
-
5
- #include <stdio.h>
6
- #include <stdarg.h>
7
- #include <boost/scoped_array.hpp>
8
-
9
-
10
- namespace Rucy
11
- {
12
-
13
-
14
- String
15
- stringf (const char* format, ...)
16
- {
17
- va_list args;
18
- va_start(args, format);
19
- String ret = stringf(format, args);
20
- va_end(args);
21
- return ret;
22
- }
23
-
24
- String
25
- stringf (const char* format, va_list args)
26
- {
27
- enum {BUFSIZE = 256};
28
- char stack[BUFSIZE];
29
- if (vsnprintf(&stack[0], BUFSIZE, format, args) <= BUFSIZE)
30
- return &stack[0];
31
-
32
- int bufsize = BUFSIZE;// vscprintf(format, args);
33
- boost::scoped_array<char> heap;
34
- while (true)
35
- {
36
- bufsize *= 2;
37
- heap.reset(new char[bufsize]);
38
- if (vsnprintf(&heap[0], bufsize, format, args) <= bufsize)
39
- return &heap[0];
40
- }
41
-
42
- return NULL;
43
- }
44
-
45
- template <> String
46
- to_s<int> (const int& val)
47
- {
48
- return stringf("%d", val);
49
- }
50
-
51
- template <> String
52
- to_s<float> (const float& val)
53
- {
54
- return stringf("%f", val);
55
- }
56
-
57
- template <> String
58
- to_s<double> (const double& val)
59
- {
60
- return stringf("%f", val);
61
- }
62
-
63
- typedef const char* const_char_p;
64
-
65
- template <> String
66
- to_s<const_char_p> (const const_char_p& val)
67
- {
68
- return val;
69
- }
70
-
71
- template <> String
72
- to_s<String> (const String& val)
73
- {
74
- return val;
75
- }
76
-
77
-
78
- }// Rucy
data/support.rb DELETED
@@ -1,64 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
-
4
- require 'erb'
5
- require 'pp'
6
-
7
-
8
- NPARAM_MAX = 8
9
- NTIMES = (0..NPARAM_MAX)
10
-
11
-
12
- def glob (*patterns)
13
- paths = []
14
- patterns.each do |pattern|
15
- paths.concat Dir.glob(pattern)
16
- end
17
- paths
18
- end
19
-
20
- def erb (str)
21
- ERB.new(str, nil, "%").result binding
22
- end
23
-
24
- def compile (path, out)
25
- open(path) do |input|
26
- open(out, "w") do |output|
27
- output.write erb(input.read)
28
- end
29
- end
30
- #rescue
31
- end
32
-
33
- def params (n, sep = "", &block)
34
- raise "block not given." unless block
35
- return "" if n == 0
36
- (1..n).map(&block).join(sep)
37
- end
38
-
39
- def convertions (paths, convs)
40
- raise "empty conversion." if convs.empty?
41
- paths = paths.map do |path|
42
- convpath = path
43
- convs.each do |from, to|
44
- convpath = convpath.sub(/#{from.gsub('.', '\.')}$/, to)
45
- end
46
- [path, convpath]
47
- end
48
- Hash[*paths.flatten]
49
- end
50
-
51
- alias sh_original sh
52
-
53
- def sh (*args)
54
- sh_original *args
55
- #rescue
56
- end
57
-
58
- def win32? ()
59
- RUBY_PLATFORM =~ /mswin|ming|cygwin/
60
- end
61
-
62
- def cocoa? ()
63
- RUBY_PLATFORM =~ /darwin/
64
- end