Skip to content

Commit 8b34eb0

Browse files
andrykonchineregon
authored andcommitted
[GR-45043] Import the latest YARP (0.14.0)
PullRequest: truffleruby/4035
2 parents 1747391 + 3042b52 commit 8b34eb0

File tree

19 files changed

+1780
-1408
lines changed

19 files changed

+1780
-1408
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ workingsets.xml
2525
# C extensions
2626
*.o
2727
*.so
28+
*.a
2829
*.bundle
2930
*.dylib
3031
*.log

spec/tags/truffle/parsing/parsing_tags.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,6 @@ fails:Parsing a Return (return operator in a method (with a value)) case is pars
197197
fails:Parsing a Return (return operator in a method without value) case is parsed correctly
198198
fails:Parsing a Return (return operator with splat operator (return *a)) case is parsed correctly
199199
fails:Parsing a Sequence of expressions () case is parsed correctly
200-
fails:Parsing a String (Frozen literal) case is parsed correctly
201200
fails:Parsing a String (Literal with interpolation when when expressions are % String literals) case is parsed correctly
202201
fails:Parsing a String (Literal with interpolation when expressions are Strings) case is parsed correctly
203202
fails:Parsing a Symbol (Literal with interpolation when expressions are % String literals) case is parsed correctly

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include "prism/pack.h"
99
#include "prism/parser.h"
1010
#include "prism/regexp.h"
11-
#include "prism/unescape.h"
1211
#include "prism/util/pm_buffer.h"
1312
#include "prism/util/pm_char.h"
1413
#include "prism/util/pm_memchr.h"
@@ -35,7 +34,7 @@ void pm_print_node(pm_parser_t *parser, pm_node_t *node);
3534
void pm_parser_metadata(pm_parser_t *parser, const char *metadata);
3635

3736
// Generate a scope node from the given node.
38-
void pm_scope_node_init(pm_node_t *node, pm_scope_node_t *dest);
37+
void pm_scope_node_init(const pm_node_t *node, pm_scope_node_t *scope, pm_scope_node_t *previous, pm_parser_t *parser);
3938

4039
// The prism version and the serialization format.
4140
PRISM_EXPORTED_FUNCTION const char * pm_version(void);

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

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,10 @@ typedef uint16_t pm_node_flags_t;
358358

359359
// We store the flags enum in every node in the tree. Some flags are common to
360360
// all nodes (the ones listed below). Others are specific to certain node types.
361-
static const pm_node_flags_t PM_NODE_FLAG_NEWLINE = 0x1;
362-
static const pm_node_flags_t PM_NODE_FLAG_STATIC_LITERAL = 0x2;
361+
#define PM_NODE_FLAG_BITS (sizeof(pm_node_flags_t) * 8)
362+
static const pm_node_flags_t PM_NODE_FLAG_NEWLINE = (1 << (PM_NODE_FLAG_BITS - 1));
363+
static const pm_node_flags_t PM_NODE_FLAG_STATIC_LITERAL = (1 << (PM_NODE_FLAG_BITS - 2));
364+
static const pm_node_flags_t PM_NODE_FLAG_COMMON_MASK = (1 << (PM_NODE_FLAG_BITS - 1)) | (1 << (PM_NODE_FLAG_BITS - 2));
363365

364366
// For easy access, we define some macros to check node type
365367
#define PM_NODE_TYPE(node) ((enum pm_node_type)node->type)
@@ -474,6 +476,7 @@ typedef struct pm_assoc_splat_node {
474476
// Type: PM_BACK_REFERENCE_READ_NODE
475477
typedef struct pm_back_reference_read_node {
476478
pm_node_t base;
479+
pm_constant_id_t name;
477480
} pm_back_reference_read_node_t;
478481

479482
// BeginNode
@@ -1193,11 +1196,11 @@ typedef struct pm_integer_node {
11931196
// PM_REGULAR_EXPRESSION_FLAGS_IGNORE_CASE
11941197
// PM_REGULAR_EXPRESSION_FLAGS_EXTENDED
11951198
// PM_REGULAR_EXPRESSION_FLAGS_MULTI_LINE
1199+
// PM_REGULAR_EXPRESSION_FLAGS_ONCE
11961200
// PM_REGULAR_EXPRESSION_FLAGS_EUC_JP
11971201
// PM_REGULAR_EXPRESSION_FLAGS_ASCII_8BIT
11981202
// PM_REGULAR_EXPRESSION_FLAGS_WINDOWS_31J
11991203
// PM_REGULAR_EXPRESSION_FLAGS_UTF_8
1200-
// PM_REGULAR_EXPRESSION_FLAGS_ONCE
12011204
typedef struct pm_interpolated_match_last_line_node {
12021205
pm_node_t base;
12031206
pm_location_t opening_loc;
@@ -1212,11 +1215,11 @@ typedef struct pm_interpolated_match_last_line_node {
12121215
// PM_REGULAR_EXPRESSION_FLAGS_IGNORE_CASE
12131216
// PM_REGULAR_EXPRESSION_FLAGS_EXTENDED
12141217
// PM_REGULAR_EXPRESSION_FLAGS_MULTI_LINE
1218+
// PM_REGULAR_EXPRESSION_FLAGS_ONCE
12151219
// PM_REGULAR_EXPRESSION_FLAGS_EUC_JP
12161220
// PM_REGULAR_EXPRESSION_FLAGS_ASCII_8BIT
12171221
// PM_REGULAR_EXPRESSION_FLAGS_WINDOWS_31J
12181222
// PM_REGULAR_EXPRESSION_FLAGS_UTF_8
1219-
// PM_REGULAR_EXPRESSION_FLAGS_ONCE
12201223
typedef struct pm_interpolated_regular_expression_node {
12211224
pm_node_t base;
12221225
pm_location_t opening_loc;
@@ -1369,11 +1372,11 @@ typedef struct pm_local_variable_write_node {
13691372
// PM_REGULAR_EXPRESSION_FLAGS_IGNORE_CASE
13701373
// PM_REGULAR_EXPRESSION_FLAGS_EXTENDED
13711374
// PM_REGULAR_EXPRESSION_FLAGS_MULTI_LINE
1375+
// PM_REGULAR_EXPRESSION_FLAGS_ONCE
13721376
// PM_REGULAR_EXPRESSION_FLAGS_EUC_JP
13731377
// PM_REGULAR_EXPRESSION_FLAGS_ASCII_8BIT
13741378
// PM_REGULAR_EXPRESSION_FLAGS_WINDOWS_31J
13751379
// PM_REGULAR_EXPRESSION_FLAGS_UTF_8
1376-
// PM_REGULAR_EXPRESSION_FLAGS_ONCE
13771380
typedef struct pm_match_last_line_node {
13781381
pm_node_t base;
13791382
pm_location_t opening_loc;
@@ -1616,11 +1619,11 @@ typedef struct pm_redo_node {
16161619
// PM_REGULAR_EXPRESSION_FLAGS_IGNORE_CASE
16171620
// PM_REGULAR_EXPRESSION_FLAGS_EXTENDED
16181621
// PM_REGULAR_EXPRESSION_FLAGS_MULTI_LINE
1622+
// PM_REGULAR_EXPRESSION_FLAGS_ONCE
16191623
// PM_REGULAR_EXPRESSION_FLAGS_EUC_JP
16201624
// PM_REGULAR_EXPRESSION_FLAGS_ASCII_8BIT
16211625
// PM_REGULAR_EXPRESSION_FLAGS_WINDOWS_31J
16221626
// PM_REGULAR_EXPRESSION_FLAGS_UTF_8
1623-
// PM_REGULAR_EXPRESSION_FLAGS_ONCE
16241627
typedef struct pm_regular_expression_node {
16251628
pm_node_t base;
16261629
pm_location_t opening_loc;
@@ -1888,43 +1891,43 @@ typedef struct pm_yield_node {
18881891

18891892
// CallNodeFlags
18901893
typedef enum pm_call_node_flags {
1891-
PM_CALL_NODE_FLAGS_SAFE_NAVIGATION = 1 << 2,
1892-
PM_CALL_NODE_FLAGS_VARIABLE_CALL = 1 << 3,
1894+
PM_CALL_NODE_FLAGS_SAFE_NAVIGATION = 1 << 0,
1895+
PM_CALL_NODE_FLAGS_VARIABLE_CALL = 1 << 1,
18931896
} pm_call_node_flags_t;
18941897

18951898
// IntegerBaseFlags
18961899
typedef enum pm_integer_base_flags {
1897-
PM_INTEGER_BASE_FLAGS_BINARY = 1 << 2,
1898-
PM_INTEGER_BASE_FLAGS_OCTAL = 1 << 3,
1899-
PM_INTEGER_BASE_FLAGS_DECIMAL = 1 << 4,
1900-
PM_INTEGER_BASE_FLAGS_HEXADECIMAL = 1 << 5,
1900+
PM_INTEGER_BASE_FLAGS_BINARY = 1 << 0,
1901+
PM_INTEGER_BASE_FLAGS_OCTAL = 1 << 1,
1902+
PM_INTEGER_BASE_FLAGS_DECIMAL = 1 << 2,
1903+
PM_INTEGER_BASE_FLAGS_HEXADECIMAL = 1 << 3,
19011904
} pm_integer_base_flags_t;
19021905

19031906
// LoopFlags
19041907
typedef enum pm_loop_flags {
1905-
PM_LOOP_FLAGS_BEGIN_MODIFIER = 1 << 2,
1908+
PM_LOOP_FLAGS_BEGIN_MODIFIER = 1 << 0,
19061909
} pm_loop_flags_t;
19071910

19081911
// RangeFlags
19091912
typedef enum pm_range_flags {
1910-
PM_RANGE_FLAGS_EXCLUDE_END = 1 << 2,
1913+
PM_RANGE_FLAGS_EXCLUDE_END = 1 << 0,
19111914
} pm_range_flags_t;
19121915

19131916
// RegularExpressionFlags
19141917
typedef enum pm_regular_expression_flags {
1915-
PM_REGULAR_EXPRESSION_FLAGS_IGNORE_CASE = 1 << 2,
1916-
PM_REGULAR_EXPRESSION_FLAGS_EXTENDED = 1 << 3,
1917-
PM_REGULAR_EXPRESSION_FLAGS_MULTI_LINE = 1 << 4,
1918-
PM_REGULAR_EXPRESSION_FLAGS_EUC_JP = 1 << 5,
1919-
PM_REGULAR_EXPRESSION_FLAGS_ASCII_8BIT = 1 << 6,
1920-
PM_REGULAR_EXPRESSION_FLAGS_WINDOWS_31J = 1 << 7,
1921-
PM_REGULAR_EXPRESSION_FLAGS_UTF_8 = 1 << 8,
1922-
PM_REGULAR_EXPRESSION_FLAGS_ONCE = 1 << 9,
1918+
PM_REGULAR_EXPRESSION_FLAGS_IGNORE_CASE = 1 << 0,
1919+
PM_REGULAR_EXPRESSION_FLAGS_EXTENDED = 1 << 1,
1920+
PM_REGULAR_EXPRESSION_FLAGS_MULTI_LINE = 1 << 2,
1921+
PM_REGULAR_EXPRESSION_FLAGS_ONCE = 1 << 3,
1922+
PM_REGULAR_EXPRESSION_FLAGS_EUC_JP = 1 << 4,
1923+
PM_REGULAR_EXPRESSION_FLAGS_ASCII_8BIT = 1 << 5,
1924+
PM_REGULAR_EXPRESSION_FLAGS_WINDOWS_31J = 1 << 6,
1925+
PM_REGULAR_EXPRESSION_FLAGS_UTF_8 = 1 << 7,
19231926
} pm_regular_expression_flags_t;
19241927

19251928
// StringFlags
19261929
typedef enum pm_string_flags {
1927-
PM_STRING_FLAGS_FROZEN = 1 << 2,
1930+
PM_STRING_FLAGS_FROZEN = 1 << 0,
19281931
} pm_string_flags_t;
19291932

19301933
#define PRISM_SERIALIZE_ONLY_SEMANTICS_FIELDS 1

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,17 @@ PRISM_EXPORTED_FUNCTION const char * pm_node_type_to_str(pm_node_type_t node_typ
3333
// declare them here to avoid generating them.
3434
typedef struct pm_scope_node {
3535
pm_node_t base;
36+
struct pm_scope_node *previous;
3637
pm_node_t *ast_node;
3738
struct pm_parameters_node *parameters;
3839
pm_node_t *body;
3940
pm_constant_id_list_t locals;
41+
pm_parser_t *parser;
42+
43+
// We don't have the CRuby types ID and st_table within Prism
44+
// so we use void *
45+
void *constants; // ID *constants
46+
void *index_lookup_table; // st_table *index_lookup_table
4047
} pm_scope_node_t;
4148

4249
#endif // PRISM_NODE_H

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "prism/util/pm_list.h"
99
#include "prism/util/pm_newline_list.h"
1010
#include "prism/util/pm_state_stack.h"
11+
#include "prism/util/pm_string.h"
1112

1213
#include <stdbool.h>
1314

@@ -172,6 +173,11 @@ typedef struct pm_lex_mode {
172173
// This is the pointer to the character where lexing should resume
173174
// once the heredoc has been completely processed.
174175
const uint8_t *next_start;
176+
177+
// This is used to track the amount of common whitespace on each
178+
// line so that we know how much to dedent each line in the case of
179+
// a tilde heredoc.
180+
size_t common_whitespace;
175181
} heredoc;
176182
} as;
177183

@@ -244,6 +250,16 @@ typedef struct pm_comment {
244250
pm_comment_type_t type;
245251
} pm_comment_t;
246252

253+
// This is a node in the linked list of magic comments that we've found while
254+
// parsing.
255+
typedef struct {
256+
pm_list_node_t node;
257+
const uint8_t *key_start;
258+
const uint8_t *value_start;
259+
uint32_t key_length;
260+
uint32_t value_length;
261+
} pm_magic_comment_t;
262+
247263
// When the encoding that is being used to parse the source is changed by prism,
248264
// we provide the ability here to call out to a user-defined function.
249265
typedef void (*pm_encoding_changed_callback_t)(pm_parser_t *parser);
@@ -347,6 +363,7 @@ struct pm_parser {
347363
const uint8_t *heredoc_end;
348364

349365
pm_list_t comment_list; // the list of comments that have been found while parsing
366+
pm_list_t magic_comment_list; // the list of magic comments that have been found while parsing.
350367
pm_list_t warning_list; // the list of warnings that have been found while parsing
351368
pm_list_t error_list; // the list of errors that have been found while parsing
352369
pm_scope_t *current_scope; // the current local scope
@@ -393,6 +410,10 @@ struct pm_parser {
393410
// when we find tokens that we need it for.
394411
pm_node_flags_t integer_base;
395412

413+
// This string is used to pass information from the lexer to the parser. It
414+
// is particularly necessary because of escape sequences.
415+
pm_string_t current_string;
416+
396417
// Whether or not we're at the beginning of a command
397418
bool command_start;
398419

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

Lines changed: 0 additions & 48 deletions
This file was deleted.

src/main/c/yarp/include/prism/util/pm_buffer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ typedef struct {
2121
// Return the size of the pm_buffer_t struct.
2222
PRISM_EXPORTED_FUNCTION size_t pm_buffer_sizeof(void);
2323

24+
// Initialize a pm_buffer_t with the given capacity.
25+
bool pm_buffer_init_capacity(pm_buffer_t *buffer, size_t capacity);
26+
2427
// Initialize a pm_buffer_t with its default values.
2528
PRISM_EXPORTED_FUNCTION bool pm_buffer_init(pm_buffer_t *buffer);
2629

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#define PRISM_VERSION_MAJOR 0
2-
#define PRISM_VERSION_MINOR 13
2+
#define PRISM_VERSION_MINOR 14
33
#define PRISM_VERSION_PATCH 0
4-
#define PRISM_VERSION "0.13.0"
4+
#define PRISM_VERSION "0.14.0"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ pm_diagnostic_message(pm_diagnostic_id_t diag_id) {
265265
// Append an error to the given list of diagnostic.
266266
bool
267267
pm_diagnostic_list_append(pm_list_t *list, const uint8_t *start, const uint8_t *end, pm_diagnostic_id_t diag_id) {
268-
pm_diagnostic_t *diagnostic = (pm_diagnostic_t *) malloc(sizeof(pm_diagnostic_t));
268+
pm_diagnostic_t *diagnostic = (pm_diagnostic_t *) calloc(sizeof(pm_diagnostic_t), 1);
269269
if (diagnostic == NULL) return false;
270270

271271
*diagnostic = (pm_diagnostic_t) { .start = start, .end = end, .message = pm_diagnostic_message(diag_id) };

0 commit comments

Comments
 (0)