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.
Files changed (149) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -1
  3. data/.idea/vcs.xml +28 -0
  4. data/CHANGELOG.md +8 -0
  5. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/addr2line.h +22 -0
  6. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/builtin.h +119 -0
  7. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/ccan/build_assert/build_assert.h +40 -0
  8. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/ccan/check_type/check_type.h +63 -0
  9. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/ccan/container_of/container_of.h +142 -0
  10. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/ccan/list/list.h +791 -0
  11. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/ccan/str/str.h +17 -0
  12. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/constant.h +53 -0
  13. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/darray.h +209 -0
  14. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/debug_counter.h +423 -0
  15. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/dln.h +32 -0
  16. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/encindex.h +70 -0
  17. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/eval_intern.h +324 -0
  18. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/hrtime.h +237 -0
  19. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/id.h +347 -0
  20. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/id_table.h +39 -0
  21. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/insns.inc +265 -0
  22. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/insns_info.inc +9902 -0
  23. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/array.h +152 -0
  24. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/basic_operators.h +64 -0
  25. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/bignum.h +244 -0
  26. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/bits.h +568 -0
  27. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/class.h +283 -0
  28. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/cmdlineopt.h +65 -0
  29. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/compar.h +29 -0
  30. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/compile.h +34 -0
  31. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/compilers.h +107 -0
  32. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/complex.h +29 -0
  33. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/cont.h +35 -0
  34. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/dir.h +16 -0
  35. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/enc.h +19 -0
  36. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/encoding.h +36 -0
  37. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/enum.h +18 -0
  38. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/enumerator.h +21 -0
  39. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/error.h +218 -0
  40. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/eval.h +33 -0
  41. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/file.h +38 -0
  42. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/fixnum.h +184 -0
  43. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/gc.h +322 -0
  44. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/hash.h +192 -0
  45. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/imemo.h +261 -0
  46. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/inits.h +47 -0
  47. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/io.h +143 -0
  48. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/load.h +18 -0
  49. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/loadpath.h +16 -0
  50. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/math.h +23 -0
  51. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/missing.h +19 -0
  52. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/numeric.h +274 -0
  53. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/object.h +63 -0
  54. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/parse.h +129 -0
  55. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/proc.h +30 -0
  56. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/process.h +124 -0
  57. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/ractor.h +6 -0
  58. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/random.h +17 -0
  59. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/range.h +40 -0
  60. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/rational.h +71 -0
  61. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/re.h +28 -0
  62. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/ruby_parser.h +102 -0
  63. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/sanitizers.h +326 -0
  64. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/serial.h +23 -0
  65. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/signal.h +24 -0
  66. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/st.h +11 -0
  67. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/static_assert.h +16 -0
  68. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/string.h +186 -0
  69. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/struct.h +127 -0
  70. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/symbol.h +45 -0
  71. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/thread.h +85 -0
  72. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/time.h +34 -0
  73. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/transcode.h +23 -0
  74. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/util.h +27 -0
  75. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/variable.h +72 -0
  76. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/vm.h +137 -0
  77. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal/warnings.h +16 -0
  78. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/internal.h +108 -0
  79. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/iseq.h +340 -0
  80. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/known_errors.inc +1419 -0
  81. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/method.h +255 -0
  82. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/node.h +111 -0
  83. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/node_name.inc +224 -0
  84. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/optinsn.inc +128 -0
  85. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/optunifs.inc +43 -0
  86. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/parse.h +244 -0
  87. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/parser_bits.h +564 -0
  88. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/parser_node.h +32 -0
  89. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/parser_st.h +162 -0
  90. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/parser_value.h +106 -0
  91. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/prism/ast.h +7524 -0
  92. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/prism/defines.h +242 -0
  93. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/prism/diagnostic.h +450 -0
  94. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/prism/encoding.h +283 -0
  95. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/prism/extension.h +19 -0
  96. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/prism/node.h +129 -0
  97. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/prism/options.h +396 -0
  98. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/prism/pack.h +163 -0
  99. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/prism/parser.h +933 -0
  100. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/prism/prettyprint.h +34 -0
  101. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/prism/prism.h +336 -0
  102. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/prism/regexp.h +43 -0
  103. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/prism/static_literals.h +121 -0
  104. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/prism/util/pm_buffer.h +218 -0
  105. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/prism/util/pm_char.h +204 -0
  106. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/prism/util/pm_constant_pool.h +218 -0
  107. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/prism/util/pm_integer.h +126 -0
  108. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/prism/util/pm_list.h +97 -0
  109. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/prism/util/pm_memchr.h +29 -0
  110. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/prism/util/pm_newline_list.h +113 -0
  111. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/prism/util/pm_string.h +190 -0
  112. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/prism/util/pm_strncasecmp.h +32 -0
  113. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/prism/util/pm_strpbrk.h +46 -0
  114. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/prism/version.h +29 -0
  115. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/prism_compile.h +99 -0
  116. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/probes_helper.h +42 -0
  117. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/ractor_core.h +382 -0
  118. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/regenc.h +254 -0
  119. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/regint.h +1006 -0
  120. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/regparse.h +371 -0
  121. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/revision.h +5 -0
  122. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/rjit.h +101 -0
  123. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/rjit_c.h +165 -0
  124. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/ruby_assert.h +14 -0
  125. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/ruby_atomic.h +23 -0
  126. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/rubyparser.h +1350 -0
  127. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/shape.h +234 -0
  128. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/siphash.h +48 -0
  129. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/symbol.h +123 -0
  130. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/thread_none.h +21 -0
  131. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/thread_pthread.h +168 -0
  132. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/thread_win32.h +58 -0
  133. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/timev.h +58 -0
  134. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/transcode_data.h +138 -0
  135. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/variable.h +39 -0
  136. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/version.h +69 -0
  137. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/vm.inc +5840 -0
  138. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/vm_call_iseq_optimized.inc +244 -0
  139. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/vm_callinfo.h +627 -0
  140. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/vm_core.h +2222 -0
  141. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/vm_debug.h +124 -0
  142. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/vm_exec.h +199 -0
  143. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/vm_insnhelper.h +277 -0
  144. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/vm_opts.h +67 -0
  145. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/vm_sync.h +137 -0
  146. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/vmtc.inc +259 -0
  147. data/lib/debase/ruby_core_source/ruby-3.4.0-preview2/yjit.h +79 -0
  148. data/lib/debase/ruby_core_source/version.rb +1 -1
  149. metadata +150 -6
@@ -0,0 +1,396 @@
1
+ /**
2
+ * @file options.h
3
+ *
4
+ * The options that can be passed to parsing.
5
+ */
6
+ #ifndef PRISM_OPTIONS_H
7
+ #define PRISM_OPTIONS_H
8
+
9
+ #include "prism/defines.h"
10
+ #include "prism/util/pm_char.h"
11
+ #include "prism/util/pm_string.h"
12
+
13
+ #include <stdbool.h>
14
+ #include <stddef.h>
15
+ #include <stdint.h>
16
+
17
+ /**
18
+ * String literals should be made frozen.
19
+ */
20
+ #define PM_OPTIONS_FROZEN_STRING_LITERAL_DISABLED ((int8_t) -1)
21
+
22
+ /**
23
+ * String literals may be frozen or mutable depending on the implementation
24
+ * default.
25
+ */
26
+ #define PM_OPTIONS_FROZEN_STRING_LITERAL_UNSET ((int8_t) 0)
27
+
28
+ /**
29
+ * String literals should be made mutable.
30
+ */
31
+ #define PM_OPTIONS_FROZEN_STRING_LITERAL_ENABLED ((int8_t) 1)
32
+
33
+ /**
34
+ * A scope of locals surrounding the code that is being parsed.
35
+ */
36
+ typedef struct pm_options_scope {
37
+ /** The number of locals in the scope. */
38
+ size_t locals_count;
39
+
40
+ /** The names of the locals in the scope. */
41
+ pm_string_t *locals;
42
+ } pm_options_scope_t;
43
+
44
+ // Forward declaration needed by the callback typedef.
45
+ struct pm_options;
46
+
47
+ /**
48
+ * The callback called when additional switches are found in a shebang comment
49
+ * that need to be processed by the runtime.
50
+ *
51
+ * @param options The options struct that may be updated by this callback.
52
+ * Certain fields will be checked for changes, specifically encoding,
53
+ * command_line, and frozen_string_literal.
54
+ * @param source The source of the shebang comment.
55
+ * @param length The length of the source.
56
+ * @param shebang_callback_data Any additional data that should be passed along
57
+ * to the callback.
58
+ */
59
+ typedef void (*pm_options_shebang_callback_t)(struct pm_options *options, const uint8_t *source, size_t length, void *shebang_callback_data);
60
+
61
+ /**
62
+ * The version of Ruby syntax that we should be parsing with. This is used to
63
+ * allow consumers to specify which behavior they want in case they need to
64
+ * parse in the same way as a specific version of CRuby would have.
65
+ */
66
+ typedef enum {
67
+ /** The current version of prism. */
68
+ PM_OPTIONS_VERSION_LATEST = 0,
69
+
70
+ /** The vendored version of prism in CRuby 3.3.x. */
71
+ PM_OPTIONS_VERSION_CRUBY_3_3 = 1
72
+ } pm_options_version_t;
73
+
74
+ /**
75
+ * The options that can be passed to the parser.
76
+ */
77
+ typedef struct pm_options {
78
+ /**
79
+ * The callback to call when additional switches are found in a shebang
80
+ * comment.
81
+ */
82
+ pm_options_shebang_callback_t shebang_callback;
83
+
84
+ /**
85
+ * Any additional data that should be passed along to the shebang callback
86
+ * if one was set.
87
+ */
88
+ void *shebang_callback_data;
89
+
90
+ /** The name of the file that is currently being parsed. */
91
+ pm_string_t filepath;
92
+
93
+ /**
94
+ * The line within the file that the parse starts on. This value is
95
+ * 1-indexed.
96
+ */
97
+ int32_t line;
98
+
99
+ /**
100
+ * The name of the encoding that the source file is in. Note that this must
101
+ * correspond to a name that can be found with Encoding.find in Ruby.
102
+ */
103
+ pm_string_t encoding;
104
+
105
+ /**
106
+ * The number of scopes surrounding the code that is being parsed.
107
+ */
108
+ size_t scopes_count;
109
+
110
+ /**
111
+ * The scopes surrounding the code that is being parsed. For most parses
112
+ * this will be NULL, but for evals it will be the locals that are in scope
113
+ * surrounding the eval. Scopes are ordered from the outermost scope to the
114
+ * innermost one.
115
+ */
116
+ pm_options_scope_t *scopes;
117
+
118
+ /**
119
+ * The version of prism that we should be parsing with. This is used to
120
+ * allow consumers to specify which behavior they want in case they need to
121
+ * parse exactly as a specific version of CRuby.
122
+ */
123
+ pm_options_version_t version;
124
+
125
+ /** A bitset of the various options that were set on the command line. */
126
+ uint8_t command_line;
127
+
128
+ /**
129
+ * Whether or not the frozen string literal option has been set.
130
+ * May be:
131
+ * - PM_OPTIONS_FROZEN_STRING_LITERAL_DISABLED
132
+ * - PM_OPTIONS_FROZEN_STRING_LITERAL_ENABLED
133
+ * - PM_OPTIONS_FROZEN_STRING_LITERAL_UNSET
134
+ */
135
+ int8_t frozen_string_literal;
136
+
137
+ /**
138
+ * Whether or not the encoding magic comments should be respected. This is a
139
+ * niche use-case where you want to parse a file with a specific encoding
140
+ * but ignore any encoding magic comments at the top of the file.
141
+ */
142
+ bool encoding_locked;
143
+
144
+ /**
145
+ * When the file being parsed is the main script, the shebang will be
146
+ * considered for command-line flags (or for implicit -x). The caller needs
147
+ * to pass this information to the parser so that it can behave correctly.
148
+ */
149
+ bool main_script;
150
+
151
+ /**
152
+ * When the file being parsed is considered a "partial" script, jumps will
153
+ * not be marked as errors if they are not contained within loops/blocks.
154
+ * This is used in the case that you're parsing a script that you know will
155
+ * be embedded inside another script later, but you do not have that context
156
+ * yet. For example, when parsing an ERB template that will be evaluated
157
+ * inside another script.
158
+ */
159
+ bool partial_script;
160
+ } pm_options_t;
161
+
162
+ /**
163
+ * A bit representing whether or not the command line -a option was set. -a
164
+ * splits the input line $_ into $F.
165
+ */
166
+ static const uint8_t PM_OPTIONS_COMMAND_LINE_A = 0x1;
167
+
168
+ /**
169
+ * A bit representing whether or not the command line -e option was set. -e
170
+ * allow the user to specify a script to be executed. This is necessary for
171
+ * prism to know because certain warnings are not generated when -e is used.
172
+ */
173
+ static const uint8_t PM_OPTIONS_COMMAND_LINE_E = 0x2;
174
+
175
+ /**
176
+ * A bit representing whether or not the command line -l option was set. -l
177
+ * chomps the input line by default.
178
+ */
179
+ static const uint8_t PM_OPTIONS_COMMAND_LINE_L = 0x4;
180
+
181
+ /**
182
+ * A bit representing whether or not the command line -n option was set. -n
183
+ * wraps the script in a while gets loop.
184
+ */
185
+ static const uint8_t PM_OPTIONS_COMMAND_LINE_N = 0x8;
186
+
187
+ /**
188
+ * A bit representing whether or not the command line -p option was set. -p
189
+ * prints the value of $_ at the end of each loop.
190
+ */
191
+ static const uint8_t PM_OPTIONS_COMMAND_LINE_P = 0x10;
192
+
193
+ /**
194
+ * A bit representing whether or not the command line -x option was set. -x
195
+ * searches the input file for a shebang that matches the current Ruby engine.
196
+ */
197
+ static const uint8_t PM_OPTIONS_COMMAND_LINE_X = 0x20;
198
+
199
+ /**
200
+ * Set the shebang callback option on the given options struct.
201
+ *
202
+ * @param options The options struct to set the shebang callback on.
203
+ * @param shebang_callback The shebang callback to set.
204
+ * @param shebang_callback_data Any additional data that should be passed along
205
+ * to the callback.
206
+ */
207
+ PRISM_EXPORTED_FUNCTION void pm_options_shebang_callback_set(pm_options_t *options, pm_options_shebang_callback_t shebang_callback, void *shebang_callback_data);
208
+
209
+ /**
210
+ * Set the filepath option on the given options struct.
211
+ *
212
+ * @param options The options struct to set the filepath on.
213
+ * @param filepath The filepath to set.
214
+ */
215
+ PRISM_EXPORTED_FUNCTION void pm_options_filepath_set(pm_options_t *options, const char *filepath);
216
+
217
+ /**
218
+ * Set the line option on the given options struct.
219
+ *
220
+ * @param options The options struct to set the line on.
221
+ * @param line The line to set.
222
+ */
223
+ PRISM_EXPORTED_FUNCTION void pm_options_line_set(pm_options_t *options, int32_t line);
224
+
225
+ /**
226
+ * Set the encoding option on the given options struct.
227
+ *
228
+ * @param options The options struct to set the encoding on.
229
+ * @param encoding The encoding to set.
230
+ */
231
+ PRISM_EXPORTED_FUNCTION void pm_options_encoding_set(pm_options_t *options, const char *encoding);
232
+
233
+ /**
234
+ * Set the encoding_locked option on the given options struct.
235
+ *
236
+ * @param options The options struct to set the encoding_locked value on.
237
+ * @param encoding_locked The encoding_locked value to set.
238
+ */
239
+ PRISM_EXPORTED_FUNCTION void pm_options_encoding_locked_set(pm_options_t *options, bool encoding_locked);
240
+
241
+ /**
242
+ * Set the frozen string literal option on the given options struct.
243
+ *
244
+ * @param options The options struct to set the frozen string literal value on.
245
+ * @param frozen_string_literal The frozen string literal value to set.
246
+ */
247
+ PRISM_EXPORTED_FUNCTION void pm_options_frozen_string_literal_set(pm_options_t *options, bool frozen_string_literal);
248
+
249
+ /**
250
+ * Sets the command line option on the given options struct.
251
+ *
252
+ * @param options The options struct to set the command line option on.
253
+ * @param command_line The command_line value to set.
254
+ */
255
+ PRISM_EXPORTED_FUNCTION void pm_options_command_line_set(pm_options_t *options, uint8_t command_line);
256
+
257
+ /**
258
+ * Set the version option on the given options struct by parsing the given
259
+ * string. If the string contains an invalid option, this returns false.
260
+ * Otherwise, it returns true.
261
+ *
262
+ * @param options The options struct to set the version on.
263
+ * @param version The version to set.
264
+ * @param length The length of the version string.
265
+ * @return Whether or not the version was parsed successfully.
266
+ */
267
+ PRISM_EXPORTED_FUNCTION bool pm_options_version_set(pm_options_t *options, const char *version, size_t length);
268
+
269
+ /**
270
+ * Set the main script option on the given options struct.
271
+ *
272
+ * @param options The options struct to set the main script value on.
273
+ * @param main_script The main script value to set.
274
+ */
275
+ PRISM_EXPORTED_FUNCTION void pm_options_main_script_set(pm_options_t *options, bool main_script);
276
+
277
+ /**
278
+ * Set the partial script option on the given options struct.
279
+ *
280
+ * @param options The options struct to set the partial script value on.
281
+ * @param partial_script The partial script value to set.
282
+ */
283
+ PRISM_EXPORTED_FUNCTION void pm_options_partial_script_set(pm_options_t *options, bool partial_script);
284
+
285
+ /**
286
+ * Allocate and zero out the scopes array on the given options struct.
287
+ *
288
+ * @param options The options struct to initialize the scopes array on.
289
+ * @param scopes_count The number of scopes to allocate.
290
+ * @return Whether or not the scopes array was initialized successfully.
291
+ */
292
+ PRISM_EXPORTED_FUNCTION bool pm_options_scopes_init(pm_options_t *options, size_t scopes_count);
293
+
294
+ /**
295
+ * Return a pointer to the scope at the given index within the given options.
296
+ *
297
+ * @param options The options struct to get the scope from.
298
+ * @param index The index of the scope to get.
299
+ * @return A pointer to the scope at the given index.
300
+ */
301
+ PRISM_EXPORTED_FUNCTION const pm_options_scope_t * pm_options_scope_get(const pm_options_t *options, size_t index);
302
+
303
+ /**
304
+ * Create a new options scope struct. This will hold a set of locals that are in
305
+ * scope surrounding the code that is being parsed.
306
+ *
307
+ * @param scope The scope struct to initialize.
308
+ * @param locals_count The number of locals to allocate.
309
+ * @return Whether or not the scope was initialized successfully.
310
+ */
311
+ PRISM_EXPORTED_FUNCTION bool pm_options_scope_init(pm_options_scope_t *scope, size_t locals_count);
312
+
313
+ /**
314
+ * Return a pointer to the local at the given index within the given scope.
315
+ *
316
+ * @param scope The scope struct to get the local from.
317
+ * @param index The index of the local to get.
318
+ * @return A pointer to the local at the given index.
319
+ */
320
+ PRISM_EXPORTED_FUNCTION const pm_string_t * pm_options_scope_local_get(const pm_options_scope_t *scope, size_t index);
321
+
322
+ /**
323
+ * Free the internal memory associated with the options.
324
+ *
325
+ * @param options The options struct whose internal memory should be freed.
326
+ */
327
+ PRISM_EXPORTED_FUNCTION void pm_options_free(pm_options_t *options);
328
+
329
+ /**
330
+ * Deserialize an options struct from the given binary string. This is used to
331
+ * pass options to the parser from an FFI call so that consumers of the library
332
+ * from an FFI perspective don't have to worry about the structure of our
333
+ * options structs. Since the source of these calls will be from Ruby
334
+ * implementation internals we assume it is from a trusted source.
335
+ *
336
+ * `data` is assumed to be a valid pointer pointing to well-formed data. The
337
+ * layout of this data should be the same every time, and is described below:
338
+ *
339
+ * | # bytes | field |
340
+ * | ------- | -------------------------- |
341
+ * | `4` | the length of the filepath |
342
+ * | ... | the filepath bytes |
343
+ * | `4` | the line number |
344
+ * | `4` | the length the encoding |
345
+ * | ... | the encoding bytes |
346
+ * | `1` | frozen string literal |
347
+ * | `1` | -p command line option |
348
+ * | `1` | -n command line option |
349
+ * | `1` | -l command line option |
350
+ * | `1` | -a command line option |
351
+ * | `1` | the version |
352
+ * | `1` | encoding locked |
353
+ * | `1` | main script |
354
+ * | `1` | partial script |
355
+ * | `4` | the number of scopes |
356
+ * | ... | the scopes |
357
+ *
358
+ * The version field is an enum, so it should be one of the following values:
359
+ *
360
+ * | value | version |
361
+ * | ----- | ------------------------- |
362
+ * | `0` | use the latest version of prism |
363
+ * | `1` | use the version of prism that is vendored in CRuby 3.3.0 |
364
+ *
365
+ * Each scope is laid out as follows:
366
+ *
367
+ * | # bytes | field |
368
+ * | ------- | -------------------------- |
369
+ * | `4` | the number of locals |
370
+ * | ... | the locals |
371
+ *
372
+ * Each local is laid out as follows:
373
+ *
374
+ * | # bytes | field |
375
+ * | ------- | -------------------------- |
376
+ * | `4` | the length of the local |
377
+ * | ... | the local bytes |
378
+ *
379
+ * Some additional things to note about this layout:
380
+ *
381
+ * * The filepath can have a length of 0, in which case we'll consider it an
382
+ * empty string.
383
+ * * The line number should be 0-indexed.
384
+ * * The encoding can have a length of 0, in which case we'll use the default
385
+ * encoding (UTF-8). If it's not 0, it should correspond to a name of an
386
+ * encoding that can be passed to `Encoding.find` in Ruby.
387
+ * * The frozen string literal, encoding locked, main script, and partial script
388
+ * fields are booleans, so their values should be either 0 or 1.
389
+ * * The number of scopes can be 0.
390
+ *
391
+ * @param options The options struct to deserialize into.
392
+ * @param data The binary string to deserialize from.
393
+ */
394
+ void pm_options_read(pm_options_t *options, const char *data);
395
+
396
+ #endif
@@ -0,0 +1,163 @@
1
+ /**
2
+ * @file pack.h
3
+ *
4
+ * A pack template string parser.
5
+ */
6
+ #ifndef PRISM_PACK_H
7
+ #define PRISM_PACK_H
8
+
9
+ #include "prism/defines.h"
10
+
11
+ // We optionally support parsing String#pack templates. For systems that don't
12
+ // want or need this functionality, it can be turned off with the
13
+ // PRISM_EXCLUDE_PACK define.
14
+ #ifdef PRISM_EXCLUDE_PACK
15
+
16
+ void pm_pack_parse(void);
17
+
18
+ #else
19
+
20
+ #include <stdint.h>
21
+ #include <stdlib.h>
22
+
23
+ /** The version of the pack template language that we are parsing. */
24
+ typedef enum pm_pack_version {
25
+ PM_PACK_VERSION_3_2_0
26
+ } pm_pack_version;
27
+
28
+ /** The type of pack template we are parsing. */
29
+ typedef enum pm_pack_variant {
30
+ PM_PACK_VARIANT_PACK,
31
+ PM_PACK_VARIANT_UNPACK
32
+ } pm_pack_variant;
33
+
34
+ /** A directive within the pack template. */
35
+ typedef enum pm_pack_type {
36
+ PM_PACK_SPACE,
37
+ PM_PACK_COMMENT,
38
+ PM_PACK_INTEGER,
39
+ PM_PACK_UTF8,
40
+ PM_PACK_BER,
41
+ PM_PACK_FLOAT,
42
+ PM_PACK_STRING_SPACE_PADDED,
43
+ PM_PACK_STRING_NULL_PADDED,
44
+ PM_PACK_STRING_NULL_TERMINATED,
45
+ PM_PACK_STRING_MSB,
46
+ PM_PACK_STRING_LSB,
47
+ PM_PACK_STRING_HEX_HIGH,
48
+ PM_PACK_STRING_HEX_LOW,
49
+ PM_PACK_STRING_UU,
50
+ PM_PACK_STRING_MIME,
51
+ PM_PACK_STRING_BASE64,
52
+ PM_PACK_STRING_FIXED,
53
+ PM_PACK_STRING_POINTER,
54
+ PM_PACK_MOVE,
55
+ PM_PACK_BACK,
56
+ PM_PACK_NULL,
57
+ PM_PACK_END
58
+ } pm_pack_type;
59
+
60
+ /** The signness of a pack directive. */
61
+ typedef enum pm_pack_signed {
62
+ PM_PACK_UNSIGNED,
63
+ PM_PACK_SIGNED,
64
+ PM_PACK_SIGNED_NA
65
+ } pm_pack_signed;
66
+
67
+ /** The endianness of a pack directive. */
68
+ typedef enum pm_pack_endian {
69
+ PM_PACK_AGNOSTIC_ENDIAN,
70
+ PM_PACK_LITTLE_ENDIAN, // aka 'VAX', or 'V'
71
+ PM_PACK_BIG_ENDIAN, // aka 'network', or 'N'
72
+ PM_PACK_NATIVE_ENDIAN,
73
+ PM_PACK_ENDIAN_NA
74
+ } pm_pack_endian;
75
+
76
+ /** The size of an integer pack directive. */
77
+ typedef enum pm_pack_size {
78
+ PM_PACK_SIZE_SHORT,
79
+ PM_PACK_SIZE_INT,
80
+ PM_PACK_SIZE_LONG,
81
+ PM_PACK_SIZE_LONG_LONG,
82
+ PM_PACK_SIZE_8,
83
+ PM_PACK_SIZE_16,
84
+ PM_PACK_SIZE_32,
85
+ PM_PACK_SIZE_64,
86
+ PM_PACK_SIZE_P,
87
+ PM_PACK_SIZE_NA
88
+ } pm_pack_size;
89
+
90
+ /** The type of length of a pack directive. */
91
+ typedef enum pm_pack_length_type {
92
+ PM_PACK_LENGTH_FIXED,
93
+ PM_PACK_LENGTH_MAX,
94
+ PM_PACK_LENGTH_RELATIVE, // special case for unpack @*
95
+ PM_PACK_LENGTH_NA
96
+ } pm_pack_length_type;
97
+
98
+ /** The type of encoding for a pack template string. */
99
+ typedef enum pm_pack_encoding {
100
+ PM_PACK_ENCODING_START,
101
+ PM_PACK_ENCODING_ASCII_8BIT,
102
+ PM_PACK_ENCODING_US_ASCII,
103
+ PM_PACK_ENCODING_UTF_8
104
+ } pm_pack_encoding;
105
+
106
+ /** The result of parsing a pack template. */
107
+ typedef enum pm_pack_result {
108
+ PM_PACK_OK,
109
+ PM_PACK_ERROR_UNSUPPORTED_DIRECTIVE,
110
+ PM_PACK_ERROR_UNKNOWN_DIRECTIVE,
111
+ PM_PACK_ERROR_LENGTH_TOO_BIG,
112
+ PM_PACK_ERROR_BANG_NOT_ALLOWED,
113
+ PM_PACK_ERROR_DOUBLE_ENDIAN
114
+ } pm_pack_result;
115
+
116
+ /**
117
+ * Parse a single directive from a pack or unpack format string.
118
+ *
119
+ * @param variant (in) pack or unpack
120
+ * @param format (in, out) the start of the next directive to parse on calling,
121
+ * and advanced beyond the parsed directive on return, or as much of it as
122
+ * was consumed until an error was encountered
123
+ * @param format_end (in) the end of the format string
124
+ * @param type (out) the type of the directive
125
+ * @param signed_type (out) whether the value is signed
126
+ * @param endian (out) the endianness of the value
127
+ * @param size (out) the size of the value
128
+ * @param length_type (out) what kind of length is specified
129
+ * @param length (out) the length of the directive
130
+ * @param encoding (in, out) takes the current encoding of the string which
131
+ * would result from parsing the whole format string, and returns a possibly
132
+ * changed directive - the encoding should be `PM_PACK_ENCODING_START` when
133
+ * pm_pack_parse is called for the first directive in a format string
134
+ *
135
+ * @return `PM_PACK_OK` on success or `PM_PACK_ERROR_*` on error
136
+ * @note Consult Ruby documentation for the meaning of directives.
137
+ */
138
+ PRISM_EXPORTED_FUNCTION pm_pack_result
139
+ pm_pack_parse(
140
+ pm_pack_variant variant,
141
+ const char **format,
142
+ const char *format_end,
143
+ pm_pack_type *type,
144
+ pm_pack_signed *signed_type,
145
+ pm_pack_endian *endian,
146
+ pm_pack_size *size,
147
+ pm_pack_length_type *length_type,
148
+ uint64_t *length,
149
+ pm_pack_encoding *encoding
150
+ );
151
+
152
+ /**
153
+ * Prism abstracts sizes away from the native system - this converts an abstract
154
+ * size to a native size.
155
+ *
156
+ * @param size The abstract size to convert.
157
+ * @return The native size.
158
+ */
159
+ PRISM_EXPORTED_FUNCTION size_t pm_size_to_native(pm_pack_size size);
160
+
161
+ #endif
162
+
163
+ #endif