prism 0.16.0 → 0.17.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +16 -1
  3. data/Makefile +6 -0
  4. data/README.md +1 -1
  5. data/config.yml +50 -35
  6. data/docs/fuzzing.md +1 -1
  7. data/docs/serialization.md +28 -29
  8. data/ext/prism/api_node.c +802 -770
  9. data/ext/prism/api_pack.c +20 -9
  10. data/ext/prism/extension.c +464 -162
  11. data/ext/prism/extension.h +1 -1
  12. data/include/prism/ast.h +3173 -763
  13. data/include/prism/defines.h +32 -9
  14. data/include/prism/diagnostic.h +36 -3
  15. data/include/prism/enc/pm_encoding.h +118 -28
  16. data/include/prism/node.h +38 -13
  17. data/include/prism/options.h +204 -0
  18. data/include/prism/pack.h +44 -33
  19. data/include/prism/parser.h +445 -200
  20. data/include/prism/prettyprint.h +12 -1
  21. data/include/prism/regexp.h +16 -2
  22. data/include/prism/util/pm_buffer.h +94 -16
  23. data/include/prism/util/pm_char.h +162 -48
  24. data/include/prism/util/pm_constant_pool.h +126 -32
  25. data/include/prism/util/pm_list.h +68 -38
  26. data/include/prism/util/pm_memchr.h +18 -3
  27. data/include/prism/util/pm_newline_list.h +70 -27
  28. data/include/prism/util/pm_state_stack.h +25 -7
  29. data/include/prism/util/pm_string.h +115 -27
  30. data/include/prism/util/pm_string_list.h +25 -6
  31. data/include/prism/util/pm_strncasecmp.h +32 -0
  32. data/include/prism/util/pm_strpbrk.h +31 -17
  33. data/include/prism/version.h +27 -2
  34. data/include/prism.h +224 -31
  35. data/lib/prism/compiler.rb +6 -3
  36. data/lib/prism/debug.rb +23 -7
  37. data/lib/prism/dispatcher.rb +33 -18
  38. data/lib/prism/dsl.rb +10 -5
  39. data/lib/prism/ffi.rb +132 -80
  40. data/lib/prism/lex_compat.rb +25 -15
  41. data/lib/prism/mutation_compiler.rb +10 -5
  42. data/lib/prism/node.rb +370 -135
  43. data/lib/prism/node_ext.rb +1 -1
  44. data/lib/prism/node_inspector.rb +1 -1
  45. data/lib/prism/pack.rb +79 -40
  46. data/lib/prism/parse_result/comments.rb +7 -2
  47. data/lib/prism/parse_result/newlines.rb +4 -0
  48. data/lib/prism/parse_result.rb +150 -30
  49. data/lib/prism/pattern.rb +11 -0
  50. data/lib/prism/ripper_compat.rb +28 -10
  51. data/lib/prism/serialize.rb +86 -54
  52. data/lib/prism/visitor.rb +10 -3
  53. data/lib/prism.rb +20 -2
  54. data/prism.gemspec +4 -2
  55. data/rbi/prism.rbi +104 -60
  56. data/rbi/prism_static.rbi +16 -2
  57. data/sig/prism.rbs +72 -43
  58. data/sig/prism_static.rbs +14 -1
  59. data/src/diagnostic.c +56 -53
  60. data/src/enc/pm_big5.c +1 -0
  61. data/src/enc/pm_euc_jp.c +1 -0
  62. data/src/enc/pm_gbk.c +1 -0
  63. data/src/enc/pm_shift_jis.c +1 -0
  64. data/src/enc/pm_tables.c +316 -80
  65. data/src/enc/pm_unicode.c +53 -8
  66. data/src/enc/pm_windows_31j.c +1 -0
  67. data/src/node.c +334 -321
  68. data/src/options.c +170 -0
  69. data/src/prettyprint.c +74 -47
  70. data/src/prism.c +1642 -856
  71. data/src/regexp.c +151 -95
  72. data/src/serialize.c +44 -20
  73. data/src/token_type.c +3 -1
  74. data/src/util/pm_buffer.c +45 -15
  75. data/src/util/pm_char.c +103 -57
  76. data/src/util/pm_constant_pool.c +51 -21
  77. data/src/util/pm_list.c +12 -4
  78. data/src/util/pm_memchr.c +5 -3
  79. data/src/util/pm_newline_list.c +20 -12
  80. data/src/util/pm_state_stack.c +9 -3
  81. data/src/util/pm_string.c +95 -85
  82. data/src/util/pm_string_list.c +14 -15
  83. data/src/util/pm_strncasecmp.c +10 -3
  84. data/src/util/pm_strpbrk.c +25 -19
  85. metadata +5 -3
  86. data/docs/prism.png +0 -0
data/src/util/pm_buffer.c CHANGED
@@ -1,12 +1,16 @@
1
1
  #include "prism/util/pm_buffer.h"
2
2
 
3
- // Return the size of the pm_buffer_t struct.
3
+ /**
4
+ * Return the size of the pm_buffer_t struct.
5
+ */
4
6
  size_t
5
7
  pm_buffer_sizeof(void) {
6
8
  return sizeof(pm_buffer_t);
7
9
  }
8
10
 
9
- // Initialize a pm_buffer_t with the given capacity.
11
+ /**
12
+ * Initialize a pm_buffer_t with the given capacity.
13
+ */
10
14
  bool
11
15
  pm_buffer_init_capacity(pm_buffer_t *buffer, size_t capacity) {
12
16
  buffer->length = 0;
@@ -16,25 +20,33 @@ pm_buffer_init_capacity(pm_buffer_t *buffer, size_t capacity) {
16
20
  return buffer->value != NULL;
17
21
  }
18
22
 
19
- // Initialize a pm_buffer_t with its default values.
23
+ /**
24
+ * Initialize a pm_buffer_t with its default values.
25
+ */
20
26
  bool
21
27
  pm_buffer_init(pm_buffer_t *buffer) {
22
28
  return pm_buffer_init_capacity(buffer, 1024);
23
29
  }
24
30
 
25
- // Return the value of the buffer.
31
+ /**
32
+ * Return the value of the buffer.
33
+ */
26
34
  char *
27
35
  pm_buffer_value(pm_buffer_t *buffer) {
28
36
  return buffer->value;
29
37
  }
30
38
 
31
- // Return the length of the buffer.
39
+ /**
40
+ * Return the length of the buffer.
41
+ */
32
42
  size_t
33
43
  pm_buffer_length(pm_buffer_t *buffer) {
34
44
  return buffer->length;
35
45
  }
36
46
 
37
- // Append the given amount of space to the buffer.
47
+ /**
48
+ * Append the given amount of space to the buffer.
49
+ */
38
50
  static inline void
39
51
  pm_buffer_append_length(pm_buffer_t *buffer, size_t length) {
40
52
  size_t next_length = buffer->length + length;
@@ -54,7 +66,9 @@ pm_buffer_append_length(pm_buffer_t *buffer, size_t length) {
54
66
  buffer->length = next_length;
55
67
  }
56
68
 
57
- // Append a generic pointer to memory to the buffer.
69
+ /**
70
+ * Append a generic pointer to memory to the buffer.
71
+ */
58
72
  static inline void
59
73
  pm_buffer_append(pm_buffer_t *buffer, const void *source, size_t length) {
60
74
  size_t cursor = buffer->length;
@@ -62,7 +76,9 @@ pm_buffer_append(pm_buffer_t *buffer, const void *source, size_t length) {
62
76
  memcpy(buffer->value + cursor, source, length);
63
77
  }
64
78
 
65
- // Append the given amount of space as zeroes to the buffer.
79
+ /**
80
+ * Append the given amount of space as zeroes to the buffer.
81
+ */
66
82
  void
67
83
  pm_buffer_append_zeroes(pm_buffer_t *buffer, size_t length) {
68
84
  size_t cursor = buffer->length;
@@ -70,7 +86,9 @@ pm_buffer_append_zeroes(pm_buffer_t *buffer, size_t length) {
70
86
  memset(buffer->value + cursor, 0, length);
71
87
  }
72
88
 
73
- // Append a formatted string to the buffer.
89
+ /**
90
+ * Append a formatted string to the buffer.
91
+ */
74
92
  void
75
93
  pm_buffer_append_format(pm_buffer_t *buffer, const char *format, ...) {
76
94
  va_list arguments;
@@ -91,26 +109,34 @@ pm_buffer_append_format(pm_buffer_t *buffer, const char *format, ...) {
91
109
  buffer->length--;
92
110
  }
93
111
 
94
- // Append a string to the buffer.
112
+ /**
113
+ * Append a string to the buffer.
114
+ */
95
115
  void
96
116
  pm_buffer_append_string(pm_buffer_t *buffer, const char *value, size_t length) {
97
117
  pm_buffer_append(buffer, value, length);
98
118
  }
99
119
 
100
- // Append a list of bytes to the buffer.
120
+ /**
121
+ * Append a list of bytes to the buffer.
122
+ */
101
123
  void
102
124
  pm_buffer_append_bytes(pm_buffer_t *buffer, const uint8_t *value, size_t length) {
103
125
  pm_buffer_append(buffer, (const char *) value, length);
104
126
  }
105
127
 
106
- // Append a single byte to the buffer.
128
+ /**
129
+ * Append a single byte to the buffer.
130
+ */
107
131
  void
108
132
  pm_buffer_append_byte(pm_buffer_t *buffer, uint8_t value) {
109
133
  const void *source = &value;
110
134
  pm_buffer_append(buffer, source, sizeof(uint8_t));
111
135
  }
112
136
 
113
- // Append a 32-bit unsigned integer to the buffer as a variable-length integer.
137
+ /**
138
+ * Append a 32-bit unsigned integer to the buffer as a variable-length integer.
139
+ */
114
140
  void
115
141
  pm_buffer_append_varint(pm_buffer_t *buffer, uint32_t value) {
116
142
  if (value < 128) {
@@ -125,7 +151,9 @@ pm_buffer_append_varint(pm_buffer_t *buffer, uint32_t value) {
125
151
  }
126
152
  }
127
153
 
128
- // Concatenate one buffer onto another.
154
+ /**
155
+ * Concatenate one buffer onto another.
156
+ */
129
157
  void
130
158
  pm_buffer_concat(pm_buffer_t *destination, const pm_buffer_t *source) {
131
159
  if (source->length > 0) {
@@ -133,7 +161,9 @@ pm_buffer_concat(pm_buffer_t *destination, const pm_buffer_t *source) {
133
161
  }
134
162
  }
135
163
 
136
- // Free the internal memory associated with the buffer.
164
+ /**
165
+ * Free the memory associated with the buffer.
166
+ */
137
167
  void
138
168
  pm_buffer_free(pm_buffer_t *buffer) {
139
169
  free(buffer->value);
data/src/util/pm_char.c CHANGED
@@ -53,6 +53,10 @@ static const uint8_t pm_number_table[256] = {
53
53
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Fx
54
54
  };
55
55
 
56
+ /**
57
+ * Returns the number of characters at the start of the string that match the
58
+ * given kind. Disallows searching past the given maximum number of characters.
59
+ */
56
60
  static inline size_t
57
61
  pm_strspn_char_kind(const uint8_t *string, ptrdiff_t length, uint8_t kind) {
58
62
  if (length <= 0) return 0;
@@ -64,16 +68,20 @@ pm_strspn_char_kind(const uint8_t *string, ptrdiff_t length, uint8_t kind) {
64
68
  return size;
65
69
  }
66
70
 
67
- // Returns the number of characters at the start of the string that are
68
- // whitespace. Disallows searching past the given maximum number of characters.
71
+ /**
72
+ * Returns the number of characters at the start of the string that are
73
+ * whitespace. Disallows searching past the given maximum number of characters.
74
+ */
69
75
  size_t
70
76
  pm_strspn_whitespace(const uint8_t *string, ptrdiff_t length) {
71
77
  return pm_strspn_char_kind(string, length, PRISM_CHAR_BIT_WHITESPACE);
72
78
  }
73
79
 
74
- // Returns the number of characters at the start of the string that are
75
- // whitespace while also tracking the location of each newline. Disallows
76
- // searching past the given maximum number of characters.
80
+ /**
81
+ * Returns the number of characters at the start of the string that are
82
+ * whitespace while also tracking the location of each newline. Disallows
83
+ * searching past the given maximum number of characters.
84
+ */
77
85
  size_t
78
86
  pm_strspn_whitespace_newlines(const uint8_t *string, ptrdiff_t length, pm_newline_list_t *newline_list) {
79
87
  if (length <= 0) return 0;
@@ -92,40 +100,53 @@ pm_strspn_whitespace_newlines(const uint8_t *string, ptrdiff_t length, pm_newlin
92
100
  return size;
93
101
  }
94
102
 
95
- // Returns the number of characters at the start of the string that are inline
96
- // whitespace. Disallows searching past the given maximum number of characters.
103
+ /**
104
+ * Returns the number of characters at the start of the string that are inline
105
+ * whitespace. Disallows searching past the given maximum number of characters.
106
+ */
97
107
  size_t
98
108
  pm_strspn_inline_whitespace(const uint8_t *string, ptrdiff_t length) {
99
109
  return pm_strspn_char_kind(string, length, PRISM_CHAR_BIT_INLINE_WHITESPACE);
100
110
  }
101
111
 
102
- // Returns the number of characters at the start of the string that are regexp
103
- // options. Disallows searching past the given maximum number of characters.
112
+ /**
113
+ * Returns the number of characters at the start of the string that are regexp
114
+ * options. Disallows searching past the given maximum number of characters.
115
+ */
104
116
  size_t
105
117
  pm_strspn_regexp_option(const uint8_t *string, ptrdiff_t length) {
106
118
  return pm_strspn_char_kind(string, length, PRISM_CHAR_BIT_REGEXP_OPTION);
107
119
  }
108
120
 
121
+ /**
122
+ * Returns true if the given character matches the given kind.
123
+ */
109
124
  static inline bool
110
125
  pm_char_is_char_kind(const uint8_t b, uint8_t kind) {
111
126
  return (pm_byte_table[b] & kind) != 0;
112
127
  }
113
128
 
114
- // Returns true if the given character is a whitespace character.
129
+ /**
130
+ * Returns true if the given character is a whitespace character.
131
+ */
115
132
  bool
116
133
  pm_char_is_whitespace(const uint8_t b) {
117
134
  return pm_char_is_char_kind(b, PRISM_CHAR_BIT_WHITESPACE);
118
135
  }
119
136
 
120
- // Returns true if the given character is an inline whitespace character.
137
+ /**
138
+ * Returns true if the given character is an inline whitespace character.
139
+ */
121
140
  bool
122
141
  pm_char_is_inline_whitespace(const uint8_t b) {
123
142
  return pm_char_is_char_kind(b, PRISM_CHAR_BIT_INLINE_WHITESPACE);
124
143
  }
125
144
 
126
- // Scan through the string and return the number of characters at the start of
127
- // the string that match the given kind. Disallows searching past the given
128
- // maximum number of characters.
145
+ /**
146
+ * Scan through the string and return the number of characters at the start of
147
+ * the string that match the given kind. Disallows searching past the given
148
+ * maximum number of characters.
149
+ */
129
150
  static inline size_t
130
151
  pm_strspn_number_kind(const uint8_t *string, ptrdiff_t length, uint8_t kind) {
131
152
  if (length <= 0) return 0;
@@ -137,12 +158,14 @@ pm_strspn_number_kind(const uint8_t *string, ptrdiff_t length, uint8_t kind) {
137
158
  return size;
138
159
  }
139
160
 
140
- // Scan through the string and return the number of characters at the start of
141
- // the string that match the given kind. Disallows searching past the given
142
- // maximum number of characters.
143
- //
144
- // Additionally, report the location of the last invalid underscore character
145
- // found in the string through the out invalid parameter.
161
+ /**
162
+ * Scan through the string and return the number of characters at the start of
163
+ * the string that match the given kind. Disallows searching past the given
164
+ * maximum number of characters.
165
+ *
166
+ * Additionally, report the location of the last invalid underscore character
167
+ * found in the string through the out invalid parameter.
168
+ */
146
169
  static inline size_t
147
170
  pm_strspn_number_kind_underscores(const uint8_t *string, ptrdiff_t length, const uint8_t **invalid, uint8_t kind) {
148
171
  if (length <= 0) return 0;
@@ -166,93 +189,116 @@ pm_strspn_number_kind_underscores(const uint8_t *string, ptrdiff_t length, const
166
189
  return size;
167
190
  }
168
191
 
169
- // Returns the number of characters at the start of the string that are binary
170
- // digits or underscores. Disallows searching past the given maximum number of
171
- // characters.
172
- //
173
- // If multiple underscores are found in a row or if an underscore is
174
- // found at the end of the number, then the invalid pointer is set to the index
175
- // of the first invalid underscore.
192
+ /**
193
+ * Returns the number of characters at the start of the string that are binary
194
+ * digits or underscores. Disallows searching past the given maximum number of
195
+ * characters.
196
+ *
197
+ * If multiple underscores are found in a row or if an underscore is
198
+ * found at the end of the number, then the invalid pointer is set to the index
199
+ * of the first invalid underscore.
200
+ */
176
201
  size_t
177
202
  pm_strspn_binary_number(const uint8_t *string, ptrdiff_t length, const uint8_t **invalid) {
178
203
  return pm_strspn_number_kind_underscores(string, length, invalid, PRISM_NUMBER_BIT_BINARY_NUMBER);
179
204
  }
180
205
 
181
- // Returns the number of characters at the start of the string that are octal
182
- // digits or underscores. Disallows searching past the given maximum number of
183
- // characters.
184
- //
185
- // If multiple underscores are found in a row or if an underscore is
186
- // found at the end of the number, then the invalid pointer is set to the index
187
- // of the first invalid underscore.
206
+ /**
207
+ * Returns the number of characters at the start of the string that are octal
208
+ * digits or underscores. Disallows searching past the given maximum number of
209
+ * characters.
210
+ *
211
+ * If multiple underscores are found in a row or if an underscore is
212
+ * found at the end of the number, then the invalid pointer is set to the index
213
+ * of the first invalid underscore.
214
+ */
188
215
  size_t
189
216
  pm_strspn_octal_number(const uint8_t *string, ptrdiff_t length, const uint8_t **invalid) {
190
217
  return pm_strspn_number_kind_underscores(string, length, invalid, PRISM_NUMBER_BIT_OCTAL_NUMBER);
191
218
  }
192
219
 
193
- // Returns the number of characters at the start of the string that are decimal
194
- // digits. Disallows searching past the given maximum number of characters.
220
+ /**
221
+ * Returns the number of characters at the start of the string that are decimal
222
+ * digits. Disallows searching past the given maximum number of characters.
223
+ */
195
224
  size_t
196
225
  pm_strspn_decimal_digit(const uint8_t *string, ptrdiff_t length) {
197
226
  return pm_strspn_number_kind(string, length, PRISM_NUMBER_BIT_DECIMAL_DIGIT);
198
227
  }
199
228
 
200
- // Returns the number of characters at the start of the string that are decimal
201
- // digits or underscores. Disallows searching past the given maximum number of
202
- // characters.
203
- //
204
- // If multiple underscores are found in a row or if an underscore is
205
- // found at the end of the number, then the invalid pointer is set to the index
206
- // of the first invalid underscore.
229
+ /**
230
+ * Returns the number of characters at the start of the string that are decimal
231
+ * digits or underscores. Disallows searching past the given maximum number of
232
+ * characters.
233
+ *
234
+ * If multiple underscores are found in a row or if an underscore is
235
+ * found at the end of the number, then the invalid pointer is set to the index
236
+ * of the first invalid underscore
237
+ */
207
238
  size_t
208
239
  pm_strspn_decimal_number(const uint8_t *string, ptrdiff_t length, const uint8_t **invalid) {
209
240
  return pm_strspn_number_kind_underscores(string, length, invalid, PRISM_NUMBER_BIT_DECIMAL_NUMBER);
210
241
  }
211
242
 
212
- // Returns the number of characters at the start of the string that are
213
- // hexadecimal digits. Disallows searching past the given maximum number of
214
- // characters.
243
+ /**
244
+ * Returns the number of characters at the start of the string that are
245
+ * hexadecimal digits. Disallows searching past the given maximum number of
246
+ * characters.
247
+ */
215
248
  size_t
216
249
  pm_strspn_hexadecimal_digit(const uint8_t *string, ptrdiff_t length) {
217
250
  return pm_strspn_number_kind(string, length, PRISM_NUMBER_BIT_HEXADECIMAL_DIGIT);
218
251
  }
219
252
 
220
- // Returns the number of characters at the start of the string that are
221
- // hexadecimal digits or underscores. Disallows searching past the given maximum
222
- // number of characters.
223
- //
224
- // If multiple underscores are found in a row or if an underscore is
225
- // found at the end of the number, then the invalid pointer is set to the index
226
- // of the first invalid underscore.
253
+ /**
254
+ * Returns the number of characters at the start of the string that are
255
+ * hexadecimal digits or underscores. Disallows searching past the given maximum
256
+ * number of characters.
257
+ *
258
+ * If multiple underscores are found in a row or if an underscore is
259
+ * found at the end of the number, then the invalid pointer is set to the index
260
+ * of the first invalid underscore.
261
+ */
227
262
  size_t
228
263
  pm_strspn_hexadecimal_number(const uint8_t *string, ptrdiff_t length, const uint8_t **invalid) {
229
264
  return pm_strspn_number_kind_underscores(string, length, invalid, PRISM_NUMBER_BIT_HEXADECIMAL_NUMBER);
230
265
  }
231
266
 
267
+ /**
268
+ * Returns true if the given character matches the given kind.
269
+ */
232
270
  static inline bool
233
271
  pm_char_is_number_kind(const uint8_t b, uint8_t kind) {
234
272
  return (pm_number_table[b] & kind) != 0;
235
273
  }
236
274
 
237
- // Returns true if the given character is a binary digit.
275
+ /**
276
+ * Returns true if the given character is a binary digit.
277
+ */
238
278
  bool
239
279
  pm_char_is_binary_digit(const uint8_t b) {
240
280
  return pm_char_is_number_kind(b, PRISM_NUMBER_BIT_BINARY_DIGIT);
241
281
  }
242
282
 
243
- // Returns true if the given character is an octal digit.
283
+ /**
284
+ * Returns true if the given character is an octal digit.
285
+ */
244
286
  bool
245
287
  pm_char_is_octal_digit(const uint8_t b) {
246
288
  return pm_char_is_number_kind(b, PRISM_NUMBER_BIT_OCTAL_DIGIT);
247
289
  }
248
290
 
249
- // Returns true if the given character is a decimal digit.
291
+ /**
292
+ * Returns true if the given character is a decimal digit.
293
+ */
250
294
  bool
251
295
  pm_char_is_decimal_digit(const uint8_t b) {
252
296
  return pm_char_is_number_kind(b, PRISM_NUMBER_BIT_DECIMAL_DIGIT);
253
297
  }
254
298
 
255
- // Returns true if the given character is a hexadecimal digit.
299
+ /**
300
+ * Returns true if the given character is a hexadecimal digit.
301
+ */
256
302
  bool
257
303
  pm_char_is_hexadecimal_digit(const uint8_t b) {
258
304
  return pm_char_is_number_kind(b, PRISM_NUMBER_BIT_HEXADECIMAL_DIGIT);
@@ -1,6 +1,8 @@
1
1
  #include "prism/util/pm_constant_pool.h"
2
2
 
3
- // Initialize a list of constant ids.
3
+ /**
4
+ * Initialize a list of constant ids.
5
+ */
4
6
  void
5
7
  pm_constant_id_list_init(pm_constant_id_list_t *list) {
6
8
  list->ids = NULL;
@@ -8,8 +10,10 @@ pm_constant_id_list_init(pm_constant_id_list_t *list) {
8
10
  list->capacity = 0;
9
11
  }
10
12
 
11
- // Append a constant id to a list of constant ids. Returns false if any
12
- // potential reallocations fail.
13
+ /**
14
+ * Append a constant id to a list of constant ids. Returns false if any
15
+ * potential reallocations fail.
16
+ */
13
17
  bool
14
18
  pm_constant_id_list_append(pm_constant_id_list_t *list, pm_constant_id_t id) {
15
19
  if (list->size >= list->capacity) {
@@ -22,7 +26,9 @@ pm_constant_id_list_append(pm_constant_id_list_t *list, pm_constant_id_t id) {
22
26
  return true;
23
27
  }
24
28
 
25
- // Checks if the current constant id list includes the given constant id.
29
+ /**
30
+ * Checks if the current constant id list includes the given constant id.
31
+ */
26
32
  bool
27
33
  pm_constant_id_list_includes(pm_constant_id_list_t *list, pm_constant_id_t id) {
28
34
  for (size_t index = 0; index < list->size; index++) {
@@ -31,13 +37,17 @@ pm_constant_id_list_includes(pm_constant_id_list_t *list, pm_constant_id_t id) {
31
37
  return false;
32
38
  }
33
39
 
34
- // Get the memory size of a list of constant ids.
40
+ /**
41
+ * Get the memory size of a list of constant ids.
42
+ */
35
43
  size_t
36
44
  pm_constant_id_list_memsize(pm_constant_id_list_t *list) {
37
45
  return sizeof(pm_constant_id_list_t) + (list->capacity * sizeof(pm_constant_id_t));
38
46
  }
39
47
 
40
- // Free the memory associated with a list of constant ids.
48
+ /**
49
+ * Free the memory associated with a list of constant ids.
50
+ */
41
51
  void
42
52
  pm_constant_id_list_free(pm_constant_id_list_t *list) {
43
53
  if (list->ids != NULL) {
@@ -45,8 +55,10 @@ pm_constant_id_list_free(pm_constant_id_list_t *list) {
45
55
  }
46
56
  }
47
57
 
48
- // A relatively simple hash function (djb2) that is used to hash strings. We are
49
- // optimizing here for simplicity and speed.
58
+ /**
59
+ * A relatively simple hash function (djb2) that is used to hash strings. We are
60
+ * optimizing here for simplicity and speed.
61
+ */
50
62
  static inline uint32_t
51
63
  pm_constant_pool_hash(const uint8_t *start, size_t length) {
52
64
  // This is a prime number used as the initial value for the hash function.
@@ -59,7 +71,9 @@ pm_constant_pool_hash(const uint8_t *start, size_t length) {
59
71
  return value;
60
72
  }
61
73
 
62
- // https://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2
74
+ /**
75
+ * https://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2
76
+ */
63
77
  static uint32_t
64
78
  next_power_of_two(uint32_t v) {
65
79
  // Avoid underflow in subtraction on next line.
@@ -84,7 +98,9 @@ is_power_of_two(uint32_t size) {
84
98
  }
85
99
  #endif
86
100
 
87
- // Resize a constant pool to a given capacity.
101
+ /**
102
+ * Resize a constant pool to a given capacity.
103
+ */
88
104
  static inline bool
89
105
  pm_constant_pool_resize(pm_constant_pool_t *pool) {
90
106
  assert(is_power_of_two(pool->capacity));
@@ -136,7 +152,9 @@ pm_constant_pool_resize(pm_constant_pool_t *pool) {
136
152
  return true;
137
153
  }
138
154
 
139
- // Initialize a new constant pool with a given capacity.
155
+ /**
156
+ * Initialize a new constant pool with a given capacity.
157
+ */
140
158
  bool
141
159
  pm_constant_pool_init(pm_constant_pool_t *pool, uint32_t capacity) {
142
160
  const uint32_t maximum = (~((uint32_t) 0));
@@ -154,14 +172,18 @@ pm_constant_pool_init(pm_constant_pool_t *pool, uint32_t capacity) {
154
172
  return true;
155
173
  }
156
174
 
157
- // Return a pointer to the constant indicated by the given constant id.
175
+ /**
176
+ * Return a pointer to the constant indicated by the given constant id.
177
+ */
158
178
  pm_constant_t *
159
179
  pm_constant_pool_id_to_constant(const pm_constant_pool_t *pool, pm_constant_id_t constant_id) {
160
180
  assert(constant_id > 0 && constant_id <= pool->size);
161
181
  return &pool->constants[constant_id - 1];
162
182
  }
163
183
 
164
- // Insert a constant into a constant pool and return its index in the pool.
184
+ /**
185
+ * Insert a constant into a constant pool and return its index in the pool.
186
+ */
165
187
  static inline pm_constant_id_t
166
188
  pm_constant_pool_insert(pm_constant_pool_t *pool, const uint8_t *start, size_t length, pm_constant_pool_bucket_type_t type) {
167
189
  if (pool->size >= (pool->capacity / 4 * 3)) {
@@ -225,29 +247,37 @@ pm_constant_pool_insert(pm_constant_pool_t *pool, const uint8_t *start, size_t l
225
247
  return id;
226
248
  }
227
249
 
228
- // Insert a constant into a constant pool. Returns the id of the constant, or 0
229
- // if any potential calls to resize fail.
250
+ /**
251
+ * Insert a constant into a constant pool. Returns the id of the constant, or 0
252
+ * if any potential calls to resize fail.
253
+ */
230
254
  pm_constant_id_t
231
255
  pm_constant_pool_insert_shared(pm_constant_pool_t *pool, const uint8_t *start, size_t length) {
232
256
  return pm_constant_pool_insert(pool, start, length, PM_CONSTANT_POOL_BUCKET_DEFAULT);
233
257
  }
234
258
 
235
- // Insert a constant into a constant pool from memory that is now owned by the
236
- // constant pool. Returns the id of the constant, or 0 if any potential calls to
237
- // resize fail.
259
+ /**
260
+ * Insert a constant into a constant pool from memory that is now owned by the
261
+ * constant pool. Returns the id of the constant, or 0 if any potential calls to
262
+ * resize fail.
263
+ */
238
264
  pm_constant_id_t
239
265
  pm_constant_pool_insert_owned(pm_constant_pool_t *pool, const uint8_t *start, size_t length) {
240
266
  return pm_constant_pool_insert(pool, start, length, PM_CONSTANT_POOL_BUCKET_OWNED);
241
267
  }
242
268
 
243
- // Insert a constant into a constant pool from memory that is constant. Returns
244
- // the id of the constant, or 0 if any potential calls to resize fail.
269
+ /**
270
+ * Insert a constant into a constant pool from memory that is constant. Returns
271
+ * the id of the constant, or 0 if any potential calls to resize fail.
272
+ */
245
273
  pm_constant_id_t
246
274
  pm_constant_pool_insert_constant(pm_constant_pool_t *pool, const uint8_t *start, size_t length) {
247
275
  return pm_constant_pool_insert(pool, start, length, PM_CONSTANT_POOL_BUCKET_CONSTANT);
248
276
  }
249
277
 
250
- // Free the memory associated with a constant pool.
278
+ /**
279
+ * Free the memory associated with a constant pool.
280
+ */
251
281
  void
252
282
  pm_constant_pool_free(pm_constant_pool_t *pool) {
253
283
  // For each constant in the current constant pool, free the contents if the
data/src/util/pm_list.c CHANGED
@@ -1,18 +1,24 @@
1
1
  #include "prism/util/pm_list.h"
2
2
 
3
- // Returns true if the given list is empty.
3
+ /**
4
+ * Returns true if the given list is empty.
5
+ */
4
6
  PRISM_EXPORTED_FUNCTION bool
5
7
  pm_list_empty_p(pm_list_t *list) {
6
8
  return list->head == NULL;
7
9
  }
8
10
 
9
- // Returns the size of the list.
11
+ /**
12
+ * Returns the size of the list.
13
+ */
10
14
  PRISM_EXPORTED_FUNCTION size_t
11
15
  pm_list_size(pm_list_t *list) {
12
16
  return list->size;
13
17
  }
14
18
 
15
- // Append a node to the given list.
19
+ /**
20
+ * Append a node to the given list.
21
+ */
16
22
  void
17
23
  pm_list_append(pm_list_t *list, pm_list_node_t *node) {
18
24
  if (list->head == NULL) {
@@ -25,7 +31,9 @@ pm_list_append(pm_list_t *list, pm_list_node_t *node) {
25
31
  list->size++;
26
32
  }
27
33
 
28
- // Deallocate the internal state of the given list.
34
+ /**
35
+ * Deallocate the internal state of the given list.
36
+ */
29
37
  PRISM_EXPORTED_FUNCTION void
30
38
  pm_list_free(pm_list_t *list) {
31
39
  pm_list_node_t *node = list->head;
data/src/util/pm_memchr.c CHANGED
@@ -2,9 +2,11 @@
2
2
 
3
3
  #define PRISM_MEMCHR_TRAILING_BYTE_MINIMUM 0x40
4
4
 
5
- // We need to roll our own memchr to handle cases where the encoding changes and
6
- // we need to search for a character in a buffer that could be the trailing byte
7
- // of a multibyte character.
5
+ /**
6
+ * We need to roll our own memchr to handle cases where the encoding changes and
7
+ * we need to search for a character in a buffer that could be the trailing byte
8
+ * of a multibyte character.
9
+ */
8
10
  void *
9
11
  pm_memchr(const void *memory, int character, size_t number, bool encoding_changed, pm_encoding_t *encoding) {
10
12
  if (encoding_changed && encoding->multibyte && character >= PRISM_MEMCHR_TRAILING_BYTE_MINIMUM) {