Skip to content

Commit e4d8a56

Browse files
eregonandrykonchin
authored andcommitted
Import ruby/prism@v0.20.0
1 parent 6823e88 commit e4d8a56

File tree

16 files changed

+158
-188
lines changed

16 files changed

+158
-188
lines changed

src/main/c/yarp/Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ SOEXT := $(shell ruby -e 'puts RbConfig::CONFIG["SOEXT"]')
1212

1313
CPPFLAGS := -Iinclude
1414
CFLAGS := -g -O2 -std=c99 -Wall -Werror -Wextra -Wpedantic -Wundef -Wconversion -Wno-missing-braces -fPIC -fvisibility=hidden
15-
JAVA_WASM_CFLAGS := -O0 -g -o -std=c99 -Wall -Werror -Wextra -Wpedantic -Wundef -Wconversion -Wno-missing-braces -fPIC -fvisibility=hidden -nostartfiles -Wl,--no-entry -Wl,
1615
CC := cc
1716
WASI_SDK_PATH := /opt/wasi-sdk
1817

@@ -42,7 +41,7 @@ javascript/src/prism.wasm: Makefile $(SOURCES) $(HEADERS)
4241

4342
java-wasm/src/test/resources/prism.wasm: Makefile $(SOURCES) $(HEADERS)
4443
$(ECHO) "building $@"
45-
$(Q) $(WASI_SDK_PATH)/bin/clang $(DEBUG_FLAGS) -DPRISM_EXPORT_SYMBOLS -D_WASI_EMULATED_MMAN -lwasi-emulated-mman $(CPPFLAGS) $(JAVA_WASM_CFLAGS) -Wl,--export-all -Wl,--no-entry -mexec-model=reactor -lc++ -lc++abi -o $@ $(SOURCES)
44+
$(Q) $(WASI_SDK_PATH)/bin/clang $(DEBUG_FLAGS) -DPRISM_EXPORT_SYMBOLS -D_WASI_EMULATED_MMAN -lwasi-emulated-mman $(CPPFLAGS) $(CFLAGS) -Wl,--export-all -Wl,--no-entry -mexec-model=reactor -lc++ -lc++abi -o $@ $(SOURCES)
4645

4746
build/shared/%.o: src/%.c Makefile $(HEADERS)
4847
$(ECHO) "compiling $@"

src/main/c/yarp/include/prism/ast.h

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1502,11 +1502,6 @@ typedef struct pm_block_node {
15021502
*/
15031503
pm_constant_id_list_t locals;
15041504

1505-
/**
1506-
* BlockNode#locals_body_index
1507-
*/
1508-
uint32_t locals_body_index;
1509-
15101505
/**
15111506
* BlockNode#parameters
15121507
*/
@@ -2584,11 +2579,6 @@ typedef struct pm_def_node {
25842579
*/
25852580
pm_constant_id_list_t locals;
25862581

2587-
/**
2588-
* DefNode#locals_body_index
2589-
*/
2590-
uint32_t locals_body_index;
2591-
25922582
/**
25932583
* DefNode#def_keyword_loc
25942584
*/
@@ -3944,11 +3934,6 @@ typedef struct pm_lambda_node {
39443934
*/
39453935
pm_constant_id_list_t locals;
39463936

3947-
/**
3948-
* LambdaNode#locals_body_index
3949-
*/
3950-
uint32_t locals_body_index;
3951-
39523937
/**
39533938
* LambdaNode#operator_loc
39543939
*/

src/main/c/yarp/include/prism/diagnostic.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ typedef enum {
259259
PM_ERR_RESCUE_TERM,
260260
PM_ERR_RESCUE_VARIABLE,
261261
PM_ERR_RETURN_INVALID,
262+
PM_ERR_SINGLETON_FOR_LITERALS,
262263
PM_ERR_STATEMENT_ALIAS,
263264
PM_ERR_STATEMENT_POSTEXE_END,
264265
PM_ERR_STATEMENT_PREEXE_BEGIN,

src/main/c/yarp/include/prism/encoding.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,16 @@ typedef struct {
7979
*/
8080
#define PRISM_ENCODING_UPPERCASE_BIT 1 << 2
8181

82+
/**
83+
* Return the size of the next character in the UTF-8 encoding.
84+
*
85+
* @param b The bytes to read.
86+
* @param n The number of bytes that can be read.
87+
* @returns The number of bytes that the next character takes if it is valid in
88+
* the encoding, or 0 if it is not.
89+
*/
90+
size_t pm_encoding_utf_8_char_width(const uint8_t *b, ptrdiff_t n);
91+
8292
/**
8393
* Return the size of the next character in the UTF-8 encoding if it is an
8494
* alphabetical character.

src/main/c/yarp/include/prism/options.h

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ typedef struct {
4646

4747
/**
4848
* The line within the file that the parse starts on. This value is
49-
* 0-indexed.
49+
* 1-indexed.
5050
*/
5151
int32_t line;
5252

@@ -78,13 +78,6 @@ typedef struct {
7878

7979
/** Whether or not the frozen string literal option has been set. */
8080
bool frozen_string_literal;
81-
82-
/**
83-
* Whether or not we should suppress warnings. This is purposefully negated
84-
* so that the default is to not suppress warnings, which allows us to still
85-
* create an options struct with zeroed memory.
86-
*/
87-
bool suppress_warnings;
8881
} pm_options_t;
8982

9083
/**
@@ -119,14 +112,6 @@ PRISM_EXPORTED_FUNCTION void pm_options_encoding_set(pm_options_t *options, cons
119112
*/
120113
PRISM_EXPORTED_FUNCTION void pm_options_frozen_string_literal_set(pm_options_t *options, bool frozen_string_literal);
121114

122-
/**
123-
* Set the suppress warnings option on the given options struct.
124-
*
125-
* @param options The options struct to set the suppress warnings value on.
126-
* @param suppress_warnings The suppress warnings value to set.
127-
*/
128-
PRISM_EXPORTED_FUNCTION void pm_options_suppress_warnings_set(pm_options_t *options, bool suppress_warnings);
129-
130115
/**
131116
* Set the version option on the given options struct by parsing the given
132117
* string. If the string contains an invalid option, this returns false.

src/main/c/yarp/include/prism/parser.h

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,19 @@ typedef struct pm_scope {
469469
*/
470470
bool explicit_params;
471471

472+
/**
473+
* Booleans indicating whether the parameters for this scope have declared
474+
* forwarding parameters.
475+
*
476+
* For example, some combinations of:
477+
* def foo(*); end
478+
* def foo(**); end
479+
* def foo(&); end
480+
* def foo(...); end
481+
*/
482+
483+
uint8_t forwarding_params;
484+
472485
/**
473486
* An integer indicating the number of numbered parameters on this scope.
474487
* This is necessary to determine if child blocks are allowed to use
@@ -478,6 +491,11 @@ typedef struct pm_scope {
478491
uint8_t numbered_parameters;
479492
} pm_scope_t;
480493

494+
static const uint8_t PM_FORWARDING_POSITIONALS = 0x1;
495+
static const uint8_t PM_FORWARDING_KEYWORDS = 0x2;
496+
static const uint8_t PM_FORWARDING_BLOCK = 0x4;
497+
static const uint8_t PM_FORWARDING_ALL = 0x8;
498+
481499
/**
482500
* This struct represents the overall parser. It contains a reference to the
483501
* source file, as well as pointers that indicate where in the source it's
@@ -709,13 +727,6 @@ struct pm_parser {
709727
* a true value.
710728
*/
711729
bool frozen_string_literal;
712-
713-
/**
714-
* Whether or not we should emit warnings. This will be set to false if the
715-
* consumer of the library specified it, usually because they are parsing
716-
* when $VERBOSE is nil.
717-
*/
718-
bool suppress_warnings;
719730
};
720731

721732
#endif

src/main/c/yarp/include/prism/version.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
/**
1515
* The minor version of the Prism library as an int.
1616
*/
17-
#define PRISM_VERSION_MINOR 19
17+
#define PRISM_VERSION_MINOR 20
1818

1919
/**
2020
* The patch version of the Prism library as an int.
@@ -24,6 +24,6 @@
2424
/**
2525
* The version of the Prism library as a constant string.
2626
*/
27-
#define PRISM_VERSION "0.19.0"
27+
#define PRISM_VERSION "0.20.0"
2828

2929
#endif

src/main/c/yarp/src/diagnostic.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ static const pm_diagnostic_data_t diagnostic_messages[PM_DIAGNOSTIC_ID_LEN] = {
261261
[PM_ERR_RESCUE_TERM] = { "expected a closing delimiter for the `rescue` clause", PM_ERROR_LEVEL_FATAL },
262262
[PM_ERR_RESCUE_VARIABLE] = { "expected an exception variable after `=>` in a rescue statement", PM_ERROR_LEVEL_FATAL },
263263
[PM_ERR_RETURN_INVALID] = { "invalid `return` in a class or module body", PM_ERROR_LEVEL_FATAL },
264+
[PM_ERR_SINGLETON_FOR_LITERALS] = { "cannot define singleton method for literals", PM_ERROR_LEVEL_FATAL },
264265
[PM_ERR_STATEMENT_ALIAS] = { "unexpected an `alias` at a non-statement position", PM_ERROR_LEVEL_FATAL },
265266
[PM_ERR_STATEMENT_POSTEXE_END] = { "unexpected an `END` at a non-statement position", PM_ERROR_LEVEL_FATAL },
266267
[PM_ERR_STATEMENT_PREEXE_BEGIN] = { "unexpected a `BEGIN` at a non-statement position", PM_ERROR_LEVEL_FATAL },

src/main/c/yarp/src/encoding.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2277,7 +2277,10 @@ pm_utf_8_codepoint(const uint8_t *b, ptrdiff_t n, size_t *width) {
22772277
return 0;
22782278
}
22792279

2280-
static size_t
2280+
/**
2281+
* Return the size of the next character in the UTF-8 encoding.
2282+
*/
2283+
size_t
22812284
pm_encoding_utf_8_char_width(const uint8_t *b, ptrdiff_t n) {
22822285
size_t width;
22832286
pm_utf_8_codepoint(b, n, &width);

src/main/c/yarp/src/options.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,6 @@ pm_options_frozen_string_literal_set(pm_options_t *options, bool frozen_string_l
3232
options->frozen_string_literal = frozen_string_literal;
3333
}
3434

35-
/**
36-
* Set the suppress warnings option on the given options struct.
37-
*/
38-
PRISM_EXPORTED_FUNCTION void
39-
pm_options_suppress_warnings_set(pm_options_t *options, bool suppress_warnings) {
40-
options->suppress_warnings = suppress_warnings;
41-
}
42-
4335
/**
4436
* Set the version option on the given options struct by parsing the given
4537
* string. If the string contains an invalid option, this returns false.
@@ -189,7 +181,6 @@ pm_options_read(pm_options_t *options, const char *data) {
189181
}
190182

191183
options->frozen_string_literal = *data++;
192-
options->suppress_warnings = *data++;
193184
options->version = (pm_options_version_t) *data++;
194185

195186
uint32_t scopes_count = pm_options_read_u32(data);

0 commit comments

Comments
 (0)