kanayago 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +7 -0
  2. data/.rubocop.yml +15 -0
  3. data/.rubocop_todo.yml +23 -0
  4. data/LICENSE.txt +21 -0
  5. data/README.md +79 -0
  6. data/Rakefile +182 -0
  7. data/ext/kanayago/ccan/check_type/check_type.h +63 -0
  8. data/ext/kanayago/ccan/container_of/container_of.h +142 -0
  9. data/ext/kanayago/ccan/list/list.h +791 -0
  10. data/ext/kanayago/ccan/str/str.h +17 -0
  11. data/ext/kanayago/constant.h +53 -0
  12. data/ext/kanayago/extconf.rb +21 -0
  13. data/ext/kanayago/id.h +347 -0
  14. data/ext/kanayago/id_table.h +39 -0
  15. data/ext/kanayago/internal/array.h +151 -0
  16. data/ext/kanayago/internal/basic_operators.h +64 -0
  17. data/ext/kanayago/internal/bignum.h +244 -0
  18. data/ext/kanayago/internal/bits.h +568 -0
  19. data/ext/kanayago/internal/compile.h +34 -0
  20. data/ext/kanayago/internal/compilers.h +107 -0
  21. data/ext/kanayago/internal/complex.h +29 -0
  22. data/ext/kanayago/internal/encoding.h +36 -0
  23. data/ext/kanayago/internal/error.h +218 -0
  24. data/ext/kanayago/internal/fixnum.h +184 -0
  25. data/ext/kanayago/internal/gc.h +322 -0
  26. data/ext/kanayago/internal/hash.h +191 -0
  27. data/ext/kanayago/internal/imemo.h +261 -0
  28. data/ext/kanayago/internal/io.h +140 -0
  29. data/ext/kanayago/internal/numeric.h +274 -0
  30. data/ext/kanayago/internal/parse.h +117 -0
  31. data/ext/kanayago/internal/rational.h +71 -0
  32. data/ext/kanayago/internal/re.h +28 -0
  33. data/ext/kanayago/internal/ruby_parser.h +125 -0
  34. data/ext/kanayago/internal/sanitizers.h +297 -0
  35. data/ext/kanayago/internal/serial.h +23 -0
  36. data/ext/kanayago/internal/static_assert.h +16 -0
  37. data/ext/kanayago/internal/string.h +186 -0
  38. data/ext/kanayago/internal/symbol.h +45 -0
  39. data/ext/kanayago/internal/thread.h +79 -0
  40. data/ext/kanayago/internal/variable.h +72 -0
  41. data/ext/kanayago/internal/vm.h +137 -0
  42. data/ext/kanayago/internal/warnings.h +16 -0
  43. data/ext/kanayago/internal.h +108 -0
  44. data/ext/kanayago/kanayago.c +420 -0
  45. data/ext/kanayago/kanayago.h +21 -0
  46. data/ext/kanayago/lex.c +302 -0
  47. data/ext/kanayago/method.h +255 -0
  48. data/ext/kanayago/node.c +440 -0
  49. data/ext/kanayago/node.h +111 -0
  50. data/ext/kanayago/node_name.inc +224 -0
  51. data/ext/kanayago/parse.c +26931 -0
  52. data/ext/kanayago/parse.h +244 -0
  53. data/ext/kanayago/parse.tmp.y +16145 -0
  54. data/ext/kanayago/parser_bits.h +564 -0
  55. data/ext/kanayago/parser_node.h +32 -0
  56. data/ext/kanayago/parser_st.c +164 -0
  57. data/ext/kanayago/parser_st.h +162 -0
  58. data/ext/kanayago/parser_value.h +106 -0
  59. data/ext/kanayago/probes.h +4 -0
  60. data/ext/kanayago/ruby_assert.h +14 -0
  61. data/ext/kanayago/ruby_atomic.h +23 -0
  62. data/ext/kanayago/ruby_parser.c +1165 -0
  63. data/ext/kanayago/rubyparser.h +1391 -0
  64. data/ext/kanayago/shape.h +234 -0
  65. data/ext/kanayago/st.c +2339 -0
  66. data/ext/kanayago/symbol.h +123 -0
  67. data/ext/kanayago/thread_pthread.h +168 -0
  68. data/ext/kanayago/universal_parser.c +230 -0
  69. data/ext/kanayago/vm_core.h +2215 -0
  70. data/ext/kanayago/vm_opts.h +67 -0
  71. data/lib/kanayago/version.rb +5 -0
  72. data/lib/kanayago.rb +11 -0
  73. data/sig/kanayago.rbs +4 -0
  74. metadata +116 -0
@@ -0,0 +1,17 @@
1
+ /* CC0 (Public domain) - see ccan/licenses/CC0 file for details */
2
+ #ifndef CCAN_STR_H
3
+ #define CCAN_STR_H
4
+ /**
5
+ * ccan_stringify - Turn expression into a string literal
6
+ * @expr: any C expression
7
+ *
8
+ * Example:
9
+ * #define PRINT_COND_IF_FALSE(cond) \
10
+ * ((cond) || printf("%s is false!", ccan_stringify(cond)))
11
+ */
12
+ #define stringify(expr) ccan_stringify_1(expr)
13
+ #define ccan_stringify(expr) ccan_stringify_1(expr)
14
+ /* Double-indirection required to stringify expansions */
15
+ #define ccan_stringify_1(expr) #expr
16
+
17
+ #endif /* CCAN_STR_H */
@@ -0,0 +1,53 @@
1
+ #ifndef CONSTANT_H
2
+ #define CONSTANT_H
3
+ /**********************************************************************
4
+
5
+ constant.h -
6
+
7
+ $Author$
8
+ created at: Sun Nov 15 00:09:33 2009
9
+
10
+ Copyright (C) 2009 Yusuke Endoh
11
+
12
+ **********************************************************************/
13
+ #include "ruby/ruby.h"
14
+ #include "id_table.h"
15
+
16
+ typedef enum {
17
+ CONST_DEPRECATED = 0x100,
18
+
19
+ CONST_VISIBILITY_MASK = 0xff,
20
+ CONST_PUBLIC = 0x00,
21
+ CONST_PRIVATE,
22
+ CONST_VISIBILITY_MAX
23
+ } rb_const_flag_t;
24
+
25
+ #define RB_CONST_PRIVATE_P(ce) \
26
+ (((ce)->flag & CONST_VISIBILITY_MASK) == CONST_PRIVATE)
27
+ #define RB_CONST_PUBLIC_P(ce) \
28
+ (((ce)->flag & CONST_VISIBILITY_MASK) == CONST_PUBLIC)
29
+
30
+ #define RB_CONST_DEPRECATED_P(ce) \
31
+ ((ce)->flag & CONST_DEPRECATED)
32
+
33
+ typedef struct rb_const_entry_struct {
34
+ rb_const_flag_t flag;
35
+ int line;
36
+ VALUE value; /* should be mark */
37
+ VALUE file; /* should be mark */
38
+ } rb_const_entry_t;
39
+
40
+ VALUE rb_mod_private_constant(int argc, const VALUE *argv, VALUE obj);
41
+ VALUE rb_mod_public_constant(int argc, const VALUE *argv, VALUE obj);
42
+ VALUE rb_mod_deprecate_constant(int argc, const VALUE *argv, VALUE obj);
43
+ void rb_free_const_table(struct rb_id_table *tbl);
44
+ VALUE rb_const_source_location(VALUE, ID);
45
+
46
+ int rb_autoloading_value(VALUE mod, ID id, VALUE *value, rb_const_flag_t *flag);
47
+ rb_const_entry_t *rb_const_lookup(VALUE klass, ID id);
48
+ VALUE rb_public_const_get_at(VALUE klass, ID id);
49
+ VALUE rb_public_const_get_from(VALUE klass, ID id);
50
+ int rb_public_const_defined_from(VALUE klass, ID id);
51
+ VALUE rb_const_source_location_at(VALUE, ID);
52
+
53
+ #endif /* CONSTANT_H */
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'mkmf'
4
+
5
+ $objs = %w[
6
+ node
7
+ parse
8
+ parser_st
9
+ ruby_parser
10
+ kanayago
11
+ ].map do |o|
12
+ o + ".#{$OBJEXT}"
13
+ end
14
+
15
+ append_cflags('-fvisibility=hidden')
16
+ append_cppflags('-DUNIVERSAL_PARSER=1')
17
+
18
+ $INCFLAGS << ' -I' << File.expand_path('../kanayago', __dir__)
19
+ $INCFLAGS << ' -I' << File.expand_path('../..', __dir__)
20
+
21
+ create_makefile('kanayago/kanayago')
data/ext/kanayago/id.h ADDED
@@ -0,0 +1,347 @@
1
+ /* DO NOT EDIT THIS FILE DIRECTLY */
2
+ /**********************************************************************
3
+
4
+ id.h -
5
+
6
+ $Author$
7
+ created at: Sun Oct 19 21:12:51 2008
8
+
9
+ Copyright (C) 2007 Koichi Sasada
10
+
11
+ **********************************************************************/
12
+
13
+ #ifndef RUBY_ID_H
14
+ #define RUBY_ID_H
15
+
16
+ enum ruby_id_types {
17
+ RUBY_ID_STATIC_SYM = 0x01,
18
+ RUBY_ID_LOCAL = 0x00,
19
+ RUBY_ID_INSTANCE = (0x01<<1),
20
+ RUBY_ID_GLOBAL = (0x03<<1),
21
+ RUBY_ID_ATTRSET = (0x04<<1),
22
+ RUBY_ID_CONST = (0x05<<1),
23
+ RUBY_ID_CLASS = (0x06<<1),
24
+ RUBY_ID_JUNK = (0x07<<1),
25
+ RUBY_ID_INTERNAL = RUBY_ID_JUNK,
26
+ RUBY_ID_SCOPE_SHIFT = 4,
27
+ RUBY_ID_SCOPE_MASK = (~(~0U<<(RUBY_ID_SCOPE_SHIFT-1))<<1)
28
+ };
29
+
30
+ #define ID_STATIC_SYM RUBY_ID_STATIC_SYM
31
+ #define ID_SCOPE_SHIFT RUBY_ID_SCOPE_SHIFT
32
+ #define ID_SCOPE_MASK RUBY_ID_SCOPE_MASK
33
+ #define ID_LOCAL RUBY_ID_LOCAL
34
+ #define ID_INSTANCE RUBY_ID_INSTANCE
35
+ #define ID_GLOBAL RUBY_ID_GLOBAL
36
+ #define ID_ATTRSET RUBY_ID_ATTRSET
37
+ #define ID_CONST RUBY_ID_CONST
38
+ #define ID_CLASS RUBY_ID_CLASS
39
+ #define ID_JUNK RUBY_ID_JUNK
40
+ #define ID_INTERNAL RUBY_ID_INTERNAL
41
+
42
+ #define symIFUNC ID2SYM(idIFUNC)
43
+ #define symCFUNC ID2SYM(idCFUNC)
44
+
45
+ #define RUBY_TOKEN_DOT2 128
46
+ #define RUBY_TOKEN_DOT3 129
47
+ #define RUBY_TOKEN_BDOT2 130
48
+ #define RUBY_TOKEN_BDOT3 131
49
+ #define RUBY_TOKEN_UPLUS 132
50
+ #define RUBY_TOKEN_UMINUS 133
51
+ #define RUBY_TOKEN_POW 134
52
+ #define RUBY_TOKEN_CMP 135
53
+ #define RUBY_TOKEN_LSHFT 136
54
+ #define RUBY_TOKEN_RSHFT 137
55
+ #define RUBY_TOKEN_LEQ 138
56
+ #define RUBY_TOKEN_GEQ 139
57
+ #define RUBY_TOKEN_EQ 140
58
+ #define RUBY_TOKEN_EQQ 141
59
+ #define RUBY_TOKEN_NEQ 142
60
+ #define RUBY_TOKEN_MATCH 143
61
+ #define RUBY_TOKEN_NMATCH 144
62
+ #define RUBY_TOKEN_AREF 145
63
+ #define RUBY_TOKEN_ASET 146
64
+ #define RUBY_TOKEN_COLON2 147
65
+ #define RUBY_TOKEN_ANDOP 148
66
+ #define RUBY_TOKEN_OROP 149
67
+ #define RUBY_TOKEN_ANDDOT 150
68
+ #define RUBY_TOKEN(t) RUBY_TOKEN_##t
69
+
70
+ #define RUBY_TOKEN2ID_TYPE(tok, type) ((tok<<RUBY_ID_SCOPE_SHIFT)|type|RUBY_ID_STATIC_SYM)
71
+ #define TOKEN2LOCALID(tok) RUBY_TOKEN2ID_TYPE(tok, RUBY_ID_LOCAL)
72
+ #define TOKEN2INSTANCEID(tok) RUBY_TOKEN2ID_TYPE(tok, RUBY_ID_INSTANCE)
73
+ #define TOKEN2GLOBALID(tok) RUBY_TOKEN2ID_TYPE(tok, RUBY_ID_GLOBAL)
74
+ #define TOKEN2CONSTID(tok) RUBY_TOKEN2ID_TYPE(tok, RUBY_ID_CONST)
75
+ #define TOKEN2CLASSID(tok) RUBY_TOKEN2ID_TYPE(tok, RUBY_ID_CLASS)
76
+ #define TOKEN2ATTRSETID(tok) RUBY_TOKEN2ID_TYPE(tok, RUBY_ID_ATTRSET)
77
+
78
+ enum ruby_method_ids {
79
+ idDot2 = RUBY_TOKEN(DOT2),
80
+ idDot3 = RUBY_TOKEN(DOT3),
81
+ idUPlus = RUBY_TOKEN(UPLUS),
82
+ idUMinus = RUBY_TOKEN(UMINUS),
83
+ idPow = RUBY_TOKEN(POW),
84
+ idCmp = RUBY_TOKEN(CMP),
85
+ idPLUS = '+',
86
+ idMINUS = '-',
87
+ idMULT = '*',
88
+ idDIV = '/',
89
+ idMOD = '%',
90
+ idLTLT = RUBY_TOKEN(LSHFT),
91
+ idGTGT = RUBY_TOKEN(RSHFT),
92
+ idLT = '<',
93
+ idLE = RUBY_TOKEN(LEQ),
94
+ idGT = '>',
95
+ idGE = RUBY_TOKEN(GEQ),
96
+ idEq = RUBY_TOKEN(EQ),
97
+ idEqq = RUBY_TOKEN(EQQ),
98
+ idNeq = RUBY_TOKEN(NEQ),
99
+ idNot = '!',
100
+ idAnd = '&',
101
+ idOr = '|',
102
+ idBackquote = '`',
103
+ idEqTilde = RUBY_TOKEN(MATCH),
104
+ idNeqTilde = RUBY_TOKEN(NMATCH),
105
+ idAREF = RUBY_TOKEN(AREF),
106
+ idASET = RUBY_TOKEN(ASET),
107
+ idCOLON2 = RUBY_TOKEN(COLON2),
108
+ idANDOP = RUBY_TOKEN(ANDOP),
109
+ idOROP = RUBY_TOKEN(OROP),
110
+ idANDDOT = RUBY_TOKEN(ANDDOT),
111
+ tPRESERVED_ID_BEGIN = 150,
112
+ idNilP,
113
+ idNULL,
114
+ idEmptyP,
115
+ idEqlP,
116
+ idRespond_to,
117
+ idRespond_to_missing,
118
+ idIFUNC,
119
+ idCFUNC,
120
+ id_core_set_method_alias,
121
+ id_core_set_variable_alias,
122
+ id_core_undef_method,
123
+ id_core_define_method,
124
+ id_core_define_singleton_method,
125
+ id_core_set_postexe,
126
+ id_core_hash_merge_ptr,
127
+ id_core_hash_merge_kwd,
128
+ id_core_raise,
129
+ id_core_sprintf,
130
+ id_debug_created_info,
131
+ tPRESERVED_ID_END,
132
+
133
+ /* LOCAL tokens {{{ */
134
+ tTOKEN_LOCAL_BEGIN = tPRESERVED_ID_END-1,
135
+ tMax,
136
+ tMin,
137
+ tHash,
138
+ tFreeze,
139
+ tInspect,
140
+ tIntern,
141
+ tObject_id,
142
+ tConst_added,
143
+ tConst_missing,
144
+ tMethodMissing,
145
+ tMethod_added,
146
+ tSingleton_method_added,
147
+ tMethod_removed,
148
+ tSingleton_method_removed,
149
+ tMethod_undefined,
150
+ tSingleton_method_undefined,
151
+ tLength,
152
+ tSize,
153
+ tGets,
154
+ tSucc,
155
+ tEach,
156
+ tProc,
157
+ tLambda,
158
+ tSend,
159
+ t__send__,
160
+ t__recursive_key__,
161
+ tInitialize,
162
+ tInitialize_copy,
163
+ tInitialize_clone,
164
+ tInitialize_dup,
165
+ tTo_int,
166
+ tTo_ary,
167
+ tTo_str,
168
+ tTo_sym,
169
+ tTo_hash,
170
+ tTo_proc,
171
+ tTo_io,
172
+ tTo_a,
173
+ tTo_s,
174
+ tTo_i,
175
+ tTo_f,
176
+ tTo_r,
177
+ tBt,
178
+ tBt_locations,
179
+ tCall,
180
+ tMesg,
181
+ tException,
182
+ tLocals,
183
+ tNOT,
184
+ tAND,
185
+ tOR,
186
+ tDiv,
187
+ tDivmod,
188
+ tFdiv,
189
+ tQuo,
190
+ tName,
191
+ tNil,
192
+ tPath,
193
+ tPack,
194
+ tBuffer,
195
+ tUScore,
196
+ tNUMPARAM_1,
197
+ tNUMPARAM_2,
198
+ tNUMPARAM_3,
199
+ tNUMPARAM_4,
200
+ tNUMPARAM_5,
201
+ tNUMPARAM_6,
202
+ tNUMPARAM_7,
203
+ tNUMPARAM_8,
204
+ tNUMPARAM_9,
205
+ tDefault,
206
+ tTOKEN_LOCAL_END,
207
+ /* LOCAL tokens }}} */
208
+
209
+ /* INSTANCE tokens {{{ */
210
+ tTOKEN_INSTANCE_BEGIN = tTOKEN_LOCAL_END-1,
211
+ tTOKEN_INSTANCE_END,
212
+ /* INSTANCE tokens }}} */
213
+
214
+ /* GLOBAL tokens {{{ */
215
+ tTOKEN_GLOBAL_BEGIN = tTOKEN_INSTANCE_END-1,
216
+ tLASTLINE,
217
+ tBACKREF,
218
+ tERROR_INFO,
219
+ tTOKEN_GLOBAL_END,
220
+ /* GLOBAL tokens }}} */
221
+
222
+ /* CONST tokens {{{ */
223
+ tTOKEN_CONST_BEGIN = tTOKEN_GLOBAL_END-1,
224
+ tTOKEN_CONST_END,
225
+ /* CONST tokens }}} */
226
+
227
+ /* CLASS tokens {{{ */
228
+ tTOKEN_CLASS_BEGIN = tTOKEN_CONST_END-1,
229
+ tTOKEN_CLASS_END,
230
+ /* CLASS tokens }}} */
231
+
232
+ /* ATTRSET tokens {{{ */
233
+ tTOKEN_ATTRSET_BEGIN = tTOKEN_CLASS_END-1,
234
+ tTOKEN_ATTRSET_END,
235
+ /* ATTRSET tokens }}} */
236
+
237
+ tNEXT_ID = tTOKEN_ATTRSET_END,
238
+
239
+ /* LOCAL IDs {{{ */
240
+ #define DEFINE_LOCALID_FROM_TOKEN(n) id##n = TOKEN2LOCALID(t##n)
241
+ DEFINE_LOCALID_FROM_TOKEN(Max),
242
+ DEFINE_LOCALID_FROM_TOKEN(Min),
243
+ DEFINE_LOCALID_FROM_TOKEN(Hash),
244
+ DEFINE_LOCALID_FROM_TOKEN(Freeze),
245
+ DEFINE_LOCALID_FROM_TOKEN(Inspect),
246
+ DEFINE_LOCALID_FROM_TOKEN(Intern),
247
+ DEFINE_LOCALID_FROM_TOKEN(Object_id),
248
+ DEFINE_LOCALID_FROM_TOKEN(Const_added),
249
+ DEFINE_LOCALID_FROM_TOKEN(Const_missing),
250
+ DEFINE_LOCALID_FROM_TOKEN(MethodMissing),
251
+ DEFINE_LOCALID_FROM_TOKEN(Method_added),
252
+ DEFINE_LOCALID_FROM_TOKEN(Singleton_method_added),
253
+ DEFINE_LOCALID_FROM_TOKEN(Method_removed),
254
+ DEFINE_LOCALID_FROM_TOKEN(Singleton_method_removed),
255
+ DEFINE_LOCALID_FROM_TOKEN(Method_undefined),
256
+ DEFINE_LOCALID_FROM_TOKEN(Singleton_method_undefined),
257
+ DEFINE_LOCALID_FROM_TOKEN(Length),
258
+ DEFINE_LOCALID_FROM_TOKEN(Size),
259
+ DEFINE_LOCALID_FROM_TOKEN(Gets),
260
+ DEFINE_LOCALID_FROM_TOKEN(Succ),
261
+ DEFINE_LOCALID_FROM_TOKEN(Each),
262
+ DEFINE_LOCALID_FROM_TOKEN(Proc),
263
+ DEFINE_LOCALID_FROM_TOKEN(Lambda),
264
+ DEFINE_LOCALID_FROM_TOKEN(Send),
265
+ DEFINE_LOCALID_FROM_TOKEN(__send__),
266
+ DEFINE_LOCALID_FROM_TOKEN(__recursive_key__),
267
+ DEFINE_LOCALID_FROM_TOKEN(Initialize),
268
+ DEFINE_LOCALID_FROM_TOKEN(Initialize_copy),
269
+ DEFINE_LOCALID_FROM_TOKEN(Initialize_clone),
270
+ DEFINE_LOCALID_FROM_TOKEN(Initialize_dup),
271
+ DEFINE_LOCALID_FROM_TOKEN(To_int),
272
+ DEFINE_LOCALID_FROM_TOKEN(To_ary),
273
+ DEFINE_LOCALID_FROM_TOKEN(To_str),
274
+ DEFINE_LOCALID_FROM_TOKEN(To_sym),
275
+ DEFINE_LOCALID_FROM_TOKEN(To_hash),
276
+ DEFINE_LOCALID_FROM_TOKEN(To_proc),
277
+ DEFINE_LOCALID_FROM_TOKEN(To_io),
278
+ DEFINE_LOCALID_FROM_TOKEN(To_a),
279
+ DEFINE_LOCALID_FROM_TOKEN(To_s),
280
+ DEFINE_LOCALID_FROM_TOKEN(To_i),
281
+ DEFINE_LOCALID_FROM_TOKEN(To_f),
282
+ DEFINE_LOCALID_FROM_TOKEN(To_r),
283
+ DEFINE_LOCALID_FROM_TOKEN(Bt),
284
+ DEFINE_LOCALID_FROM_TOKEN(Bt_locations),
285
+ DEFINE_LOCALID_FROM_TOKEN(Call),
286
+ DEFINE_LOCALID_FROM_TOKEN(Mesg),
287
+ DEFINE_LOCALID_FROM_TOKEN(Exception),
288
+ DEFINE_LOCALID_FROM_TOKEN(Locals),
289
+ DEFINE_LOCALID_FROM_TOKEN(NOT),
290
+ DEFINE_LOCALID_FROM_TOKEN(AND),
291
+ DEFINE_LOCALID_FROM_TOKEN(OR),
292
+ DEFINE_LOCALID_FROM_TOKEN(Div),
293
+ DEFINE_LOCALID_FROM_TOKEN(Divmod),
294
+ DEFINE_LOCALID_FROM_TOKEN(Fdiv),
295
+ DEFINE_LOCALID_FROM_TOKEN(Quo),
296
+ DEFINE_LOCALID_FROM_TOKEN(Name),
297
+ DEFINE_LOCALID_FROM_TOKEN(Nil),
298
+ DEFINE_LOCALID_FROM_TOKEN(Path),
299
+ DEFINE_LOCALID_FROM_TOKEN(Pack),
300
+ DEFINE_LOCALID_FROM_TOKEN(Buffer),
301
+ DEFINE_LOCALID_FROM_TOKEN(UScore),
302
+ DEFINE_LOCALID_FROM_TOKEN(NUMPARAM_1),
303
+ DEFINE_LOCALID_FROM_TOKEN(NUMPARAM_2),
304
+ DEFINE_LOCALID_FROM_TOKEN(NUMPARAM_3),
305
+ DEFINE_LOCALID_FROM_TOKEN(NUMPARAM_4),
306
+ DEFINE_LOCALID_FROM_TOKEN(NUMPARAM_5),
307
+ DEFINE_LOCALID_FROM_TOKEN(NUMPARAM_6),
308
+ DEFINE_LOCALID_FROM_TOKEN(NUMPARAM_7),
309
+ DEFINE_LOCALID_FROM_TOKEN(NUMPARAM_8),
310
+ DEFINE_LOCALID_FROM_TOKEN(NUMPARAM_9),
311
+ DEFINE_LOCALID_FROM_TOKEN(Default),
312
+ #undef DEFINE_LOCALID_FROM_TOKEN
313
+ /* LOCAL IDs }}} */
314
+
315
+ /* INSTANCE IDs {{{ */
316
+ #define DEFINE_INSTANCEID_FROM_TOKEN(n) id##n = TOKEN2INSTANCEID(t##n)
317
+ #undef DEFINE_INSTANCEID_FROM_TOKEN
318
+ /* INSTANCE IDs }}} */
319
+
320
+ /* GLOBAL IDs {{{ */
321
+ #define DEFINE_GLOBALID_FROM_TOKEN(n) id##n = TOKEN2GLOBALID(t##n)
322
+ DEFINE_GLOBALID_FROM_TOKEN(LASTLINE),
323
+ DEFINE_GLOBALID_FROM_TOKEN(BACKREF),
324
+ DEFINE_GLOBALID_FROM_TOKEN(ERROR_INFO),
325
+ #undef DEFINE_GLOBALID_FROM_TOKEN
326
+ /* GLOBAL IDs }}} */
327
+
328
+ /* CONST IDs {{{ */
329
+ #define DEFINE_CONSTID_FROM_TOKEN(n) id##n = TOKEN2CONSTID(t##n)
330
+ #undef DEFINE_CONSTID_FROM_TOKEN
331
+ /* CONST IDs }}} */
332
+
333
+ /* CLASS IDs {{{ */
334
+ #define DEFINE_CLASSID_FROM_TOKEN(n) id##n = TOKEN2CLASSID(t##n)
335
+ #undef DEFINE_CLASSID_FROM_TOKEN
336
+ /* CLASS IDs }}} */
337
+
338
+ /* ATTRSET IDs {{{ */
339
+ #define DEFINE_ATTRSETID_FROM_TOKEN(n) id##n = TOKEN2ATTRSETID(t##n)
340
+ #undef DEFINE_ATTRSETID_FROM_TOKEN
341
+ /* ATTRSET IDs }}} */
342
+
343
+ tLAST_OP_ID = tPRESERVED_ID_END-1,
344
+ idLAST_OP_ID = tLAST_OP_ID >> ID_SCOPE_SHIFT
345
+ };
346
+
347
+ #endif /* RUBY_ID_H */
@@ -0,0 +1,39 @@
1
+ #ifndef RUBY_ID_TABLE_H
2
+ #define RUBY_ID_TABLE_H 1
3
+ #include "ruby/internal/config.h"
4
+ #include <stddef.h>
5
+ #include "ruby/ruby.h"
6
+
7
+ struct rb_id_table;
8
+
9
+ /* compatible with ST_* */
10
+ enum rb_id_table_iterator_result {
11
+ ID_TABLE_CONTINUE = ST_CONTINUE,
12
+ ID_TABLE_STOP = ST_STOP,
13
+ ID_TABLE_DELETE = ST_DELETE,
14
+ ID_TABLE_REPLACE = ST_REPLACE,
15
+ ID_TABLE_ITERATOR_RESULT_END
16
+ };
17
+
18
+ struct rb_id_table *rb_id_table_create(size_t size);
19
+ void rb_id_table_free(struct rb_id_table *tbl);
20
+ void rb_id_table_clear(struct rb_id_table *tbl);
21
+
22
+ size_t rb_id_table_memsize(const struct rb_id_table *tbl);
23
+
24
+ int rb_id_table_insert(struct rb_id_table *tbl, ID id, VALUE val);
25
+ int rb_id_table_lookup(struct rb_id_table *tbl, ID id, VALUE *valp);
26
+ int rb_id_table_delete(struct rb_id_table *tbl, ID id);
27
+
28
+ typedef enum rb_id_table_iterator_result rb_id_table_update_value_callback_func_t(VALUE *val, void *data, int existing);
29
+ typedef enum rb_id_table_iterator_result rb_id_table_foreach_func_t(ID id, VALUE val, void *data);
30
+ typedef enum rb_id_table_iterator_result rb_id_table_foreach_values_func_t(VALUE val, void *data);
31
+ void rb_id_table_foreach(struct rb_id_table *tbl, rb_id_table_foreach_func_t *func, void *data);
32
+ void rb_id_table_foreach_values(struct rb_id_table *tbl, rb_id_table_foreach_values_func_t *func, void *data);
33
+ void rb_id_table_foreach_values_with_replace(struct rb_id_table *tbl, rb_id_table_foreach_values_func_t *func, rb_id_table_update_value_callback_func_t *replace, void *data);
34
+
35
+ RUBY_SYMBOL_EXPORT_BEGIN
36
+ size_t rb_id_table_size(const struct rb_id_table *tbl);
37
+ RUBY_SYMBOL_EXPORT_END
38
+
39
+ #endif /* RUBY_ID_TABLE_H */
@@ -0,0 +1,151 @@
1
+ #ifndef INTERNAL_ARRAY_H /*-*-C-*-vi:se ft=c:*/
2
+ #define INTERNAL_ARRAY_H
3
+ /**
4
+ * @author Ruby developers <ruby-core@ruby-lang.org>
5
+ * @copyright This file is a part of the programming language Ruby.
6
+ * Permission is hereby granted, to either redistribute and/or
7
+ * modify this file, provided that the conditions mentioned in the
8
+ * file COPYING are met. Consult the file for details.
9
+ * @brief Internal header for Array.
10
+ */
11
+ #include "ruby/internal/config.h"
12
+ #include <stddef.h> /* for size_t */
13
+ #include "internal/static_assert.h" /* for STATIC_ASSERT */
14
+ #include "ruby/internal/stdbool.h" /* for bool */
15
+ #include "ruby/ruby.h" /* for RARRAY_LEN */
16
+
17
+ #ifndef ARRAY_DEBUG
18
+ # define ARRAY_DEBUG (0+RUBY_DEBUG)
19
+ #endif
20
+
21
+ #define RARRAY_SHARED_FLAG ELTS_SHARED
22
+ #define RARRAY_SHARED_ROOT_FLAG FL_USER12
23
+ #define RARRAY_PTR_IN_USE_FLAG FL_USER14
24
+
25
+ /* array.c */
26
+ VALUE rb_ary_hash_values(long len, const VALUE *elements);
27
+ VALUE rb_ary_last(int, const VALUE *, VALUE);
28
+ void rb_ary_set_len(VALUE, long);
29
+ void rb_ary_delete_same(VALUE, VALUE);
30
+ VALUE rb_ary_hidden_new_fill(long capa);
31
+ VALUE rb_ary_at(VALUE, VALUE);
32
+ size_t rb_ary_memsize(VALUE);
33
+ VALUE rb_to_array_type(VALUE obj);
34
+ VALUE rb_to_array(VALUE obj);
35
+ void rb_ary_cancel_sharing(VALUE ary);
36
+ size_t rb_ary_size_as_embedded(VALUE ary);
37
+ void rb_ary_make_embedded(VALUE ary);
38
+ bool rb_ary_embeddable_p(VALUE ary);
39
+ VALUE rb_ary_diff(VALUE ary1, VALUE ary2);
40
+
41
+ static inline VALUE rb_ary_entry_internal(VALUE ary, long offset);
42
+ static inline bool ARY_PTR_USING_P(VALUE ary);
43
+
44
+ VALUE rb_ary_tmp_new_from_values(VALUE, long, const VALUE *);
45
+ VALUE rb_check_to_array(VALUE ary);
46
+ VALUE rb_ary_behead(VALUE, long);
47
+ VALUE rb_ary_aref1(VALUE ary, VALUE i);
48
+
49
+ struct rb_execution_context_struct;
50
+ VALUE rb_ec_ary_new_from_values(struct rb_execution_context_struct *ec, long n, const VALUE *elts);
51
+
52
+ // YJIT needs this function to never allocate and never raise
53
+ static inline VALUE
54
+ rb_ary_entry_internal(VALUE ary, long offset)
55
+ {
56
+ long len = RARRAY_LEN(ary);
57
+ const VALUE *ptr = RARRAY_CONST_PTR(ary);
58
+ if (len == 0) return Qnil;
59
+ if (offset < 0) {
60
+ offset += len;
61
+ if (offset < 0) return Qnil;
62
+ }
63
+ else if (len <= offset) {
64
+ return Qnil;
65
+ }
66
+ return ptr[offset];
67
+ }
68
+
69
+ static inline bool
70
+ ARY_PTR_USING_P(VALUE ary)
71
+ {
72
+ return FL_TEST_RAW(ary, RARRAY_PTR_IN_USE_FLAG);
73
+ }
74
+
75
+ RBIMPL_ATTR_MAYBE_UNUSED()
76
+ static inline int
77
+ ary_should_not_be_shared_and_embedded(VALUE ary)
78
+ {
79
+ return !FL_ALL_RAW(ary, RARRAY_SHARED_FLAG|RARRAY_EMBED_FLAG);
80
+ }
81
+
82
+ static inline bool
83
+ ARY_SHARED_P(VALUE ary)
84
+ {
85
+ assert(RB_TYPE_P(ary, T_ARRAY));
86
+ assert(ary_should_not_be_shared_and_embedded(ary));
87
+ return FL_TEST_RAW(ary, RARRAY_SHARED_FLAG);
88
+ }
89
+
90
+ static inline bool
91
+ ARY_EMBED_P(VALUE ary)
92
+ {
93
+ assert(RB_TYPE_P(ary, T_ARRAY));
94
+ assert(ary_should_not_be_shared_and_embedded(ary));
95
+ return FL_TEST_RAW(ary, RARRAY_EMBED_FLAG);
96
+ }
97
+
98
+ static inline VALUE
99
+ ARY_SHARED_ROOT(VALUE ary)
100
+ {
101
+ assert(ARY_SHARED_P(ary));
102
+ return RARRAY(ary)->as.heap.aux.shared_root;
103
+ }
104
+
105
+ static inline bool
106
+ ARY_SHARED_ROOT_P(VALUE ary)
107
+ {
108
+ assert(RB_TYPE_P(ary, T_ARRAY));
109
+ return FL_TEST_RAW(ary, RARRAY_SHARED_ROOT_FLAG);
110
+ }
111
+
112
+ static inline long
113
+ ARY_SHARED_ROOT_REFCNT(VALUE ary)
114
+ {
115
+ assert(ARY_SHARED_ROOT_P(ary));
116
+ return RARRAY(ary)->as.heap.aux.capa;
117
+ }
118
+
119
+ #undef rb_ary_new_from_args
120
+ #if RBIMPL_HAS_WARNING("-Wgnu-zero-variadic-macro-arguments")
121
+ # /* Skip it; clang -pedantic doesn't like the following */
122
+ #elif defined(__GNUC__) && defined(HAVE_VA_ARGS_MACRO)
123
+ #define rb_ary_new_from_args(n, ...) \
124
+ __extension__ ({ \
125
+ const VALUE args_to_new_ary[] = {__VA_ARGS__}; \
126
+ if (__builtin_constant_p(n)) { \
127
+ STATIC_ASSERT(rb_ary_new_from_args, numberof(args_to_new_ary) == (n)); \
128
+ } \
129
+ rb_ary_new_from_values(numberof(args_to_new_ary), args_to_new_ary); \
130
+ })
131
+ #endif
132
+
133
+ #undef RARRAY_AREF
134
+ RBIMPL_ATTR_PURE_UNLESS_DEBUG()
135
+ RBIMPL_ATTR_ARTIFICIAL()
136
+ static inline VALUE
137
+ RARRAY_AREF(VALUE ary, long i)
138
+ {
139
+ VALUE val;
140
+ RBIMPL_ASSERT_TYPE(ary, RUBY_T_ARRAY);
141
+
142
+ RBIMPL_WARNING_PUSH();
143
+ #if defined(__GNUC__) && !defined(__clang__) && __GNUC__ == 13
144
+ RBIMPL_WARNING_IGNORED(-Warray-bounds);
145
+ #endif
146
+ val = RARRAY_CONST_PTR(ary)[i];
147
+ RBIMPL_WARNING_POP();
148
+ return val;
149
+ }
150
+
151
+ #endif /* INTERNAL_ARRAY_H */
@@ -0,0 +1,64 @@
1
+ #ifndef INTERNAL_BOP_H /*-*-C-*-vi:se ft=c:*/
2
+ #define INTERNAL_BOP_H
3
+
4
+ #include "internal.h"
5
+ #include "ruby/internal/dllexport.h"
6
+
7
+ enum ruby_basic_operators {
8
+ BOP_PLUS,
9
+ BOP_MINUS,
10
+ BOP_MULT,
11
+ BOP_DIV,
12
+ BOP_MOD,
13
+ BOP_EQ,
14
+ BOP_EQQ,
15
+ BOP_LT,
16
+ BOP_LE,
17
+ BOP_LTLT,
18
+ BOP_AREF,
19
+ BOP_ASET,
20
+ BOP_LENGTH,
21
+ BOP_SIZE,
22
+ BOP_EMPTY_P,
23
+ BOP_NIL_P,
24
+ BOP_SUCC,
25
+ BOP_GT,
26
+ BOP_GE,
27
+ BOP_NOT,
28
+ BOP_NEQ,
29
+ BOP_MATCH,
30
+ BOP_FREEZE,
31
+ BOP_UMINUS,
32
+ BOP_MAX,
33
+ BOP_MIN,
34
+ BOP_HASH,
35
+ BOP_CALL,
36
+ BOP_AND,
37
+ BOP_OR,
38
+ BOP_CMP,
39
+ BOP_DEFAULT,
40
+ BOP_PACK,
41
+
42
+ BOP_LAST_
43
+ };
44
+
45
+ RUBY_EXTERN short ruby_vm_redefined_flag[BOP_LAST_];
46
+
47
+ /* optimize insn */
48
+ #define INTEGER_REDEFINED_OP_FLAG (1 << 0)
49
+ #define FLOAT_REDEFINED_OP_FLAG (1 << 1)
50
+ #define STRING_REDEFINED_OP_FLAG (1 << 2)
51
+ #define ARRAY_REDEFINED_OP_FLAG (1 << 3)
52
+ #define HASH_REDEFINED_OP_FLAG (1 << 4)
53
+ /* #define BIGNUM_REDEFINED_OP_FLAG (1 << 5) */
54
+ #define SYMBOL_REDEFINED_OP_FLAG (1 << 6)
55
+ #define TIME_REDEFINED_OP_FLAG (1 << 7)
56
+ #define REGEXP_REDEFINED_OP_FLAG (1 << 8)
57
+ #define NIL_REDEFINED_OP_FLAG (1 << 9)
58
+ #define TRUE_REDEFINED_OP_FLAG (1 << 10)
59
+ #define FALSE_REDEFINED_OP_FLAG (1 << 11)
60
+ #define PROC_REDEFINED_OP_FLAG (1 << 12)
61
+
62
+ #define BASIC_OP_UNREDEFINED_P(op, klass) (LIKELY((ruby_vm_redefined_flag[(op)]&(klass)) == 0))
63
+
64
+ #endif