prism 0.24.0 → 0.29.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/BSDmakefile +58 -0
- data/CHANGELOG.md +132 -1
- data/Makefile +25 -18
- data/README.md +45 -6
- data/config.yml +828 -25
- data/docs/build_system.md +31 -0
- data/docs/configuration.md +4 -0
- data/docs/cruby_compilation.md +1 -1
- data/docs/parser_translation.md +14 -9
- data/docs/releasing.md +7 -9
- data/docs/ripper_translation.md +50 -0
- data/docs/ruby_api.md +1 -0
- data/docs/serialization.md +26 -5
- data/ext/prism/api_node.c +1037 -936
- data/ext/prism/api_pack.c +9 -0
- data/ext/prism/extconf.rb +62 -18
- data/ext/prism/extension.c +351 -71
- data/ext/prism/extension.h +5 -4
- data/include/prism/ast.h +539 -101
- data/include/prism/defines.h +106 -2
- data/include/prism/diagnostic.h +168 -74
- data/include/prism/encoding.h +22 -4
- data/include/prism/node.h +93 -0
- data/include/prism/options.h +84 -9
- data/include/prism/pack.h +11 -0
- data/include/prism/parser.h +213 -54
- data/include/prism/prettyprint.h +8 -0
- data/include/prism/static_literals.h +120 -0
- data/include/prism/util/pm_buffer.h +65 -2
- data/include/prism/util/pm_constant_pool.h +18 -1
- data/include/prism/util/pm_integer.h +119 -0
- data/include/prism/util/pm_list.h +1 -1
- data/include/prism/util/pm_newline_list.h +8 -0
- data/include/prism/util/pm_string.h +26 -2
- data/include/prism/version.h +2 -2
- data/include/prism.h +59 -1
- data/lib/prism/compiler.rb +8 -1
- data/lib/prism/debug.rb +46 -3
- data/lib/prism/desugar_compiler.rb +5 -3
- data/lib/prism/dispatcher.rb +29 -0
- data/lib/prism/dot_visitor.rb +141 -54
- data/lib/prism/dsl.rb +48 -36
- data/lib/prism/ffi.rb +82 -17
- data/lib/prism/inspect_visitor.rb +2156 -0
- data/lib/prism/lex_compat.rb +34 -15
- data/lib/prism/mutation_compiler.rb +13 -2
- data/lib/prism/node.rb +4453 -4459
- data/lib/prism/node_ext.rb +249 -30
- data/lib/prism/pack.rb +4 -0
- data/lib/prism/parse_result/comments.rb +35 -18
- data/lib/prism/parse_result/newlines.rb +2 -2
- data/lib/prism/parse_result.rb +218 -43
- data/lib/prism/pattern.rb +28 -10
- data/lib/prism/polyfill/byteindex.rb +13 -0
- data/lib/prism/polyfill/unpack1.rb +14 -0
- data/lib/prism/reflection.rb +411 -0
- data/lib/prism/serialize.rb +480 -112
- data/lib/prism/translation/parser/compiler.rb +376 -88
- data/lib/prism/translation/parser/lexer.rb +103 -22
- data/lib/prism/translation/parser/rubocop.rb +41 -13
- data/lib/prism/translation/parser.rb +123 -11
- data/lib/prism/translation/parser33.rb +1 -1
- data/lib/prism/translation/parser34.rb +1 -1
- data/lib/prism/translation/ripper/sexp.rb +125 -0
- data/lib/prism/translation/ripper/shim.rb +5 -0
- data/lib/prism/translation/ripper.rb +3216 -462
- data/lib/prism/translation/ruby_parser.rb +111 -56
- data/lib/prism/translation.rb +3 -1
- data/lib/prism/visitor.rb +10 -0
- data/lib/prism.rb +12 -20
- data/prism.gemspec +46 -14
- data/rbi/prism/compiler.rbi +12 -0
- data/rbi/prism/inspect_visitor.rbi +12 -0
- data/rbi/prism/node.rbi +8712 -0
- data/rbi/prism/node_ext.rbi +107 -0
- data/rbi/prism/parse_result.rbi +358 -0
- data/rbi/prism/reflection.rbi +58 -0
- data/rbi/prism/translation/parser.rbi +11 -0
- data/rbi/prism/translation/parser33.rbi +6 -0
- data/rbi/prism/translation/parser34.rbi +6 -0
- data/rbi/prism/translation/ripper.rbi +15 -0
- data/rbi/prism/visitor.rbi +470 -0
- data/rbi/prism.rbi +38 -7748
- data/sig/prism/compiler.rbs +9 -0
- data/sig/prism/dispatcher.rbs +16 -0
- data/sig/prism/dot_visitor.rbs +6 -0
- data/sig/prism/dsl.rbs +462 -0
- data/sig/prism/inspect_visitor.rbs +22 -0
- data/sig/prism/lex_compat.rbs +10 -0
- data/sig/prism/mutation_compiler.rbs +158 -0
- data/sig/prism/node.rbs +3558 -0
- data/sig/prism/node_ext.rbs +82 -0
- data/sig/prism/pack.rbs +43 -0
- data/sig/prism/parse_result.rbs +160 -0
- data/sig/prism/pattern.rbs +13 -0
- data/sig/prism/reflection.rbs +50 -0
- data/sig/prism/serialize.rbs +6 -0
- data/sig/prism/visitor.rbs +168 -0
- data/sig/prism.rbs +188 -4767
- data/src/diagnostic.c +636 -230
- data/src/encoding.c +211 -108
- data/src/node.c +7555 -451
- data/src/options.c +66 -31
- data/src/pack.c +33 -17
- data/src/prettyprint.c +1383 -1431
- data/src/prism.c +4734 -1310
- data/src/regexp.c +17 -2
- data/src/serialize.c +68 -46
- data/src/static_literals.c +638 -0
- data/src/token_type.c +10 -9
- data/src/util/pm_buffer.c +147 -20
- data/src/util/pm_char.c +4 -4
- data/src/util/pm_constant_pool.c +35 -11
- data/src/util/pm_integer.c +642 -0
- data/src/util/pm_list.c +1 -1
- data/src/util/pm_newline_list.c +14 -5
- data/src/util/pm_string.c +134 -5
- data/src/util/pm_string_list.c +2 -2
- metadata +41 -9
- data/docs/ripper.md +0 -36
- data/include/prism/util/pm_state_stack.h +0 -42
- data/lib/prism/node_inspector.rb +0 -68
- data/rbi/prism_static.rbi +0 -207
- data/sig/prism_static.rbs +0 -201
- data/src/util/pm_state_stack.c +0 -25
data/ext/prism/api_pack.c
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
#include "prism/extension.h"
|
2
2
|
|
3
|
+
#ifdef PRISM_EXCLUDE_PACK
|
4
|
+
|
5
|
+
void
|
6
|
+
Init_prism_pack(void) {}
|
7
|
+
|
8
|
+
#else
|
9
|
+
|
3
10
|
static VALUE rb_cPrism;
|
4
11
|
static VALUE rb_cPrismPack;
|
5
12
|
static VALUE rb_cPrismPackDirective;
|
@@ -265,3 +272,5 @@ Init_prism_pack(void) {
|
|
265
272
|
pack_symbol = ID2SYM(rb_intern("pack"));
|
266
273
|
unpack_symbol = ID2SYM(rb_intern("unpack"));
|
267
274
|
}
|
275
|
+
|
276
|
+
#endif
|
data/ext/prism/extconf.rb
CHANGED
@@ -1,22 +1,31 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "rbconfig"
|
4
|
+
|
3
5
|
if ARGV.delete("--help")
|
4
6
|
print(<<~TEXT)
|
5
7
|
USAGE: ruby #{$PROGRAM_NAME} [options]
|
6
8
|
|
7
9
|
Flags that are always valid:
|
8
10
|
|
9
|
-
--enable-debug
|
10
|
-
Enable debug
|
11
|
-
You may also
|
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.
|
12
18
|
|
13
19
|
--help
|
14
20
|
Display this message.
|
15
21
|
|
16
22
|
Environment variables used:
|
17
23
|
|
18
|
-
|
19
|
-
Equivalent to `--enable-debug
|
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.
|
20
29
|
|
21
30
|
TEXT
|
22
31
|
exit!(0)
|
@@ -36,25 +45,51 @@ end
|
|
36
45
|
# Runs `make` in the root directory of the project. Note that this is the
|
37
46
|
# `Makefile` for the overall project, not the `Makefile` that is being generated
|
38
47
|
# by this script.`
|
39
|
-
def make(target)
|
48
|
+
def make(env, target)
|
49
|
+
puts "Running make #{target} with #{env.inspect}"
|
40
50
|
Dir.chdir(File.expand_path("../..", __dir__)) do
|
41
|
-
system(
|
51
|
+
system(
|
52
|
+
env,
|
53
|
+
RUBY_PLATFORM.include?("openbsd") ? "gmake" : "make",
|
54
|
+
target,
|
55
|
+
exception: true
|
56
|
+
)
|
42
57
|
end
|
43
58
|
end
|
44
59
|
|
45
|
-
require "rbconfig"
|
46
|
-
|
47
60
|
# On non-CRuby we only need the shared library since we'll interface with it
|
48
61
|
# through FFI, so we'll build only that and not the C extension. We also avoid
|
49
|
-
# `require "mkmf"` as that prepends the LLVM toolchain to PATH on TruffleRuby,
|
50
|
-
# but we want to use the
|
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.
|
51
64
|
if RUBY_ENGINE != "ruby"
|
52
65
|
generate_templates
|
53
|
-
|
66
|
+
soext = RbConfig::CONFIG["SOEXT"]
|
67
|
+
# Pass SOEXT to avoid an extra subprocess just to query that
|
68
|
+
make({ "SOEXT" => soext }, "build/libprism.#{soext}")
|
54
69
|
File.write("Makefile", "all install clean:\n\t@#{RbConfig::CONFIG["NULLCMD"]}\n")
|
55
70
|
return
|
56
71
|
end
|
57
72
|
|
73
|
+
# We're going to need to run `make` using prism's `Makefile`.
|
74
|
+
# We want to use the same toolchain (compiler, flags, etc) to compile libprism.a and
|
75
|
+
# the C extension since they will be linked together.
|
76
|
+
# The C extension uses RbConfig, which contains values from the toolchain that built the running Ruby.
|
77
|
+
env = RbConfig::CONFIG.slice("SOEXT", "CPPFLAGS", "CFLAGS", "CC", "AR", "ARFLAGS", "MAKEDIRS", "RMALL")
|
78
|
+
|
79
|
+
# It's possible that the Ruby that is being run wasn't actually compiled on this
|
80
|
+
# machine, in which case parts of RbConfig might be incorrect. In this case
|
81
|
+
# we'll need to do some additional checks and potentially fall back to defaults.
|
82
|
+
if env.key?("CC") && !File.exist?(env["CC"])
|
83
|
+
env.delete("CC")
|
84
|
+
env.delete("CFLAGS")
|
85
|
+
env.delete("CPPFLAGS")
|
86
|
+
end
|
87
|
+
|
88
|
+
if env.key?("AR") && !File.exist?(env["AR"])
|
89
|
+
env.delete("AR")
|
90
|
+
env.delete("ARFLAGS")
|
91
|
+
end
|
92
|
+
|
58
93
|
require "mkmf"
|
59
94
|
|
60
95
|
# First, ensure that we can find the header for the prism library.
|
@@ -71,13 +106,22 @@ unless find_header("prism/extension.h", File.expand_path("..", __dir__))
|
|
71
106
|
raise "prism/extension.h is required"
|
72
107
|
end
|
73
108
|
|
74
|
-
# If `--enable-debug
|
75
|
-
# `
|
76
|
-
# `
|
109
|
+
# If `--enable-build-debug` is passed to this script or the
|
110
|
+
# `PRISM_BUILD_DEBUG` environment variable is defined, we'll build with the
|
111
|
+
# `PRISM_BUILD_DEBUG` macro defined. This causes parse functions to
|
77
112
|
# duplicate their input so that they have clearly set bounds, which is useful
|
78
113
|
# for finding bugs that cause the parser to read off the end of the input.
|
79
|
-
if enable_config("debug
|
80
|
-
append_cflags("-
|
114
|
+
if enable_config("build-debug", ENV["PRISM_BUILD_DEBUG"] || false)
|
115
|
+
append_cflags("-DPRISM_BUILD_DEBUG")
|
116
|
+
end
|
117
|
+
|
118
|
+
# If `--enable-build-minimal` is passed to this script or the
|
119
|
+
# `PRISM_BUILD_MINIMAL` environment variable is defined, we'll build with the
|
120
|
+
# set of defines that comprise the minimal set. This causes the parser to be
|
121
|
+
# built with minimal features, necessary for stripping out functionality when
|
122
|
+
# the size of the final built artifact is a concern.
|
123
|
+
if enable_config("build-minimal", ENV["PRISM_BUILD_MINIMAL"] || false)
|
124
|
+
append_cflags("-DPRISM_BUILD_MINIMAL")
|
81
125
|
end
|
82
126
|
|
83
127
|
# By default, all symbols are hidden in the shared library.
|
@@ -89,7 +133,7 @@ append_cflags("-fvisibility=hidden")
|
|
89
133
|
archive_target = "build/libprism.a"
|
90
134
|
archive_path = File.expand_path("../../#{archive_target}", __dir__)
|
91
135
|
|
92
|
-
make(archive_target) unless File.exist?(archive_path)
|
136
|
+
make(env, archive_target) unless File.exist?(archive_path)
|
93
137
|
$LOCAL_LIBS << " #{archive_path}"
|
94
138
|
|
95
139
|
# Finally, we'll create the `Makefile` that is going to be used to configure and
|