summaryrefslogtreecommitdiff
path: root/compile.c
diff options
context:
space:
mode:
authorJemma Issroff <jemmaissroff@gmail.com>2023-08-29 12:27:00 -0400
committerGitHub <noreply@github.com>2023-08-29 09:27:00 -0700
commit535045ab3b27dd42030e837bcd83b74ff075b84b (patch)
tree6150360f5171eb7598435f708e3be201fa7230d7 /compile.c
parent36e210718cc0242d3d1a043bd32b4618db592024 (diff)
[YARP] Compile basic types (#8311)
* Add a compile_context arg to yp_compile_node The compile_context will allow us to pass around the parser, and the constants and lookup table (to be used in future commits). * Compile yp_program_node_t and yp_statements_node_t Add the compilation for program and statements node so that we can successfully compile an empty program with YARP. * Helper functions for parsing numbers, strings, and symbols * Compile basic numeric / boolean node types in YARP * Compile StringNode and SymbolNodes in YARP * Compile several basic node types in YARP * Added error return for missing node
Notes
Notes: Merged-By: jemmaissroff
Diffstat (limited to 'compile.c')
-rw-r--r--compile.c33
1 files changed, 28 insertions, 5 deletions
diff --git a/compile.c b/compile.c
index d7f345d0af..2673df5dbb 100644
--- a/compile.c
+++ b/compile.c
@@ -45,8 +45,6 @@
#include "insns_info.inc"
#include "yarp/yarp.h"
-VALUE rb_iseq_compile_yarp_node(rb_iseq_t * iseq, const yp_node_t * yarp_pointer);
-
#undef RUBY_UNTYPED_DATA_WARNING
#define RUBY_UNTYPED_DATA_WARNING 0
@@ -858,15 +856,40 @@ rb_iseq_compile_node(rb_iseq_t *iseq, const NODE *node)
return iseq_setup(iseq, ret);
}
-static VALUE rb_translate_yarp(rb_iseq_t *iseq, const yp_node_t *node, LINK_ANCHOR *const ret);
+typedef struct yp_compile_context {
+ yp_parser_t *parser;
+ struct yp_compile_context *previous;
+ ID *constants;
+ st_table *index_lookup_table;
+} yp_compile_context_t;
+
+static VALUE rb_translate_yarp(rb_iseq_t *iseq, const yp_node_t *node, LINK_ANCHOR *const ret, yp_compile_context_t *compile_context);
VALUE
-rb_iseq_compile_yarp_node(rb_iseq_t * iseq, const yp_node_t * yarp_pointer)
+rb_iseq_compile_yarp_node(rb_iseq_t * iseq, const yp_node_t *yarp_pointer, yp_parser_t *parser)
{
DECL_ANCHOR(ret);
INIT_ANCHOR(ret);
- CHECK(rb_translate_yarp(iseq, yarp_pointer, ret));
+ ID *constants = calloc(parser->constant_pool.size, sizeof(ID));
+ rb_encoding *encoding = rb_enc_find(parser->encoding.name);
+
+ for (size_t index = 0; index < parser->constant_pool.capacity; index++) {
+ yp_constant_t constant = parser->constant_pool.constants[index];
+
+ if (constant.id != 0) {
+ constants[constant.id - 1] = rb_intern3(constant.start, constant.length, encoding);
+ }
+ }
+
+ yp_compile_context_t compile_context = {
+ .parser = parser,
+ .previous = NULL,
+ .constants = constants
+ };
+
+ CHECK(rb_translate_yarp(iseq, yarp_pointer, ret, &compile_context));
+ free(constants);
CHECK(iseq_setup_insn(iseq, ret));
return iseq_setup(iseq, ret);