ed-precompiled_prism 1.5.2

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 (154) hide show
  1. checksums.yaml +7 -0
  2. data/BSDmakefile +58 -0
  3. data/CHANGELOG.md +723 -0
  4. data/CODE_OF_CONDUCT.md +76 -0
  5. data/CONTRIBUTING.md +58 -0
  6. data/LICENSE.md +7 -0
  7. data/Makefile +110 -0
  8. data/README.md +143 -0
  9. data/config.yml +4714 -0
  10. data/docs/build_system.md +119 -0
  11. data/docs/configuration.md +68 -0
  12. data/docs/cruby_compilation.md +27 -0
  13. data/docs/design.md +53 -0
  14. data/docs/encoding.md +121 -0
  15. data/docs/fuzzing.md +88 -0
  16. data/docs/heredocs.md +36 -0
  17. data/docs/javascript.md +118 -0
  18. data/docs/local_variable_depth.md +229 -0
  19. data/docs/mapping.md +117 -0
  20. data/docs/parser_translation.md +24 -0
  21. data/docs/parsing_rules.md +22 -0
  22. data/docs/releasing.md +98 -0
  23. data/docs/relocation.md +34 -0
  24. data/docs/ripper_translation.md +72 -0
  25. data/docs/ruby_api.md +44 -0
  26. data/docs/ruby_parser_translation.md +19 -0
  27. data/docs/serialization.md +233 -0
  28. data/docs/testing.md +55 -0
  29. data/ext/prism/api_node.c +6941 -0
  30. data/ext/prism/api_pack.c +276 -0
  31. data/ext/prism/extconf.rb +127 -0
  32. data/ext/prism/extension.c +1419 -0
  33. data/ext/prism/extension.h +19 -0
  34. data/include/prism/ast.h +8220 -0
  35. data/include/prism/defines.h +260 -0
  36. data/include/prism/diagnostic.h +456 -0
  37. data/include/prism/encoding.h +283 -0
  38. data/include/prism/node.h +129 -0
  39. data/include/prism/options.h +482 -0
  40. data/include/prism/pack.h +163 -0
  41. data/include/prism/parser.h +933 -0
  42. data/include/prism/prettyprint.h +34 -0
  43. data/include/prism/regexp.h +43 -0
  44. data/include/prism/static_literals.h +121 -0
  45. data/include/prism/util/pm_buffer.h +236 -0
  46. data/include/prism/util/pm_char.h +204 -0
  47. data/include/prism/util/pm_constant_pool.h +218 -0
  48. data/include/prism/util/pm_integer.h +130 -0
  49. data/include/prism/util/pm_list.h +103 -0
  50. data/include/prism/util/pm_memchr.h +29 -0
  51. data/include/prism/util/pm_newline_list.h +113 -0
  52. data/include/prism/util/pm_string.h +200 -0
  53. data/include/prism/util/pm_strncasecmp.h +32 -0
  54. data/include/prism/util/pm_strpbrk.h +46 -0
  55. data/include/prism/version.h +29 -0
  56. data/include/prism.h +408 -0
  57. data/lib/prism/compiler.rb +801 -0
  58. data/lib/prism/desugar_compiler.rb +392 -0
  59. data/lib/prism/dispatcher.rb +2210 -0
  60. data/lib/prism/dot_visitor.rb +4762 -0
  61. data/lib/prism/dsl.rb +1003 -0
  62. data/lib/prism/ffi.rb +570 -0
  63. data/lib/prism/inspect_visitor.rb +2392 -0
  64. data/lib/prism/lex_compat.rb +928 -0
  65. data/lib/prism/mutation_compiler.rb +772 -0
  66. data/lib/prism/node.rb +18816 -0
  67. data/lib/prism/node_ext.rb +511 -0
  68. data/lib/prism/pack.rb +230 -0
  69. data/lib/prism/parse_result/comments.rb +188 -0
  70. data/lib/prism/parse_result/errors.rb +66 -0
  71. data/lib/prism/parse_result/newlines.rb +155 -0
  72. data/lib/prism/parse_result.rb +911 -0
  73. data/lib/prism/pattern.rb +269 -0
  74. data/lib/prism/polyfill/append_as_bytes.rb +15 -0
  75. data/lib/prism/polyfill/byteindex.rb +13 -0
  76. data/lib/prism/polyfill/scan_byte.rb +14 -0
  77. data/lib/prism/polyfill/unpack1.rb +14 -0
  78. data/lib/prism/polyfill/warn.rb +36 -0
  79. data/lib/prism/reflection.rb +416 -0
  80. data/lib/prism/relocation.rb +505 -0
  81. data/lib/prism/serialize.rb +2398 -0
  82. data/lib/prism/string_query.rb +31 -0
  83. data/lib/prism/translation/parser/builder.rb +62 -0
  84. data/lib/prism/translation/parser/compiler.rb +2234 -0
  85. data/lib/prism/translation/parser/lexer.rb +820 -0
  86. data/lib/prism/translation/parser.rb +374 -0
  87. data/lib/prism/translation/parser33.rb +13 -0
  88. data/lib/prism/translation/parser34.rb +13 -0
  89. data/lib/prism/translation/parser35.rb +13 -0
  90. data/lib/prism/translation/parser_current.rb +24 -0
  91. data/lib/prism/translation/ripper/sexp.rb +126 -0
  92. data/lib/prism/translation/ripper/shim.rb +5 -0
  93. data/lib/prism/translation/ripper.rb +3474 -0
  94. data/lib/prism/translation/ruby_parser.rb +1929 -0
  95. data/lib/prism/translation.rb +16 -0
  96. data/lib/prism/visitor.rb +813 -0
  97. data/lib/prism.rb +97 -0
  98. data/prism.gemspec +174 -0
  99. data/rbi/prism/compiler.rbi +12 -0
  100. data/rbi/prism/dsl.rbi +524 -0
  101. data/rbi/prism/inspect_visitor.rbi +12 -0
  102. data/rbi/prism/node.rbi +8734 -0
  103. data/rbi/prism/node_ext.rbi +107 -0
  104. data/rbi/prism/parse_result.rbi +404 -0
  105. data/rbi/prism/reflection.rbi +58 -0
  106. data/rbi/prism/string_query.rbi +12 -0
  107. data/rbi/prism/translation/parser.rbi +11 -0
  108. data/rbi/prism/translation/parser33.rbi +6 -0
  109. data/rbi/prism/translation/parser34.rbi +6 -0
  110. data/rbi/prism/translation/parser35.rbi +6 -0
  111. data/rbi/prism/translation/ripper.rbi +15 -0
  112. data/rbi/prism/visitor.rbi +473 -0
  113. data/rbi/prism.rbi +66 -0
  114. data/sig/prism/compiler.rbs +9 -0
  115. data/sig/prism/dispatcher.rbs +19 -0
  116. data/sig/prism/dot_visitor.rbs +6 -0
  117. data/sig/prism/dsl.rbs +351 -0
  118. data/sig/prism/inspect_visitor.rbs +22 -0
  119. data/sig/prism/lex_compat.rbs +10 -0
  120. data/sig/prism/mutation_compiler.rbs +159 -0
  121. data/sig/prism/node.rbs +4028 -0
  122. data/sig/prism/node_ext.rbs +149 -0
  123. data/sig/prism/pack.rbs +43 -0
  124. data/sig/prism/parse_result/comments.rbs +38 -0
  125. data/sig/prism/parse_result.rbs +196 -0
  126. data/sig/prism/pattern.rbs +13 -0
  127. data/sig/prism/reflection.rbs +50 -0
  128. data/sig/prism/relocation.rbs +185 -0
  129. data/sig/prism/serialize.rbs +8 -0
  130. data/sig/prism/string_query.rbs +11 -0
  131. data/sig/prism/visitor.rbs +169 -0
  132. data/sig/prism.rbs +254 -0
  133. data/src/diagnostic.c +850 -0
  134. data/src/encoding.c +5235 -0
  135. data/src/node.c +8676 -0
  136. data/src/options.c +328 -0
  137. data/src/pack.c +509 -0
  138. data/src/prettyprint.c +8941 -0
  139. data/src/prism.c +23361 -0
  140. data/src/regexp.c +790 -0
  141. data/src/serialize.c +2268 -0
  142. data/src/static_literals.c +617 -0
  143. data/src/token_type.c +703 -0
  144. data/src/util/pm_buffer.c +357 -0
  145. data/src/util/pm_char.c +318 -0
  146. data/src/util/pm_constant_pool.c +342 -0
  147. data/src/util/pm_integer.c +670 -0
  148. data/src/util/pm_list.c +49 -0
  149. data/src/util/pm_memchr.c +35 -0
  150. data/src/util/pm_newline_list.c +125 -0
  151. data/src/util/pm_string.c +381 -0
  152. data/src/util/pm_strncasecmp.c +36 -0
  153. data/src/util/pm_strpbrk.c +206 -0
  154. metadata +195 -0
@@ -0,0 +1,276 @@
1
+ #include "prism/extension.h"
2
+
3
+ #ifdef PRISM_EXCLUDE_PACK
4
+
5
+ void
6
+ Init_prism_pack(void) {}
7
+
8
+ #else
9
+
10
+ static VALUE rb_cPrism;
11
+ static VALUE rb_cPrismPack;
12
+ static VALUE rb_cPrismPackDirective;
13
+ static VALUE rb_cPrismPackFormat;
14
+
15
+ static VALUE v3_2_0_symbol;
16
+ static VALUE pack_symbol;
17
+ static VALUE unpack_symbol;
18
+
19
+ #if SIZEOF_UINT64_T == SIZEOF_LONG_LONG
20
+ # define UINT64T2NUM(x) ULL2NUM(x)
21
+ # define NUM2UINT64T(x) (uint64_t)NUM2ULL(x)
22
+ #elif SIZEOF_UINT64_T == SIZEOF_LONG
23
+ # define UINT64T2NUM(x) ULONG2NUM(x)
24
+ # define NUM2UINT64T(x) (uint64_t)NUM2ULONG(x)
25
+ #else
26
+ // error No uint64_t conversion
27
+ #endif
28
+
29
+ static VALUE
30
+ pack_type_to_symbol(pm_pack_type type) {
31
+ switch (type) {
32
+ case PM_PACK_SPACE:
33
+ return ID2SYM(rb_intern("SPACE"));
34
+ case PM_PACK_COMMENT:
35
+ return ID2SYM(rb_intern("COMMENT"));
36
+ case PM_PACK_INTEGER:
37
+ return ID2SYM(rb_intern("INTEGER"));
38
+ case PM_PACK_UTF8:
39
+ return ID2SYM(rb_intern("UTF8"));
40
+ case PM_PACK_BER:
41
+ return ID2SYM(rb_intern("BER"));
42
+ case PM_PACK_FLOAT:
43
+ return ID2SYM(rb_intern("FLOAT"));
44
+ case PM_PACK_STRING_SPACE_PADDED:
45
+ return ID2SYM(rb_intern("STRING_SPACE_PADDED"));
46
+ case PM_PACK_STRING_NULL_PADDED:
47
+ return ID2SYM(rb_intern("STRING_NULL_PADDED"));
48
+ case PM_PACK_STRING_NULL_TERMINATED:
49
+ return ID2SYM(rb_intern("STRING_NULL_TERMINATED"));
50
+ case PM_PACK_STRING_MSB:
51
+ return ID2SYM(rb_intern("STRING_MSB"));
52
+ case PM_PACK_STRING_LSB:
53
+ return ID2SYM(rb_intern("STRING_LSB"));
54
+ case PM_PACK_STRING_HEX_HIGH:
55
+ return ID2SYM(rb_intern("STRING_HEX_HIGH"));
56
+ case PM_PACK_STRING_HEX_LOW:
57
+ return ID2SYM(rb_intern("STRING_HEX_LOW"));
58
+ case PM_PACK_STRING_UU:
59
+ return ID2SYM(rb_intern("STRING_UU"));
60
+ case PM_PACK_STRING_MIME:
61
+ return ID2SYM(rb_intern("STRING_MIME"));
62
+ case PM_PACK_STRING_BASE64:
63
+ return ID2SYM(rb_intern("STRING_BASE64"));
64
+ case PM_PACK_STRING_FIXED:
65
+ return ID2SYM(rb_intern("STRING_FIXED"));
66
+ case PM_PACK_STRING_POINTER:
67
+ return ID2SYM(rb_intern("STRING_POINTER"));
68
+ case PM_PACK_MOVE:
69
+ return ID2SYM(rb_intern("MOVE"));
70
+ case PM_PACK_BACK:
71
+ return ID2SYM(rb_intern("BACK"));
72
+ case PM_PACK_NULL:
73
+ return ID2SYM(rb_intern("NULL"));
74
+ default:
75
+ return Qnil;
76
+ }
77
+ }
78
+
79
+ static VALUE
80
+ pack_signed_to_symbol(pm_pack_signed signed_type) {
81
+ switch (signed_type) {
82
+ case PM_PACK_UNSIGNED:
83
+ return ID2SYM(rb_intern("UNSIGNED"));
84
+ case PM_PACK_SIGNED:
85
+ return ID2SYM(rb_intern("SIGNED"));
86
+ case PM_PACK_SIGNED_NA:
87
+ return ID2SYM(rb_intern("SIGNED_NA"));
88
+ default:
89
+ return Qnil;
90
+ }
91
+ }
92
+
93
+ static VALUE
94
+ pack_endian_to_symbol(pm_pack_endian endian) {
95
+ switch (endian) {
96
+ case PM_PACK_AGNOSTIC_ENDIAN:
97
+ return ID2SYM(rb_intern("AGNOSTIC_ENDIAN"));
98
+ case PM_PACK_LITTLE_ENDIAN:
99
+ return ID2SYM(rb_intern("LITTLE_ENDIAN"));
100
+ case PM_PACK_BIG_ENDIAN:
101
+ return ID2SYM(rb_intern("BIG_ENDIAN"));
102
+ case PM_PACK_NATIVE_ENDIAN:
103
+ return ID2SYM(rb_intern("NATIVE_ENDIAN"));
104
+ case PM_PACK_ENDIAN_NA:
105
+ return ID2SYM(rb_intern("ENDIAN_NA"));
106
+ default:
107
+ return Qnil;
108
+ }
109
+ }
110
+
111
+ static VALUE
112
+ pack_size_to_symbol(pm_pack_size size) {
113
+ switch (size) {
114
+ case PM_PACK_SIZE_SHORT:
115
+ return ID2SYM(rb_intern("SIZE_SHORT"));
116
+ case PM_PACK_SIZE_INT:
117
+ return ID2SYM(rb_intern("SIZE_INT"));
118
+ case PM_PACK_SIZE_LONG:
119
+ return ID2SYM(rb_intern("SIZE_LONG"));
120
+ case PM_PACK_SIZE_LONG_LONG:
121
+ return ID2SYM(rb_intern("SIZE_LONG_LONG"));
122
+ case PM_PACK_SIZE_8:
123
+ return ID2SYM(rb_intern("SIZE_8"));
124
+ case PM_PACK_SIZE_16:
125
+ return ID2SYM(rb_intern("SIZE_16"));
126
+ case PM_PACK_SIZE_32:
127
+ return ID2SYM(rb_intern("SIZE_32"));
128
+ case PM_PACK_SIZE_64:
129
+ return ID2SYM(rb_intern("SIZE_64"));
130
+ case PM_PACK_SIZE_P:
131
+ return ID2SYM(rb_intern("SIZE_P"));
132
+ case PM_PACK_SIZE_NA:
133
+ return ID2SYM(rb_intern("SIZE_NA"));
134
+ default:
135
+ return Qnil;
136
+ }
137
+ }
138
+
139
+ static VALUE
140
+ pack_length_type_to_symbol(pm_pack_length_type length_type) {
141
+ switch (length_type) {
142
+ case PM_PACK_LENGTH_FIXED:
143
+ return ID2SYM(rb_intern("LENGTH_FIXED"));
144
+ case PM_PACK_LENGTH_MAX:
145
+ return ID2SYM(rb_intern("LENGTH_MAX"));
146
+ case PM_PACK_LENGTH_RELATIVE:
147
+ return ID2SYM(rb_intern("LENGTH_RELATIVE"));
148
+ case PM_PACK_LENGTH_NA:
149
+ return ID2SYM(rb_intern("LENGTH_NA"));
150
+ default:
151
+ return Qnil;
152
+ }
153
+ }
154
+
155
+ static VALUE
156
+ pack_encoding_to_ruby(pm_pack_encoding encoding) {
157
+ int index;
158
+ switch (encoding) {
159
+ case PM_PACK_ENCODING_ASCII_8BIT:
160
+ index = rb_ascii8bit_encindex();
161
+ break;
162
+ case PM_PACK_ENCODING_US_ASCII:
163
+ index = rb_usascii_encindex();
164
+ break;
165
+ case PM_PACK_ENCODING_UTF_8:
166
+ index = rb_utf8_encindex();
167
+ break;
168
+ default:
169
+ return Qnil;
170
+ }
171
+ return rb_enc_from_encoding(rb_enc_from_index(index));
172
+ }
173
+
174
+ /**
175
+ * call-seq:
176
+ * Pack::parse(version, variant, source) -> Format
177
+ *
178
+ * Parse the given source and return a format object.
179
+ */
180
+ static VALUE
181
+ pack_parse(VALUE self, VALUE version_symbol, VALUE variant_symbol, VALUE format_string) {
182
+ if (version_symbol != v3_2_0_symbol) {
183
+ rb_raise(rb_eArgError, "invalid version");
184
+ }
185
+
186
+ pm_pack_variant variant;
187
+ if (variant_symbol == pack_symbol) {
188
+ variant = PM_PACK_VARIANT_PACK;
189
+ } else if (variant_symbol == unpack_symbol) {
190
+ variant = PM_PACK_VARIANT_UNPACK;
191
+ } else {
192
+ rb_raise(rb_eArgError, "invalid variant");
193
+ }
194
+
195
+ StringValue(format_string);
196
+
197
+ const char *format = RSTRING_PTR(format_string);
198
+ const char *format_end = format + RSTRING_LEN(format_string);
199
+ pm_pack_encoding encoding = PM_PACK_ENCODING_START;
200
+
201
+ VALUE directives_array = rb_ary_new();
202
+
203
+ while (format < format_end) {
204
+ pm_pack_type type;
205
+ pm_pack_signed signed_type;
206
+ pm_pack_endian endian;
207
+ pm_pack_size size;
208
+ pm_pack_length_type length_type;
209
+ uint64_t length;
210
+
211
+ const char *directive_start = format;
212
+
213
+ pm_pack_result parse_result = pm_pack_parse(variant, &format, format_end, &type, &signed_type, &endian,
214
+ &size, &length_type, &length, &encoding);
215
+
216
+ const char *directive_end = format;
217
+
218
+ switch (parse_result) {
219
+ case PM_PACK_OK:
220
+ break;
221
+ case PM_PACK_ERROR_UNSUPPORTED_DIRECTIVE:
222
+ rb_raise(rb_eArgError, "unsupported directive");
223
+ case PM_PACK_ERROR_UNKNOWN_DIRECTIVE:
224
+ rb_raise(rb_eArgError, "unsupported directive");
225
+ case PM_PACK_ERROR_LENGTH_TOO_BIG:
226
+ rb_raise(rb_eRangeError, "pack length too big");
227
+ case PM_PACK_ERROR_BANG_NOT_ALLOWED:
228
+ rb_raise(rb_eRangeError, "bang not allowed");
229
+ case PM_PACK_ERROR_DOUBLE_ENDIAN:
230
+ rb_raise(rb_eRangeError, "double endian");
231
+ default:
232
+ rb_bug("parse result");
233
+ }
234
+
235
+ if (type == PM_PACK_END) {
236
+ break;
237
+ }
238
+
239
+ VALUE directive_args[9] = {
240
+ version_symbol,
241
+ variant_symbol,
242
+ rb_usascii_str_new(directive_start, directive_end - directive_start),
243
+ pack_type_to_symbol(type),
244
+ pack_signed_to_symbol(signed_type),
245
+ pack_endian_to_symbol(endian),
246
+ pack_size_to_symbol(size),
247
+ pack_length_type_to_symbol(length_type),
248
+ UINT64T2NUM(length)
249
+ };
250
+
251
+ rb_ary_push(directives_array, rb_class_new_instance(9, directive_args, rb_cPrismPackDirective));
252
+ }
253
+
254
+ VALUE format_args[2];
255
+ format_args[0] = directives_array;
256
+ format_args[1] = pack_encoding_to_ruby(encoding);
257
+ return rb_class_new_instance(2, format_args, rb_cPrismPackFormat);
258
+ }
259
+
260
+ /**
261
+ * The function that gets called when Ruby initializes the prism extension.
262
+ */
263
+ void
264
+ Init_prism_pack(void) {
265
+ rb_cPrism = rb_define_module("Prism");
266
+ rb_cPrismPack = rb_define_module_under(rb_cPrism, "Pack");
267
+ rb_cPrismPackDirective = rb_define_class_under(rb_cPrismPack, "Directive", rb_cObject);
268
+ rb_cPrismPackFormat = rb_define_class_under(rb_cPrismPack, "Format", rb_cObject);
269
+ rb_define_singleton_method(rb_cPrismPack, "parse", pack_parse, 3);
270
+
271
+ v3_2_0_symbol = ID2SYM(rb_intern("v3_2_0"));
272
+ pack_symbol = ID2SYM(rb_intern("pack"));
273
+ unpack_symbol = ID2SYM(rb_intern("unpack"));
274
+ }
275
+
276
+ #endif
@@ -0,0 +1,127 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rbconfig"
4
+
5
+ if ARGV.delete("--help")
6
+ print(<<~TEXT)
7
+ USAGE: ruby #{$PROGRAM_NAME} [options]
8
+
9
+ Flags that are always valid:
10
+
11
+ --enable-build-debug
12
+ Enable debug build.
13
+ You may also set the PRISM_BUILD_DEBUG environment variable.
14
+
15
+ --enable-build-minimal
16
+ Enable minimal build.
17
+ You may also set the PRISM_BUILD_MINIMAL environment variable.
18
+
19
+ --help
20
+ Display this message.
21
+
22
+ Environment variables used:
23
+
24
+ PRISM_BUILD_DEBUG
25
+ Equivalent to `--enable-build-debug` when set, even if nil or blank.
26
+
27
+ PRISM_BUILD_MINIMAL
28
+ Equivalent to `--enable-build-minimal` when set, even if nil or blank.
29
+
30
+ TEXT
31
+ exit!(0)
32
+ end
33
+
34
+ # If this gem is being build from a git source, then we need to run
35
+ # templating if it hasn't been run yet. In normal packaging, we would have
36
+ # shipped the templated files with the gem, so this wouldn't be necessary.
37
+ def generate_templates
38
+ Dir.chdir(File.expand_path("../..", __dir__)) do
39
+ if !File.exist?("include/prism/ast.h") && Dir.exist?(".git")
40
+ system("templates/template.rb", exception: true)
41
+ end
42
+ end
43
+ end
44
+
45
+ # Runs `make` in the root directory of the project. Note that this is the
46
+ # `Makefile` for the overall project, not the `Makefile` that is being generated
47
+ # by this script.`
48
+ def make(env, target)
49
+ puts "Running make #{target} with #{env.inspect}"
50
+ Dir.chdir(File.expand_path("../..", __dir__)) do
51
+ system(
52
+ env,
53
+ RUBY_PLATFORM.match?(/openbsd|freebsd/) ? "gmake" : "make",
54
+ target,
55
+ exception: true
56
+ )
57
+ end
58
+ end
59
+
60
+ # On non-CRuby we only need the shared library since we'll interface with it
61
+ # through FFI, so we'll build only that and not the C extension. We also avoid
62
+ # `require "mkmf"` as that prepends the GraalVM LLVM toolchain to PATH on TruffleRuby < 24.0,
63
+ # but we want to use the system toolchain here since libprism is run natively.
64
+ if RUBY_ENGINE != "ruby"
65
+ generate_templates
66
+ soext = RbConfig::CONFIG["SOEXT"]
67
+ # Pass SOEXT to avoid an extra subprocess just to query that
68
+ make({ "SOEXT" => soext }, "build/libprism.#{soext}")
69
+ File.write("Makefile", "all install clean:\n\t@#{RbConfig::CONFIG["NULLCMD"]}\n")
70
+ return
71
+ end
72
+
73
+ require "mkmf"
74
+
75
+ # First, ensure that we can find the header for the prism library.
76
+ generate_templates # Templates should be generated before find_header.
77
+ unless find_header("prism.h", File.expand_path("../../include", __dir__))
78
+ raise "prism.h is required"
79
+ end
80
+
81
+ # Next, ensure we can find the header for the C extension. Explicitly look for
82
+ # the extension header in the parent directory because we want to consistently
83
+ # look for `prism/extension.h` in our source files to line up with our mirroring
84
+ # in CRuby.
85
+ unless find_header("prism/extension.h", File.expand_path("..", __dir__))
86
+ raise "prism/extension.h is required"
87
+ end
88
+
89
+ # If `--enable-build-debug` is passed to this script or the
90
+ # `PRISM_BUILD_DEBUG` environment variable is defined, we'll build with the
91
+ # `PRISM_BUILD_DEBUG` macro defined. This causes parse functions to
92
+ # duplicate their input so that they have clearly set bounds, which is useful
93
+ # for finding bugs that cause the parser to read off the end of the input.
94
+ if enable_config("build-debug", ENV["PRISM_BUILD_DEBUG"] || false)
95
+ append_cflags("-DPRISM_BUILD_DEBUG")
96
+ end
97
+
98
+ # If `--enable-build-minimal` is passed to this script or the
99
+ # `PRISM_BUILD_MINIMAL` environment variable is defined, we'll build with the
100
+ # set of defines that comprise the minimal set. This causes the parser to be
101
+ # built with minimal features, necessary for stripping out functionality when
102
+ # the size of the final built artifact is a concern.
103
+ if enable_config("build-minimal", ENV["PRISM_BUILD_MINIMAL"] || false)
104
+ append_cflags("-DPRISM_BUILD_MINIMAL")
105
+ end
106
+
107
+ # By default, all symbols are hidden in the shared library.
108
+ append_cflags("-fvisibility=hidden")
109
+
110
+ def src_list(path)
111
+ srcdir = path.dup
112
+ RbConfig.expand(srcdir) # mutates srcdir :-/
113
+ Dir[File.join(srcdir, "*.{#{SRC_EXT.join(%q{,})}}")]
114
+ end
115
+
116
+ def add_libprism_source(path)
117
+ $VPATH << path
118
+ src_list path
119
+ end
120
+
121
+ $srcs = src_list("$(srcdir)") +
122
+ add_libprism_source("$(srcdir)/../../src") +
123
+ add_libprism_source("$(srcdir)/../../src/util")
124
+
125
+ # Finally, we'll create the `Makefile` that is going to be used to configure and
126
+ # build the C extension.
127
+ create_makefile("prism/prism")