debase-ruby_core_source 3.3.5 → 3.3.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/.idea/vcs.xml +28 -0
- data/CHANGELOG.md +8 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/addr2line.h +22 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/builtin.h +119 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/ccan/build_assert/build_assert.h +40 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/ccan/check_type/check_type.h +63 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/ccan/container_of/container_of.h +142 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/ccan/list/list.h +791 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/ccan/str/str.h +17 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/constant.h +53 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/darray.h +209 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/debug_counter.h +423 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/dln.h +32 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/encindex.h +70 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/eval_intern.h +324 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/hrtime.h +237 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/id.h +347 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/id_table.h +39 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/insns.inc +265 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/insns_info.inc +9902 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/array.h +152 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/basic_operators.h +64 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/bignum.h +244 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/bits.h +568 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/class.h +283 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/cmdlineopt.h +65 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/compar.h +29 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/compile.h +34 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/compilers.h +107 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/complex.h +29 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/cont.h +35 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/dir.h +16 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/enc.h +19 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/encoding.h +36 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/enum.h +18 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/enumerator.h +21 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/error.h +218 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/eval.h +33 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/file.h +38 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/fixnum.h +184 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/gc.h +322 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/hash.h +192 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/imemo.h +261 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/inits.h +47 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/io.h +143 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/load.h +18 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/loadpath.h +16 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/math.h +23 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/missing.h +19 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/numeric.h +274 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/object.h +63 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/parse.h +129 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/proc.h +30 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/process.h +124 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/ractor.h +6 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/random.h +17 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/range.h +40 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/rational.h +71 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/re.h +28 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/ruby_parser.h +102 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/sanitizers.h +326 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/serial.h +23 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/signal.h +24 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/st.h +11 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/static_assert.h +16 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/string.h +186 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/struct.h +127 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/symbol.h +45 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/thread.h +85 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/time.h +34 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/transcode.h +23 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/util.h +27 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/variable.h +72 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/vm.h +137 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/warnings.h +16 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal.h +108 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/iseq.h +340 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/known_errors.inc +1419 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/method.h +255 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/node.h +111 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/node_name.inc +224 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/optinsn.inc +128 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/optunifs.inc +43 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/parse.h +244 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/parser_bits.h +564 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/parser_node.h +32 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/parser_st.h +162 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/parser_value.h +106 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/prism/ast.h +7524 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/prism/defines.h +242 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/prism/diagnostic.h +450 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/prism/encoding.h +283 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/prism/extension.h +19 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/prism/node.h +129 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/prism/options.h +396 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/prism/pack.h +163 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/prism/parser.h +933 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/prism/prettyprint.h +34 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/prism/prism.h +336 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/prism/regexp.h +43 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/prism/static_literals.h +121 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/prism/util/pm_buffer.h +218 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/prism/util/pm_char.h +204 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/prism/util/pm_constant_pool.h +218 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/prism/util/pm_integer.h +126 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/prism/util/pm_list.h +97 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/prism/util/pm_memchr.h +29 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/prism/util/pm_newline_list.h +113 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/prism/util/pm_string.h +190 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/prism/util/pm_strncasecmp.h +32 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/prism/util/pm_strpbrk.h +46 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/prism/version.h +29 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/prism_compile.h +99 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/probes_helper.h +42 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/ractor_core.h +382 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/regenc.h +254 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/regint.h +1006 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/regparse.h +371 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/revision.h +5 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/rjit.h +101 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/rjit_c.h +165 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/ruby_assert.h +14 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/ruby_atomic.h +23 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/rubyparser.h +1350 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/shape.h +234 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/siphash.h +48 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/symbol.h +123 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/thread_none.h +21 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/thread_pthread.h +168 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/thread_win32.h +58 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/timev.h +58 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/transcode_data.h +138 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/variable.h +39 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/version.h +69 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/vm.inc +5840 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/vm_call_iseq_optimized.inc +244 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/vm_callinfo.h +627 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/vm_core.h +2222 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/vm_debug.h +124 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/vm_exec.h +199 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/vm_insnhelper.h +277 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/vm_opts.h +67 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/vm_sync.h +137 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/vmtc.inc +259 -0
- data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/yjit.h +79 -0
- data/lib/debase/ruby_core_source/version.rb +1 -1
- metadata +150 -6
@@ -0,0 +1,218 @@
|
|
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
|
+
* The different types of escaping that can be performed by the buffer when
|
142
|
+
* appending a slice of Ruby source code.
|
143
|
+
*/
|
144
|
+
typedef enum {
|
145
|
+
PM_BUFFER_ESCAPING_RUBY,
|
146
|
+
PM_BUFFER_ESCAPING_JSON
|
147
|
+
} pm_buffer_escaping_t;
|
148
|
+
|
149
|
+
/**
|
150
|
+
* Append a slice of source code to the buffer.
|
151
|
+
*
|
152
|
+
* @param buffer The buffer to append to.
|
153
|
+
* @param source The source code to append.
|
154
|
+
* @param length The length of the source code to append.
|
155
|
+
* @param escaping The type of escaping to perform.
|
156
|
+
*/
|
157
|
+
void pm_buffer_append_source(pm_buffer_t *buffer, const uint8_t *source, size_t length, pm_buffer_escaping_t escaping);
|
158
|
+
|
159
|
+
/**
|
160
|
+
* Prepend the given string to the buffer.
|
161
|
+
*
|
162
|
+
* @param buffer The buffer to prepend to.
|
163
|
+
* @param value The string to prepend.
|
164
|
+
* @param length The length of the string to prepend.
|
165
|
+
*/
|
166
|
+
void pm_buffer_prepend_string(pm_buffer_t *buffer, const char *value, size_t length);
|
167
|
+
|
168
|
+
/**
|
169
|
+
* Concatenate one buffer onto another.
|
170
|
+
*
|
171
|
+
* @param destination The buffer to concatenate onto.
|
172
|
+
* @param source The buffer to concatenate.
|
173
|
+
*/
|
174
|
+
void pm_buffer_concat(pm_buffer_t *destination, const pm_buffer_t *source);
|
175
|
+
|
176
|
+
/**
|
177
|
+
* Clear the buffer by reducing its size to 0. This does not free the allocated
|
178
|
+
* memory, but it does allow the buffer to be reused.
|
179
|
+
*
|
180
|
+
* @param buffer The buffer to clear.
|
181
|
+
*/
|
182
|
+
void pm_buffer_clear(pm_buffer_t *buffer);
|
183
|
+
|
184
|
+
/**
|
185
|
+
* Strip the whitespace from the end of the buffer.
|
186
|
+
*
|
187
|
+
* @param buffer The buffer to strip.
|
188
|
+
*/
|
189
|
+
void pm_buffer_rstrip(pm_buffer_t *buffer);
|
190
|
+
|
191
|
+
/**
|
192
|
+
* Checks if the buffer includes the given value.
|
193
|
+
*
|
194
|
+
* @param buffer The buffer to check.
|
195
|
+
* @param value The value to check for.
|
196
|
+
* @returns The index of the first occurrence of the value in the buffer, or
|
197
|
+
* SIZE_MAX if the value is not found.
|
198
|
+
*/
|
199
|
+
size_t pm_buffer_index(const pm_buffer_t *buffer, char value);
|
200
|
+
|
201
|
+
/**
|
202
|
+
* Insert the given string into the buffer at the given index.
|
203
|
+
*
|
204
|
+
* @param buffer The buffer to insert into.
|
205
|
+
* @param index The index to insert at.
|
206
|
+
* @param value The string to insert.
|
207
|
+
* @param length The length of the string to insert.
|
208
|
+
*/
|
209
|
+
void pm_buffer_insert(pm_buffer_t *buffer, size_t index, const char *value, size_t length);
|
210
|
+
|
211
|
+
/**
|
212
|
+
* Free the memory associated with the buffer.
|
213
|
+
*
|
214
|
+
* @param buffer The buffer to free.
|
215
|
+
*/
|
216
|
+
PRISM_EXPORTED_FUNCTION void pm_buffer_free(pm_buffer_t *buffer);
|
217
|
+
|
218
|
+
#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
|