Remove `rb_imemo_tmpbuf_t` from parser

No parser semantic value types are `VALUE` then no need to
use imemo for managing semantic value stack anymore.
This commit is contained in:
yui-knk 2024-04-01 14:33:17 +09:00 коммит произвёл Yuichiro Kaneko
Родитель e651395210
Коммит e816ab0b0c
7 изменённых файлов: 0 добавлений и 99 удалений

Просмотреть файл

@ -2,7 +2,6 @@
#include "ruby/ruby.h"
#include "ruby/encoding.h"
#include "internal.h"
#include "internal/imemo.h" /* needed by ruby_parser.h */
#include "rubyparser.h"
#define YYSTYPE_IS_DECLARED
#include "parse.h"

Просмотреть файл

@ -5,7 +5,6 @@
#include "internal/bignum.h"
#include "internal/compilers.h"
#include "internal/complex.h"
#include "internal/imemo.h"
#include "internal/rational.h"
#include "rubyparser.h"
#include "vm.h"

4
node.h
Просмотреть файл

@ -73,10 +73,6 @@ VALUE rb_parser_dump_tree(const NODE *node, int comment);
const struct kwtable *rb_reserved_word(const char *, unsigned int);
struct parser_params;
void *rb_parser_malloc(struct parser_params *, size_t);
void *rb_parser_realloc(struct parser_params *, void *, size_t);
void *rb_parser_calloc(struct parser_params *, size_t, size_t);
void rb_parser_free(struct parser_params *, void *);
PRINTF_ARGS(void rb_parser_printf(struct parser_params *parser, const char *fmt, ...), 2, 3);
VALUE rb_node_set_type(NODE *n, enum node_type t);

73
parse.y
Просмотреть файл

@ -49,7 +49,6 @@
#include "internal/encoding.h"
#include "internal/error.h"
#include "internal/hash.h"
#include "internal/imemo.h"
#include "internal/io.h"
#include "internal/numeric.h"
#include "internal/parse.h"
@ -354,10 +353,6 @@ RBIMPL_WARNING_POP()
#define yydebug (p->debug) /* disable the global variable definition */
#define YYMALLOC(size) rb_parser_malloc(p, (size))
#define YYREALLOC(ptr, size) rb_parser_realloc(p, (ptr), (size))
#define YYCALLOC(nelem, size) rb_parser_calloc(p, (nelem), (size))
#define YYFREE(ptr) rb_parser_free(p, (ptr))
#define YYFPRINTF(out, ...) rb_parser_printf(p, __VA_ARGS__)
#define YY_LOCATION_PRINT(File, loc, p) \
rb_parser_printf(p, "%d.%d-%d.%d", \
@ -499,8 +494,6 @@ typedef struct parser_string_buffer {
token
*/
struct parser_params {
rb_imemo_tmpbuf_t *heap;
YYSTYPE *lval;
YYLTYPE *yylloc;
@ -16147,9 +16140,6 @@ rb_ruby_parser_mark(void *ptr)
#endif
rb_gc_mark(p->debug_buffer);
rb_gc_mark(p->debug_output);
#ifdef YYMALLOC
rb_gc_mark((VALUE)p->heap);
#endif
}
void
@ -16610,69 +16600,6 @@ rb_ruby_ripper_parser_allocate(void)
#endif /* RIPPER */
#ifndef RIPPER
#ifdef YYMALLOC
#define HEAPCNT(n, size) ((n) * (size) / sizeof(YYSTYPE))
/* Keep the order; NEWHEAP then xmalloc and ADD2HEAP to get rid of
* potential memory leak */
#define NEWHEAP() rb_imemo_tmpbuf_parser_heap(0, p->heap, 0)
#define ADD2HEAP(new, cnt, ptr) ((p->heap = (new))->ptr = (ptr), \
(new)->cnt = (cnt), (ptr))
void *
rb_parser_malloc(struct parser_params *p, size_t size)
{
size_t cnt = HEAPCNT(1, size);
rb_imemo_tmpbuf_t *n = NEWHEAP();
void *ptr = xmalloc(size);
return ADD2HEAP(n, cnt, ptr);
}
void *
rb_parser_calloc(struct parser_params *p, size_t nelem, size_t size)
{
size_t cnt = HEAPCNT(nelem, size);
rb_imemo_tmpbuf_t *n = NEWHEAP();
void *ptr = xcalloc(nelem, size);
return ADD2HEAP(n, cnt, ptr);
}
void *
rb_parser_realloc(struct parser_params *p, void *ptr, size_t size)
{
rb_imemo_tmpbuf_t *n;
size_t cnt = HEAPCNT(1, size);
if (ptr && (n = p->heap) != NULL) {
do {
if (n->ptr == ptr) {
n->ptr = ptr = xrealloc(ptr, size);
if (n->cnt) n->cnt = cnt;
return ptr;
}
} while ((n = n->next) != NULL);
}
n = NEWHEAP();
ptr = xrealloc(ptr, size);
return ADD2HEAP(n, cnt, ptr);
}
void
rb_parser_free(struct parser_params *p, void *ptr)
{
rb_imemo_tmpbuf_t **prev = &p->heap, *n;
while ((n = *prev) != NULL) {
if (n->ptr == ptr) {
*prev = n->next;
break;
}
prev = &n->next;
}
}
#endif
void
rb_parser_printf(struct parser_params *p, const char *fmt, ...)
{

Просмотреть файл

@ -387,12 +387,6 @@ gc_guard(VALUE obj)
RB_GC_GUARD(obj);
}
static rb_imemo_tmpbuf_t *
tmpbuf_parser_heap(void *buf, rb_imemo_tmpbuf_t *old_heap, size_t cnt)
{
return rb_imemo_tmpbuf_parser_heap(buf, old_heap, cnt);
}
static VALUE
arg_error(void)
{
@ -462,7 +456,6 @@ static const rb_parser_config_t rb_global_parser_config = {
.nonempty_memcpy = nonempty_memcpy,
.xmalloc_mul_add = rb_xmalloc_mul_add,
.tmpbuf_parser_heap = tmpbuf_parser_heap,
.ast_new = ast_new,
.compile_callback = rb_suppress_tracing,

Просмотреть файл

@ -1241,7 +1241,6 @@ typedef struct rb_parser_config_struct {
void *(*xmalloc_mul_add)(size_t x, size_t y, size_t z);
/* imemo */
rb_imemo_tmpbuf_t *(*tmpbuf_parser_heap)(void *buf, rb_imemo_tmpbuf_t *old_heap, size_t cnt);
rb_ast_t *(*ast_new)(VALUE nb);
// VALUE rb_suppress_tracing(VALUE (*func)(VALUE), VALUE arg);

Просмотреть файл

@ -61,16 +61,6 @@
#define rb_encoding void
#ifndef INTERNAL_IMEMO_H
struct rb_imemo_tmpbuf_struct {
VALUE flags;
VALUE reserved;
VALUE *ptr; /* malloc'ed buffer */
struct rb_imemo_tmpbuf_struct *next; /* next imemo */
size_t cnt; /* buffer size in VALUE */
};
#endif
#undef xmalloc
#define xmalloc p->config->malloc
#undef xcalloc
@ -95,8 +85,6 @@ struct rb_imemo_tmpbuf_struct {
#undef MEMCPY
#define MEMCPY(p1,p2,type,n) (p->config->nonempty_memcpy((p1), (p2), sizeof(type), (n)))
#define rb_imemo_tmpbuf_parser_heap p->config->tmpbuf_parser_heap
#define compile_callback p->config->compile_callback
#define reg_named_capture_assign p->config->reg_named_capture_assign