datadog-ruby_core_source 3.4.0 → 3.4.1

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 (108) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.datadog.md +4 -0
  3. data/README.md +8 -5
  4. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/ccan/build_assert/build_assert.h +40 -0
  5. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/ccan/check_type/check_type.h +63 -0
  6. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/ccan/container_of/container_of.h +142 -0
  7. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/ccan/list/list.h +791 -0
  8. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/ccan/str/str.h +17 -0
  9. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/id.h +352 -0
  10. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/id_table.h +39 -0
  11. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/array.h +152 -0
  12. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/basic_operators.h +65 -0
  13. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/bignum.h +244 -0
  14. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/bits.h +650 -0
  15. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/class.h +283 -0
  16. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/cmdlineopt.h +61 -0
  17. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/compar.h +29 -0
  18. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/compile.h +34 -0
  19. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/compilers.h +107 -0
  20. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/complex.h +29 -0
  21. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/cont.h +35 -0
  22. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/dir.h +16 -0
  23. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/enc.h +19 -0
  24. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/encoding.h +38 -0
  25. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/enum.h +18 -0
  26. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/enumerator.h +21 -0
  27. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/error.h +244 -0
  28. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/eval.h +33 -0
  29. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/file.h +38 -0
  30. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/fixnum.h +185 -0
  31. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/gc.h +333 -0
  32. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/hash.h +193 -0
  33. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/imemo.h +257 -0
  34. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/inits.h +47 -0
  35. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/io.h +143 -0
  36. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/load.h +18 -0
  37. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/loadpath.h +16 -0
  38. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/math.h +23 -0
  39. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/missing.h +19 -0
  40. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/numeric.h +274 -0
  41. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/object.h +63 -0
  42. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/parse.h +131 -0
  43. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/proc.h +30 -0
  44. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/process.h +124 -0
  45. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/ractor.h +10 -0
  46. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/random.h +17 -0
  47. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/range.h +40 -0
  48. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/rational.h +71 -0
  49. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/re.h +28 -0
  50. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/ruby_parser.h +102 -0
  51. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/sanitizers.h +330 -0
  52. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/serial.h +23 -0
  53. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/signal.h +24 -0
  54. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/st.h +11 -0
  55. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/static_assert.h +16 -0
  56. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/string.h +199 -0
  57. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/struct.h +119 -0
  58. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/symbol.h +47 -0
  59. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/thread.h +108 -0
  60. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/time.h +37 -0
  61. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/transcode.h +23 -0
  62. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/util.h +27 -0
  63. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/variable.h +70 -0
  64. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/vm.h +137 -0
  65. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/warnings.h +16 -0
  66. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal.h +108 -0
  67. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/iseq.h +351 -0
  68. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/method.h +258 -0
  69. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/node.h +122 -0
  70. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/parser_st.h +162 -0
  71. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/parser_value.h +106 -0
  72. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/prism/ast.h +7964 -0
  73. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/prism/defines.h +260 -0
  74. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/prism/diagnostic.h +451 -0
  75. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/prism/encoding.h +283 -0
  76. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/prism/extension.h +19 -0
  77. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/prism/node.h +129 -0
  78. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/prism/options.h +442 -0
  79. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/prism/pack.h +163 -0
  80. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/prism/parser.h +933 -0
  81. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/prism/prettyprint.h +34 -0
  82. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/prism/prism.h +383 -0
  83. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/prism/regexp.h +43 -0
  84. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/prism/static_literals.h +121 -0
  85. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/prism/util/pm_buffer.h +228 -0
  86. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/prism/util/pm_char.h +204 -0
  87. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/prism/util/pm_constant_pool.h +218 -0
  88. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/prism/util/pm_integer.h +126 -0
  89. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/prism/util/pm_list.h +97 -0
  90. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/prism/util/pm_memchr.h +29 -0
  91. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/prism/util/pm_newline_list.h +113 -0
  92. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/prism/util/pm_string.h +190 -0
  93. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/prism/util/pm_strncasecmp.h +32 -0
  94. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/prism/util/pm_strpbrk.h +46 -0
  95. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/prism/version.h +29 -0
  96. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/prism_compile.h +105 -0
  97. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/ractor_core.h +382 -0
  98. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/ruby_assert.h +14 -0
  99. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/ruby_atomic.h +23 -0
  100. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/rubyparser.h +1380 -0
  101. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/shape.h +234 -0
  102. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/thread_none.h +21 -0
  103. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/thread_pthread.h +167 -0
  104. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/vm_core.h +2235 -0
  105. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/vm_debug.h +124 -0
  106. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/vm_opts.h +67 -0
  107. data/lib/datadog/ruby_core_source/version.rb +1 -1
  108. metadata +105 -2
@@ -0,0 +1,228 @@
1
+ /**
2
+ * @file pm_buffer.h
3
+ *
4
+ * A wrapper around a contiguous block of allocated memory.
5
+ */
6
+ #ifndef PRISM_BUFFER_H
7
+ #define PRISM_BUFFER_H
8
+
9
+ #include "prism/defines.h"
10
+ #include "prism/util/pm_char.h"
11
+
12
+ #include <assert.h>
13
+ #include <stdbool.h>
14
+ #include <stdint.h>
15
+ #include <stdlib.h>
16
+ #include <string.h>
17
+
18
+ /**
19
+ * A pm_buffer_t is a simple memory buffer that stores data in a contiguous
20
+ * block of memory.
21
+ */
22
+ typedef struct {
23
+ /** The length of the buffer in bytes. */
24
+ size_t length;
25
+
26
+ /** The capacity of the buffer in bytes that has been allocated. */
27
+ size_t capacity;
28
+
29
+ /** A pointer to the start of the buffer. */
30
+ char *value;
31
+ } pm_buffer_t;
32
+
33
+ /**
34
+ * Return the size of the pm_buffer_t struct.
35
+ *
36
+ * @returns The size of the pm_buffer_t struct.
37
+ */
38
+ PRISM_EXPORTED_FUNCTION size_t pm_buffer_sizeof(void);
39
+
40
+ /**
41
+ * Initialize a pm_buffer_t with the given capacity.
42
+ *
43
+ * @param buffer The buffer to initialize.
44
+ * @param capacity The capacity of the buffer.
45
+ * @returns True if the buffer was initialized successfully, false otherwise.
46
+ */
47
+ bool pm_buffer_init_capacity(pm_buffer_t *buffer, size_t capacity);
48
+
49
+ /**
50
+ * Initialize a pm_buffer_t with its default values.
51
+ *
52
+ * @param buffer The buffer to initialize.
53
+ * @returns True if the buffer was initialized successfully, false otherwise.
54
+ */
55
+ PRISM_EXPORTED_FUNCTION bool pm_buffer_init(pm_buffer_t *buffer);
56
+
57
+ /**
58
+ * Return the value of the buffer.
59
+ *
60
+ * @param buffer The buffer to get the value of.
61
+ * @returns The value of the buffer.
62
+ */
63
+ PRISM_EXPORTED_FUNCTION char * pm_buffer_value(const pm_buffer_t *buffer);
64
+
65
+ /**
66
+ * Return the length of the buffer.
67
+ *
68
+ * @param buffer The buffer to get the length of.
69
+ * @returns The length of the buffer.
70
+ */
71
+ PRISM_EXPORTED_FUNCTION size_t pm_buffer_length(const pm_buffer_t *buffer);
72
+
73
+ /**
74
+ * Append the given amount of space as zeroes to the buffer.
75
+ *
76
+ * @param buffer The buffer to append to.
77
+ * @param length The amount of space to append and zero.
78
+ */
79
+ void pm_buffer_append_zeroes(pm_buffer_t *buffer, size_t length);
80
+
81
+ /**
82
+ * Append a formatted string to the buffer.
83
+ *
84
+ * @param buffer The buffer to append to.
85
+ * @param format The format string to append.
86
+ * @param ... The arguments to the format string.
87
+ */
88
+ void pm_buffer_append_format(pm_buffer_t *buffer, const char *format, ...) PRISM_ATTRIBUTE_FORMAT(2, 3);
89
+
90
+ /**
91
+ * Append a string to the buffer.
92
+ *
93
+ * @param buffer The buffer to append to.
94
+ * @param value The string to append.
95
+ * @param length The length of the string to append.
96
+ */
97
+ void pm_buffer_append_string(pm_buffer_t *buffer, const char *value, size_t length);
98
+
99
+ /**
100
+ * Append a list of bytes to the buffer.
101
+ *
102
+ * @param buffer The buffer to append to.
103
+ * @param value The bytes to append.
104
+ * @param length The length of the bytes to append.
105
+ */
106
+ void pm_buffer_append_bytes(pm_buffer_t *buffer, const uint8_t *value, size_t length);
107
+
108
+ /**
109
+ * Append a single byte to the buffer.
110
+ *
111
+ * @param buffer The buffer to append to.
112
+ * @param value The byte to append.
113
+ */
114
+ void pm_buffer_append_byte(pm_buffer_t *buffer, uint8_t value);
115
+
116
+ /**
117
+ * Append a 32-bit unsigned integer to the buffer as a variable-length integer.
118
+ *
119
+ * @param buffer The buffer to append to.
120
+ * @param value The integer to append.
121
+ */
122
+ void pm_buffer_append_varuint(pm_buffer_t *buffer, uint32_t value);
123
+
124
+ /**
125
+ * Append a 32-bit signed integer to the buffer as a variable-length integer.
126
+ *
127
+ * @param buffer The buffer to append to.
128
+ * @param value The integer to append.
129
+ */
130
+ void pm_buffer_append_varsint(pm_buffer_t *buffer, int32_t value);
131
+
132
+ /**
133
+ * Append a double to the buffer.
134
+ *
135
+ * @param buffer The buffer to append to.
136
+ * @param value The double to append.
137
+ */
138
+ void pm_buffer_append_double(pm_buffer_t *buffer, double value);
139
+
140
+ /**
141
+ * Append a unicode codepoint to the buffer.
142
+ *
143
+ * @param buffer The buffer to append to.
144
+ * @param value The character to append.
145
+ * @returns True if the codepoint was valid and appended successfully, false
146
+ * otherwise.
147
+ */
148
+ bool pm_buffer_append_unicode_codepoint(pm_buffer_t *buffer, uint32_t value);
149
+
150
+ /**
151
+ * The different types of escaping that can be performed by the buffer when
152
+ * appending a slice of Ruby source code.
153
+ */
154
+ typedef enum {
155
+ PM_BUFFER_ESCAPING_RUBY,
156
+ PM_BUFFER_ESCAPING_JSON
157
+ } pm_buffer_escaping_t;
158
+
159
+ /**
160
+ * Append a slice of source code to the buffer.
161
+ *
162
+ * @param buffer The buffer to append to.
163
+ * @param source The source code to append.
164
+ * @param length The length of the source code to append.
165
+ * @param escaping The type of escaping to perform.
166
+ */
167
+ void pm_buffer_append_source(pm_buffer_t *buffer, const uint8_t *source, size_t length, pm_buffer_escaping_t escaping);
168
+
169
+ /**
170
+ * Prepend the given string to the buffer.
171
+ *
172
+ * @param buffer The buffer to prepend to.
173
+ * @param value The string to prepend.
174
+ * @param length The length of the string to prepend.
175
+ */
176
+ void pm_buffer_prepend_string(pm_buffer_t *buffer, const char *value, size_t length);
177
+
178
+ /**
179
+ * Concatenate one buffer onto another.
180
+ *
181
+ * @param destination The buffer to concatenate onto.
182
+ * @param source The buffer to concatenate.
183
+ */
184
+ void pm_buffer_concat(pm_buffer_t *destination, const pm_buffer_t *source);
185
+
186
+ /**
187
+ * Clear the buffer by reducing its size to 0. This does not free the allocated
188
+ * memory, but it does allow the buffer to be reused.
189
+ *
190
+ * @param buffer The buffer to clear.
191
+ */
192
+ void pm_buffer_clear(pm_buffer_t *buffer);
193
+
194
+ /**
195
+ * Strip the whitespace from the end of the buffer.
196
+ *
197
+ * @param buffer The buffer to strip.
198
+ */
199
+ void pm_buffer_rstrip(pm_buffer_t *buffer);
200
+
201
+ /**
202
+ * Checks if the buffer includes the given value.
203
+ *
204
+ * @param buffer The buffer to check.
205
+ * @param value The value to check for.
206
+ * @returns The index of the first occurrence of the value in the buffer, or
207
+ * SIZE_MAX if the value is not found.
208
+ */
209
+ size_t pm_buffer_index(const pm_buffer_t *buffer, char value);
210
+
211
+ /**
212
+ * Insert the given string into the buffer at the given index.
213
+ *
214
+ * @param buffer The buffer to insert into.
215
+ * @param index The index to insert at.
216
+ * @param value The string to insert.
217
+ * @param length The length of the string to insert.
218
+ */
219
+ void pm_buffer_insert(pm_buffer_t *buffer, size_t index, const char *value, size_t length);
220
+
221
+ /**
222
+ * Free the memory associated with the buffer.
223
+ *
224
+ * @param buffer The buffer to free.
225
+ */
226
+ PRISM_EXPORTED_FUNCTION void pm_buffer_free(pm_buffer_t *buffer);
227
+
228
+ #endif
@@ -0,0 +1,204 @@
1
+ /**
2
+ * @file pm_char.h
3
+ *
4
+ * Functions for working with characters and strings.
5
+ */
6
+ #ifndef PRISM_CHAR_H
7
+ #define PRISM_CHAR_H
8
+
9
+ #include "prism/defines.h"
10
+ #include "prism/util/pm_newline_list.h"
11
+
12
+ #include <stdbool.h>
13
+ #include <stddef.h>
14
+
15
+ /**
16
+ * Returns the number of characters at the start of the string that are
17
+ * whitespace. Disallows searching past the given maximum number of characters.
18
+ *
19
+ * @param string The string to search.
20
+ * @param length The maximum number of characters to search.
21
+ * @return The number of characters at the start of the string that are
22
+ * whitespace.
23
+ */
24
+ size_t pm_strspn_whitespace(const uint8_t *string, ptrdiff_t length);
25
+
26
+ /**
27
+ * Returns the number of characters at the start of the string that are
28
+ * whitespace while also tracking the location of each newline. Disallows
29
+ * searching past the given maximum number of characters.
30
+ *
31
+ * @param string The string to search.
32
+ * @param length The maximum number of characters to search.
33
+ * @param newline_list The list of newlines to populate.
34
+ * @return The number of characters at the start of the string that are
35
+ * whitespace.
36
+ */
37
+ size_t pm_strspn_whitespace_newlines(const uint8_t *string, ptrdiff_t length, pm_newline_list_t *newline_list);
38
+
39
+ /**
40
+ * Returns the number of characters at the start of the string that are inline
41
+ * whitespace. Disallows searching past the given maximum number of characters.
42
+ *
43
+ * @param string The string to search.
44
+ * @param length The maximum number of characters to search.
45
+ * @return The number of characters at the start of the string that are inline
46
+ * whitespace.
47
+ */
48
+ size_t pm_strspn_inline_whitespace(const uint8_t *string, ptrdiff_t length);
49
+
50
+ /**
51
+ * Returns the number of characters at the start of the string that are decimal
52
+ * digits. Disallows searching past the given maximum number of characters.
53
+ *
54
+ * @param string The string to search.
55
+ * @param length The maximum number of characters to search.
56
+ * @return The number of characters at the start of the string that are decimal
57
+ * digits.
58
+ */
59
+ size_t pm_strspn_decimal_digit(const uint8_t *string, ptrdiff_t length);
60
+
61
+ /**
62
+ * Returns the number of characters at the start of the string that are
63
+ * hexadecimal digits. Disallows searching past the given maximum number of
64
+ * characters.
65
+ *
66
+ * @param string The string to search.
67
+ * @param length The maximum number of characters to search.
68
+ * @return The number of characters at the start of the string that are
69
+ * hexadecimal digits.
70
+ */
71
+ size_t pm_strspn_hexadecimal_digit(const uint8_t *string, ptrdiff_t length);
72
+
73
+ /**
74
+ * Returns the number of characters at the start of the string that are octal
75
+ * digits or underscores. Disallows searching past the given maximum number of
76
+ * characters.
77
+ *
78
+ * If multiple underscores are found in a row or if an underscore is
79
+ * found at the end of the number, then the invalid pointer is set to the index
80
+ * of the first invalid underscore.
81
+ *
82
+ * @param string The string to search.
83
+ * @param length The maximum number of characters to search.
84
+ * @param invalid The pointer to set to the index of the first invalid
85
+ * underscore.
86
+ * @return The number of characters at the start of the string that are octal
87
+ * digits or underscores.
88
+ */
89
+ size_t pm_strspn_octal_number(const uint8_t *string, ptrdiff_t length, const uint8_t **invalid);
90
+
91
+ /**
92
+ * Returns the number of characters at the start of the string that are decimal
93
+ * digits or underscores. Disallows searching past the given maximum number of
94
+ * characters.
95
+ *
96
+ * If multiple underscores are found in a row or if an underscore is
97
+ * found at the end of the number, then the invalid pointer is set to the index
98
+ * of the first invalid underscore.
99
+ *
100
+ * @param string The string to search.
101
+ * @param length The maximum number of characters to search.
102
+ * @param invalid The pointer to set to the index of the first invalid
103
+ * underscore.
104
+ * @return The number of characters at the start of the string that are decimal
105
+ * digits or underscores.
106
+ */
107
+ size_t pm_strspn_decimal_number(const uint8_t *string, ptrdiff_t length, const uint8_t **invalid);
108
+
109
+ /**
110
+ * Returns the number of characters at the start of the string that are
111
+ * hexadecimal digits or underscores. Disallows searching past the given maximum
112
+ * number of characters.
113
+ *
114
+ * If multiple underscores are found in a row or if an underscore is
115
+ * found at the end of the number, then the invalid pointer is set to the index
116
+ * of the first invalid underscore.
117
+ *
118
+ * @param string The string to search.
119
+ * @param length The maximum number of characters to search.
120
+ * @param invalid The pointer to set to the index of the first invalid
121
+ * underscore.
122
+ * @return The number of characters at the start of the string that are
123
+ * hexadecimal digits or underscores.
124
+ */
125
+ size_t pm_strspn_hexadecimal_number(const uint8_t *string, ptrdiff_t length, const uint8_t **invalid);
126
+
127
+ /**
128
+ * Returns the number of characters at the start of the string that are regexp
129
+ * options. Disallows searching past the given maximum number of characters.
130
+ *
131
+ * @param string The string to search.
132
+ * @param length The maximum number of characters to search.
133
+ * @return The number of characters at the start of the string that are regexp
134
+ * options.
135
+ */
136
+ size_t pm_strspn_regexp_option(const uint8_t *string, ptrdiff_t length);
137
+
138
+ /**
139
+ * Returns the number of characters at the start of the string that are binary
140
+ * digits or underscores. Disallows searching past the given maximum number of
141
+ * characters.
142
+ *
143
+ * If multiple underscores are found in a row or if an underscore is
144
+ * found at the end of the number, then the invalid pointer is set to the index
145
+ * of the first invalid underscore.
146
+ *
147
+ * @param string The string to search.
148
+ * @param length The maximum number of characters to search.
149
+ * @param invalid The pointer to set to the index of the first invalid
150
+ * underscore.
151
+ * @return The number of characters at the start of the string that are binary
152
+ * digits or underscores.
153
+ */
154
+ size_t pm_strspn_binary_number(const uint8_t *string, ptrdiff_t length, const uint8_t **invalid);
155
+
156
+ /**
157
+ * Returns true if the given character is a whitespace character.
158
+ *
159
+ * @param b The character to check.
160
+ * @return True if the given character is a whitespace character.
161
+ */
162
+ bool pm_char_is_whitespace(const uint8_t b);
163
+
164
+ /**
165
+ * Returns true if the given character is an inline whitespace character.
166
+ *
167
+ * @param b The character to check.
168
+ * @return True if the given character is an inline whitespace character.
169
+ */
170
+ bool pm_char_is_inline_whitespace(const uint8_t b);
171
+
172
+ /**
173
+ * Returns true if the given character is a binary digit.
174
+ *
175
+ * @param b The character to check.
176
+ * @return True if the given character is a binary digit.
177
+ */
178
+ bool pm_char_is_binary_digit(const uint8_t b);
179
+
180
+ /**
181
+ * Returns true if the given character is an octal digit.
182
+ *
183
+ * @param b The character to check.
184
+ * @return True if the given character is an octal digit.
185
+ */
186
+ bool pm_char_is_octal_digit(const uint8_t b);
187
+
188
+ /**
189
+ * Returns true if the given character is a decimal digit.
190
+ *
191
+ * @param b The character to check.
192
+ * @return True if the given character is a decimal digit.
193
+ */
194
+ bool pm_char_is_decimal_digit(const uint8_t b);
195
+
196
+ /**
197
+ * Returns true if the given character is a hexadecimal digit.
198
+ *
199
+ * @param b The character to check.
200
+ * @return True if the given character is a hexadecimal digit.
201
+ */
202
+ bool pm_char_is_hexadecimal_digit(const uint8_t b);
203
+
204
+ #endif
@@ -0,0 +1,218 @@
1
+ /**
2
+ * @file pm_constant_pool.h
3
+ *
4
+ * A data structure that stores a set of strings.
5
+ *
6
+ * Each string is assigned a unique id, which can be used to compare strings for
7
+ * equality. This comparison ends up being much faster than strcmp, since it
8
+ * only requires a single integer comparison.
9
+ */
10
+ #ifndef PRISM_CONSTANT_POOL_H
11
+ #define PRISM_CONSTANT_POOL_H
12
+
13
+ #include "prism/defines.h"
14
+
15
+ #include <assert.h>
16
+ #include <stdbool.h>
17
+ #include <stdint.h>
18
+ #include <stdlib.h>
19
+ #include <string.h>
20
+
21
+ /**
22
+ * When we allocate constants into the pool, we reserve 0 to mean that the slot
23
+ * is not yet filled. This constant is reused in other places to indicate the
24
+ * lack of a constant id.
25
+ */
26
+ #define PM_CONSTANT_ID_UNSET 0
27
+
28
+ /**
29
+ * A constant id is a unique identifier for a constant in the constant pool.
30
+ */
31
+ typedef uint32_t pm_constant_id_t;
32
+
33
+ /**
34
+ * A list of constant IDs. Usually used to represent a set of locals.
35
+ */
36
+ typedef struct {
37
+ /** The number of constant ids in the list. */
38
+ size_t size;
39
+
40
+ /** The number of constant ids that have been allocated in the list. */
41
+ size_t capacity;
42
+
43
+ /** The constant ids in the list. */
44
+ pm_constant_id_t *ids;
45
+ } pm_constant_id_list_t;
46
+
47
+ /**
48
+ * Initialize a list of constant ids.
49
+ *
50
+ * @param list The list to initialize.
51
+ */
52
+ void pm_constant_id_list_init(pm_constant_id_list_t *list);
53
+
54
+ /**
55
+ * Initialize a list of constant ids with a given capacity.
56
+ *
57
+ * @param list The list to initialize.
58
+ * @param capacity The initial capacity of the list.
59
+ */
60
+ void pm_constant_id_list_init_capacity(pm_constant_id_list_t *list, size_t capacity);
61
+
62
+ /**
63
+ * Append a constant id to a list of constant ids. Returns false if any
64
+ * potential reallocations fail.
65
+ *
66
+ * @param list The list to append to.
67
+ * @param id The id to append.
68
+ * @return Whether the append succeeded.
69
+ */
70
+ bool pm_constant_id_list_append(pm_constant_id_list_t *list, pm_constant_id_t id);
71
+
72
+ /**
73
+ * Insert a constant id into a list of constant ids at the specified index.
74
+ *
75
+ * @param list The list to insert into.
76
+ * @param index The index at which to insert.
77
+ * @param id The id to insert.
78
+ */
79
+ void pm_constant_id_list_insert(pm_constant_id_list_t *list, size_t index, pm_constant_id_t id);
80
+
81
+ /**
82
+ * Checks if the current constant id list includes the given constant id.
83
+ *
84
+ * @param list The list to check.
85
+ * @param id The id to check for.
86
+ * @return Whether the list includes the given id.
87
+ */
88
+ bool pm_constant_id_list_includes(pm_constant_id_list_t *list, pm_constant_id_t id);
89
+
90
+ /**
91
+ * Free the memory associated with a list of constant ids.
92
+ *
93
+ * @param list The list to free.
94
+ */
95
+ void pm_constant_id_list_free(pm_constant_id_list_t *list);
96
+
97
+ /**
98
+ * The type of bucket in the constant pool hash map. This determines how the
99
+ * bucket should be freed.
100
+ */
101
+ typedef unsigned int pm_constant_pool_bucket_type_t;
102
+
103
+ /** By default, each constant is a slice of the source. */
104
+ static const pm_constant_pool_bucket_type_t PM_CONSTANT_POOL_BUCKET_DEFAULT = 0;
105
+
106
+ /** An owned constant is one for which memory has been allocated. */
107
+ static const pm_constant_pool_bucket_type_t PM_CONSTANT_POOL_BUCKET_OWNED = 1;
108
+
109
+ /** A constant constant is known at compile time. */
110
+ static const pm_constant_pool_bucket_type_t PM_CONSTANT_POOL_BUCKET_CONSTANT = 2;
111
+
112
+ /** A bucket in the hash map. */
113
+ typedef struct {
114
+ /** The incremental ID used for indexing back into the pool. */
115
+ unsigned int id: 30;
116
+
117
+ /** The type of the bucket, which determines how to free it. */
118
+ pm_constant_pool_bucket_type_t type: 2;
119
+
120
+ /** The hash of the bucket. */
121
+ uint32_t hash;
122
+ } pm_constant_pool_bucket_t;
123
+
124
+ /** A constant in the pool which effectively stores a string. */
125
+ typedef struct {
126
+ /** A pointer to the start of the string. */
127
+ const uint8_t *start;
128
+
129
+ /** The length of the string. */
130
+ size_t length;
131
+ } pm_constant_t;
132
+
133
+ /** The overall constant pool, which stores constants found while parsing. */
134
+ typedef struct {
135
+ /** The buckets in the hash map. */
136
+ pm_constant_pool_bucket_t *buckets;
137
+
138
+ /** The constants that are stored in the buckets. */
139
+ pm_constant_t *constants;
140
+
141
+ /** The number of buckets in the hash map. */
142
+ uint32_t size;
143
+
144
+ /** The number of buckets that have been allocated in the hash map. */
145
+ uint32_t capacity;
146
+ } pm_constant_pool_t;
147
+
148
+ /**
149
+ * Initialize a new constant pool with a given capacity.
150
+ *
151
+ * @param pool The pool to initialize.
152
+ * @param capacity The initial capacity of the pool.
153
+ * @return Whether the initialization succeeded.
154
+ */
155
+ bool pm_constant_pool_init(pm_constant_pool_t *pool, uint32_t capacity);
156
+
157
+ /**
158
+ * Return a pointer to the constant indicated by the given constant id.
159
+ *
160
+ * @param pool The pool to get the constant from.
161
+ * @param constant_id The id of the constant to get.
162
+ * @return A pointer to the constant.
163
+ */
164
+ pm_constant_t * pm_constant_pool_id_to_constant(const pm_constant_pool_t *pool, pm_constant_id_t constant_id);
165
+
166
+ /**
167
+ * Find a constant in a constant pool. Returns the id of the constant, or 0 if
168
+ * the constant is not found.
169
+ *
170
+ * @param pool The pool to find the constant in.
171
+ * @param start A pointer to the start of the constant.
172
+ * @param length The length of the constant.
173
+ * @return The id of the constant.
174
+ */
175
+ pm_constant_id_t pm_constant_pool_find(const pm_constant_pool_t *pool, const uint8_t *start, size_t length);
176
+
177
+ /**
178
+ * Insert a constant into a constant pool that is a slice of a source string.
179
+ * Returns the id of the constant, or 0 if any potential calls to resize fail.
180
+ *
181
+ * @param pool The pool to insert the constant into.
182
+ * @param start A pointer to the start of the constant.
183
+ * @param length The length of the constant.
184
+ * @return The id of the constant.
185
+ */
186
+ pm_constant_id_t pm_constant_pool_insert_shared(pm_constant_pool_t *pool, const uint8_t *start, size_t length);
187
+
188
+ /**
189
+ * Insert a constant into a constant pool from memory that is now owned by the
190
+ * constant pool. Returns the id of the constant, or 0 if any potential calls to
191
+ * resize fail.
192
+ *
193
+ * @param pool The pool to insert the constant into.
194
+ * @param start A pointer to the start of the constant.
195
+ * @param length The length of the constant.
196
+ * @return The id of the constant.
197
+ */
198
+ pm_constant_id_t pm_constant_pool_insert_owned(pm_constant_pool_t *pool, uint8_t *start, size_t length);
199
+
200
+ /**
201
+ * Insert a constant into a constant pool from memory that is constant. Returns
202
+ * the id of the constant, or 0 if any potential calls to resize fail.
203
+ *
204
+ * @param pool The pool to insert the constant into.
205
+ * @param start A pointer to the start of the constant.
206
+ * @param length The length of the constant.
207
+ * @return The id of the constant.
208
+ */
209
+ pm_constant_id_t pm_constant_pool_insert_constant(pm_constant_pool_t *pool, const uint8_t *start, size_t length);
210
+
211
+ /**
212
+ * Free the memory associated with a constant pool.
213
+ *
214
+ * @param pool The pool to free.
215
+ */
216
+ void pm_constant_pool_free(pm_constant_pool_t *pool);
217
+
218
+ #endif