Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
yui-knk committed Apr 23, 2024
1 parent c7d9376 commit 4fa20ef
Show file tree
Hide file tree
Showing 8 changed files with 7 additions and 81 deletions.
4 changes: 0 additions & 4 deletions ext/ripper/ripper_init.c.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,8 @@ ripper_s_allocate(VALUE klass)
VALUE self = TypedData_Make_Struct(klass, struct ripper,
&parser_data_type, r);

#ifdef UNIVERSAL_PARSER
const rb_parser_config_t *config = rb_ruby_parser_config();
r->p = rb_ripper_parser_params_allocate(config);
#else
r->p = rb_ruby_ripper_parser_allocate();
#endif
rb_ruby_parser_set_value(r->p, self);
return self;
}
Expand Down
5 changes: 0 additions & 5 deletions internal/parse.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,6 @@ int rb_parser_local_defined(struct parser_params *p, ID id, const struct rb_iseq

RUBY_SYMBOL_EXPORT_END

#ifndef UNIVERSAL_PARSER
rb_parser_t *rb_ruby_parser_allocate(void);
rb_parser_t *rb_ruby_parser_new(void);
#endif

#ifdef RIPPER
void ripper_parser_mark(void *ptr);
void ripper_parser_free(void *ptr);
Expand Down
16 changes: 0 additions & 16 deletions node.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,8 @@ init_node_buffer_list(node_buffer_list_t *nb, node_buffer_elem_t *head, void *xm
#define ruby_xmalloc config->malloc
#endif

#ifdef UNIVERSAL_PARSER
static node_buffer_t *
rb_node_buffer_new(const rb_parser_config_t *config)
#else
static node_buffer_t *
rb_node_buffer_new(void)
#endif
{
const size_t bucket_size = offsetof(node_buffer_elem_t, buf) + NODE_BUF_DEFAULT_SIZE;
const size_t alloc_size = sizeof(node_buffer_t) + (bucket_size);
Expand All @@ -59,9 +54,7 @@ rb_node_buffer_new(void)
init_node_buffer_list(&nb->buffer_list, (node_buffer_elem_t*)&nb[1], ruby_xmalloc);
nb->local_tables = 0;
nb->tokens = 0;
#ifdef UNIVERSAL_PARSER
nb->config = config;
#endif
return nb;
}

Expand Down Expand Up @@ -299,21 +292,12 @@ rb_ast_delete_node(rb_ast_t *ast, NODE *n)
/* should we implement freelist? */
}

#ifdef UNIVERSAL_PARSER
rb_ast_t *
rb_ast_new(const rb_parser_config_t *config)
{
node_buffer_t *nb = rb_node_buffer_new(config);
return config->ast_new((VALUE)nb);
}
#else
rb_ast_t *
rb_ast_new(void)
{
node_buffer_t *nb = rb_node_buffer_new();
return IMEMO_NEW(rb_ast_t, imemo_ast, (VALUE)nb);
}
#endif

static void
iterate_buffer_elements(rb_ast_t *ast, node_buffer_elem_t *nbe, long len, node_itr_t *func, void *ctx)
Expand Down
6 changes: 0 additions & 6 deletions node.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,12 @@ struct node_buffer_struct {
// - location info
// Array, whose entry is array
rb_parser_ary_t *tokens;
#ifdef UNIVERSAL_PARSER
const rb_parser_config_t *config;
#endif
};

RUBY_SYMBOL_EXPORT_BEGIN

#ifdef UNIVERSAL_PARSER
rb_ast_t *rb_ast_new(const rb_parser_config_t *config);
#else
rb_ast_t *rb_ast_new(void);
#endif
size_t rb_ast_memsize(const rb_ast_t*);
void rb_ast_dispose(rb_ast_t*);
const char *ruby_node_name(int node);
Expand Down
29 changes: 3 additions & 26 deletions parse.y
Original file line number Diff line number Diff line change
Expand Up @@ -550,10 +550,8 @@ struct parser_params {
NODE *eval_tree_begin;
NODE *eval_tree;
const struct rb_iseq_struct *parent_iseq;

#ifdef UNIVERSAL_PARSER
const rb_parser_config_t *config;
#endif

/* compile_option */
signed int frozen_string_literal:2; /* -1: not specified, 0: false, 1: true */

Expand Down Expand Up @@ -7776,7 +7774,7 @@ yycompile(struct parser_params *p, VALUE fname, int line)

p->lvtbl = NULL;

p->ast = ast = rb_ast_new();
p->ast = ast = rb_ast_new(p->config);
compile_callback(yycompile0, (VALUE)p);
p->ast = 0;

Expand Down Expand Up @@ -15889,7 +15887,6 @@ rb_reserved_word(const char *str, unsigned int len)
return reserved_word(str, len);
}

#ifdef UNIVERSAL_PARSER
rb_parser_t *
rb_ruby_parser_allocate(const rb_parser_config_t *config)
{
Expand All @@ -15907,24 +15904,6 @@ rb_ruby_parser_new(const rb_parser_config_t *config)
parser_initialize(p);
return p;
}
#else
rb_parser_t *
rb_ruby_parser_allocate(void)
{
/* parser_initialize expects fields to be set to 0 */
rb_parser_t *p = (rb_parser_t *)ruby_xcalloc(1, sizeof(rb_parser_t));
return p;
}

rb_parser_t *
rb_ruby_parser_new(void)
{
/* parser_initialize expects fields to be set to 0 */
rb_parser_t *p = rb_ruby_parser_allocate();
parser_initialize(p);
return p;
}
#endif

rb_parser_t *
rb_ruby_parser_set_context(rb_parser_t *p, const struct rb_iseq_struct *base, int main)
Expand Down Expand Up @@ -16061,7 +16040,7 @@ void
rb_ruby_ripper_parse0(rb_parser_t *p)
{
parser_prepare(p);
p->ast = rb_ast_new();
p->ast = rb_ast_new(p->config);
ripper_yyparse((void*)p);
rb_ast_dispose(p->ast);
p->ast = 0;
Expand Down Expand Up @@ -16125,15 +16104,13 @@ rb_ruby_ripper_lex_state_name(struct parser_params *p, int state)
return rb_parser_lex_state_name(p, (enum lex_state_e)state);
}

#ifdef UNIVERSAL_PARSER
rb_parser_t *
rb_ripper_parser_params_allocate(const rb_parser_config_t *config)
{
rb_parser_t *p = (rb_parser_t *)config->calloc(1, sizeof(rb_parser_t));
p->config = config;
return p;
}
#endif

struct parser_params*
rb_ruby_ripper_parser_allocate(void)
Expand Down
19 changes: 3 additions & 16 deletions ruby_parser.c
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
/* This is a wrapper for parse.y */

#include "internal/parse.h"
#include "internal/re.h"
#include "internal/ruby_parser.h"

#include "node.h"
#include "rubyparser.h"
#include "internal/error.h"

#ifdef UNIVERSAL_PARSER

#include "internal.h"
#include "internal/array.h"
#include "internal/bignum.h"
#include "internal/compile.h"
#include "internal/complex.h"
#include "internal/encoding.h"
#include "internal/error.h"
#include "internal/gc.h"
#include "internal/hash.h"
#include "internal/io.h"
#include "internal/parse.h"
#include "internal/rational.h"
#include "internal/re.h"
#include "internal/ruby_parser.h"
#include "internal/string.h"
#include "internal/symbol.h"
#include "internal/thread.h"
Expand Down Expand Up @@ -497,7 +493,6 @@ static const rb_parser_config_t rb_global_parser_config = {
.static_id2sym = static_id2sym,
.str_coderange_scan_restartable = str_coderange_scan_restartable,
};
#endif

enum lex_type {
lex_type_str,
Expand Down Expand Up @@ -566,7 +561,6 @@ static const rb_data_type_t ruby_parser_data_type = {
0, 0, RUBY_TYPED_FREE_IMMEDIATELY
};

#ifdef UNIVERSAL_PARSER
const rb_parser_config_t *
rb_ruby_parser_config(void)
{
Expand All @@ -578,13 +572,6 @@ rb_parser_params_new(void)
{
return rb_ruby_parser_new(&rb_global_parser_config);
}
#else
rb_parser_t *
rb_parser_params_new(void)
{
return rb_ruby_parser_new();
}
#endif /* UNIVERSAL_PARSER */

VALUE
rb_parser_new(void)
Expand Down
6 changes: 1 addition & 5 deletions rubyparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -1236,7 +1236,6 @@ typedef struct parser_params rb_parser_t;
typedef struct rb_imemo_tmpbuf_struct rb_imemo_tmpbuf_t;
#endif

#ifdef UNIVERSAL_PARSER
typedef struct rb_parser_config_struct {
/* Memory */
void *(*malloc)(size_t size);
Expand Down Expand Up @@ -1411,18 +1410,15 @@ typedef struct rb_parser_config_struct {
long (*str_coderange_scan_restartable)(const char *s, const char *e, rb_encoding *enc, int *cr);
} rb_parser_config_t;

#ifdef UNIVERSAL_PARSER
#undef rb_encoding
#undef OnigCodePoint
#endif /* UNIVERSAL_PARSER */

RUBY_SYMBOL_EXPORT_BEGIN
void rb_ruby_parser_free(void *ptr);

#ifdef UNIVERSAL_PARSER
rb_parser_t *rb_ruby_parser_allocate(const rb_parser_config_t *config);
rb_parser_t *rb_ruby_parser_new(const rb_parser_config_t *config);
#endif

long rb_parser_string_length(rb_parser_string_t *str);
char *rb_parser_string_pointer(rb_parser_string_t *str);

Expand Down
3 changes: 0 additions & 3 deletions universal_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,3 @@
#define rb_enc_mbminlen p->config->enc_mbminlen
#define rb_enc_isascii p->config->enc_isascii
#define rb_enc_mbc_to_codepoint p->config->enc_mbc_to_codepoint

#define rb_ast_new() \
rb_ast_new(p->config)

0 comments on commit 4fa20ef

Please sign in to comment.