kanayago 0.1.1 → 0.2.0

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 (77) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +12 -0
  3. data/.ruby-version +1 -0
  4. data/README.md +20 -29
  5. data/Rakefile +43 -96
  6. data/ext/kanayago/extconf.rb +6 -0
  7. data/ext/kanayago/id.h +12 -5
  8. data/ext/kanayago/id_table.h +15 -0
  9. data/ext/kanayago/include/ruby/st.h +199 -0
  10. data/ext/kanayago/internal/array.h +3 -0
  11. data/ext/kanayago/internal/basic_operators.h +1 -0
  12. data/ext/kanayago/internal/bignum.h +1 -0
  13. data/ext/kanayago/internal/bits.h +82 -0
  14. data/ext/kanayago/internal/encoding.h +4 -1
  15. data/ext/kanayago/internal/error.h +33 -0
  16. data/ext/kanayago/internal/fixnum.h +1 -0
  17. data/ext/kanayago/internal/gc.h +47 -11
  18. data/ext/kanayago/internal/hash.h +3 -0
  19. data/ext/kanayago/internal/imemo.h +93 -32
  20. data/ext/kanayago/internal/io.h +30 -7
  21. data/ext/kanayago/internal/namespace.h +81 -0
  22. data/ext/kanayago/internal/numeric.h +1 -0
  23. data/ext/kanayago/internal/parse.h +17 -3
  24. data/ext/kanayago/internal/re.h +7 -2
  25. data/ext/kanayago/internal/sanitizers.h +88 -39
  26. data/ext/kanayago/internal/set_table.h +70 -0
  27. data/ext/kanayago/internal/string.h +33 -16
  28. data/ext/kanayago/internal/symbol.h +4 -3
  29. data/ext/kanayago/internal/thread.h +42 -9
  30. data/ext/kanayago/internal/variable.h +13 -11
  31. data/ext/kanayago/internal/vm.h +4 -5
  32. data/ext/kanayago/internal.h +0 -3
  33. data/ext/kanayago/kanayago.c +554 -235
  34. data/ext/kanayago/kanayago.h +5 -0
  35. data/ext/kanayago/literal_node.c +343 -0
  36. data/ext/kanayago/literal_node.h +30 -0
  37. data/ext/kanayago/method.h +18 -2
  38. data/ext/kanayago/node.c +7 -1
  39. data/ext/kanayago/node.h +14 -3
  40. data/ext/kanayago/parse.c +7602 -7156
  41. data/ext/kanayago/parse.h +39 -39
  42. data/ext/kanayago/parser_st.c +2 -1
  43. data/ext/kanayago/pattern_node.c +78 -0
  44. data/ext/kanayago/pattern_node.h +13 -0
  45. data/ext/kanayago/ruby_atomic.h +43 -0
  46. data/ext/kanayago/ruby_parser.c +7 -35
  47. data/ext/kanayago/rubyparser.h +83 -80
  48. data/ext/kanayago/scope_node.c +34 -0
  49. data/ext/kanayago/scope_node.h +8 -0
  50. data/ext/kanayago/shape.h +321 -111
  51. data/ext/kanayago/st.c +905 -21
  52. data/ext/kanayago/statement_node.c +795 -0
  53. data/ext/kanayago/statement_node.h +66 -0
  54. data/ext/kanayago/string_node.c +192 -0
  55. data/ext/kanayago/string_node.h +19 -0
  56. data/ext/kanayago/symbol.h +2 -9
  57. data/ext/kanayago/thread_pthread.h +10 -3
  58. data/ext/kanayago/universal_parser.c +1 -20
  59. data/ext/kanayago/variable_node.c +72 -0
  60. data/ext/kanayago/variable_node.h +12 -0
  61. data/ext/kanayago/vm_core.h +205 -71
  62. data/lib/kanayago/literal_node.rb +87 -0
  63. data/lib/kanayago/pattern_node.rb +19 -0
  64. data/lib/kanayago/statement_node.rb +222 -0
  65. data/lib/kanayago/string_node.rb +43 -0
  66. data/lib/kanayago/variable_node.rb +23 -0
  67. data/lib/kanayago/version.rb +1 -1
  68. data/lib/kanayago.rb +22 -0
  69. data/patch/3.4/copy_target.rb +78 -0
  70. data/patch/3.4/kanayago.patch +162 -0
  71. data/patch/head/copy_target.rb +84 -0
  72. data/patch/head/kanayago.patch +162 -0
  73. data/sample/minitest_generator.rb +266 -0
  74. data/sample/test_generator.rb +272 -0
  75. data/typeprof.conf.json +9 -0
  76. metadata +32 -4
  77. data/ext/kanayago/parse.tmp.y +0 -16145
@@ -0,0 +1,66 @@
1
+ #ifndef KANAYAGO_STATEMENT_NODE_H
2
+ #define KANAYAGO_STATEMENT_NODE_H
3
+
4
+ #include "internal/ruby_parser.h"
5
+ #include "kanayago.h"
6
+
7
+ VALUE if_statement_node_new(const NODE *);
8
+ VALUE unless_statement_node_new(const NODE *);
9
+ VALUE or_node_new(const NODE *);
10
+ VALUE and_node_new(const NODE *);
11
+ VALUE while_node_new(const NODE *);
12
+ VALUE until_node_new(const NODE *);
13
+ VALUE for_node_new(const NODE *);
14
+ VALUE alias_node_new(const NODE *);
15
+ VALUE valias_node_new(const NODE *);
16
+ VALUE undef_node_new(const NODE *);
17
+ VALUE return_node_new(const NODE *);
18
+ VALUE global_assignment_node_new(const NODE *);
19
+ VALUE class_variable_assignment_node_new(const NODE *);
20
+ VALUE instance_assignment_node_new(const NODE *);
21
+ VALUE local_assignment_node_new(const NODE *);
22
+ VALUE singleton_definition_node_new(const NODE *);
23
+ VALUE singleton_class_node_new(const NODE *);
24
+ VALUE attribute_assignment_node_new(const NODE *);
25
+ VALUE safe_call_node_new(const NODE *);
26
+ VALUE super_node_new(const NODE *);
27
+ VALUE zero_super_node_new(const NODE *);
28
+ VALUE case_node_new(const NODE *);
29
+ VALUE case2_node_new(const NODE *);
30
+ VALUE case3_node_new(const NODE *);
31
+ VALUE when_node_new(const NODE *);
32
+ VALUE retry_node_new(const NODE *);
33
+ VALUE redo_node_new(const NODE *);
34
+ VALUE break_node_new(const NODE *);
35
+ VALUE next_node_new(const NODE *);
36
+ VALUE defined_node_new(const NODE *);
37
+ VALUE iter_node_new(const NODE *);
38
+ VALUE ensure_node_new(const NODE *);
39
+ VALUE rescue_node_new(const NODE *);
40
+ VALUE resbody_node_new(const NODE *);
41
+ VALUE operator_assignment1_node_new(const NODE *);
42
+ VALUE operator_assignment2_node_new(const NODE *);
43
+ VALUE operator_assignment_and_node_new(const NODE *);
44
+ VALUE operator_assignment_or_node_new(const NODE *);
45
+ VALUE operator_constant_declaration_node_new(const NODE *);
46
+ VALUE yield_node_new(const NODE *);
47
+ VALUE lambda_node_new(const NODE *);
48
+ VALUE splat_node_new(const NODE *);
49
+ VALUE block_pass_node_new(const NODE *);
50
+ VALUE args_aux_node_new(const NODE *);
51
+ VALUE opt_arg_node_new(const NODE *);
52
+ VALUE kw_arg_node_new(const NODE *);
53
+ VALUE post_arg_node_new(const NODE *);
54
+ VALUE args_cat_node_new(const NODE *);
55
+ VALUE args_push_node_new(const NODE *);
56
+ VALUE for_masgn_node_new(const NODE *);
57
+ VALUE masgn_node_new(const NODE *);
58
+ VALUE dasgn_node_new(const NODE *);
59
+ VALUE once_node_new(const NODE *);
60
+ VALUE errinfo_node_new(const NODE *);
61
+ VALUE postexe_node_new(const NODE *);
62
+ VALUE error_node_new(const NODE *);
63
+
64
+ void Init_StatementNode(VALUE);
65
+
66
+ #endif
@@ -0,0 +1,192 @@
1
+ #include "string_node.h"
2
+ #include "internal/ruby_parser.h"
3
+ #include "internal/encoding.h"
4
+ #include "kanayago.h"
5
+
6
+ VALUE rb_cDynamicStringNode;
7
+ VALUE rb_cDynamicSymbolNode;
8
+ VALUE rb_cEmbeddedExpressionStringNode;
9
+ VALUE rb_cExecuteStringNode;
10
+ VALUE rb_cDynamicExecuteStringNode;
11
+ VALUE rb_cRegexpNode;
12
+ VALUE rb_cDynamicRegexpNode;
13
+ VALUE rb_cMatchNode;
14
+ VALUE rb_cMatch2Node;
15
+ VALUE rb_cMatch3Node;
16
+
17
+ VALUE
18
+ dynamic_string_node_new(const NODE *node)
19
+ {
20
+ VALUE obj = rb_class_new_instance(0, 0, rb_cDynamicStringNode);
21
+ rb_parser_string_t *str = RNODE_DSTR(node)->string;
22
+ rb_encoding *enc = str->enc;
23
+ char *ptr = str->ptr;
24
+ long len = str->len;
25
+
26
+ rb_ivar_set(obj, rb_intern("@string"), rb_enc_str_new(ptr, len, enc));
27
+ rb_ivar_set(obj, rb_intern("@next_nodes"), ast_to_node_instance((const NODE *)RNODE_DSTR(node)->nd_next));
28
+
29
+ return obj;
30
+ }
31
+
32
+ VALUE
33
+ dynamic_symbol_node_new(const NODE *node)
34
+ {
35
+ VALUE obj = rb_class_new_instance(0, 0, rb_cDynamicSymbolNode);
36
+ rb_parser_string_t *str = RNODE_DSYM(node)->string;
37
+ rb_encoding *enc = str->enc;
38
+ char *ptr = str->ptr;
39
+ long len = str->len;
40
+
41
+ rb_ivar_set(obj, rb_intern("@string"), rb_enc_str_new(ptr, len, enc));
42
+ rb_ivar_set(obj, rb_intern("@next_nodes"), ast_to_node_instance((const NODE *)RNODE_DSYM(node)->nd_next));
43
+
44
+ return obj;
45
+ }
46
+
47
+ VALUE
48
+ embedded_expression_string_node_new(const NODE *node)
49
+ {
50
+ VALUE obj = rb_class_new_instance(0, 0, rb_cEmbeddedExpressionStringNode);
51
+
52
+ rb_ivar_set(obj, rb_intern("@body"), ast_to_node_instance(RNODE_EVSTR(node)->nd_body));
53
+
54
+ return obj;
55
+ }
56
+
57
+ VALUE
58
+ execute_string_node_new(const NODE *node)
59
+ {
60
+ VALUE result = rb_class_new_instance(0, 0, rb_cExecuteStringNode);
61
+ rb_parser_string_t *str = RNODE_XSTR(node)->string;
62
+ rb_encoding *enc = str->enc;
63
+ char *ptr = str->ptr;
64
+ long len = str->len;
65
+ enum rb_parser_string_coderange_type coderange = str->coderange;
66
+
67
+ rb_ivar_set(result, rb_intern("@ptr"), rb_enc_str_new(ptr, len, enc));
68
+ rb_ivar_set(result, rb_intern("@len"), LONG2FIX(len));
69
+ rb_ivar_set(result, rb_intern("@enc"), rb_enc_from_encoding(enc));
70
+ rb_ivar_set(result, rb_intern("@coderange"), INT2FIX(coderange));
71
+
72
+ return result;
73
+ }
74
+
75
+ VALUE
76
+ dynamic_execute_string_node_new(const NODE *node)
77
+ {
78
+ VALUE obj = rb_class_new_instance(0, 0, rb_cDynamicExecuteStringNode);
79
+ rb_parser_string_t *str = RNODE_DXSTR(node)->string;
80
+ rb_encoding *enc = str->enc;
81
+ char *ptr = str->ptr;
82
+ long len = str->len;
83
+
84
+ rb_ivar_set(obj, rb_intern("@string"), rb_enc_str_new(ptr, len, enc));
85
+ rb_ivar_set(obj, rb_intern("@next_nodes"), ast_to_node_instance((const NODE *)RNODE_DXSTR(node)->nd_next));
86
+
87
+ return obj;
88
+ }
89
+
90
+ VALUE
91
+ regexp_node_new(const NODE *node)
92
+ {
93
+ VALUE result = rb_class_new_instance(0, 0, rb_cRegexpNode);
94
+ rb_parser_string_t *str = RNODE_REGX(node)->string;
95
+ rb_encoding *enc = str->enc;
96
+ char *ptr = str->ptr;
97
+ long len = str->len;
98
+ enum rb_parser_string_coderange_type coderange = str->coderange;
99
+ int options = RNODE_REGX(node)->options;
100
+
101
+ rb_ivar_set(result, rb_intern("@ptr"), rb_enc_str_new(ptr, len, enc));
102
+ rb_ivar_set(result, rb_intern("@len"), LONG2FIX(len));
103
+ rb_ivar_set(result, rb_intern("@enc"), rb_enc_from_encoding(enc));
104
+ rb_ivar_set(result, rb_intern("@coderange"), INT2FIX(coderange));
105
+ rb_ivar_set(result, rb_intern("@options"), INT2FIX(options));
106
+
107
+ return result;
108
+ }
109
+
110
+ VALUE
111
+ dynamic_regexp_node_new(const NODE *node)
112
+ {
113
+ VALUE obj = rb_class_new_instance(0, 0, rb_cDynamicRegexpNode);
114
+ rb_parser_string_t *str = RNODE_DREGX(node)->string;
115
+ rb_encoding *enc = str->enc;
116
+ char *ptr = str->ptr;
117
+ long len = str->len;
118
+ long options = RNODE_DREGX(node)->as.nd_cflag;
119
+
120
+ rb_ivar_set(obj, rb_intern("@string"), rb_enc_str_new(ptr, len, enc));
121
+ rb_ivar_set(obj, rb_intern("@next_nodes"), ast_to_node_instance((const NODE *)RNODE_DREGX(node)->nd_next));
122
+ rb_ivar_set(obj, rb_intern("@options"), LONG2FIX(options));
123
+
124
+ return obj;
125
+ }
126
+
127
+ VALUE
128
+ match_node_new(const NODE *node)
129
+ {
130
+ VALUE result = rb_class_new_instance(0, 0, rb_cMatchNode);
131
+ rb_parser_string_t *str = RNODE_MATCH(node)->string;
132
+ rb_encoding *enc = str->enc;
133
+ char *ptr = str->ptr;
134
+ long len = str->len;
135
+ enum rb_parser_string_coderange_type coderange = str->coderange;
136
+ int options = RNODE_MATCH(node)->options;
137
+
138
+ rb_ivar_set(result, rb_intern("@ptr"), rb_enc_str_new(ptr, len, enc));
139
+ rb_ivar_set(result, rb_intern("@len"), LONG2FIX(len));
140
+ rb_ivar_set(result, rb_intern("@enc"), rb_enc_from_encoding(enc));
141
+ rb_ivar_set(result, rb_intern("@coderange"), INT2FIX(coderange));
142
+ rb_ivar_set(result, rb_intern("@options"), INT2FIX(options));
143
+
144
+ return result;
145
+ }
146
+
147
+ VALUE
148
+ match2_node_new(const NODE *node)
149
+ {
150
+ VALUE obj = rb_class_new_instance(0, 0, rb_cMatch2Node);
151
+
152
+ rb_ivar_set(obj, rb_intern("@recv"), ast_to_node_instance(RNODE_MATCH2(node)->nd_recv));
153
+ rb_ivar_set(obj, rb_intern("@value"), ast_to_node_instance(RNODE_MATCH2(node)->nd_value));
154
+ rb_ivar_set(obj, rb_intern("@args"), ast_to_node_instance(RNODE_MATCH2(node)->nd_args));
155
+
156
+ return obj;
157
+ }
158
+
159
+ VALUE
160
+ match3_node_new(const NODE *node)
161
+ {
162
+ VALUE obj = rb_class_new_instance(0, 0, rb_cMatch3Node);
163
+
164
+ rb_ivar_set(obj, rb_intern("@recv"), ast_to_node_instance(RNODE_MATCH3(node)->nd_recv));
165
+ rb_ivar_set(obj, rb_intern("@value"), ast_to_node_instance(RNODE_MATCH3(node)->nd_value));
166
+
167
+ return obj;
168
+ }
169
+
170
+ void
171
+ Init_StringNode(VALUE module)
172
+ {
173
+ rb_cDynamicStringNode = rb_define_class_under(module, "DynamicStringNode", rb_cObject);
174
+
175
+ rb_cDynamicSymbolNode = rb_define_class_under(module, "DynamicSymbolNode", rb_cObject);
176
+
177
+ rb_cEmbeddedExpressionStringNode = rb_define_class_under(module, "EmbeddedExpressionStringNode", rb_cObject);
178
+
179
+ rb_cExecuteStringNode = rb_define_class_under(module, "ExecuteStringNode", rb_cObject);
180
+
181
+ rb_cDynamicExecuteStringNode = rb_define_class_under(module, "DynamicExecuteStringNode", rb_cObject);
182
+
183
+ rb_cRegexpNode = rb_define_class_under(module, "RegexpNode", rb_cObject);
184
+
185
+ rb_cDynamicRegexpNode = rb_define_class_under(module, "DynamicRegexpNode", rb_cObject);
186
+
187
+ rb_cMatchNode = rb_define_class_under(module, "MatchNode", rb_cObject);
188
+
189
+ rb_cMatch2Node = rb_define_class_under(module, "Match2Node", rb_cObject);
190
+
191
+ rb_cMatch3Node = rb_define_class_under(module, "Match3Node", rb_cObject);
192
+ }
@@ -0,0 +1,19 @@
1
+ #ifndef KANAYAGO_STRING_NODE_H
2
+ #define KANAYAGO_STRING_NODE_H
3
+
4
+ #include "kanayago.h"
5
+
6
+ VALUE dynamic_string_node_new(const NODE*);
7
+ VALUE dynamic_symbol_node_new(const NODE*);
8
+ VALUE embedded_expression_string_node_new(const NODE *);
9
+ VALUE execute_string_node_new(const NODE *);
10
+ VALUE dynamic_execute_string_node_new(const NODE *);
11
+ VALUE regexp_node_new(const NODE *);
12
+ VALUE dynamic_regexp_node_new(const NODE *);
13
+ VALUE match_node_new(const NODE *);
14
+ VALUE match2_node_new(const NODE *);
15
+ VALUE match3_node_new(const NODE *);
16
+
17
+ void Init_StringNode(VALUE);
18
+
19
+ #endif
@@ -39,7 +39,7 @@ struct RSymbol {
39
39
  #define is_attrset_id(id) ((id)==idASET||id_type(id)==ID_ATTRSET)
40
40
  #define is_const_id(id) (id_type(id)==ID_CONST)
41
41
  #define is_class_id(id) (id_type(id)==ID_CLASS)
42
- #define is_junk_id(id) (id_type(id)==ID_JUNK)
42
+ #define is_internal_id(id) (id_type(id)==ID_INTERNAL)
43
43
 
44
44
  static inline int
45
45
  id_type(ID id)
@@ -58,13 +58,6 @@ static const uint32_t RB_ID_SERIAL_MAX = /* 256M on LP32 */
58
58
  ((sizeof(ID)-sizeof(rb_id_serial_t))*CHAR_BIT < RUBY_ID_SCOPE_SHIFT ?
59
59
  RUBY_ID_SCOPE_SHIFT : 0);
60
60
 
61
- typedef struct {
62
- rb_id_serial_t last_id;
63
- st_table *str_sym;
64
- VALUE ids;
65
- VALUE dsymbol_fstr_hash;
66
- } rb_symbols_t;
67
-
68
61
  static inline rb_id_serial_t
69
62
  rb_id_to_serial(ID id)
70
63
  {
@@ -98,7 +91,7 @@ sym_type(VALUE sym)
98
91
  #define is_attrset_sym(sym) (sym_type(sym)==ID_ATTRSET)
99
92
  #define is_const_sym(sym) (sym_type(sym)==ID_CONST)
100
93
  #define is_class_sym(sym) (sym_type(sym)==ID_CLASS)
101
- #define is_junk_sym(sym) (sym_type(sym)==ID_JUNK)
94
+ #define is_internal_sym(sym) (sym_type(sym)==ID_INTERNAL)
102
95
 
103
96
  #ifndef RIPPER
104
97
  RUBY_FUNC_EXPORTED
@@ -17,6 +17,11 @@
17
17
  #define RB_NATIVETHREAD_LOCK_INIT PTHREAD_MUTEX_INITIALIZER
18
18
  #define RB_NATIVETHREAD_COND_INIT PTHREAD_COND_INITIALIZER
19
19
 
20
+ // TLS can not be accessed across .so on arm64 and perhaps ppc64le too.
21
+ #if defined(__arm64__) || defined(__aarch64__) || defined(__powerpc64__)
22
+ # define RB_THREAD_CURRENT_EC_NOINLINE
23
+ #endif
24
+
20
25
  // this data should be protected by timer_th.waiting_lock
21
26
  struct rb_thread_sched_waiting {
22
27
  enum thread_sched_waiting_flag {
@@ -132,10 +137,8 @@ struct rb_thread_sched {
132
137
 
133
138
  #ifdef RB_THREAD_LOCAL_SPECIFIER
134
139
  NOINLINE(void rb_current_ec_set(struct rb_execution_context_struct *));
135
- NOINLINE(struct rb_execution_context_struct *rb_current_ec_noinline(void));
136
140
 
137
- # ifdef __APPLE__
138
- // on Darwin, TLS can not be accessed across .so
141
+ # ifdef RB_THREAD_CURRENT_EC_NOINLINE
139
142
  NOINLINE(struct rb_execution_context_struct *rb_current_ec(void));
140
143
  # else
141
144
  RUBY_EXTERN RB_THREAD_LOCAL_SPECIFIER struct rb_execution_context_struct *ruby_current_ec;
@@ -165,4 +168,8 @@ native_tls_set(native_tls_key_t key, void *ptr)
165
168
  RUBY_EXTERN native_tls_key_t ruby_current_ec_key;
166
169
  #endif
167
170
 
171
+ struct rb_ractor_struct;
172
+ void rb_ractor_sched_wait(struct rb_execution_context_struct *ec, struct rb_ractor_struct *cr, rb_unblock_function_t *ubf, void *ptr);
173
+ void rb_ractor_sched_wakeup(struct rb_ractor_struct *r, struct rb_thread_struct *th);
174
+
168
175
  #endif /* RUBY_THREAD_PTHREAD_H */
@@ -13,7 +13,6 @@
13
13
  #include "ruby/backward/2/inttypes.h"
14
14
  #include "probes.h"
15
15
 
16
- #define LIKELY(x) RB_LIKELY(x)
17
16
  #define UNLIKELY(x) RB_UNLIKELY(x)
18
17
  #ifndef TRUE
19
18
  # define TRUE 1
@@ -23,13 +22,9 @@
23
22
  # define FALSE 0
24
23
  #endif
25
24
  #define numberof(array) ((int)(sizeof(array) / sizeof((array)[0])))
26
- #define rb_strlen_lit(str) (sizeof(str "") - 1)
25
+ #define rb_strlen_lit(str) ((sizeof(str "") / sizeof(str ""[0])) - 1)
27
26
  #undef FIXNUM_MAX
28
27
  #define FIXNUM_MAX (LONG_MAX / 2)
29
- #undef RSTRING_GETMEM
30
- #define RSTRING_GETMEM(str, ptrvar, lenvar) \
31
- ((ptrvar) = RSTRING_PTR(str), \
32
- (lenvar) = RSTRING_LEN(str))
33
28
 
34
29
  /* parser_st */
35
30
  #define st_table parser_st_table
@@ -90,8 +85,6 @@
90
85
 
91
86
  #define rb_attr_get p->config->attr_get
92
87
 
93
- #define rb_ary_new p->config->ary_new
94
- #define rb_ary_push p->config->ary_push
95
88
  #undef rb_ary_new_from_args
96
89
  #define rb_ary_new_from_args p->config->ary_new_from_args
97
90
  #define rb_ary_unshift p->config->ary_unshift
@@ -113,32 +106,23 @@
113
106
  #define rb_id2str p->config->id2str
114
107
  #undef ID2SYM
115
108
  #define ID2SYM p->config->id2sym
116
- #undef SYM2ID
117
- #define SYM2ID p->config->sym2id
118
109
 
119
110
  #define rb_str_catf p->config->str_catf
120
111
  #undef rb_str_cat_cstr
121
112
  #define rb_str_cat_cstr p->config->str_cat_cstr
122
- #define rb_str_modify p->config->str_modify
123
- #define rb_str_set_len p->config->str_set_len
124
- #define rb_str_cat p->config->str_cat
125
113
  #define rb_str_resize p->config->str_resize
126
114
  #undef rb_str_new
127
115
  #define rb_str_new p->config->str_new
128
116
  #undef rb_str_new_cstr
129
117
  #define rb_str_new_cstr p->config->str_new_cstr
130
118
  #define rb_str_to_interned_str p->config->str_to_interned_str
131
- #define is_ascii_string p->config->is_ascii_string
132
119
  #define rb_enc_str_new p->config->enc_str_new
133
120
  #define rb_str_vcatf p->config->str_vcatf
134
121
  #define rb_sprintf p->config->rb_sprintf
135
122
  #undef RSTRING_PTR
136
123
  #define RSTRING_PTR p->config->rstring_ptr
137
- #undef RSTRING_END
138
- #define RSTRING_END p->config->rstring_end
139
124
  #undef RSTRING_LEN
140
125
  #define RSTRING_LEN p->config->rstring_len
141
- #define rb_obj_as_string p->config->obj_as_string
142
126
 
143
127
  #undef INT2NUM
144
128
  #define INT2NUM p->config->int2num
@@ -162,7 +146,6 @@
162
146
  #define rb_enc_get p->config->enc_get
163
147
  #define rb_enc_asciicompat p->config->enc_asciicompat
164
148
  #define rb_utf8_encoding p->config->utf8_encoding
165
- #define rb_enc_associate p->config->enc_associate
166
149
  #define rb_ascii8bit_encoding p->config->ascii8bit_encoding
167
150
  #define rb_enc_codelen p->config->enc_codelen
168
151
  #define rb_enc_mbcput p->config->enc_mbcput
@@ -171,7 +154,6 @@
171
154
  #define rb_enc_isspace p->config->enc_isspace
172
155
  #define ENC_CODERANGE_7BIT p->config->enc_coderange_7bit
173
156
  #define ENC_CODERANGE_UNKNOWN p->config->enc_coderange_unknown
174
- #define rb_usascii_encoding p->config->usascii_encoding
175
157
 
176
158
  #define rb_local_defined p->config->local_defined
177
159
  #define rb_dvar_defined p->config->dvar_defined
@@ -182,7 +164,6 @@
182
164
 
183
165
  #define rb_errinfo p->config->errinfo
184
166
  #define rb_set_errinfo p->config->set_errinfo
185
- #define rb_exc_raise p->config->exc_raise
186
167
  #define rb_make_exception p->config->make_exception
187
168
 
188
169
  #define ruby_sized_xfree p->config->sized_xfree
@@ -0,0 +1,72 @@
1
+ #include "internal/ruby_parser.h"
2
+ #include "kanayago.h"
3
+
4
+ VALUE rb_cLocalVariableNode;
5
+ VALUE rb_cDynamicVariableNode;
6
+ VALUE rb_cInstanceVariableNode;
7
+ VALUE rb_cClassVariableNode;
8
+ VALUE rb_cGlobalVariableNode;
9
+
10
+ VALUE
11
+ local_variable_node_new(const NODE *node)
12
+ {
13
+ VALUE obj = rb_class_new_instance(0, 0, rb_cLocalVariableNode);
14
+
15
+ rb_ivar_set(obj, rb_intern("@vid"), ID2SYM(RNODE_LVAR(node)->nd_vid));
16
+
17
+ return obj;
18
+ }
19
+
20
+ VALUE
21
+ dynamic_variable_node_new(const NODE *node)
22
+ {
23
+ VALUE obj = rb_class_new_instance(0, 0, rb_cDynamicVariableNode);
24
+
25
+ rb_ivar_set(obj, rb_intern("@vid"), ID2SYM(RNODE_DVAR(node)->nd_vid));
26
+
27
+ return obj;
28
+ }
29
+
30
+ VALUE
31
+ instance_variable_node_new(const NODE *node)
32
+ {
33
+ VALUE obj = rb_class_new_instance(0, 0, rb_cInstanceVariableNode);
34
+
35
+ rb_ivar_set(obj, rb_intern("@vid"), ID2SYM(RNODE_IVAR(node)->nd_vid));
36
+
37
+ return obj;
38
+ }
39
+
40
+ VALUE
41
+ class_variable_node_new(const NODE *node)
42
+ {
43
+ VALUE obj = rb_class_new_instance(0, 0, rb_cClassVariableNode);
44
+
45
+ rb_ivar_set(obj, rb_intern("@vid"), ID2SYM(RNODE_IVAR(node)->nd_vid));
46
+
47
+ return obj;
48
+ }
49
+
50
+ VALUE
51
+ global_variable_node_new(const NODE *node)
52
+ {
53
+ VALUE obj = rb_class_new_instance(0, 0, rb_cGlobalVariableNode);
54
+
55
+ rb_ivar_set(obj, rb_intern("@vid"), ID2SYM(RNODE_GVAR(node)->nd_vid));
56
+
57
+ return obj;
58
+ }
59
+
60
+ void
61
+ Init_VariableNode(VALUE module)
62
+ {
63
+ rb_cLocalVariableNode = rb_define_class_under(module, "LocalVariableNode", rb_cObject);
64
+
65
+ rb_cDynamicVariableNode = rb_define_class_under(module, "DynamicVariableNode", rb_cObject);
66
+
67
+ rb_cInstanceVariableNode = rb_define_class_under(module, "InstanceVariableNode", rb_cObject);
68
+
69
+ rb_cClassVariableNode = rb_define_class_under(module, "ClassVariableNode", rb_cObject);
70
+
71
+ rb_cGlobalVariableNode = rb_define_class_under(module, "GlobalVariableNode", rb_cObject);
72
+ }
@@ -0,0 +1,12 @@
1
+ #ifndef KANAYAGO_VARIABLE_NODE_H
2
+ #define KANAYAGO_VARIABLE_NODE_H
3
+ #include "kanayago.h"
4
+
5
+ VALUE local_variable_node_new(const NODE *);
6
+ VALUE dynamic_variable_node_new(const NODE *);
7
+ VALUE instance_variable_node_new(const NODE *);
8
+ VALUE class_variable_node_new(const NODE *);
9
+ VALUE global_variable_node_new(const NODE *);
10
+
11
+ void Init_VariableNode(VALUE);
12
+ #endif