Skip to content

Commit 63ff781

Browse files
committed
[GR-45043] Update to the latest YARP
PullRequest: truffleruby/4031
2 parents cf372f0 + 03f72a6 commit 63ff781

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+13332
-13151
lines changed

doc/contributor/prism.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Prism
2+
3+
## Update Prism
4+
5+
* Clone `prism` as a sibling of `truffleruby-ws`.
6+
* Run `tool/import-prism.sh` in the truffleruby repo.
7+
* Commit the result with message `Import ruby/prism@COMMIT`
8+
9+
## Print Detailed Prism AST
10+
11+
```bash
12+
cd prism
13+
bundle exec rake
14+
bin/parse -e '1&.itself'
15+
```
16+
17+
We can also see what the AST as Java nodes and without extra location fields looks like on TruffleRuby with:
18+
```bash
19+
cd truffleruby
20+
jt -q ruby -e 'puts Truffle::Debug.yarp_parse(ARGV[0])' -- '1&.itself'
21+
```

doc/contributor/yarp.md

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

mx.truffleruby/suite.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@
138138

139139
# ------------- Projects -------------
140140

141-
"org.yarp": {
141+
"org.prism": {
142142
"dir": "src/yarp",
143143
"sourceDirs": ["java"],
144144
"jniHeaders": True,
@@ -219,7 +219,7 @@
219219
"ldflags": ["-pthread"],
220220
},
221221

222-
"org.yarp.libyarp": {
222+
"org.prism.libyarp": {
223223
"class": "YARPNativeProject",
224224
"dir": "src/main/c/yarp",
225225
# "makeTarget": "all-no-debug", # Can use this to build without asserts
@@ -232,13 +232,13 @@
232232
"native": "shared_lib",
233233
"deliverable": "yarp",
234234
"buildDependencies": [
235-
"org.yarp.libyarp", # librubyparser.a
236-
"org.yarp", # for the generated JNI header file
235+
"org.prism.libyarp", # librubyparser.a
236+
"org.prism", # for the generated JNI header file
237237
],
238238
"use_jdk_headers": True, # the generated JNI header includes jni.h
239-
"cflags": ["-g", "-Wall", "-Werror", "-pthread", "-I<path:org.yarp.libyarp>/include"],
239+
"cflags": ["-g", "-Wall", "-Werror", "-pthread", "-I<path:org.prism.libyarp>/include"],
240240
"ldflags": ["-pthread"],
241-
"ldlibs": ["<path:org.yarp.libyarp>/build/librubyparser.a"],
241+
"ldlibs": ["<path:org.prism.libyarp>/build/librubyparser.a"],
242242
"description": "JNI bindings for YARP"
243243
},
244244

@@ -254,7 +254,7 @@
254254
],
255255
"dependencies": [
256256
# Projects
257-
"org.yarp",
257+
"org.prism",
258258
# Distributions, keep in sync with TRUFFLERUBY.distDependencies
259259
"truffleruby:TRUFFLERUBY-ANNOTATIONS",
260260
"truffleruby:TRUFFLERUBY-SHARED",

src/main/c/yarp/.gitignore

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

src/main/c/yarp/Makefile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ build/librubyparser.a: $(STATIC_OBJECTS)
3535
build/shared/%.o: src/%.c Makefile $(HEADERS)
3636
$(ECHO) "compiling $@"
3737
$(Q) mkdir -p $(@D)
38-
$(Q) $(CC) $(DEBUG_FLAGS) -DYP_EXPORT_SYMBOLS $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
38+
$(Q) $(CC) $(DEBUG_FLAGS) -DPRISM_EXPORT_SYMBOLS $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
3939

4040
build/static/%.o: src/%.c Makefile $(HEADERS)
4141
$(ECHO) "compiling $@"
@@ -55,20 +55,20 @@ build/fuzz.heisenbug.%: $(SOURCES) fuzz/%.c fuzz/heisenbug.c
5555

5656
fuzz-debug:
5757
$(ECHO) "entering debug shell"
58-
$(Q) docker run -it --rm -e HISTFILE=/yarp/fuzz/output/.bash_history -v $(shell pwd):/yarp -v $(FUZZ_OUTPUT_DIR):/fuzz_output yarp/fuzz
58+
$(Q) docker run -it --rm -e HISTFILE=/prism/fuzz/output/.bash_history -v $(shell pwd):/prism -v $(FUZZ_OUTPUT_DIR):/fuzz_output prism/fuzz
5959

6060
fuzz-docker-build: fuzz/docker/Dockerfile
6161
$(ECHO) "building docker image"
62-
$(Q) docker build -t yarp/fuzz fuzz/docker/
62+
$(Q) docker build -t prism/fuzz fuzz/docker/
6363

6464
fuzz-run-%: FORCE fuzz-docker-build
6565
$(ECHO) "generating templates"
6666
$(Q) bundle exec rake templates
6767
$(ECHO) "running $* fuzzer"
68-
$(Q) docker run --rm -v $(shell pwd):/yarp yarp/fuzz /bin/bash -c "FUZZ_FLAGS=\"$(FUZZ_FLAGS)\" make build/fuzz.$*"
68+
$(Q) docker run --rm -v $(shell pwd):/prism prism/fuzz /bin/bash -c "FUZZ_FLAGS=\"$(FUZZ_FLAGS)\" make build/fuzz.$*"
6969
$(ECHO) "starting AFL++ run"
7070
$(Q) mkdir -p $(FUZZ_OUTPUT_DIR)/$*
71-
$(Q) docker run -it --rm -v $(shell pwd):/yarp -v $(FUZZ_OUTPUT_DIR):/fuzz_output yarp/fuzz /bin/bash -c "./fuzz/$*.sh /fuzz_output/$*"
71+
$(Q) docker run -it --rm -v $(shell pwd):/prism -v $(FUZZ_OUTPUT_DIR):/fuzz_output prism/fuzz /bin/bash -c "./fuzz/$*.sh /fuzz_output/$*"
7272
FORCE:
7373

7474
fuzz-clean:

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

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#ifndef PRISM_H
2+
#define PRISM_H
3+
4+
#include "prism/defines.h"
5+
#include "prism/ast.h"
6+
#include "prism/diagnostic.h"
7+
#include "prism/node.h"
8+
#include "prism/pack.h"
9+
#include "prism/parser.h"
10+
#include "prism/regexp.h"
11+
#include "prism/unescape.h"
12+
#include "prism/util/pm_buffer.h"
13+
#include "prism/util/pm_char.h"
14+
#include "prism/util/pm_memchr.h"
15+
#include "prism/util/pm_strpbrk.h"
16+
#include "prism/version.h"
17+
18+
#include <assert.h>
19+
#include <errno.h>
20+
#include <stdarg.h>
21+
#include <stdbool.h>
22+
#include <stdint.h>
23+
#include <stdio.h>
24+
#include <stdlib.h>
25+
#include <string.h>
26+
27+
#ifndef _WIN32
28+
#include <strings.h>
29+
#endif
30+
31+
void pm_serialize_content(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer);
32+
33+
void pm_print_node(pm_parser_t *parser, pm_node_t *node);
34+
35+
void pm_parser_metadata(pm_parser_t *parser, const char *metadata);
36+
37+
// Generate a scope node from the given node.
38+
void pm_scope_node_init(pm_node_t *node, pm_scope_node_t *dest);
39+
40+
// The prism version and the serialization format.
41+
PRISM_EXPORTED_FUNCTION const char * pm_version(void);
42+
43+
// Initialize a parser with the given start and end pointers.
44+
PRISM_EXPORTED_FUNCTION void pm_parser_init(pm_parser_t *parser, const uint8_t *source, size_t size, const char *filepath);
45+
46+
// Register a callback that will be called whenever prism changes the encoding it
47+
// is using to parse based on the magic comment.
48+
PRISM_EXPORTED_FUNCTION void pm_parser_register_encoding_changed_callback(pm_parser_t *parser, pm_encoding_changed_callback_t callback);
49+
50+
// Register a callback that will be called when prism encounters a magic comment
51+
// with an encoding referenced that it doesn't understand. The callback should
52+
// return NULL if it also doesn't understand the encoding or it should return a
53+
// pointer to a pm_encoding_t struct that contains the functions necessary to
54+
// parse identifiers.
55+
PRISM_EXPORTED_FUNCTION void pm_parser_register_encoding_decode_callback(pm_parser_t *parser, pm_encoding_decode_callback_t callback);
56+
57+
// Free any memory associated with the given parser.
58+
PRISM_EXPORTED_FUNCTION void pm_parser_free(pm_parser_t *parser);
59+
60+
// Parse the Ruby source associated with the given parser and return the tree.
61+
PRISM_EXPORTED_FUNCTION pm_node_t * pm_parse(pm_parser_t *parser);
62+
63+
// Pretty-prints the AST represented by the given node to the given buffer.
64+
PRISM_EXPORTED_FUNCTION void pm_prettyprint(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer);
65+
66+
// Serialize the AST represented by the given node to the given buffer.
67+
PRISM_EXPORTED_FUNCTION void pm_serialize(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer);
68+
69+
// Parse the given source to the AST and serialize the AST to the given buffer.
70+
PRISM_EXPORTED_FUNCTION void pm_parse_serialize(const uint8_t *source, size_t size, pm_buffer_t *buffer, const char *metadata);
71+
72+
// Lex the given source and serialize to the given buffer.
73+
PRISM_EXPORTED_FUNCTION void pm_lex_serialize(const uint8_t *source, size_t size, const char *filepath, pm_buffer_t *buffer);
74+
75+
// Parse and serialize both the AST and the tokens represented by the given
76+
// source to the given buffer.
77+
PRISM_EXPORTED_FUNCTION void pm_parse_lex_serialize(const uint8_t *source, size_t size, pm_buffer_t *buffer, const char *metadata);
78+
79+
// Returns a string representation of the given token type.
80+
PRISM_EXPORTED_FUNCTION const char * pm_token_type_to_str(pm_token_type_t token_type);
81+
82+
#endif

0 commit comments

Comments
 (0)