Skip to content

Commit

Permalink
Merge pull request #3 from hasumikin/upgrade-resources
Browse files Browse the repository at this point in the history
Upgrade resources
  • Loading branch information
yui-knk authored Mar 23, 2024
2 parents 56f7bc0 + c041e60 commit 09ae269
Show file tree
Hide file tree
Showing 48 changed files with 11,316 additions and 2,723 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/ext/ruby-parser/ruby/parse.c
/ext/ruby-parser/ruby/parse.h
/lib/*.bundle
/lib/ruby_parser.so
/tmp
/Gemfile.lock
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
source 'https://rubygems.org'

gem "lrama", "0.6.0"
gem "lrama", "0.6.3"
gem "rake-compiler", "~> 1.0"
33 changes: 32 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,56 @@ require "fileutils"
require "rake/extensiontask"

COPY_TARGETS = %w[
ccan/check_type/check_type.h
ccan/container_of/container_of.h
ccan/list/list.h
ccan/str/str.h
internal/array.h
internal/basic_operators.h
internal/bignum.h
internal/bits.h
internal/compile.h
internal/compilers.h
internal/complex.h
internal/encoding.h
internal/error.h
internal/fixnum.h
internal/gc.h
internal/hash.h
internal/imemo.h
internal/io.h
internal/numeric.h
internal/parse.h
internal/rational.h
internal/re.h
internal/ruby_parser.h
internal/sanitizers.h
internal/serial.h
internal/static_assert.h
internal/string.h
internal/symbol.h
internal/thread.h
internal/warnings.h
internal/vm.h
internal.h
method.h
node.c
node.h
parser_bits.h
parser_node.h
parser_st.c
parser_st.h
parser_value.h
ruby_assert.h
ruby_atomic.h
ruby_parser.c
rubyparser.h
st.c
universal_parser.c
symbol.h
thread_pthread.h
universal_parser.c
vm_core.h
vm_opts.h
]

namespace "build" do
Expand Down
32 changes: 2 additions & 30 deletions ext/ruby-parser/helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ nil_p(VALUE obj)
}

static VALUE
fstring(VALUE obj)
str_to_interned_str(VALUE obj)
{
return obj;
}
Expand Down Expand Up @@ -184,12 +184,6 @@ str_subseq(VALUE str, long beg, long len)
return (VALUE)string_new_with_str_len(rstring_ptr(str) + beg, len);
}

static int
obj_frozen(VALUE obj)
{
return 0;
}

static VALUE
verbose(void)
{
Expand Down Expand Up @@ -276,12 +270,6 @@ is_local_id(ID id)
return 0;
}

static VALUE
cstr_to_inum(const char *str, int base, int badcheck)
{
return (VALUE)number_new_with_long((long)atoi(str));
}

static VALUE
obj_written(VALUE old, VALUE slot, VALUE young)
{
Expand All @@ -306,12 +294,6 @@ obj_hide(VALUE obj)
return obj;
}

static VALUE
sym_intern_ascii_cstr(const char *ptr)
{
return id_new();
}

static VALUE
hash_aset(VALUE hash, VALUE key, VALUE val)
{
Expand All @@ -324,12 +306,6 @@ obj_write(VALUE old, VALUE *slot, VALUE young)
return old;
}

static VALUE
int2fix(long i)
{
return (VALUE)number_new_with_long(i);
}

static void
print_literal(FILE *fp, VALUE lit)
{
Expand Down Expand Up @@ -467,29 +443,25 @@ parser_config_initialize(rb_parser_config_t *config)
config->enc_asciicompat = enc_asciicompat;
config->str_new_frozen = str_new_frozen;
config->nil_p = nil_p;
config->fstring = fstring;
config->str_to_interned_str = str_to_interned_str;
config->string_value_cstr = string_value_cstr;
config->ast_new = ast_new;
config->compile_callback = compile_callback;
config->rstring_ptr = rstring_ptr;
config->rstring_len = rstring_len;
config->str_subseq = str_subseq;
config->obj_frozen = obj_frozen;
config->verbose = verbose;
config->rtest = rtest;
config->enc_isalnum = enc_isalnum;
config->enc_precise_mbclen = enc_precise_mbclen;
config->mbclen_charfound_p = mbclen_charfound_p;
config->intern3 = intern3;
config->is_local_id = is_local_id;
config->cstr_to_inum = cstr_to_inum;
config->obj_written = obj_written;
config->ident_hash_new = ident_hash_new;
config->obj_hide = obj_hide;
config->sym_intern_ascii_cstr = sym_intern_ascii_cstr;
config->hash_aset = hash_aset;
config->obj_write = obj_write;
config->int2fix = int2fix;
}

void
Expand Down
63 changes: 63 additions & 0 deletions ext/ruby-parser/ruby/ccan/check_type/check_type.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/* CC0 (Public domain) - see ccan/licenses/CC0 file for details */
#ifndef CCAN_CHECK_TYPE_H
#define CCAN_CHECK_TYPE_H

/**
* ccan_check_type - issue a warning or build failure if type is not correct.
* @expr: the expression whose type we should check (not evaluated).
* @type: the exact type we expect the expression to be.
*
* This macro is usually used within other macros to try to ensure that a macro
* argument is of the expected type. No type promotion of the expression is
* done: an unsigned int is not the same as an int!
*
* ccan_check_type() always evaluates to 0.
*
* If your compiler does not support typeof, then the best we can do is fail
* to compile if the sizes of the types are unequal (a less complete check).
*
* Example:
* // They should always pass a 64-bit value to _set_some_value!
* #define set_some_value(expr) \
* _set_some_value((ccan_check_type((expr), uint64_t), (expr)))
*/

/**
* ccan_check_types_match - issue a warning or build failure if types are not same.
* @expr1: the first expression (not evaluated).
* @expr2: the second expression (not evaluated).
*
* This macro is usually used within other macros to try to ensure that
* arguments are of identical types. No type promotion of the expressions is
* done: an unsigned int is not the same as an int!
*
* ccan_check_types_match() always evaluates to 0.
*
* If your compiler does not support typeof, then the best we can do is fail
* to compile if the sizes of the types are unequal (a less complete check).
*
* Example:
* // Do subtraction to get to enclosing type, but make sure that
* // pointer is of correct type for that member.
* #define ccan_container_of(mbr_ptr, encl_type, mbr) \
* (ccan_check_types_match((mbr_ptr), &((encl_type *)0)->mbr), \
* ((encl_type *) \
* ((char *)(mbr_ptr) - offsetof(enclosing_type, mbr))))
*/
#if defined(HAVE_TYPEOF) && HAVE_TYPEOF
#define ccan_check_type(expr, type) \
((typeof(expr) *)0 != (type *)0)

#define ccan_check_types_match(expr1, expr2) \
((typeof(expr1) *)0 != (typeof(expr2) *)0)
#else
#include "ccan/build_assert/build_assert.h"
/* Without typeof, we can only test the sizes. */
#define ccan_check_type(expr, type) \
CCAN_BUILD_ASSERT_OR_ZERO(sizeof(expr) == sizeof(type))

#define ccan_check_types_match(expr1, expr2) \
CCAN_BUILD_ASSERT_OR_ZERO(sizeof(expr1) == sizeof(expr2))
#endif /* HAVE_TYPEOF */

#endif /* CCAN_CHECK_TYPE_H */
142 changes: 142 additions & 0 deletions ext/ruby-parser/ruby/ccan/container_of/container_of.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
/* CC0 (Public domain) - see ccan/licenses/CC0 file for details */
#ifndef CCAN_CONTAINER_OF_H
#define CCAN_CONTAINER_OF_H
#include "ccan/check_type/check_type.h"

/**
* ccan_container_of - get pointer to enclosing structure
* @member_ptr: pointer to the structure member
* @containing_type: the type this member is within
* @member: the name of this member within the structure.
*
* Given a pointer to a member of a structure, this macro does pointer
* subtraction to return the pointer to the enclosing type.
*
* Example:
* struct foo {
* int fielda, fieldb;
* // ...
* };
* struct info {
* int some_other_field;
* struct foo my_foo;
* };
*
* static struct info *foo_to_info(struct foo *foo)
* {
* return ccan_container_of(foo, struct info, my_foo);
* }
*/
#define ccan_container_of(member_ptr, containing_type, member) \
((containing_type *) \
((char *)(member_ptr) \
- ccan_container_off(containing_type, member)) \
+ ccan_check_types_match(*(member_ptr), ((containing_type *)0)->member))


/**
* ccan_container_of_or_null - get pointer to enclosing structure, or NULL
* @member_ptr: pointer to the structure member
* @containing_type: the type this member is within
* @member: the name of this member within the structure.
*
* Given a pointer to a member of a structure, this macro does pointer
* subtraction to return the pointer to the enclosing type, unless it
* is given NULL, in which case it also returns NULL.
*
* Example:
* struct foo {
* int fielda, fieldb;
* // ...
* };
* struct info {
* int some_other_field;
* struct foo my_foo;
* };
*
* static struct info *foo_to_info_allowing_null(struct foo *foo)
* {
* return ccan_container_of_or_null(foo, struct info, my_foo);
* }
*/
static inline char *container_of_or_null_(void *member_ptr, size_t offset)
{
return member_ptr ? (char *)member_ptr - offset : NULL;
}
#define ccan_container_of_or_null(member_ptr, containing_type, member) \
((containing_type *) \
ccan_container_of_or_null_(member_ptr, \
ccan_container_off(containing_type, member)) \
+ ccan_check_types_match(*(member_ptr), ((containing_type *)0)->member))

/**
* ccan_container_off - get offset to enclosing structure
* @containing_type: the type this member is within
* @member: the name of this member within the structure.
*
* Given a pointer to a member of a structure, this macro does
* typechecking and figures out the offset to the enclosing type.
*
* Example:
* struct foo {
* int fielda, fieldb;
* // ...
* };
* struct info {
* int some_other_field;
* struct foo my_foo;
* };
*
* static struct info *foo_to_info(struct foo *foo)
* {
* size_t off = ccan_container_off(struct info, my_foo);
* return (void *)((char *)foo - off);
* }
*/
#define ccan_container_off(containing_type, member) \
offsetof(containing_type, member)

/**
* ccan_container_of_var - get pointer to enclosing structure using a variable
* @member_ptr: pointer to the structure member
* @container_var: a pointer of same type as this member's container
* @member: the name of this member within the structure.
*
* Given a pointer to a member of a structure, this macro does pointer
* subtraction to return the pointer to the enclosing type.
*
* Example:
* static struct info *foo_to_i(struct foo *foo)
* {
* struct info *i = ccan_container_of_var(foo, i, my_foo);
* return i;
* }
*/
#if defined(HAVE_TYPEOF) && HAVE_TYPEOF
#define ccan_container_of_var(member_ptr, container_var, member) \
ccan_container_of(member_ptr, typeof(*container_var), member)
#else
#define ccan_container_of_var(member_ptr, container_var, member) \
((void *)((char *)(member_ptr) - \
ccan_container_off_var(container_var, member)))
#endif

/**
* ccan_container_off_var - get offset of a field in enclosing structure
* @container_var: a pointer to a container structure
* @member: the name of a member within the structure.
*
* Given (any) pointer to a structure and a its member name, this
* macro does pointer subtraction to return offset of member in a
* structure memory layout.
*
*/
#if defined(HAVE_TYPEOF) && HAVE_TYPEOF
#define ccan_container_off_var(var, member) \
ccan_container_off(typeof(*var), member)
#else
#define ccan_container_off_var(var, member) \
((const char *)&(var)->member - (const char *)(var))
#endif

#endif /* CCAN_CONTAINER_OF_H */
Loading

0 comments on commit 09ae269

Please sign in to comment.