summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJemma Issroff <jemmaissroff@gmail.com>2023-08-31 12:56:13 -0400
committerGitHub <noreply@github.com>2023-08-31 09:56:13 -0700
commitb90457b210e6b1dc465d82dd08db126ce1a8228e (patch)
treee296261e78391f2732c71cbfbce9d444554b2862
parent3678734fac7a4d3d7e160200153090dcba6e3d94 (diff)
[YARP] Implement SourceNodes (File, Line, Encoding) (#8328)
* [YARP] Implement SourceNodes (File, Line, Encoding)
Notes
Notes: Merged-By: jemmaissroff
-rw-r--r--yarp/yarp_compiler.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/yarp/yarp_compiler.c b/yarp/yarp_compiler.c
index 57638a36fb..bd1352ebd7 100644
--- a/yarp/yarp_compiler.c
+++ b/yarp/yarp_compiler.c
@@ -1272,6 +1272,39 @@ yp_compile_node(rb_iseq_t *iseq, const yp_node_t *node, LINK_ANCHOR *const ret,
return;
}
+ case YP_NODE_SOURCE_ENCODING_NODE: {
+ const char *encoding = compile_context->parser->encoding.name;
+ if (!popped) {
+ rb_encoding *enc = rb_find_encoding(rb_str_new_cstr(encoding));
+ if (!enc) {
+ rb_bug("Encoding not found!");
+ }
+ ADD_INSN1(ret, &dummy_line_node, putobject, rb_enc_from_encoding(enc));
+ }
+ return;
+ }
+ case YP_NODE_SOURCE_FILE_NODE: {
+ yp_source_file_node_t *source_file_node = (yp_source_file_node_t *)node;
+
+ if (!popped) {
+ VALUE filepath;
+ if (source_file_node->filepath.length == 0) {
+ filepath = rb_fstring_lit("<compiled>");
+ }
+ else {
+ filepath = parse_string(&source_file_node->filepath);
+ }
+
+ ADD_INSN1(ret, &dummy_line_node, putstring, filepath);
+ }
+ return;
+ }
+ case YP_NODE_SOURCE_LINE_NODE: {
+ if (!popped) {
+ ADD_INSN1(ret, &dummy_line_node, putobject, INT2FIX(lineno));
+ }
+ return;
+ }
case YP_NODE_SPLAT_NODE: {
yp_splat_node_t *splat_node = (yp_splat_node_t *)node;
yp_compile_node(iseq, splat_node->expression, ret, src, popped, compile_context);