rice 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (166) hide show
  1. data/COPYING +23 -0
  2. data/Doxyfile +1253 -0
  3. data/Makefile.am +26 -0
  4. data/Makefile.in +736 -0
  5. data/README +881 -0
  6. data/README.mingw +8 -0
  7. data/bootstrap +8 -0
  8. data/config.guess +1535 -0
  9. data/config.sub +1644 -0
  10. data/configure +7310 -0
  11. data/configure.ac +48 -0
  12. data/depcomp +584 -0
  13. data/doxygen.ac +314 -0
  14. data/doxygen.am +186 -0
  15. data/install-sh +507 -0
  16. data/missing +367 -0
  17. data/post-autoconf.rb +22 -0
  18. data/post-automake.rb +28 -0
  19. data/rice/Address_Registration_Guard.hpp +7 -0
  20. data/rice/Address_Registration_Guard.ipp +34 -0
  21. data/rice/Address_Registration_Guard_defn.hpp +65 -0
  22. data/rice/Allocation_Strategies.hpp +37 -0
  23. data/rice/Array.hpp +220 -0
  24. data/rice/Array.ipp +262 -0
  25. data/rice/Builtin_Object.hpp +8 -0
  26. data/rice/Builtin_Object.ipp +50 -0
  27. data/rice/Builtin_Object_defn.hpp +51 -0
  28. data/rice/Class.cpp +57 -0
  29. data/rice/Class.hpp +8 -0
  30. data/rice/Class.ipp +4 -0
  31. data/rice/Class_defn.hpp +83 -0
  32. data/rice/Constructor.hpp +189 -0
  33. data/rice/Critical_Guard.hpp +34 -0
  34. data/rice/Critical_Guard.ipp +20 -0
  35. data/rice/Data_Object.hpp +127 -0
  36. data/rice/Data_Object.ipp +129 -0
  37. data/rice/Data_Type.cpp +21 -0
  38. data/rice/Data_Type.hpp +8 -0
  39. data/rice/Data_Type.ipp +227 -0
  40. data/rice/Data_Type_defn.hpp +219 -0
  41. data/rice/Data_Type_fwd.hpp +12 -0
  42. data/rice/Enum.hpp +118 -0
  43. data/rice/Enum.ipp +246 -0
  44. data/rice/Exception.cpp +59 -0
  45. data/rice/Exception.hpp +69 -0
  46. data/rice/Exception_Base.hpp +30 -0
  47. data/rice/Exception_Base.ipp +11 -0
  48. data/rice/Hash.hpp +206 -0
  49. data/rice/Hash.ipp +336 -0
  50. data/rice/Identifier.cpp +8 -0
  51. data/rice/Identifier.hpp +50 -0
  52. data/rice/Identifier.ipp +33 -0
  53. data/rice/Jump_Tag.hpp +24 -0
  54. data/rice/Makefile.am +112 -0
  55. data/rice/Makefile.in +675 -0
  56. data/rice/Module.cpp +75 -0
  57. data/rice/Module.hpp +8 -0
  58. data/rice/Module.ipp +6 -0
  59. data/rice/Module_defn.hpp +87 -0
  60. data/rice/Module_impl.hpp +237 -0
  61. data/rice/Module_impl.ipp +302 -0
  62. data/rice/Object.cpp +153 -0
  63. data/rice/Object.hpp +8 -0
  64. data/rice/Object.ipp +19 -0
  65. data/rice/Object_defn.hpp +183 -0
  66. data/rice/Require_Guard.hpp +21 -0
  67. data/rice/String.cpp +93 -0
  68. data/rice/String.hpp +88 -0
  69. data/rice/Struct.cpp +117 -0
  70. data/rice/Struct.hpp +162 -0
  71. data/rice/Struct.ipp +26 -0
  72. data/rice/Symbol.cpp +25 -0
  73. data/rice/Symbol.hpp +66 -0
  74. data/rice/Symbol.ipp +44 -0
  75. data/rice/VM.cpp +79 -0
  76. data/rice/VM.hpp +27 -0
  77. data/rice/config.hpp +23 -0
  78. data/rice/config.hpp.in +22 -0
  79. data/rice/detail/Auto_Function_Wrapper.hpp +719 -0
  80. data/rice/detail/Auto_Function_Wrapper.ipp +1354 -0
  81. data/rice/detail/Auto_Member_Function_Wrapper.hpp +685 -0
  82. data/rice/detail/Auto_Member_Function_Wrapper.ipp +1435 -0
  83. data/rice/detail/Caster.hpp +61 -0
  84. data/rice/detail/Exception_Handler.hpp +118 -0
  85. data/rice/detail/Iterator_Definer.hpp +98 -0
  86. data/rice/detail/Not_Copyable.hpp +25 -0
  87. data/rice/detail/Wrapped_Function.hpp +33 -0
  88. data/rice/detail/check_ruby_type.cpp +21 -0
  89. data/rice/detail/check_ruby_type.hpp +23 -0
  90. data/rice/detail/creation_funcs.hpp +45 -0
  91. data/rice/detail/creation_funcs.ipp +62 -0
  92. data/rice/detail/default_allocation_func.hpp +23 -0
  93. data/rice/detail/default_allocation_func.ipp +11 -0
  94. data/rice/detail/define_method_and_auto_wrap.hpp +27 -0
  95. data/rice/detail/define_method_and_auto_wrap.ipp +20 -0
  96. data/rice/detail/env.hpp +13 -0
  97. data/rice/detail/from_ruby.hpp +43 -0
  98. data/rice/detail/from_ruby.ipp +74 -0
  99. data/rice/detail/method_data.cpp +105 -0
  100. data/rice/detail/method_data.hpp +33 -0
  101. data/rice/detail/node.hpp +13 -0
  102. data/rice/detail/object_call.hpp +85 -0
  103. data/rice/detail/object_call.ipp +147 -0
  104. data/rice/detail/protect.cpp +27 -0
  105. data/rice/detail/protect.hpp +34 -0
  106. data/rice/detail/remove_const.hpp +21 -0
  107. data/rice/detail/ruby.hpp +85 -0
  108. data/rice/detail/rubysig.hpp +13 -0
  109. data/rice/detail/st.hpp +56 -0
  110. data/rice/detail/to_ruby.hpp +16 -0
  111. data/rice/detail/to_ruby.ipp +10 -0
  112. data/rice/detail/win32.hpp +16 -0
  113. data/rice/detail/wrap_function.hpp +288 -0
  114. data/rice/detail/wrap_function.ipp +473 -0
  115. data/rice/generate_code.rb +1092 -0
  116. data/rice/global_function.hpp +16 -0
  117. data/rice/global_function.ipp +11 -0
  118. data/rice/protect.hpp +91 -0
  119. data/rice/protect.ipp +803 -0
  120. data/rice/ruby_try_catch.hpp +86 -0
  121. data/rice/to_from_ruby.hpp +8 -0
  122. data/rice/to_from_ruby.ipp +299 -0
  123. data/rice/to_from_ruby_defn.hpp +71 -0
  124. data/ruby.ac +105 -0
  125. data/ruby/Makefile.am +1 -0
  126. data/ruby/Makefile.in +493 -0
  127. data/ruby/lib/Makefile.am +3 -0
  128. data/ruby/lib/Makefile.in +369 -0
  129. data/ruby/lib/mkmf-rice.rb.in +199 -0
  130. data/sample/Makefile.am +47 -0
  131. data/sample/Makefile.in +375 -0
  132. data/sample/enum/extconf.rb +3 -0
  133. data/sample/enum/sample_enum.cpp +54 -0
  134. data/sample/enum/test.rb +8 -0
  135. data/sample/inheritance/animals.cpp +98 -0
  136. data/sample/inheritance/extconf.rb +3 -0
  137. data/sample/inheritance/test.rb +7 -0
  138. data/sample/map/extconf.rb +3 -0
  139. data/sample/map/map.cpp +81 -0
  140. data/sample/map/test.rb +7 -0
  141. data/test/Makefile.am +44 -0
  142. data/test/Makefile.in +575 -0
  143. data/test/test_Address_Registration_Guard.cpp +43 -0
  144. data/test/test_Allocation_Strategies.cpp +77 -0
  145. data/test/test_Array.cpp +241 -0
  146. data/test/test_Builtin_Object.cpp +72 -0
  147. data/test/test_Class.cpp +350 -0
  148. data/test/test_Constructor.cpp +30 -0
  149. data/test/test_Critical_Guard.cpp +47 -0
  150. data/test/test_Data_Object.cpp +235 -0
  151. data/test/test_Enum.cpp +162 -0
  152. data/test/test_Exception.cpp +46 -0
  153. data/test/test_Hash.cpp +195 -0
  154. data/test/test_Identifier.cpp +70 -0
  155. data/test/test_Jump_Tag.cpp +17 -0
  156. data/test/test_Module.cpp +253 -0
  157. data/test/test_Object.cpp +148 -0
  158. data/test/test_String.cpp +94 -0
  159. data/test/test_Struct.cpp +192 -0
  160. data/test/test_Symbol.cpp +63 -0
  161. data/test/test_To_From_Ruby.cpp +281 -0
  162. data/test/test_VM.cpp +26 -0
  163. data/test/test_rice.rb +30 -0
  164. data/test/unittest.cpp +136 -0
  165. data/test/unittest.hpp +292 -0
  166. metadata +209 -0
data/rice/Object.cpp ADDED
@@ -0,0 +1,153 @@
1
+ #include "Object.hpp"
2
+ #include "Class.hpp"
3
+ #include "String.hpp"
4
+ #include "Array.hpp"
5
+
6
+ #include <algorithm>
7
+ #include <iostream>
8
+
9
+ namespace Rice
10
+ {
11
+
12
+ Object const Nil(Qnil);
13
+ Object const True(Qtrue);
14
+ Object const False(Qfalse);
15
+ Object const Undef(Qundef);
16
+
17
+ }
18
+
19
+ Rice::Class Rice::Object::
20
+ class_of() const {
21
+ return rb_class_of(value_);
22
+ }
23
+
24
+ int Rice::Object::
25
+ compare(Object const & other) const
26
+ {
27
+ Object result = call("<=>", other);
28
+ return from_ruby<int>(result);
29
+ }
30
+
31
+ void Rice::Object::
32
+ freeze()
33
+ {
34
+ protect(rb_obj_freeze, value());
35
+ }
36
+
37
+ bool Rice::Object::
38
+ is_frozen() const
39
+ {
40
+ return bool(OBJ_FROZEN(value()));
41
+ }
42
+
43
+ Rice::String Rice::Object::
44
+ to_s() const {
45
+ return call("to_s");
46
+ }
47
+
48
+ Rice::String Rice::Object::
49
+ inspect() const {
50
+ return call("inspect");
51
+ }
52
+
53
+ void Rice::Object::
54
+ swap(Rice::Object & other)
55
+ {
56
+ std::swap(value_, other.value_);
57
+ }
58
+
59
+ Rice::Object Rice::Object::
60
+ instance_eval(String const & s)
61
+ {
62
+ VALUE argv[] = { s.value() };
63
+ return protect(rb_obj_instance_eval, 1, &argv[0], *this);
64
+ }
65
+
66
+ int Rice::Object::
67
+ rb_type() const
68
+ {
69
+ return ::rb_type(*this);
70
+ }
71
+
72
+ bool Rice::Object::
73
+ is_a(Object klass) const
74
+ {
75
+ Object result = protect(rb_obj_is_kind_of, *this, klass);
76
+ return result.test();
77
+ }
78
+
79
+ bool Rice::Object::
80
+ respond_to(Identifier id) const
81
+ {
82
+ return bool(rb_respond_to(*this, id));
83
+ }
84
+
85
+ bool Rice::Object::
86
+ is_instance_of(Object klass) const
87
+ {
88
+ Object result = protect(rb_obj_is_instance_of, *this, klass);
89
+ return result.test();
90
+ }
91
+
92
+ Rice::Object Rice::Object::
93
+ iv_get(
94
+ Identifier name) const
95
+ {
96
+ return protect(rb_iv_get, *this, name.c_str());
97
+ }
98
+
99
+ Rice::Object Rice::Object::
100
+ vcall(
101
+ Identifier id,
102
+ Array args)
103
+ {
104
+ return protect(rb_funcall3, *this, id, args.size(), args->ptr);
105
+ }
106
+
107
+ void Rice::Object::
108
+ mark() const
109
+ {
110
+ rb_gc_mark(*this);
111
+ }
112
+
113
+ void Rice::Object::
114
+ set_value(VALUE v)
115
+ {
116
+ value_ = v;
117
+ }
118
+
119
+ std::ostream & Rice::
120
+ operator<<(std::ostream & out, Rice::Object const & obj)
121
+ {
122
+ String s(obj.to_s());
123
+ out << s.c_str();
124
+ return out;
125
+ }
126
+
127
+ bool Rice::
128
+ operator==(Rice::Object const & lhs, Rice::Object const & rhs)
129
+ {
130
+ Object result = lhs.call("==", rhs);
131
+ return result.test();
132
+ }
133
+
134
+ bool Rice::
135
+ operator!=(Rice::Object const & lhs, Rice::Object const & rhs)
136
+ {
137
+ return !(lhs == rhs);
138
+ }
139
+
140
+ bool Rice::
141
+ operator<(Rice::Object const & lhs, Rice::Object const & rhs)
142
+ {
143
+ Object result = lhs.call("<", rhs);
144
+ return result.test();
145
+ }
146
+
147
+ bool Rice::
148
+ operator>(Rice::Object const & lhs, Rice::Object const & rhs)
149
+ {
150
+ Object result = lhs.call(">", rhs);
151
+ return result.test();
152
+ }
153
+
data/rice/Object.hpp ADDED
@@ -0,0 +1,8 @@
1
+ #ifndef Rice__Object__hpp_
2
+ #define Rice__Object__hpp_
3
+
4
+ #include "Object_defn.hpp"
5
+ #include "Object.ipp"
6
+
7
+ #endif // Rice__Object__hpp_
8
+
data/rice/Object.ipp ADDED
@@ -0,0 +1,19 @@
1
+ #ifndef Rice__Object__ipp_
2
+ #define Rice__Object__ipp_
3
+
4
+ #include "protect.hpp"
5
+ #include "detail/ruby.hpp"
6
+
7
+ #include "detail/object_call.ipp"
8
+
9
+ template<typename T>
10
+ void Rice::Object::
11
+ iv_set(
12
+ Identifier name,
13
+ T const & value)
14
+ {
15
+ protect(rb_iv_set, *this, name.c_str(), to_ruby(value));
16
+ }
17
+
18
+ #endif // Rice__Object__ipp_
19
+
@@ -0,0 +1,183 @@
1
+ #ifndef Rice__Object_defn__hpp_
2
+ #define Rice__Object_defn__hpp_
3
+
4
+ /*! \file Object.hpp
5
+ */
6
+
7
+ #include "Identifier.hpp"
8
+ #include "detail/ruby.hpp"
9
+
10
+ #include <iosfwd>
11
+
12
+ namespace Rice
13
+ {
14
+
15
+ class Class;
16
+ class String;
17
+ class Array;
18
+
19
+ //! The base class for all Objects
20
+ /*! Perhaps the name "Object" is a misnomer, because this class really
21
+ * holds an object reference, not an object.
22
+ */
23
+ class Object
24
+ {
25
+ public:
26
+ //! Encapsulate an existing ruby object.
27
+ Object(VALUE value = Qnil) : value_(value) { }
28
+
29
+ //! Copy constructor
30
+ Object(Object const & other) : value_(other.value()) { }
31
+
32
+ //! Destructor
33
+ virtual ~Object() { }
34
+
35
+ //! Returns false if the object is nil or false; returns true
36
+ //! otherwise.
37
+ // Having this conversion also prevents accidental conversion to
38
+ // undesired integral types (e.g. long or int) by making the
39
+ // conversion ambiguous.
40
+ bool test() const { return RTEST(value_); }
41
+
42
+ //! Returns false if the object is nil or false; returns true
43
+ //! otherwise.
44
+ operator bool() const { return test(); }
45
+
46
+ //! Returns true if the object is nil, false otherwise.
47
+ bool is_nil() const { return NIL_P(value_); }
48
+
49
+ //! Implicit conversion to VALUE.
50
+ operator VALUE() const { return value_; }
51
+
52
+ //! Explicitly get the encapsulated VALUE.
53
+ // Returns a const ref so that Address_Registration_Guard can access
54
+ // the address where the VALUE is stored
55
+ VALUE const volatile & value() const { return value_; }
56
+
57
+ //! Get the class of an object.
58
+ /*! \return the object's Class.
59
+ */
60
+ Class class_of() const;
61
+
62
+ //! Compare this object to another object.
63
+ /*! Gets the result of self <=> other and returns the result. The
64
+ * result will be less than zero if self < other, greater than zero
65
+ * if self > other, and equal to zero if self == other.
66
+ */
67
+ int compare(Object const & other) const;
68
+
69
+ //! Return a string representation of an object.
70
+ /*! \return the result of calling to_s on the object. A String is not
71
+ * returned, because it is not possible to return an instance of a
72
+ * derived class.
73
+ */
74
+ String to_s() const;
75
+
76
+ //! Inspect the object.
77
+ /*! \return the result of calling inspect on the object. A String is
78
+ * not returned, because it is not possible to return an instance of
79
+ * a derived class.
80
+ */
81
+ String inspect() const;
82
+
83
+ //! Freeze the object.
84
+ void freeze();
85
+
86
+ //! Determine if the object is frozen.
87
+ /*! \return true if the object is frozen, false otherwise.
88
+ */
89
+ bool is_frozen() const;
90
+
91
+ //! Swap with another Object.
92
+ void swap(Object & other);
93
+
94
+ //! Evaluate the given string in the context of the object.
95
+ /*! This is equivalant to calling obj.instance_eval(s) from inside the
96
+ * interpreter.
97
+ * \return the result of the expression.
98
+ */
99
+ Object instance_eval(String const & s);
100
+
101
+ //! Return the type of the underlying C object.
102
+ /*! This is equivalent to calling rb_type(obj).
103
+ * \return the type of the underlying C object (e.g. T_DATA, T_ARRAY,
104
+ * etc.).
105
+ */
106
+ int rb_type() const;
107
+
108
+ //! Determine whether the object is an instance of a class/module.
109
+ /*! \param klass a class or module.
110
+ * \return true if the object is an instance of the given
111
+ * class/module or one of its descendants.
112
+ */
113
+ bool is_a(Object klass) const;
114
+
115
+ //! Determine if the objects responds to a method.
116
+ /*! \param id the name of the method
117
+ * \return true if the objects responds to the method, false
118
+ * otherwise.
119
+ */
120
+ bool respond_to(Identifier id) const;
121
+
122
+ //! Determine whether class is the object's class.
123
+ /*! \param klass a class.
124
+ * \return true if the object is an instance of the given class.
125
+ */
126
+ bool is_instance_of(Object klass) const;
127
+
128
+ //! Set an instance variable.
129
+ /*! \param name the name of the instance variable to set (including
130
+ * the leading @ sign)
131
+ * \param value the value of the variable, which will be converted to
132
+ * a Ruby type if necessary.
133
+ */
134
+ template<typename T>
135
+ void iv_set(
136
+ Identifier name,
137
+ T const & value);
138
+
139
+ //! Get the value of an instance variable.
140
+ /*! \param name the name of the instance variable to get
141
+ * \return the value of the instance variable
142
+ */
143
+ Object iv_get(
144
+ Identifier name) const;
145
+
146
+ #include "detail/object_call.hpp"
147
+
148
+ //! Vectorized call.
149
+ /*! Calls the method identified by id with the list of arguments
150
+ * identified by args.
151
+ * \param id the name of the method to call
152
+ * \param args the arguments to the method
153
+ * \return the return value of the method call
154
+ */
155
+ Object vcall(Identifier id, Array args);
156
+
157
+ //! Mark the object with the garbage collector.
158
+ void mark() const;
159
+
160
+ protected:
161
+ //! Set the encapsulated value.
162
+ void set_value(VALUE v);
163
+
164
+ private:
165
+ volatile VALUE value_;
166
+ };
167
+
168
+ std::ostream & operator<<(std::ostream & out, Object const & obj);
169
+
170
+ bool operator==(Object const & lhs, Object const & rhs);
171
+ bool operator!=(Object const & lhs, Object const & rhs);
172
+ bool operator<(Object const & lhs, Object const & rhs);
173
+ bool operator>(Object const & lhs, Object const & rhs);
174
+
175
+ extern Object const Nil;
176
+ extern Object const True;
177
+ extern Object const False;
178
+ extern Object const Undef;
179
+
180
+ } // namespace Rice
181
+
182
+ #endif // Rice__Object_defn__hpp_
183
+
@@ -0,0 +1,21 @@
1
+ #ifndef Rice__Require_Guard__hpp_
2
+ #define Rice__Require_Guard__hpp_
3
+
4
+ /*! \def RICE_REQUIRE_GUARD
5
+ * \brief Put this inside your Init_module function to keep it from
6
+ * being required more than once with the same name (if you use
7
+ * Rice, and your module is initialized more than once, an
8
+ * exception will be thrown).
9
+ */
10
+ #define RICE_REQUIRE_GUARD \
11
+ static bool Rice__module_initialized = false; \
12
+ if(Rice__module_initialized) \
13
+ { \
14
+ return; \
15
+ } \
16
+ /* TODO: If module initialization fails, it's not possible to */ \
17
+ /* retry */ \
18
+ Rice__module_initialized = true
19
+
20
+ #endif // Rice__Require_Guard__hpp_
21
+
data/rice/String.cpp ADDED
@@ -0,0 +1,93 @@
1
+ #include "String.hpp"
2
+ #include "protect.hpp"
3
+ #include "detail/ruby.hpp"
4
+
5
+ #ifdef HAVE_STDARG_PROTOTYPES
6
+ #include <stdarg.h>
7
+ #define va_init_list(a,b) va_start(a,b)
8
+ #else
9
+ #include <varargs.h>
10
+ #define va_init_list(a,b) va_start(a)
11
+ #endif
12
+
13
+ Rice::String::
14
+ String()
15
+ : Builtin_Object<RString, T_STRING>(protect(rb_str_new2, ""))
16
+ {
17
+ }
18
+
19
+ Rice::String::
20
+ String(VALUE v)
21
+ : Builtin_Object<RString, T_STRING>(v)
22
+ {
23
+ }
24
+
25
+ Rice::String::
26
+ String(Object v)
27
+ : Builtin_Object<RString, T_STRING>(v)
28
+ {
29
+ }
30
+
31
+ Rice::String::
32
+ String(char const * s)
33
+ : Builtin_Object<RString, T_STRING>(protect(rb_str_new2, s))
34
+ {
35
+ }
36
+
37
+ Rice::String::
38
+ String(std::string const & s)
39
+ : Builtin_Object<RString, T_STRING>(protect(rb_str_new, s.c_str(), s.length()))
40
+ {
41
+ }
42
+
43
+ Rice::String::
44
+ String(Identifier id)
45
+ : Builtin_Object<RString, T_STRING>(protect(rb_str_new2, id.c_str()))
46
+ {
47
+ }
48
+
49
+ Rice::String Rice::String::
50
+ format(char const * fmt, ...)
51
+ {
52
+ va_list args;
53
+ char buf[BUFSIZ];
54
+
55
+ va_init_list(args, fmt);
56
+ vsnprintf(buf, BUFSIZ, fmt, args);
57
+ buf[BUFSIZ - 1] = '\0';
58
+ va_end(args);
59
+
60
+ String s = String(buf);
61
+ return s;
62
+ }
63
+
64
+ size_t Rice::String::
65
+ length() const
66
+ {
67
+ return RSTRING_LEN(value());
68
+ }
69
+
70
+ char Rice::String::
71
+ operator[](ptrdiff_t index) const
72
+ {
73
+ return RSTRING_PTR(value())[index];
74
+ }
75
+
76
+ char const * Rice::String::
77
+ c_str() const
78
+ {
79
+ return RSTRING_PTR(value());
80
+ }
81
+
82
+ std::string Rice::String::
83
+ str() const
84
+ {
85
+ return RSTRING_PTR(value());
86
+ }
87
+
88
+ Rice::Identifier Rice::String::
89
+ intern() const
90
+ {
91
+ return rb_intern(c_str());
92
+ }
93
+