rucy 0.1.3 → 0.1.4

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.
Files changed (50) hide show
  1. data/.doc/ext/rucy/class.cpp +244 -0
  2. data/.doc/ext/rucy/exception.cpp +99 -0
  3. data/.doc/ext/rucy/function.cpp +63 -0
  4. data/.doc/ext/rucy/struct.cpp +80 -0
  5. data/.doc/ext/rucy/tester.cpp +41 -184
  6. data/.doc/ext/rucy/value.cpp +42 -0
  7. data/.gitignore +22 -0
  8. data/Rakefile +4 -29
  9. data/VERSION +1 -1
  10. data/ext/rucy/class.cpp +262 -0
  11. data/ext/rucy/class.h +96 -0
  12. data/ext/rucy/exception.cpp +107 -0
  13. data/ext/rucy/extconf.rb +9 -8
  14. data/ext/rucy/function.cpp +68 -0
  15. data/ext/rucy/struct.cpp +83 -0
  16. data/ext/rucy/tester.cpp +41 -197
  17. data/ext/rucy/tester.h +10 -0
  18. data/ext/rucy/value.cpp +46 -0
  19. data/include/rucy/defs.h.erb +17 -0
  20. data/include/rucy/exception.h +2 -0
  21. data/include/rucy/extension.h +206 -0
  22. data/include/rucy/rucy.h +25 -2
  23. data/include/rucy/symbol.h +11 -0
  24. data/include/rucy/value.h.erb +66 -14
  25. data/include/rucy.h +1 -1
  26. data/lib/rucy/module.rb +9 -2
  27. data/rucy.gemspec +16 -40
  28. data/src/exception.cpp +17 -25
  29. data/src/rucy.cpp +2 -2
  30. data/src/symbol.cpp +24 -0
  31. data/src/value.cpp.erb +161 -25
  32. data/task/doc.rake +50 -0
  33. data/test/helpers.rb +7 -0
  34. data/test/test_class.rb +161 -0
  35. data/test/test_exception.rb +39 -0
  36. data/test/test_function.rb +31 -0
  37. data/test/test_struct.rb +30 -0
  38. data/test/test_value.rb +18 -0
  39. metadata +123 -74
  40. data/include/rucy/defs.h +0 -101
  41. data/include/rucy/function.h +0 -245
  42. data/include/rucy/gc.h +0 -59
  43. data/include/rucy/module.h +0 -98
  44. data/include/rucy/value.h +0 -291
  45. data/src/function.cpp +0 -158
  46. data/src/gc.cpp +0 -63
  47. data/src/module.cpp +0 -325
  48. data/src/value.cpp +0 -511
  49. data/task/ext.rake +0 -96
  50. data/test/test_rucy.rb +0 -73
@@ -1,98 +0,0 @@
1
- // -*- c++ -*-
2
- #pragma once
3
- #ifndef __RUCY_MODULE_H__
4
- #define __RUCY_MODULE_H__
5
-
6
-
7
- #include <ruby.h>
8
- #include <rucy/defs.h>
9
- #include <rucy/value.h>
10
-
11
-
12
- namespace Rucy
13
- {
14
-
15
-
16
- class Class;
17
-
18
-
19
- class Module : public Value
20
- {
21
-
22
- typedef Value Super;
23
-
24
- public:
25
-
26
- Module (VALUE v = Qnil);
27
-
28
- Module define_module (const char* name);
29
-
30
- Class define_class (const char* name, Value super = rb_cObject);
31
-
32
- Module define_const (const char* name, Value val);
33
-
34
- Module define_attr (const char* name, bool read = true, bool write = true);
35
-
36
- Module define_alias (const char* new_, const char* old);
37
-
38
- Module undef_method (const char* name);
39
-
40
- Module include_module (Value module);
41
-
42
- Module extend_module (Value module);
43
-
44
- Module define_function (const char* name, RubyFunctionN fun);
45
- Module define_function (const char* name, RubyFunction0 fun);
46
- Module define_function (const char* name, RubyFunction1 fun);
47
- Module define_function (const char* name, RubyFunction2 fun);
48
- Module define_function (const char* name, RubyFunction3 fun);
49
- Module define_function (const char* name, RubyFunction4 fun);
50
- Module define_function (const char* name, RubyFunction5 fun);
51
- Module define_function (const char* name, RubyFunction6 fun);
52
- Module define_function (const char* name, RubyFunction7 fun);
53
- Module define_function (const char* name, RubyFunction8 fun);
54
- Module define_method (const char* name, RubyFunctionN fun);
55
- Module define_method (const char* name, RubyFunction0 fun);
56
- Module define_method (const char* name, RubyFunction1 fun);
57
- Module define_method (const char* name, RubyFunction2 fun);
58
- Module define_method (const char* name, RubyFunction3 fun);
59
- Module define_method (const char* name, RubyFunction4 fun);
60
- Module define_method (const char* name, RubyFunction5 fun);
61
- Module define_method (const char* name, RubyFunction6 fun);
62
- Module define_method (const char* name, RubyFunction7 fun);
63
- Module define_method (const char* name, RubyFunction8 fun);
64
- Module define_private_method (const char* name, RubyFunctionN fun);
65
- Module define_private_method (const char* name, RubyFunction0 fun);
66
- Module define_private_method (const char* name, RubyFunction1 fun);
67
- Module define_private_method (const char* name, RubyFunction2 fun);
68
- Module define_private_method (const char* name, RubyFunction3 fun);
69
- Module define_private_method (const char* name, RubyFunction4 fun);
70
- Module define_private_method (const char* name, RubyFunction5 fun);
71
- Module define_private_method (const char* name, RubyFunction6 fun);
72
- Module define_private_method (const char* name, RubyFunction7 fun);
73
- Module define_private_method (const char* name, RubyFunction8 fun);
74
- Module define_singleton_method (const char* name, RubyFunctionN fun);
75
- Module define_singleton_method (const char* name, RubyFunction0 fun);
76
- Module define_singleton_method (const char* name, RubyFunction1 fun);
77
- Module define_singleton_method (const char* name, RubyFunction2 fun);
78
- Module define_singleton_method (const char* name, RubyFunction3 fun);
79
- Module define_singleton_method (const char* name, RubyFunction4 fun);
80
- Module define_singleton_method (const char* name, RubyFunction5 fun);
81
- Module define_singleton_method (const char* name, RubyFunction6 fun);
82
- Module define_singleton_method (const char* name, RubyFunction7 fun);
83
- Module define_singleton_method (const char* name, RubyFunction8 fun);
84
-
85
- };// Module
86
-
87
-
88
- Module define_module (const char* name);
89
-
90
- Class define_class (const char* name, Value super = rb_cObject);
91
-
92
- void define_const (const char* name, Value val);
93
-
94
-
95
- }// Rucy
96
-
97
-
98
- #endif//EOH
data/include/rucy/value.h DELETED
@@ -1,291 +0,0 @@
1
- // -*- c++ -*-
2
- #pragma once
3
- #ifndef __RUCY_VALUE_H__
4
- #define __RUCY_VALUE_H__
5
-
6
-
7
- #include <ruby.h>
8
- #include <rucy/symbol.h>
9
-
10
-
11
- namespace Rucy
12
- {
13
-
14
-
15
- class Value
16
- {
17
-
18
- public:
19
-
20
- Value ();
21
-
22
- Value (bool b);
23
-
24
- Value (int i);
25
-
26
- Value (float f);
27
-
28
- Value (double d);
29
-
30
- Value (const char* s, bool tainted = false);
31
-
32
- Value (const char* s, size_t len, bool tainted = false);
33
-
34
- Value (size_t size, const Value* values);
35
-
36
- Value (VALUE v);
37
-
38
- VALUE value () const;
39
-
40
- void mark () const;
41
-
42
- int type () const;
43
-
44
- Value klass () const;
45
-
46
- bool is_kind_of (Value klass) const;
47
-
48
- int size () const;
49
-
50
- int length () const;
51
-
52
- Value to_i () const;
53
-
54
- Value to_f () const;
55
-
56
- Value to_s () const;
57
-
58
- Value to_sym () const;
59
-
60
- bool is_i () const;
61
-
62
- bool is_f () const;
63
-
64
- bool is_s () const;
65
-
66
- bool is_sym () const;
67
-
68
- bool is_a () const;
69
-
70
- int as_i (bool convert = false) const;
71
-
72
- double as_f (bool convert = false) const;
73
-
74
- const char* as_s (bool convert = false) const;
75
-
76
- Symbol as_sym (bool convert = false) const;
77
-
78
- Value call (Symbol name, int argc, const Value* argv) const;
79
- Value call (Symbol name) const;
80
- Value call (Symbol name, Value v1) const;
81
- Value call (Symbol name, Value v1, Value v2) const;
82
- Value call (Symbol name, Value v1, Value v2, Value v3) const;
83
- Value call (Symbol name, Value v1, Value v2, Value v3, Value v4) const;
84
- Value call (Symbol name, Value v1, Value v2, Value v3, Value v4, Value v5) const;
85
- Value call (Symbol name, Value v1, Value v2, Value v3, Value v4, Value v5, Value v6) const;
86
- Value call (Symbol name, Value v1, Value v2, Value v3, Value v4, Value v5, Value v6, Value v7) const;
87
- Value call (Symbol name, Value v1, Value v2, Value v3, Value v4, Value v5, Value v6, Value v7, Value v8) const;
88
- Value operator () (Symbol name, int argc, const Value* argv) const;
89
- Value operator () (Symbol name) const;
90
- Value operator () (Symbol name, Value v1) const;
91
- Value operator () (Symbol name, Value v1, Value v2) const;
92
- Value operator () (Symbol name, Value v1, Value v2, Value v3) const;
93
- Value operator () (Symbol name, Value v1, Value v2, Value v3, Value v4) const;
94
- Value operator () (Symbol name, Value v1, Value v2, Value v3, Value v4, Value v5) const;
95
- Value operator () (Symbol name, Value v1, Value v2, Value v3, Value v4, Value v5, Value v6) const;
96
- Value operator () (Symbol name, Value v1, Value v2, Value v3, Value v4, Value v5, Value v6, Value v7) const;
97
- Value operator () (Symbol name, Value v1, Value v2, Value v3, Value v4, Value v5, Value v6, Value v7, Value v8) const;
98
-
99
- Value inspect () const;
100
-
101
- const char* c_str () const;
102
-
103
- Value& operator [] (int i);
104
-
105
- const Value& operator [] (int i) const;
106
-
107
- operator VALUE () const;
108
-
109
- operator bool () const;
110
-
111
- bool operator ! () const;
112
-
113
- bool operator == (const Value& rhs) const;
114
-
115
- bool operator != (const Value& rhs) const;
116
-
117
- // Array
118
-
119
- Value push (Value obj);
120
-
121
- Value pop ();
122
-
123
- Value shift ();
124
-
125
- Value unshift (Value obj);
126
-
127
- private:
128
-
129
- VALUE v;
130
-
131
- friend class GCGuard;
132
-
133
- };// Value
134
-
135
-
136
- Value value (bool b);
137
-
138
- Value value (char c);
139
-
140
- Value value (unsigned char c);
141
-
142
- Value value (short s);
143
-
144
- Value value (unsigned short s);
145
-
146
- Value value (int i);
147
-
148
- Value value (unsigned int i);
149
-
150
- Value value (long l);
151
-
152
- Value value (unsigned long l);
153
-
154
- Value value (long long ll);
155
-
156
- Value value (unsigned long long ll);
157
-
158
- Value value (float f);
159
-
160
- Value value (double d);
161
-
162
- Value value (const char* s, bool tainted = false);
163
-
164
- Value value (const char* s, size_t len, bool tainted = false);
165
-
166
- Value value (size_t size, const Value* values);
167
-
168
- Value value (Symbol sym);
169
-
170
-
171
- template <typename T> T value_to (Value obj, bool convert = true);
172
-
173
- template <> inline bool
174
- value_to<bool> (Value obj, bool convert)
175
- {
176
- return (bool) obj;
177
- }
178
-
179
- template <> inline int
180
- value_to<int> (Value obj, bool convert)
181
- {
182
- if (convert) obj = obj.to_i();
183
- return NUM2INT(obj.value());
184
- }
185
-
186
- template <> inline unsigned int
187
- value_to<unsigned int> (Value obj, bool convert)
188
- {
189
- if (convert) obj = obj.to_i();
190
- return NUM2UINT(obj.value());
191
- }
192
-
193
- template <> inline char
194
- value_to<char> (Value obj, bool convert)
195
- {
196
- return (char) value_to<int>(obj, convert);
197
- }
198
-
199
- template <> inline unsigned char
200
- value_to<unsigned char> (Value obj, bool convert)
201
- {
202
- return (unsigned char) value_to<int>(obj, convert);
203
- }
204
-
205
- template <> inline short
206
- value_to<short> (Value obj, bool convert)
207
- {
208
- return (short) value_to<int>(obj, convert);
209
- }
210
-
211
- template <> inline unsigned short
212
- value_to<unsigned short> (Value obj, bool convert)
213
- {
214
- return (unsigned short) value_to<int>(obj, convert);
215
- }
216
-
217
- template <> inline long
218
- value_to<long> (Value obj, bool convert)
219
- {
220
- if (convert) obj = obj.to_i();
221
- return NUM2LONG(obj.value());
222
- }
223
-
224
- template <> inline unsigned long
225
- value_to<unsigned long> (Value obj, bool convert)
226
- {
227
- if (convert) obj = obj.to_i();
228
- return NUM2ULONG(obj.value());
229
- }
230
-
231
- template <> inline long long
232
- value_to<long long> (Value obj, bool convert)
233
- {
234
- if (convert) obj = obj.to_i();
235
- return NUM2LL(obj.value());
236
- }
237
-
238
- template <> inline unsigned long long
239
- value_to<unsigned long long> (Value obj, bool convert)
240
- {
241
- if (convert) obj = obj.to_i();
242
- return NUM2ULL(obj.value());
243
- }
244
-
245
- template <> inline double
246
- value_to<double> (Value obj, bool convert)
247
- {
248
- if (convert) obj = obj.to_f();
249
- Check_Type(obj, T_FLOAT);
250
- return RFLOAT_VALUE(obj.value());
251
- }
252
-
253
- template <> inline float
254
- value_to<float> (Value obj, bool convert)
255
- {
256
- return (float) value_to<double>(obj, convert);
257
- }
258
-
259
- template <> inline char*
260
- value_to<char*> (Value obj, bool convert)
261
- {
262
- if (convert) obj = obj.to_s();
263
- VALUE s = obj.value();
264
- return StringValueCStr(s);
265
- }
266
-
267
- template <> inline const char*
268
- value_to<const char*> (Value obj, bool convert)
269
- {
270
- return value_to<char*>(obj, convert);
271
- }
272
-
273
- template <> inline Symbol
274
- value_to<Symbol> (Value obj, bool convert)
275
- {
276
- if (convert) obj = obj.to_sym();
277
- Check_Type(obj, T_SYMBOL);
278
- return SYM2ID(obj.value());
279
- }
280
-
281
-
282
- template <typename T> inline T to (Value obj, bool convert = true)
283
- {
284
- return value_to<T>(obj, convert);
285
- }
286
-
287
-
288
- }// Rucy
289
-
290
-
291
- #endif//EOH
data/src/function.cpp DELETED
@@ -1,158 +0,0 @@
1
- // -*- c++ -*-
2
- #include "rucy/function.h"
3
-
4
-
5
- #include <rucy/exception.h>
6
-
7
-
8
- #ifndef TAG_RAISE
9
- #define TAG_RAISE 0x6
10
- #endif
11
-
12
-
13
- namespace Rucy
14
- {
15
-
16
-
17
- void
18
- define_function (const char* name, RubyFunctionN fun)
19
- {
20
- rb_define_global_function(name, RUBY_METHOD_FUNC(fun), -1);
21
- }
22
- void
23
- define_function (const char* name, RubyFunction0 fun)
24
- {
25
- rb_define_global_function(name, RUBY_METHOD_FUNC(fun), 0);
26
- }
27
- void
28
- define_function (const char* name, RubyFunction1 fun)
29
- {
30
- rb_define_global_function(name, RUBY_METHOD_FUNC(fun), 1);
31
- }
32
- void
33
- define_function (const char* name, RubyFunction2 fun)
34
- {
35
- rb_define_global_function(name, RUBY_METHOD_FUNC(fun), 2);
36
- }
37
- void
38
- define_function (const char* name, RubyFunction3 fun)
39
- {
40
- rb_define_global_function(name, RUBY_METHOD_FUNC(fun), 3);
41
- }
42
- void
43
- define_function (const char* name, RubyFunction4 fun)
44
- {
45
- rb_define_global_function(name, RUBY_METHOD_FUNC(fun), 4);
46
- }
47
- void
48
- define_function (const char* name, RubyFunction5 fun)
49
- {
50
- rb_define_global_function(name, RUBY_METHOD_FUNC(fun), 5);
51
- }
52
- void
53
- define_function (const char* name, RubyFunction6 fun)
54
- {
55
- rb_define_global_function(name, RUBY_METHOD_FUNC(fun), 6);
56
- }
57
- void
58
- define_function (const char* name, RubyFunction7 fun)
59
- {
60
- rb_define_global_function(name, RUBY_METHOD_FUNC(fun), 7);
61
- }
62
- void
63
- define_function (const char* name, RubyFunction8 fun)
64
- {
65
- rb_define_global_function(name, RUBY_METHOD_FUNC(fun), 8);
66
- }
67
-
68
- Value
69
- call (Symbol name, int argc, const Value* argv)
70
- {
71
- return protect(rb_funcall2, Qnil, name.id(), argc, (const VALUE*) argv);
72
- }
73
- Value
74
- call (Symbol name)
75
- {
76
- const VALUE args[] = {};
77
- return protect(rb_funcall2, Qnil, name.id(), 0, args);
78
- }
79
- Value
80
- call (Symbol name, Value v1)
81
- {
82
- const VALUE args[] = {v1};
83
- return protect(rb_funcall2, Qnil, name.id(), 1, args);
84
- }
85
- Value
86
- call (Symbol name, Value v1, Value v2)
87
- {
88
- const VALUE args[] = {v1, v2};
89
- return protect(rb_funcall2, Qnil, name.id(), 2, args);
90
- }
91
- Value
92
- call (Symbol name, Value v1, Value v2, Value v3)
93
- {
94
- const VALUE args[] = {v1, v2, v3};
95
- return protect(rb_funcall2, Qnil, name.id(), 3, args);
96
- }
97
- Value
98
- call (Symbol name, Value v1, Value v2, Value v3, Value v4)
99
- {
100
- const VALUE args[] = {v1, v2, v3, v4};
101
- return protect(rb_funcall2, Qnil, name.id(), 4, args);
102
- }
103
- Value
104
- call (Symbol name, Value v1, Value v2, Value v3, Value v4, Value v5)
105
- {
106
- const VALUE args[] = {v1, v2, v3, v4, v5};
107
- return protect(rb_funcall2, Qnil, name.id(), 5, args);
108
- }
109
- Value
110
- call (Symbol name, Value v1, Value v2, Value v3, Value v4, Value v5, Value v6)
111
- {
112
- const VALUE args[] = {v1, v2, v3, v4, v5, v6};
113
- return protect(rb_funcall2, Qnil, name.id(), 6, args);
114
- }
115
- Value
116
- call (Symbol name, Value v1, Value v2, Value v3, Value v4, Value v5, Value v6, Value v7)
117
- {
118
- const VALUE args[] = {v1, v2, v3, v4, v5, v6, v7};
119
- return protect(rb_funcall2, Qnil, name.id(), 7, args);
120
- }
121
- Value
122
- call (Symbol name, Value v1, Value v2, Value v3, Value v4, Value v5, Value v6, Value v7, Value v8)
123
- {
124
- const VALUE args[] = {v1, v2, v3, v4, v5, v6, v7, v8};
125
- return protect(rb_funcall2, Qnil, name.id(), 8, args);
126
- }
127
-
128
- Value
129
- eval (const char* str)
130
- {
131
- SYM(eval);
132
- return call(eval, str);
133
- }
134
-
135
-
136
- Value
137
- call_protect (VALUE (*fun)(VALUE), VALUE arg)
138
- {
139
- int state = 0;
140
- VALUE ret = rb_protect(fun, arg, &state);
141
-
142
- if (state != 0)
143
- {
144
- VALUE exception = rb_errinfo();
145
- if (state == TAG_RAISE && RTEST(exception))
146
- {
147
- rb_set_errinfo(Qnil);
148
- throw RubyException(exception);
149
- }
150
-
151
- throw RubyJumptag(state);
152
- }
153
-
154
- return ret;
155
- }
156
-
157
-
158
- }// Rucy
data/src/gc.cpp DELETED
@@ -1,63 +0,0 @@
1
- // -*- c++ -*-
2
- #include "rucy/gc.h"
3
-
4
-
5
- namespace Rucy
6
- {
7
-
8
-
9
- static void
10
- register_value (VALUE* v)
11
- {
12
- if (!v) return;
13
- rb_gc_register_address(v);
14
- }
15
-
16
- static void
17
- unregister_value (VALUE* v)
18
- {
19
- if (!v) return;
20
- rb_gc_unregister_address(v);
21
- }
22
-
23
- GCGuard::GCGuard (VALUE* v)
24
- : pval(v)
25
- {
26
- register_value(pval);
27
- }
28
-
29
- GCGuard::GCGuard (Value* v)
30
- : pval(v ? &v->v : NULL)
31
- {
32
- register_value(pval);
33
- }
34
-
35
- GCGuard::~GCGuard ()
36
- {
37
- unregister_value(pval);
38
- }
39
-
40
-
41
- GlobalValue::GlobalValue (Value v)
42
- : val(v), guard(&val)
43
- {
44
- }
45
-
46
- Value
47
- GlobalValue::value () const
48
- {
49
- return val;
50
- }
51
-
52
- GlobalValue::operator VALUE () const
53
- {
54
- return value();
55
- }
56
-
57
- GlobalValue::operator Value () const
58
- {
59
- return value();
60
- }
61
-
62
-
63
- }// Rucy