Skip to content

Commit 681fcca

Browse files
eregonandrykonchin
authored andcommitted
1 parent d150a48 commit 681fcca

File tree

12 files changed

+698
-436
lines changed

12 files changed

+698
-436
lines changed

src/main/c/yarp/Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ 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,
1516
CC := cc
1617
WASI_SDK_PATH := /opt/wasi-sdk
1718

@@ -25,6 +26,7 @@ all: shared static
2526
shared: build/libprism.$(SOEXT)
2627
static: build/libprism.a
2728
wasm: javascript/src/prism.wasm
29+
java-wasm: java-wasm/src/test/resources/prism.wasm
2830

2931
build/libprism.$(SOEXT): $(SHARED_OBJECTS)
3032
$(ECHO) "linking $@"
@@ -38,6 +40,10 @@ javascript/src/prism.wasm: Makefile $(SOURCES) $(HEADERS)
3840
$(ECHO) "building $@"
3941
$(Q) $(WASI_SDK_PATH)/bin/clang --sysroot=$(WASI_SDK_PATH)/share/wasi-sysroot/ $(DEBUG_FLAGS) -DPRISM_EXPORT_SYMBOLS -D_WASI_EMULATED_MMAN -lwasi-emulated-mman $(CPPFLAGS) $(CFLAGS) -Wl,--export-all -Wl,--no-entry -mexec-model=reactor -o $@ $(SOURCES)
4042

43+
java-wasm/src/test/resources/prism.wasm: Makefile $(SOURCES) $(HEADERS)
44+
$(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)
46+
4147
build/shared/%.o: src/%.c Makefile $(HEADERS)
4248
$(ECHO) "compiling $@"
4349
$(Q) mkdir -p $(@D)

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

Lines changed: 71 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,8 +1173,7 @@ typedef struct pm_and_node {
11731173
/**
11741174
* AndNode#left
11751175
*
1176-
* Represents the left side of the expression. It can be any kind of node
1177-
* that represents a non-void expression.
1176+
* Represents the left side of the expression. It can be any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
11781177
*
11791178
* left and right
11801179
* ^^^^
@@ -1187,8 +1186,7 @@ typedef struct pm_and_node {
11871186
/**
11881187
* AndNode#right
11891188
*
1190-
* Represents the right side of the expression. It can be any kind of
1191-
* node that represents a non-void expression.
1189+
* Represents the right side of the expression. It can be any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
11921190
*
11931191
* left && right
11941192
* ^^^^^
@@ -1313,8 +1311,7 @@ typedef struct pm_assoc_node {
13131311
/**
13141312
* AssocNode#key
13151313
*
1316-
* The key of the association. This can be any node that represents a
1317-
* non-void expression.
1314+
* The key of the association. This can be any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
13181315
*
13191316
* { a: b }
13201317
* ^
@@ -1330,9 +1327,7 @@ typedef struct pm_assoc_node {
13301327
/**
13311328
* AssocNode#value
13321329
*
1333-
* The value of the association, if present. This can be any node that
1334-
* represents a non-void expression. It can be optionally omitted if this
1335-
* node is an element in a `HashPatternNode`.
1330+
* The value of the association, if present. This can be any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
13361331
*
13371332
* { foo => bar }
13381333
* ^^^
@@ -1367,8 +1362,7 @@ typedef struct pm_assoc_splat_node {
13671362
/**
13681363
* AssocSplatNode#value
13691364
*
1370-
* The value to be splatted, if present. Will be missing when keyword
1371-
* rest argument forwarding is used.
1365+
* The value to be splatted, if present. Will be missing when keyword rest argument forwarding is used.
13721366
*
13731367
* { **foo }
13741368
* ^^^
@@ -1399,6 +1393,12 @@ typedef struct pm_back_reference_read_node {
13991393

14001394
/**
14011395
* BackReferenceReadNode#name
1396+
*
1397+
* The name of the back-reference variable, including the leading `$`.
1398+
*
1399+
* $& # name `:$&`
1400+
*
1401+
* $+ # name `:$+`
14021402
*/
14031403
pm_constant_id_t name;
14041404
} pm_back_reference_read_node_t;
@@ -1682,9 +1682,7 @@ typedef struct pm_call_node {
16821682
/**
16831683
* CallNode#receiver
16841684
*
1685-
* The object that the method is being called on. This can be either
1686-
* `nil` or a node representing any kind of expression that returns a
1687-
* non-void value.
1685+
* The object that the method is being called on. This can be either `nil` or any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
16881686
*
16891687
* foo.bar
16901688
* ^^^
@@ -2146,6 +2144,12 @@ typedef struct pm_class_variable_read_node {
21462144

21472145
/**
21482146
* ClassVariableReadNode#name
2147+
*
2148+
* The name of the class variable, which is a `@@` followed by an [identifier](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#identifiers).
2149+
*
2150+
* @@abc # name `:@@abc`
2151+
*
2152+
* @@_test # name `:@@_test`
21492153
*/
21502154
pm_constant_id_t name;
21512155
} pm_class_variable_read_node_t;
@@ -2480,6 +2484,12 @@ typedef struct pm_constant_read_node {
24802484

24812485
/**
24822486
* ConstantReadNode#name
2487+
*
2488+
* The name of the [constant](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#constants).
2489+
*
2490+
* X # name `:X`
2491+
*
2492+
* SOME_CONSTANT # name `:SOME_CONSTANT`
24832493
*/
24842494
pm_constant_id_t name;
24852495
} pm_constant_read_node_t;
@@ -3042,6 +3052,12 @@ typedef struct pm_global_variable_read_node {
30423052

30433053
/**
30443054
* GlobalVariableReadNode#name
3055+
*
3056+
* The name of the global variable, which is a `$` followed by an [identifier](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#identifier). Alternatively, it can be one of the special global variables designated by a symbol.
3057+
*
3058+
* $foo # name `:$foo`
3059+
*
3060+
* $_Test # name `:$_Test`
30453061
*/
30463062
pm_constant_id_t name;
30473063
} pm_global_variable_read_node_t;
@@ -3629,6 +3645,12 @@ typedef struct pm_instance_variable_read_node {
36293645

36303646
/**
36313647
* InstanceVariableReadNode#name
3648+
*
3649+
* The name of the instance variable, which is a `@` followed by an [identifier](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#identifiers).
3650+
*
3651+
* @x # name `:@x`
3652+
*
3653+
* @_test # name `:@_test`
36323654
*/
36333655
pm_constant_id_t name;
36343656
} pm_instance_variable_read_node_t;
@@ -4082,11 +4104,33 @@ typedef struct pm_local_variable_read_node {
40824104

40834105
/**
40844106
* LocalVariableReadNode#name
4107+
*
4108+
* The name of the local variable, which is an [identifier](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#identifiers).
4109+
*
4110+
* x # name `:x`
4111+
*
4112+
* _Test # name `:_Test`
4113+
*
4114+
* Note that this can also be an underscore followed by a number for the default block parameters.
4115+
*
4116+
* _1 # name `:_1`
4117+
*
4118+
* Finally, for the default `it` block parameter, the name is `0it`. This is to distinguish it from an `it` local variable that is explicitly declared.
4119+
*
4120+
* it # name `:0it`
40854121
*/
40864122
pm_constant_id_t name;
40874123

40884124
/**
40894125
* LocalVariableReadNode#depth
4126+
*
4127+
* The number of visible scopes that should be searched to find the origin of this local variable.
4128+
*
4129+
* foo = 1; foo # depth 0
4130+
*
4131+
* bar = 2; tap { bar } # depth 1
4132+
*
4133+
* The specific rules for calculating the depth may differ from individual Ruby implementations, as they are not specified by the language. For more information, see [the Prism documentation](https://github.com/ruby/prism/blob/main/docs/local_variable_depth.md).
40904134
*/
40914135
uint32_t depth;
40924136
} pm_local_variable_read_node_t;
@@ -4494,6 +4538,14 @@ typedef struct pm_numbered_reference_read_node {
44944538

44954539
/**
44964540
* NumberedReferenceReadNode#number
4541+
*
4542+
* The (1-indexed, from the left) number of the capture group. Numbered references that would overflow a `uint32` result in a `number` of exactly `2**32 - 1`.
4543+
*
4544+
* $1 # number `1`
4545+
*
4546+
* $5432 # number `5432`
4547+
*
4548+
* $4294967296 # number `4294967295`
44974549
*/
44984550
uint32_t number;
44994551
} pm_numbered_reference_read_node_t;
@@ -4575,8 +4627,7 @@ typedef struct pm_or_node {
45754627
/**
45764628
* OrNode#left
45774629
*
4578-
* Represents the left side of the expression. It can be any kind of node
4579-
* that represents a non-void expression.
4630+
* Represents the left side of the expression. It can be any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
45804631
*
45814632
* left or right
45824633
* ^^^^
@@ -4589,8 +4640,7 @@ typedef struct pm_or_node {
45894640
/**
45904641
* OrNode#right
45914642
*
4592-
* Represents the right side of the expression. It can be any kind of
4593-
* node that represents a non-void expression.
4643+
* Represents the right side of the expression. It can be any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
45944644
*
45954645
* left || right
45964646
* ^^^^^
@@ -4841,9 +4891,7 @@ typedef struct pm_range_node {
48414891
/**
48424892
* RangeNode#left
48434893
*
4844-
* The left-hand side of the range, if present. Can be either `nil` or
4845-
* a node representing any kind of expression that returns a non-void
4846-
* value.
4894+
* The left-hand side of the range, if present. It can be either `nil` or any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
48474895
*
48484896
* 1...
48494897
* ^
@@ -4856,17 +4904,14 @@ typedef struct pm_range_node {
48564904
/**
48574905
* RangeNode#right
48584906
*
4859-
* The right-hand side of the range, if present. Can be either `nil` or
4860-
* a node representing any kind of expression that returns a non-void
4861-
* value.
4907+
* The right-hand side of the range, if present. It can be either `nil` or any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
48624908
*
48634909
* ..5
48644910
* ^
48654911
*
48664912
* 1...foo
48674913
* ^^^
4868-
* If neither right-hand or left-hand side was included, this will be a
4869-
* MissingNode.
4914+
* If neither right-hand or left-hand side was included, this will be a MissingNode.
48704915
*/
48714916
struct pm_node *right;
48724917

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,24 @@
1414
#include <stdlib.h>
1515
#include <assert.h>
1616

17+
/**
18+
* The levels of errors generated during parsing.
19+
*/
20+
typedef enum {
21+
/** For errors that cannot be recovered from. */
22+
PM_ERROR_LEVEL_FATAL = 0
23+
} pm_error_level_t;
24+
25+
/**
26+
* The levels of warnings generated during parsing.
27+
*/
28+
typedef enum {
29+
/** For warnings which should be emitted if $VERBOSE != nil. */
30+
PM_WARNING_LEVEL_DEFAULT = 0,
31+
/** For warnings which should be emitted if $VERBOSE == true. */
32+
PM_WARNING_LEVEL_VERBOSE = 1
33+
} pm_warning_level_t;
34+
1735
/**
1836
* This struct represents a diagnostic generated during parsing.
1937
*
@@ -35,6 +53,12 @@ typedef struct {
3553
* diagnostic is freed.
3654
*/
3755
bool owned;
56+
57+
/**
58+
* The level of the diagnostic, see `pm_error_level_t` and
59+
* `pm_warning_level_t` for possible values.
60+
*/
61+
uint8_t level;
3862
} pm_diagnostic_t;
3963

4064
/**

0 commit comments

Comments
 (0)