rucy 0.1.6 → 0.1.7
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.
- checksums.yaml +7 -0
- data/.doc/ext/rucy/class.cpp +48 -56
- data/.doc/ext/rucy/exception.cpp +1 -1
- data/.doc/ext/rucy/function.cpp +14 -2
- data/.doc/ext/rucy/struct.cpp +2 -20
- data/.doc/ext/rucy/tester.cpp +7 -19
- data/.doc/ext/rucy/value.cpp +23 -1
- data/{README → README.md} +0 -0
- data/Rakefile +7 -5
- data/VERSION +1 -1
- data/bin/rucy2rdoc +8 -5
- data/ext/rucy/class.cpp +78 -87
- data/ext/rucy/class.h +12 -6
- data/ext/rucy/exception.cpp +17 -17
- data/ext/rucy/extconf.rb +11 -52
- data/ext/rucy/function.cpp +25 -12
- data/ext/rucy/struct.cpp +8 -26
- data/ext/rucy/tester.cpp +11 -24
- data/ext/rucy/value.cpp +32 -9
- data/include/rucy/class.h +5 -3
- data/include/rucy/exception.h +17 -71
- data/include/rucy/extension.h.erb +489 -0
- data/include/rucy/function.h.erb +20 -34
- data/include/rucy/module.h.erb +20 -14
- data/include/rucy/ruby.h +23 -0
- data/include/rucy/rucy.h +7 -66
- data/include/rucy/symbol.h +11 -11
- data/include/rucy/value.h.erb +98 -176
- data/include/rucy.h +9 -1
- data/lib/rucy/module.rb +11 -7
- data/rucy.gemspec +3 -4
- data/src/class.cpp +34 -6
- data/src/exception.cpp +69 -54
- data/src/extension.cpp +59 -0
- data/src/function.cpp.erb +17 -25
- data/src/module.cpp.erb +25 -16
- data/src/rucy.cpp +15 -25
- data/src/symbol.cpp +18 -17
- data/src/value.cpp.erb +374 -175
- data/task/doc.rake +5 -0
- data/test/helper.rb +6 -2
- data/test/test_class.rb +27 -20
- data/test/test_function.rb +6 -0
- data/test/test_value.rb +4 -0
- metadata +29 -39
- data/.gitignore +0 -22
- data/ChangeLog +0 -13
- data/include/rucy/defs.h.erb +0 -76
- data/include/rucy/extension.h +0 -206
data/ext/rucy/tester.cpp
CHANGED
@@ -2,13 +2,13 @@
|
|
2
2
|
|
3
3
|
|
4
4
|
#include <vector>
|
5
|
-
#include
|
5
|
+
#include "rucy.h"
|
6
6
|
|
7
7
|
|
8
8
|
using namespace Rucy;
|
9
9
|
|
10
10
|
|
11
|
-
static std::vector<String> logs;
|
11
|
+
static std::vector<Xot::String> logs;
|
12
12
|
|
13
13
|
|
14
14
|
void
|
@@ -18,41 +18,25 @@ log (const char* str)
|
|
18
18
|
}
|
19
19
|
|
20
20
|
|
21
|
-
/*
|
22
|
-
return last log.
|
23
|
-
*/
|
24
|
-
RUBY_DEFN(last_log)
|
25
|
-
{
|
26
|
-
if (argc > 1)
|
27
|
-
arg_count_error("#last_log", argc, 0, 1);
|
28
|
-
|
29
|
-
size_t index = (argc >= 1) ? to<size_t>(argv[0]) : logs.size() - 1;
|
30
|
-
if (index >= logs.size())
|
31
|
-
index_error();
|
32
|
-
|
33
|
-
return value(logs[index].c_str());
|
34
|
-
}
|
35
|
-
RUBY_END
|
36
|
-
|
37
21
|
/*
|
38
22
|
return all logs.
|
39
23
|
*/
|
40
|
-
|
24
|
+
RUCY_DEF0(all_logs)
|
41
25
|
{
|
42
26
|
std::vector<Value> a;
|
43
27
|
for (size_t i = 0; i < logs.size(); ++i) a.push_back(logs[i].c_str());
|
44
28
|
return value(a.size(), &a[0]);
|
45
29
|
}
|
46
|
-
|
30
|
+
RUCY_END
|
47
31
|
|
48
32
|
/*
|
49
33
|
clcear all logs.
|
50
34
|
*/
|
51
|
-
|
35
|
+
RUCY_DEF0(clear_logs)
|
52
36
|
{
|
53
37
|
logs.clear();
|
54
38
|
}
|
55
|
-
|
39
|
+
RUCY_END
|
56
40
|
|
57
41
|
|
58
42
|
void Init_value ();
|
@@ -65,12 +49,13 @@ void Init_class ();
|
|
65
49
|
extern "C" void
|
66
50
|
Init_tester ()
|
67
51
|
{
|
68
|
-
|
52
|
+
RUCY_TRY
|
53
|
+
|
54
|
+
init();
|
69
55
|
|
70
56
|
Module mRucy = define_module("Rucy");
|
71
57
|
Module mTester = mRucy.define_module("Tester");
|
72
58
|
|
73
|
-
mTester.define_function("last_log", last_log);
|
74
59
|
mTester.define_function("all_logs", all_logs);
|
75
60
|
mTester.define_function("clear_logs", clear_logs);
|
76
61
|
|
@@ -79,4 +64,6 @@ Init_tester ()
|
|
79
64
|
Init_function();
|
80
65
|
Init_struct ();
|
81
66
|
Init_class ();
|
67
|
+
|
68
|
+
RUCY_CATCH
|
82
69
|
}
|
data/ext/rucy/value.cpp
CHANGED
@@ -1,36 +1,58 @@
|
|
1
|
-
#include
|
1
|
+
#include "rucy.h"
|
2
2
|
|
3
3
|
|
4
4
|
using namespace Rucy;
|
5
5
|
|
6
6
|
|
7
7
|
static
|
8
|
-
|
8
|
+
RUCY_DEFN(true_to_value)
|
9
9
|
{
|
10
10
|
return value(true);
|
11
11
|
}
|
12
|
-
|
12
|
+
RUCY_END
|
13
13
|
|
14
14
|
static
|
15
|
-
|
15
|
+
RUCY_DEFN(false_to_value)
|
16
16
|
{
|
17
17
|
return value(false);
|
18
18
|
}
|
19
|
-
|
19
|
+
RUCY_END
|
20
20
|
|
21
21
|
static
|
22
|
-
|
22
|
+
RUCY_DEFN(NULL_to_value)
|
23
23
|
{
|
24
24
|
return nil();
|
25
25
|
}
|
26
|
-
|
26
|
+
RUCY_END
|
27
27
|
|
28
28
|
static
|
29
|
-
|
29
|
+
RUCY_DEFN(nil_value)
|
30
30
|
{
|
31
31
|
return nil();
|
32
32
|
}
|
33
|
-
|
33
|
+
RUCY_END
|
34
|
+
|
35
|
+
static
|
36
|
+
RUCY_DEFN(array_value)
|
37
|
+
{
|
38
|
+
const Value* a = argv;
|
39
|
+
switch (argc)
|
40
|
+
{
|
41
|
+
case 1: return array(a[0]);
|
42
|
+
case 2: return array(a[0], a[1]);
|
43
|
+
case 3: return array(a[0], a[1], a[2]);
|
44
|
+
case 4: return array(a[0], a[1], a[2], a[3]);
|
45
|
+
case 5: return array(a[0], a[1], a[2], a[3], a[4]);
|
46
|
+
case 6: return array(a[0], a[1], a[2], a[3], a[4], a[5]);
|
47
|
+
case 7: return array(a[0], a[1], a[2], a[3], a[4], a[5], a[6]);
|
48
|
+
case 8: return array(a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7]);
|
49
|
+
case 9: return array(a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8]);
|
50
|
+
case 10: return array(a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9]);
|
51
|
+
case 0:
|
52
|
+
default: argument_error(__FILE__, __LINE__);
|
53
|
+
}
|
54
|
+
}
|
55
|
+
RUCY_END
|
34
56
|
|
35
57
|
|
36
58
|
void
|
@@ -43,4 +65,5 @@ Init_value ()
|
|
43
65
|
mTester.define_method("false_to_value", false_to_value);
|
44
66
|
mTester.define_method("null_to_value", NULL_to_value);
|
45
67
|
mTester.define_method("nil_value", nil_value);
|
68
|
+
mTester.define_method("array_value", array_value);
|
46
69
|
}
|
data/include/rucy/class.h
CHANGED
@@ -18,13 +18,15 @@ namespace Rucy
|
|
18
18
|
|
19
19
|
public:
|
20
20
|
|
21
|
-
Class (
|
21
|
+
Class (RubyValue v = nil());
|
22
22
|
|
23
|
-
|
23
|
+
void define_alloc_func (RubyFunction0 fun);
|
24
24
|
|
25
|
-
|
25
|
+
void define_alloc_func (const char* name, RubyFunction0 fun);
|
26
26
|
// for RUBY_METHOD macro
|
27
27
|
|
28
|
+
void define_clear_override_flags (RubyFunction0 fun);
|
29
|
+
|
28
30
|
};// Class
|
29
31
|
|
30
32
|
|
data/include/rucy/exception.h
CHANGED
@@ -5,8 +5,8 @@
|
|
5
5
|
|
6
6
|
|
7
7
|
#include <stdexcept>
|
8
|
-
#include <
|
9
|
-
#include <rucy/
|
8
|
+
#include <xot/exception.h>
|
9
|
+
#include <rucy/value.h>
|
10
10
|
|
11
11
|
|
12
12
|
namespace Rucy
|
@@ -22,7 +22,7 @@ namespace Rucy
|
|
22
22
|
|
23
23
|
RubyException (Value exception);
|
24
24
|
|
25
|
-
RubyException (Value
|
25
|
+
RubyException (Value exception, const char* format, ...);
|
26
26
|
|
27
27
|
const char* what () const throw();
|
28
28
|
|
@@ -35,100 +35,46 @@ namespace Rucy
|
|
35
35
|
};// RubyException
|
36
36
|
|
37
37
|
|
38
|
-
struct
|
38
|
+
struct RubyJumpTag
|
39
39
|
{
|
40
40
|
|
41
41
|
public:
|
42
42
|
|
43
43
|
int tag;
|
44
44
|
|
45
|
-
|
45
|
+
RubyJumpTag (int tag);
|
46
46
|
|
47
|
-
};//
|
47
|
+
};// RubyJumpTag
|
48
48
|
|
49
49
|
|
50
50
|
void raise (const char* format = NULL, ...);
|
51
51
|
|
52
|
-
void raise (
|
52
|
+
void raise (RubyValue exception, const char* format = NULL, ...);
|
53
53
|
|
54
54
|
|
55
|
-
void
|
55
|
+
void rucy_error (const char* file, int line, const char* format = NULL, ...);
|
56
56
|
|
57
|
-
void
|
57
|
+
void type_error (const char* file, int line, const char* format = NULL, ...);
|
58
58
|
|
59
|
-
void
|
59
|
+
void argument_error (const char* file, int line, const char* format = NULL, ...);
|
60
|
+
|
61
|
+
void arg_count_error (const char* file, int line,
|
60
62
|
const char* method, int nargs, int nargs_expected,
|
61
63
|
int n1 = -1, int n2 = -1, int n3 = -1, int n4 = -1, int n5 = -1,
|
62
64
|
int n6 = -1, int n7 = -1, int n8 = -1, int n9 = -1, int n10 = -1);
|
63
65
|
|
64
|
-
void
|
66
|
+
void invalid_state_error (const char* file, int line, const char* format = NULL, ...);
|
65
67
|
|
66
|
-
void
|
68
|
+
void invalid_object_error (const char* file, int line, const char* format = NULL, ...);
|
67
69
|
|
70
|
+
void index_error (const char* file, int line, const char* format = NULL, ...);
|
68
71
|
|
69
|
-
void
|
72
|
+
void not_implemented_error (const char* file, int line, const char* format = NULL, ...);
|
70
73
|
|
71
|
-
void
|
74
|
+
void system_error (const char* file, int line, const char* format = NULL, ...);
|
72
75
|
|
73
76
|
|
74
77
|
}// Rucy
|
75
78
|
|
76
79
|
|
77
|
-
#define RUBY_TRY \
|
78
|
-
VALUE RUCY__rubyexception__ = Qnil; \
|
79
|
-
int RUCY__rubyjumptag__ = 0; \
|
80
|
-
\
|
81
|
-
goto RUCY__ruby_try_start__; \
|
82
|
-
\
|
83
|
-
RUCY__ruby_jump_tag__: \
|
84
|
-
if (RUCY__rubyjumptag__) rb_jump_tag(RUCY__rubyjumptag__); \
|
85
|
-
RUBY_THROW(rb_exc_new2(Rucy::native_error_class(), "Bad jump tag.")); \
|
86
|
-
\
|
87
|
-
RUCY__ruby_raise_exception__: \
|
88
|
-
rb_exc_raise(RUCY__rubyexception__); \
|
89
|
-
\
|
90
|
-
RUCY__ruby_try_start__: \
|
91
|
-
try \
|
92
|
-
{
|
93
|
-
|
94
|
-
#define RUBY_CATCH \
|
95
|
-
} \
|
96
|
-
catch (const Rucy::RubyJumptag& e) \
|
97
|
-
{ \
|
98
|
-
RUCY__rubyjumptag__ = e.tag; \
|
99
|
-
goto RUCY__ruby_jump_tag__; \
|
100
|
-
} \
|
101
|
-
catch (const Rucy::RubyException& e) \
|
102
|
-
{ \
|
103
|
-
RUBY_THROW(e.value()); \
|
104
|
-
} \
|
105
|
-
catch (const std::exception& e) \
|
106
|
-
{ \
|
107
|
-
Rucy::String text = e.what(), type = typeid(e).name(); \
|
108
|
-
if (!type.empty()) \
|
109
|
-
{ \
|
110
|
-
if (!text.empty()) text += " "; \
|
111
|
-
text += "[" + type + "]"; \
|
112
|
-
} \
|
113
|
-
RUBY_THROW(rb_exc_new2(Rucy::native_error_class(), text.c_str())); \
|
114
|
-
} \
|
115
|
-
catch (const std::string& s) \
|
116
|
-
{ \
|
117
|
-
RUBY_THROW(rb_exc_new2(Rucy::native_error_class(), s.c_str())); \
|
118
|
-
} \
|
119
|
-
catch (const char* s) \
|
120
|
-
{ \
|
121
|
-
RUBY_THROW(rb_exc_new2(Rucy::native_error_class(), s)); \
|
122
|
-
} \
|
123
|
-
catch (...) \
|
124
|
-
{ \
|
125
|
-
RUBY_THROW(rb_exc_new2( \
|
126
|
-
Rucy::native_error_class(), "Unknown C++ exception was thrown.")); \
|
127
|
-
}
|
128
|
-
|
129
|
-
#define RUBY_THROW(exception) \
|
130
|
-
RUCY__rubyexception__ = (exception); \
|
131
|
-
goto RUCY__ruby_raise_exception__
|
132
|
-
|
133
|
-
|
134
80
|
#endif//EOH
|