summaryrefslogtreecommitdiff
path: root/iseq.c
diff options
context:
space:
mode:
authorJemma Issroff <jemmaissroff@gmail.com>2023-08-29 16:13:15 -0400
committerGitHub <noreply@github.com>2023-08-29 13:13:15 -0700
commit80dc570a451ed493797fa68b59a8dd60c1fa51a6 (patch)
treedc9d22df2a72a3ba99299b2b65b8f58382bf8d92 /iseq.c
parentb435161404ed960e02fadfd1c3d983d1fbfb91a0 (diff)
Compile more YARP node types (#8322)
* Add several more node simple types to YARP's compiler: Nodes include: DefinedNode, EmbeddedStatementsNode, LocalVariableReadNode, LocalVariableWriteNode, MultiWriteNode, OptionalParameterNode, SplatNode, YieldNode * Add AssocSplatNode, RangeNode * Add RangeNode, other helpers for future nodes * Add ArrayNode, HashNode, static literal helpers * Add branch conditionals * Add IfNode, UnlessNode * Add ScopeNode * NEW_ISEQ and NEW_CHILD_ISEQ implemented for YARP * Add nodes that depend on ScopeNode * Addressed PR comments
Diffstat (limited to 'iseq.c')
-rw-r--r--iseq.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/iseq.c b/iseq.c
index cb54d267f4..9082cd4861 100644
--- a/iseq.c
+++ b/iseq.c
@@ -945,6 +945,52 @@ rb_iseq_new_with_opt(const rb_ast_body_t *ast, VALUE name, VALUE path, VALUE rea
VALUE rb_iseq_compile_yarp_node(rb_iseq_t * iseq, const yp_node_t * yarp_pointer, yp_parser_t *parser);
rb_iseq_t *
+yp_iseq_new_with_opt(yp_node_t *node, yp_parser_t *parser, VALUE name, VALUE path, VALUE realpath,
+ int first_lineno, const rb_iseq_t *parent, int isolated_depth,
+ enum rb_iseq_type type, const rb_compile_option_t *option)
+{
+ rb_iseq_t *iseq = iseq_alloc();
+ rb_compile_option_t new_opt;
+
+ if (option) {
+ new_opt = *option;
+ }
+ else {
+ new_opt = COMPILE_OPTION_DEFAULT;
+ }
+
+ VALUE script_lines = Qnil;
+
+ rb_code_location_t code_loc;
+
+ if (node) {
+ yp_line_column_t start_line_col = yp_newline_list_line_column(&(parser->newline_list), node->location.start);
+ yp_line_column_t end_line_col= yp_newline_list_line_column(&(parser->newline_list), node->location.end);
+ code_loc = (rb_code_location_t) {
+ .beg_pos = {
+ .lineno = (int)start_line_col.line,
+ .column = (int)start_line_col.column
+ },
+ .end_pos = {
+ .lineno = (int)end_line_col.line,
+ .column = (int)end_line_col.column
+ },
+ };
+ }
+
+ // TODO: node_id
+ int node_id = -1;
+ prepare_iseq_build(iseq, name, path, realpath, first_lineno, &code_loc, node_id,
+ parent, isolated_depth, type, script_lines, &new_opt);
+
+ rb_iseq_compile_yarp_node(iseq, node, parser);
+
+ finish_iseq_build(iseq);
+
+ return iseq_translate(iseq);
+}
+
+rb_iseq_t *
rb_iseq_new_with_callback(
const struct rb_iseq_new_with_callback_callback_func * ifunc,
VALUE name, VALUE path, VALUE realpath,