jameskilton-rice 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +23 -0
- data/Doxyfile +1253 -0
- data/Makefile.am +26 -0
- data/Makefile.in +749 -0
- data/README +879 -0
- data/README.mingw +8 -0
- data/Rakefile +72 -0
- data/aclocal.m4 +891 -0
- data/bootstrap +8 -0
- data/config.guess +1526 -0
- data/config.sub +1658 -0
- data/configure +7668 -0
- data/configure.ac +52 -0
- data/depcomp +589 -0
- data/doxygen.ac +314 -0
- data/doxygen.am +186 -0
- data/extconf.rb +22 -0
- data/install-sh +519 -0
- data/missing +367 -0
- data/post-autoconf.rb +22 -0
- data/post-automake.rb +28 -0
- data/rice/Address_Registration_Guard.hpp +7 -0
- data/rice/Address_Registration_Guard.ipp +34 -0
- data/rice/Address_Registration_Guard_defn.hpp +65 -0
- data/rice/Allocation_Strategies.hpp +37 -0
- data/rice/Arg.hpp +8 -0
- data/rice/Arg_impl.hpp +116 -0
- data/rice/Arg_operators.cpp +21 -0
- data/rice/Arg_operators.hpp +18 -0
- data/rice/Array.hpp +220 -0
- data/rice/Array.ipp +263 -0
- data/rice/Builtin_Object.hpp +8 -0
- data/rice/Builtin_Object.ipp +50 -0
- data/rice/Builtin_Object_defn.hpp +51 -0
- data/rice/Class.cpp +57 -0
- data/rice/Class.hpp +8 -0
- data/rice/Class.ipp +6 -0
- data/rice/Class_defn.hpp +83 -0
- data/rice/Constructor.hpp +339 -0
- data/rice/Critical_Guard.hpp +40 -0
- data/rice/Critical_Guard.ipp +26 -0
- data/rice/Data_Object.hpp +8 -0
- data/rice/Data_Object.ipp +133 -0
- data/rice/Data_Object_defn.hpp +132 -0
- data/rice/Data_Type.cpp +21 -0
- data/rice/Data_Type.hpp +8 -0
- data/rice/Data_Type.ipp +306 -0
- data/rice/Data_Type_defn.hpp +219 -0
- data/rice/Data_Type_fwd.hpp +12 -0
- data/rice/Director.cpp +19 -0
- data/rice/Director.hpp +47 -0
- data/rice/Enum.hpp +118 -0
- data/rice/Enum.ipp +246 -0
- data/rice/Exception.cpp +59 -0
- data/rice/Exception.hpp +9 -0
- data/rice/Exception_Base.hpp +8 -0
- data/rice/Exception_Base.ipp +13 -0
- data/rice/Exception_Base_defn.hpp +27 -0
- data/rice/Exception_defn.hpp +69 -0
- data/rice/Hash.hpp +210 -0
- data/rice/Hash.ipp +338 -0
- data/rice/Identifier.cpp +8 -0
- data/rice/Identifier.hpp +50 -0
- data/rice/Identifier.ipp +33 -0
- data/rice/Jump_Tag.hpp +24 -0
- data/rice/Makefile.am +140 -0
- data/rice/Makefile.in +740 -0
- data/rice/Module.cpp +84 -0
- data/rice/Module.hpp +8 -0
- data/rice/Module.ipp +6 -0
- data/rice/Module_defn.hpp +88 -0
- data/rice/Module_impl.hpp +281 -0
- data/rice/Module_impl.ipp +348 -0
- data/rice/Object.cpp +153 -0
- data/rice/Object.hpp +8 -0
- data/rice/Object.ipp +19 -0
- data/rice/Object_defn.hpp +183 -0
- data/rice/Require_Guard.hpp +21 -0
- data/rice/String.cpp +94 -0
- data/rice/String.hpp +89 -0
- data/rice/Struct.cpp +117 -0
- data/rice/Struct.hpp +162 -0
- data/rice/Struct.ipp +26 -0
- data/rice/Symbol.cpp +25 -0
- data/rice/Symbol.hpp +66 -0
- data/rice/Symbol.ipp +44 -0
- data/rice/VM.cpp +92 -0
- data/rice/VM.hpp +32 -0
- data/rice/config.hpp +44 -0
- data/rice/config.hpp.in +43 -0
- data/rice/detail/Arguments.hpp +126 -0
- data/rice/detail/Auto_Function_Wrapper.hpp +861 -0
- data/rice/detail/Auto_Function_Wrapper.ipp +2929 -0
- data/rice/detail/Auto_Member_Function_Wrapper.hpp +828 -0
- data/rice/detail/Auto_Member_Function_Wrapper.ipp +2326 -0
- data/rice/detail/Caster.hpp +63 -0
- data/rice/detail/Exception_Handler.hpp +8 -0
- data/rice/detail/Exception_Handler.ipp +68 -0
- data/rice/detail/Exception_Handler_defn.hpp +96 -0
- data/rice/detail/Iterator.hpp +93 -0
- data/rice/detail/Not_Copyable.hpp +25 -0
- data/rice/detail/Wrapped_Function.hpp +33 -0
- data/rice/detail/check_ruby_type.cpp +27 -0
- data/rice/detail/check_ruby_type.hpp +23 -0
- data/rice/detail/creation_funcs.hpp +37 -0
- data/rice/detail/creation_funcs.ipp +36 -0
- data/rice/detail/default_allocation_func.hpp +23 -0
- data/rice/detail/default_allocation_func.ipp +11 -0
- data/rice/detail/define_method_and_auto_wrap.hpp +31 -0
- data/rice/detail/define_method_and_auto_wrap.ipp +30 -0
- data/rice/detail/demangle.cpp +56 -0
- data/rice/detail/demangle.hpp +19 -0
- data/rice/detail/env.hpp +19 -0
- data/rice/detail/from_ruby.hpp +43 -0
- data/rice/detail/from_ruby.ipp +60 -0
- data/rice/detail/method_data.cpp +392 -0
- data/rice/detail/method_data.cpp.rpp +301 -0
- data/rice/detail/method_data.hpp +21 -0
- data/rice/detail/mininode.cpp +1220 -0
- data/rice/detail/mininode.cpp.rpp +62 -0
- data/rice/detail/mininode.hpp +320 -0
- data/rice/detail/mininode.hpp.rpp +119 -0
- data/rice/detail/node.hpp +13 -0
- data/rice/detail/object_call.hpp +85 -0
- data/rice/detail/object_call.ipp +147 -0
- data/rice/detail/protect.cpp +29 -0
- data/rice/detail/protect.hpp +34 -0
- data/rice/detail/remove_const.hpp +21 -0
- data/rice/detail/ruby.hpp +89 -0
- data/rice/detail/ruby_version_code.hpp +6 -0
- data/rice/detail/ruby_version_code.hpp.in +6 -0
- data/rice/detail/rubysig.hpp +19 -0
- data/rice/detail/st.hpp +60 -0
- data/rice/detail/to_ruby.hpp +22 -0
- data/rice/detail/to_ruby.ipp +37 -0
- data/rice/detail/win32.hpp +16 -0
- data/rice/detail/wrap_function.hpp +345 -0
- data/rice/detail/wrap_function.ipp +531 -0
- data/rice/generate_code.rb +1311 -0
- data/rice/global_function.hpp +33 -0
- data/rice/global_function.ipp +22 -0
- data/rice/protect.hpp +91 -0
- data/rice/protect.ipp +803 -0
- data/rice/ruby_mark.hpp +13 -0
- data/rice/ruby_try_catch.hpp +86 -0
- data/rice/rubypp.rb +97 -0
- data/rice/to_from_ruby.hpp +8 -0
- data/rice/to_from_ruby.ipp +299 -0
- data/rice/to_from_ruby_defn.hpp +71 -0
- data/ruby.ac +150 -0
- data/ruby/Makefile.am +1 -0
- data/ruby/Makefile.in +497 -0
- data/ruby/lib/Makefile.am +3 -0
- data/ruby/lib/Makefile.in +374 -0
- data/ruby/lib/mkmf-rice.rb.in +209 -0
- data/ruby/lib/version.rb +3 -0
- data/sample/Makefile.am +47 -0
- data/sample/Makefile.in +380 -0
- data/sample/enum/extconf.rb +3 -0
- data/sample/enum/sample_enum.cpp +54 -0
- data/sample/enum/test.rb +8 -0
- data/sample/inheritance/animals.cpp +98 -0
- data/sample/inheritance/extconf.rb +3 -0
- data/sample/inheritance/test.rb +7 -0
- data/sample/map/extconf.rb +3 -0
- data/sample/map/map.cpp +81 -0
- data/sample/map/test.rb +7 -0
- data/test/Makefile.am +49 -0
- data/test/Makefile.in +603 -0
- data/test/test_Address_Registration_Guard.cpp +43 -0
- data/test/test_Allocation_Strategies.cpp +77 -0
- data/test/test_Array.cpp +241 -0
- data/test/test_Builtin_Object.cpp +72 -0
- data/test/test_Class.cpp +398 -0
- data/test/test_Constructor.cpp +238 -0
- data/test/test_Critical_Guard.cpp +51 -0
- data/test/test_Data_Object.cpp +275 -0
- data/test/test_Data_Type.cpp +121 -0
- data/test/test_Director.cpp +225 -0
- data/test/test_Enum.cpp +162 -0
- data/test/test_Exception.cpp +46 -0
- data/test/test_Hash.cpp +195 -0
- data/test/test_Identifier.cpp +70 -0
- data/test/test_Jump_Tag.cpp +17 -0
- data/test/test_Module.cpp +428 -0
- data/test/test_Object.cpp +148 -0
- data/test/test_String.cpp +94 -0
- data/test/test_Struct.cpp +192 -0
- data/test/test_Symbol.cpp +63 -0
- data/test/test_To_From_Ruby.cpp +263 -0
- data/test/test_VM.cpp +26 -0
- data/test/test_global_functions.cpp +97 -0
- data/test/test_rice.rb +35 -0
- data/test/unittest.cpp +136 -0
- data/test/unittest.hpp +292 -0
- metadata +247 -0
data/rice/Struct.hpp
ADDED
@@ -0,0 +1,162 @@
|
|
1
|
+
#ifndef Rice__ruby_struct__hpp_
|
2
|
+
#define Ruplu__ruby_struct__hpp_
|
3
|
+
|
4
|
+
#include "Array.hpp"
|
5
|
+
#include "Hash.hpp"
|
6
|
+
#include "Module.hpp"
|
7
|
+
#include "Class.hpp"
|
8
|
+
#include "Builtin_Object.hpp"
|
9
|
+
#include "Address_Registration_Guard.hpp"
|
10
|
+
|
11
|
+
namespace Rice
|
12
|
+
{
|
13
|
+
class Struct;
|
14
|
+
|
15
|
+
//! Define a new Struct
|
16
|
+
Struct define_struct();
|
17
|
+
|
18
|
+
//! A wrapper for creating Struct classes.
|
19
|
+
/*! The Struct class is used for creating new Classes. Note that the
|
20
|
+
* notation used here differs slightly from the notation inside the
|
21
|
+
* interpreter.
|
22
|
+
*
|
23
|
+
* Inside the interpreter, calling Struct.new creates a new Class:
|
24
|
+
* \code
|
25
|
+
* irb(main):001:0> MyStruct = Struct.new(:a, :b, :c)
|
26
|
+
* => S
|
27
|
+
* irb(main):002:0> MyStruct.class
|
28
|
+
* => Class
|
29
|
+
* \endcode
|
30
|
+
*
|
31
|
+
* Instantiating that Class creates an instance of that Class:
|
32
|
+
* \code
|
33
|
+
* irb(main):003:0> mystruct_instance = MyStruct.new
|
34
|
+
* => #<struct MyStruct a=nil, b=nil, c=nil>
|
35
|
+
* irb(main):004:0> mystruct_instance.class
|
36
|
+
* => MyStruct
|
37
|
+
* irb(main):005:0> mystruct_instance.class.ancestors
|
38
|
+
* => [MyStruct, Struct, Enumerable, Object, Kernel]
|
39
|
+
* \endcode
|
40
|
+
*
|
41
|
+
* Thus, inside the interpreter, MyStruct is a Class which inherits
|
42
|
+
* from Struct, and mystruct_instance is an instance of MyStruct.
|
43
|
+
*
|
44
|
+
* At the C++ level, we might do this instead:
|
45
|
+
* \code
|
46
|
+
* Struct rb_cMyStruct = define_struct()
|
47
|
+
* .define_member("a")
|
48
|
+
* .define_member("b")
|
49
|
+
* .define_member("c")
|
50
|
+
* .initialize("MyStruct");
|
51
|
+
* Struct::Instance mystruct_instance(rb_cMyStruct.new_instance());
|
52
|
+
* \endcode
|
53
|
+
*
|
54
|
+
* Here rb_cMyStruct is an instance of Struct and that mystruct_instance
|
55
|
+
* is an instance of Struct::Instance.
|
56
|
+
*/
|
57
|
+
class Struct
|
58
|
+
: public Module_impl<Class, Struct>
|
59
|
+
{
|
60
|
+
public:
|
61
|
+
//! Create a new Struct.
|
62
|
+
Struct();
|
63
|
+
|
64
|
+
//! Copy constructor.
|
65
|
+
Struct(Struct const & s);
|
66
|
+
|
67
|
+
//! Destructor.
|
68
|
+
virtual ~Struct();
|
69
|
+
|
70
|
+
//! Define a new Struct member.
|
71
|
+
/*! Defines a new member of the Struct. Must be called before the
|
72
|
+
* Struct is initialized.
|
73
|
+
* \return *this
|
74
|
+
*/
|
75
|
+
Struct & define_member(
|
76
|
+
Identifier name);
|
77
|
+
|
78
|
+
//! Initialize the Struct class.
|
79
|
+
/*! Must be called after all Struct members have been defined.
|
80
|
+
* \param module the module under which to define the Struct.
|
81
|
+
* \param name the name of the Class at the ruby level.
|
82
|
+
*/
|
83
|
+
Struct & initialize(
|
84
|
+
Module module,
|
85
|
+
Identifier name);
|
86
|
+
|
87
|
+
//! Get the offset of a member in the Struct.
|
88
|
+
/*! Internally, Struct members are stored as a single array of VALUE.
|
89
|
+
* This function determines the offset of a given member in that
|
90
|
+
* array.
|
91
|
+
* \param member the name of the desired member.
|
92
|
+
* \return the index of the given member.
|
93
|
+
*/
|
94
|
+
size_t offset_of(Identifier name) const;
|
95
|
+
|
96
|
+
class Instance;
|
97
|
+
friend class Instance;
|
98
|
+
friend Struct Rice::define_struct();
|
99
|
+
|
100
|
+
//! Create a new instance of the Struct
|
101
|
+
/*! \param args the arguments to the constructor.
|
102
|
+
* \return a new Struct::Instance
|
103
|
+
*/
|
104
|
+
Instance new_instance(Array args = Array()) const;
|
105
|
+
|
106
|
+
//! Swap with another Struct.
|
107
|
+
void swap(Struct & other);
|
108
|
+
|
109
|
+
Array members() const { return members_; }
|
110
|
+
|
111
|
+
private:
|
112
|
+
Array members_;
|
113
|
+
Address_Registration_Guard members_guard_;
|
114
|
+
|
115
|
+
Hash member_offset_;
|
116
|
+
Address_Registration_Guard member_offset_guard_;
|
117
|
+
};
|
118
|
+
|
119
|
+
|
120
|
+
//! An instance of a Struct
|
121
|
+
//! \sa Struct
|
122
|
+
class Struct::Instance
|
123
|
+
: public Builtin_Object<RStruct, T_STRUCT>
|
124
|
+
{
|
125
|
+
public:
|
126
|
+
//! Create a new Instance of a Struct.
|
127
|
+
/*! \param type the Struct type to create.
|
128
|
+
* \param args the initial values for the objects of the instance.
|
129
|
+
*/
|
130
|
+
Instance(
|
131
|
+
Struct const & type,
|
132
|
+
Array args = Array());
|
133
|
+
|
134
|
+
//! Encapsulate an existing Struct instance.
|
135
|
+
/*! \param type the Struct type to encapsulate.
|
136
|
+
* \param s the instance to encapsulate.
|
137
|
+
*/
|
138
|
+
Instance(
|
139
|
+
Struct const & type,
|
140
|
+
Object s);
|
141
|
+
|
142
|
+
//! Get a member, given its offset.
|
143
|
+
/*! \param index the (integral) index into the Struct's internal
|
144
|
+
* array or its name (an Identifier or char const *)
|
145
|
+
* \return the member.
|
146
|
+
*/
|
147
|
+
template<typename T>
|
148
|
+
Object operator[](T index);
|
149
|
+
|
150
|
+
//! Swap with another Struct::Instance.
|
151
|
+
void swap(Instance & other);
|
152
|
+
|
153
|
+
private:
|
154
|
+
Struct type_;
|
155
|
+
};
|
156
|
+
|
157
|
+
} // namespace Rice
|
158
|
+
|
159
|
+
#include "Struct.ipp"
|
160
|
+
|
161
|
+
#endif // Rice__ruby_struct__hpp_
|
162
|
+
|
data/rice/Struct.ipp
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
namespace Rice
|
2
|
+
{
|
3
|
+
|
4
|
+
template<typename T>
|
5
|
+
inline Object Struct::Instance::
|
6
|
+
operator[](T index)
|
7
|
+
{
|
8
|
+
return rb_struct_aref(value(), ULONG2NUM(index));
|
9
|
+
}
|
10
|
+
|
11
|
+
template<>
|
12
|
+
inline Object Struct::Instance::
|
13
|
+
operator[]<Identifier>(Identifier member)
|
14
|
+
{
|
15
|
+
size_t index = type_.offset_of(member);
|
16
|
+
return (*this)[index];
|
17
|
+
}
|
18
|
+
|
19
|
+
template<>
|
20
|
+
inline Object Struct::Instance::
|
21
|
+
operator[]<char const *>(char const * name)
|
22
|
+
{
|
23
|
+
return (*this)[Identifier(name)];
|
24
|
+
}
|
25
|
+
|
26
|
+
} // Rice
|
data/rice/Symbol.cpp
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
#include "Symbol.hpp"
|
2
|
+
|
3
|
+
namespace
|
4
|
+
{
|
5
|
+
VALUE check_type(Rice::Object value, int type)
|
6
|
+
{
|
7
|
+
rb_check_type(value, type);
|
8
|
+
return Qnil;
|
9
|
+
}
|
10
|
+
}
|
11
|
+
|
12
|
+
Rice::Symbol::
|
13
|
+
Symbol(VALUE v)
|
14
|
+
: Object(v)
|
15
|
+
{
|
16
|
+
protect(check_type, v, T_SYMBOL);
|
17
|
+
}
|
18
|
+
|
19
|
+
Rice::Symbol::
|
20
|
+
Symbol(Object v)
|
21
|
+
: Object(v)
|
22
|
+
{
|
23
|
+
protect(check_type, v, T_SYMBOL);
|
24
|
+
}
|
25
|
+
|
data/rice/Symbol.hpp
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
#ifndef Rice__Symbol__hpp_
|
2
|
+
#define Rice__Symbol__hpp_
|
3
|
+
|
4
|
+
#include "Identifier.hpp"
|
5
|
+
#include "Object.hpp"
|
6
|
+
#include "detail/ruby.hpp"
|
7
|
+
#include <string>
|
8
|
+
|
9
|
+
namespace Rice
|
10
|
+
{
|
11
|
+
|
12
|
+
//! A wrapper for ruby's Symbol class.
|
13
|
+
/*! Symbols are internal identifiers in ruby. They are singletons and
|
14
|
+
* can be thought of as frozen strings. They differ from an Identifier
|
15
|
+
* in that they are in fact real Objects, but they can be converted
|
16
|
+
* back and forth between Identifier and Symbol.
|
17
|
+
*/
|
18
|
+
class Symbol
|
19
|
+
: public Object
|
20
|
+
{
|
21
|
+
public:
|
22
|
+
//! Wrap an existing symbol.
|
23
|
+
Symbol(VALUE v);
|
24
|
+
|
25
|
+
//! Wrap an existing symbol.
|
26
|
+
Symbol(Object v);
|
27
|
+
|
28
|
+
//! Construct a Symbol from an Identifier.
|
29
|
+
Symbol(Identifier id);
|
30
|
+
|
31
|
+
//! Construct a Symbol from a null-terminated C string.
|
32
|
+
Symbol(char const * s = "");
|
33
|
+
|
34
|
+
//! Construct a Symbol from an std::string.
|
35
|
+
Symbol(std::string const & s);
|
36
|
+
|
37
|
+
//! Return a string representation of the Symbol.
|
38
|
+
char const * c_str() const;
|
39
|
+
|
40
|
+
//! Return a string representation of the Symbol.
|
41
|
+
std::string str() const;
|
42
|
+
|
43
|
+
//! Return the Symbol as an Identifier.
|
44
|
+
Identifier to_id() const;
|
45
|
+
};
|
46
|
+
|
47
|
+
} // namespace Rice
|
48
|
+
|
49
|
+
template<>
|
50
|
+
inline
|
51
|
+
Rice::Symbol from_ruby<Rice::Symbol>(Rice::Object x)
|
52
|
+
{
|
53
|
+
return Rice::Symbol(x);
|
54
|
+
}
|
55
|
+
|
56
|
+
template<>
|
57
|
+
inline
|
58
|
+
Rice::Object to_ruby<Rice::Symbol>(Rice::Symbol const & x)
|
59
|
+
{
|
60
|
+
return x;
|
61
|
+
}
|
62
|
+
|
63
|
+
#include "Symbol.ipp"
|
64
|
+
|
65
|
+
#endif // Rice__Symbol__hpp_
|
66
|
+
|
data/rice/Symbol.ipp
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
#ifndef Rice__Symbol__ipp_
|
2
|
+
#define Rice__Symbol__ipp_
|
3
|
+
|
4
|
+
#include "protect.hpp"
|
5
|
+
#include "detail/ruby.hpp"
|
6
|
+
|
7
|
+
inline Rice::Symbol::
|
8
|
+
Symbol(char const * s)
|
9
|
+
: Object(ID2SYM(rb_intern(s)))
|
10
|
+
{
|
11
|
+
}
|
12
|
+
|
13
|
+
inline Rice::Symbol::
|
14
|
+
Symbol(std::string const & s)
|
15
|
+
: Object(ID2SYM(rb_intern(s.c_str())))
|
16
|
+
{
|
17
|
+
}
|
18
|
+
|
19
|
+
inline Rice::Symbol::
|
20
|
+
Symbol(Identifier id)
|
21
|
+
: Object(ID2SYM(id))
|
22
|
+
{
|
23
|
+
}
|
24
|
+
|
25
|
+
inline char const * Rice::Symbol::
|
26
|
+
c_str() const
|
27
|
+
{
|
28
|
+
return to_id().c_str();
|
29
|
+
}
|
30
|
+
|
31
|
+
inline std::string Rice::Symbol::
|
32
|
+
str() const
|
33
|
+
{
|
34
|
+
return to_id().str();
|
35
|
+
}
|
36
|
+
|
37
|
+
inline Rice::Identifier Rice::Symbol::
|
38
|
+
to_id() const
|
39
|
+
{
|
40
|
+
return rb_to_id(value());
|
41
|
+
}
|
42
|
+
|
43
|
+
#endif // Rice__Symbol__ipp_
|
44
|
+
|
data/rice/VM.cpp
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
#include "VM.hpp"
|
2
|
+
#include "detail/ruby.hpp"
|
3
|
+
#include "detail/env.hpp"
|
4
|
+
#include "detail/ruby_version_code.hpp"
|
5
|
+
|
6
|
+
#include <stdexcept>
|
7
|
+
|
8
|
+
Rice::VM::
|
9
|
+
VM(char * app_name)
|
10
|
+
{
|
11
|
+
init_stack();
|
12
|
+
init(1, &app_name);
|
13
|
+
}
|
14
|
+
|
15
|
+
Rice::VM::
|
16
|
+
VM(int argc, char * argv[])
|
17
|
+
{
|
18
|
+
init_stack();
|
19
|
+
init(argc, argv);
|
20
|
+
}
|
21
|
+
|
22
|
+
Rice::VM::
|
23
|
+
VM(std::vector<const char *> const & args)
|
24
|
+
{
|
25
|
+
check_not_initialized();
|
26
|
+
init_stack();
|
27
|
+
init(args.size(), const_cast<char * *>(&args[0]));
|
28
|
+
}
|
29
|
+
|
30
|
+
Rice::VM::
|
31
|
+
~VM()
|
32
|
+
{
|
33
|
+
init_stack();
|
34
|
+
}
|
35
|
+
|
36
|
+
#if RICE__RUBY_VERSION_CODE < 186
|
37
|
+
extern "C"
|
38
|
+
void Init_stack(VALUE *);
|
39
|
+
#endif
|
40
|
+
|
41
|
+
void Rice::VM::
|
42
|
+
init_stack()
|
43
|
+
{
|
44
|
+
#if RICE__RUBY_VERSION_CODE >= 186
|
45
|
+
RUBY_INIT_STACK;
|
46
|
+
#else
|
47
|
+
VALUE v;
|
48
|
+
Init_stack(&v);
|
49
|
+
#endif
|
50
|
+
}
|
51
|
+
|
52
|
+
void Rice::VM::
|
53
|
+
run()
|
54
|
+
{
|
55
|
+
#if RICE__RUBY_VERSION_CODE >= 190
|
56
|
+
ruby_run_node(node_);
|
57
|
+
#else
|
58
|
+
ruby_run();
|
59
|
+
#endif
|
60
|
+
}
|
61
|
+
|
62
|
+
extern "C"
|
63
|
+
{
|
64
|
+
|
65
|
+
#if RICE__RUBY_VERSION_CODE < 190
|
66
|
+
RUBY_EXTERN VALUE * rb_gc_stack_start;
|
67
|
+
#endif
|
68
|
+
|
69
|
+
}
|
70
|
+
|
71
|
+
void Rice::VM::
|
72
|
+
check_not_initialized() const
|
73
|
+
{
|
74
|
+
#if RICE__RUBY_VERSION_CODE < 190
|
75
|
+
if(rb_gc_stack_start)
|
76
|
+
{
|
77
|
+
throw std::runtime_error("Only one VM allowed per application");
|
78
|
+
}
|
79
|
+
#endif
|
80
|
+
// TODO: how to do this check on 1.9?
|
81
|
+
}
|
82
|
+
|
83
|
+
void Rice::VM::
|
84
|
+
init(int argc, char * argv[])
|
85
|
+
{
|
86
|
+
ruby_init();
|
87
|
+
#if RICE__RUBY_VERSION_CODE >= 190
|
88
|
+
node_ =
|
89
|
+
#endif
|
90
|
+
ruby_options(argc, argv);
|
91
|
+
}
|
92
|
+
|
data/rice/VM.hpp
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
#ifndef VM__hpp
|
2
|
+
#define VM__hpp
|
3
|
+
|
4
|
+
#include <vector>
|
5
|
+
#include "detail/ruby_version_code.hpp"
|
6
|
+
|
7
|
+
namespace Rice
|
8
|
+
{
|
9
|
+
|
10
|
+
class VM
|
11
|
+
{
|
12
|
+
public:
|
13
|
+
VM(char * app_name);
|
14
|
+
VM(int argc, char * argv[]);
|
15
|
+
VM(std::vector<const char *> const & args);
|
16
|
+
~VM();
|
17
|
+
|
18
|
+
void init_stack();
|
19
|
+
void run();
|
20
|
+
|
21
|
+
private:
|
22
|
+
void check_not_initialized() const;
|
23
|
+
void init(int argc, char * argv[]);
|
24
|
+
|
25
|
+
#if RICE__RUBY_VERSION_CODE >= 190
|
26
|
+
void * node_;
|
27
|
+
#endif
|
28
|
+
};
|
29
|
+
|
30
|
+
}
|
31
|
+
|
32
|
+
#endif // VM__hpp
|