Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/parse_y.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ jobs:

- run: make

- run: make TESTRUN_SCRIPT='-e "exit !RUBY_DESCRIPTION.include?(%[+PRISM])"' run
- run: make TESTRUN_SCRIPT='-renvutil -v -e "exit EnvUtil.current_parser == %[parse.y]"' run
env:
RUNOPT0: -I$(tooldir)/lib

- name: make ${{ matrix.test_task }}
run: make -s ${{ matrix.test_task }} RUN_OPTS="$RUN_OPTS" SPECOPTS="$SPECOPTS"
Expand Down
67 changes: 67 additions & 0 deletions bignum.c
Original file line number Diff line number Diff line change
Expand Up @@ -6757,6 +6757,73 @@ rb_big_aref(VALUE x, VALUE y)
return (xds[s1] & bit) ? INT2FIX(1) : INT2FIX(0);
}

VALUE
rb_big_aref2(VALUE x, VALUE beg, VALUE len)
{
BDIGIT *xds, *vds;
VALUE v;
size_t copy_begin, xn, shift;
ssize_t begin, length, end;
bool negative_add_one;

beg = rb_to_int(beg);
len = rb_to_int(len);
length = NUM2SSIZET(len);
begin = NUM2SSIZET(beg);
end = NUM2SSIZET(rb_int_plus(beg, len));
shift = begin < 0 ? -begin : 0;
xn = BIGNUM_LEN(x);
xds = BDIGITS(x);

if (length < 0) return rb_big_rshift(x, beg);
if (length == 0 || end <= 0) return INT2FIX(0);
if (begin < 0) begin = 0;

if ((size_t)(end - 1) / BITSPERDIG >= xn) {
/* end > xn * BITSPERDIG */
end = xn * BITSPERDIG;
}

if ((size_t)begin / BITSPERDIG < xn) {
/* begin < xn * BITSPERDIG */
size_t shift_bits, copy_end;
copy_begin = begin / BITSPERDIG;
shift_bits = begin % BITSPERDIG;
copy_end = (end - 1) / BITSPERDIG + 1;
v = bignew(copy_end - copy_begin, 1);
vds = BDIGITS(v);
MEMCPY(vds, xds + copy_begin, BDIGIT, copy_end - copy_begin);
negative_add_one = (vds[0] & ((1 << shift_bits) - 1)) == 0;
v = bignorm(v);
if (shift_bits) v = rb_int_rshift(v, SIZET2NUM(shift_bits));
}
else {
/* Out of range */
v = INT2FIX(0);
negative_add_one = false;
copy_begin = begin = end = 0;
}

if (BIGNUM_NEGATIVE_P(x)) {
size_t mask_size = length - shift;
VALUE mask = rb_int_minus(rb_int_lshift(INT2FIX(1), SIZET2NUM(mask_size)), INT2FIX(1));
v = rb_int_xor(v, mask);
for (size_t i = 0; negative_add_one && i < copy_begin; i++) {
if (xds[i]) negative_add_one = false;
}
if (negative_add_one) v = rb_int_plus(v, INT2FIX(1));
v = rb_int_and(v, mask);
}
else {
size_t mask_size = (size_t)end - begin;
VALUE mask = rb_int_minus(rb_int_lshift(INT2FIX(1), SIZET2NUM(mask_size)), INT2FIX(1));
v = rb_int_and(v, mask);
}
RB_GC_GUARD(x);
if (shift) v = rb_int_lshift(v, SSIZET2NUM(shift));
return v;
}

VALUE
rb_big_hash(VALUE x)
{
Expand Down
9 changes: 7 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -3976,7 +3976,7 @@ AS_CASE(["${YJIT_SUPPORT}"],

ZJIT_LIBS=
AS_CASE(["${ZJIT_SUPPORT}"],
[yes|dev|dev_nodebug], [
[yes|dev|dev_nodebug|stats], [
AS_IF([test x"$RUSTC" = "xno"],
AC_MSG_ERROR([rustc is required. Installation instructions available at https://www.rust-lang.org/tools/install])
)
Expand All @@ -3987,11 +3987,16 @@ AS_CASE(["${ZJIT_SUPPORT}"],
[dev], [
rb_cargo_features="$rb_cargo_features,disasm"
JIT_CARGO_SUPPORT=dev
AC_DEFINE(RUBY_DEBUG, 1)
AC_DEFINE(RUBY_DEBUG, 1)
],
[dev_nodebug], [
rb_cargo_features="$rb_cargo_features,disasm"
JIT_CARGO_SUPPORT=dev_nodebug
AC_DEFINE(ZJIT_STATS, 1)
],
[stats], [
JIT_CARGO_SUPPORT=stats
AC_DEFINE(ZJIT_STATS, 1)
])

ZJIT_LIBS="target/release/libzjit.a"
Expand Down
6 changes: 3 additions & 3 deletions gc/default/default.c
Original file line number Diff line number Diff line change
Expand Up @@ -4454,10 +4454,10 @@ rb_gc_impl_mark_maybe(void *objspace_ptr, VALUE obj)
asan_unpoisoning_object(obj) {
/* Garbage can live on the stack, so do not mark or pin */
switch (BUILTIN_TYPE(obj)) {
case T_ZOMBIE:
case T_NONE:
case T_ZOMBIE:
case T_NONE:
break;
default:
default:
gc_mark_and_pin(objspace, obj);
break;
}
Expand Down
1 change: 1 addition & 0 deletions internal/bignum.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ VALUE rb_integer_float_eq(VALUE x, VALUE y);
VALUE rb_str_convert_to_inum(VALUE str, int base, int badcheck, int raise_exception);
VALUE rb_big_comp(VALUE x);
VALUE rb_big_aref(VALUE x, VALUE y);
VALUE rb_big_aref2(VALUE num, VALUE beg, VALUE len);
VALUE rb_big_abs(VALUE x);
VALUE rb_big_size_m(VALUE big);
VALUE rb_big_bit_length(VALUE big);
Expand Down
1 change: 1 addition & 0 deletions internal/numeric.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ VALUE rb_int_cmp(VALUE x, VALUE y);
VALUE rb_int_equal(VALUE x, VALUE y);
VALUE rb_int_divmod(VALUE x, VALUE y);
VALUE rb_int_and(VALUE x, VALUE y);
VALUE rb_int_xor(VALUE x, VALUE y);
VALUE rb_int_lshift(VALUE x, VALUE y);
VALUE rb_int_rshift(VALUE x, VALUE y);
VALUE rb_int_div(VALUE x, VALUE y);
Expand Down
2 changes: 1 addition & 1 deletion internal/vm.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ VALUE rb_block_call2(VALUE obj, ID mid, int argc, const VALUE *argv, rb_block_ca
struct vm_ifunc *rb_current_ifunc(void);
VALUE rb_gccct_clear_table(VALUE);

#if USE_YJIT
#if USE_YJIT || USE_ZJIT
/* vm_exec.c */
extern uint64_t rb_vm_insns_count;
#endif
Expand Down
4 changes: 2 additions & 2 deletions lib/prism/ffi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -422,13 +422,13 @@ def dump_options_command_line(options)
def dump_options_version(version)
case version
when nil, "latest"
0
0 # Handled in pm_parser_init
when /\A3\.3(\.\d+)?\z/
1
when /\A3\.4(\.\d+)?\z/
2
when /\A3\.5(\.\d+)?\z/
0
3
else
raise ArgumentError, "invalid version: #{version}"
end
Expand Down
37 changes: 19 additions & 18 deletions numeric.c
Original file line number Diff line number Diff line change
Expand Up @@ -5115,8 +5115,8 @@ fix_xor(VALUE x, VALUE y)
*
*/

static VALUE
int_xor(VALUE x, VALUE y)
VALUE
rb_int_xor(VALUE x, VALUE y)
{
if (FIXNUM_P(x)) {
return fix_xor(x, y);
Expand Down Expand Up @@ -5288,10 +5288,23 @@ generate_mask(VALUE len)
return rb_int_minus(rb_int_lshift(INT2FIX(1), len), INT2FIX(1));
}

static VALUE
int_aref2(VALUE num, VALUE beg, VALUE len)
{
if (RB_TYPE_P(num, T_BIGNUM)) {
return rb_big_aref2(num, beg, len);
}
else {
num = rb_int_rshift(num, beg);
VALUE mask = generate_mask(len);
return rb_int_and(num, mask);
}
}

static VALUE
int_aref1(VALUE num, VALUE arg)
{
VALUE orig_num = num, beg, end;
VALUE beg, end;
int excl;

if (rb_range_values(arg, &beg, &end, &excl)) {
Expand All @@ -5311,22 +5324,19 @@ int_aref1(VALUE num, VALUE arg)
return INT2FIX(0);
}
}
num = rb_int_rshift(num, beg);

int cmp = compare_indexes(beg, end);
if (!NIL_P(end) && cmp < 0) {
VALUE len = rb_int_minus(end, beg);
if (!excl) len = rb_int_plus(len, INT2FIX(1));
VALUE mask = generate_mask(len);
num = rb_int_and(num, mask);
return int_aref2(num, beg, len);
}
else if (cmp == 0) {
if (excl) return INT2FIX(0);
num = orig_num;
arg = beg;
goto one_bit;
}
return num;
return rb_int_rshift(num, beg);
}

one_bit:
Expand All @@ -5339,15 +5349,6 @@ int_aref1(VALUE num, VALUE arg)
return Qnil;
}

static VALUE
int_aref2(VALUE num, VALUE beg, VALUE len)
{
num = rb_int_rshift(num, beg);
VALUE mask = generate_mask(len);
num = rb_int_and(num, mask);
return num;
}

/*
* call-seq:
* self[offset] -> 0 or 1
Expand Down Expand Up @@ -6366,7 +6367,7 @@ Init_Numeric(void)

rb_define_method(rb_cInteger, "&", rb_int_and, 1);
rb_define_method(rb_cInteger, "|", int_or, 1);
rb_define_method(rb_cInteger, "^", int_xor, 1);
rb_define_method(rb_cInteger, "^", rb_int_xor, 1);
rb_define_method(rb_cInteger, "[]", int_aref, -1);

rb_define_method(rb_cInteger, "<<", rb_int_lshift, 1);
Expand Down
4 changes: 2 additions & 2 deletions prism/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ pm_options_version_set(pm_options_t *options, const char *version, size_t length
}

if (strncmp(version, "3.5", 3) == 0) {
options->version = PM_OPTIONS_VERSION_LATEST;
options->version = PM_OPTIONS_VERSION_CRUBY_3_5;
return true;
}

Expand All @@ -108,7 +108,7 @@ pm_options_version_set(pm_options_t *options, const char *version, size_t length
}

if (strncmp(version, "3.5.", 4) == 0 && is_number(version + 4, length - 4)) {
options->version = PM_OPTIONS_VERSION_LATEST;
options->version = PM_OPTIONS_VERSION_CRUBY_3_5;
return true;
}
}
Expand Down
12 changes: 9 additions & 3 deletions prism/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,20 @@ typedef void (*pm_options_shebang_callback_t)(struct pm_options *options, const
* parse in the same way as a specific version of CRuby would have.
*/
typedef enum {
/** The current version of prism. */
PM_OPTIONS_VERSION_LATEST = 0,
/** If an explicit version is not provided, the current version of prism will be used. */
PM_OPTIONS_VERSION_UNSET = 0,

/** The vendored version of prism in CRuby 3.3.x. */
PM_OPTIONS_VERSION_CRUBY_3_3 = 1,

/** The vendored version of prism in CRuby 3.4.x. */
PM_OPTIONS_VERSION_CRUBY_3_4 = 2
PM_OPTIONS_VERSION_CRUBY_3_4 = 2,

/** The vendored version of prism in CRuby 3.5.x. */
PM_OPTIONS_VERSION_CRUBY_3_5 = 3,

/** The current version of prism. */
PM_OPTIONS_VERSION_LATEST = PM_OPTIONS_VERSION_CRUBY_3_5
} pm_options_version_t;

/**
Expand Down
Loading