diff options
Diffstat (limited to 'eval.c')
| -rw-r--r-- | eval.c | 86 |
1 files changed, 40 insertions, 46 deletions
@@ -37,6 +37,7 @@ #include "ruby/vm.h" #include "vm_core.h" #include "ractor_core.h" +#include "zjit.h" NORETURN(static void rb_raise_jump(VALUE, VALUE)); void rb_ec_clear_current_thread_trace_func(const rb_execution_context_t *ec); @@ -78,8 +79,9 @@ ruby_setup(void) #endif Init_BareVM(); rb_vm_encoded_insn_data_table_init(); - Init_enable_namespace(); + Init_enable_box(); Init_vm_objects(); + Init_master_box(); Init_fstring_table(); EC_PUSH_TAG(GET_EC()); @@ -328,17 +330,24 @@ ruby_exec_node(void *n) /* * call-seq: - * Module.nesting -> array - * - * Returns the list of +Modules+ nested at the point of call. + * Module.nesting -> array + * + * Returns nested module as an array of Module objects: + * + * module M0 + * def self.speak = Module.nesting + * module M1 + * def self.speak = Module.nesting + * module M2 + * def self.speak = Module.nesting + * end + * end + * end + * M0.speak # => [M0] + * M0.speak.first.class # => Module + * M0::M1.speak # => [M0::M1, M0] + * M0::M1::M2.speak # => [M0::M1::M2, M0::M1, M0] * - * module M1 - * module M2 - * $a = Module.nesting - * end - * end - * $a #=> [M1::M2, M1] - * $a[0].name #=> "M1::M2" */ static VALUE @@ -427,40 +436,10 @@ rb_class_modify_check(VALUE klass) rb_class_set_initialized(klass); } if (OBJ_FROZEN(klass)) { - const char *desc; - if (RCLASS_SINGLETON_P(klass)) { - desc = "object"; klass = RCLASS_ATTACHED_OBJECT(klass); - if (!SPECIAL_CONST_P(klass)) { - switch (BUILTIN_TYPE(klass)) { - case T_MODULE: - case T_ICLASS: - desc = "Module"; - break; - case T_CLASS: - desc = "Class"; - break; - default: - break; - } - } - } - else { - switch (BUILTIN_TYPE(klass)) { - case T_MODULE: - case T_ICLASS: - desc = "module"; - break; - case T_CLASS: - desc = "class"; - break; - default: - Check_Type(klass, T_CLASS); - UNREACHABLE; - } } - rb_frozen_error_raise(klass, "can't modify frozen %s: %"PRIsVALUE, desc, klass); + rb_error_frozen_object(klass); } } @@ -951,6 +930,9 @@ rb_f_raise(int argc, VALUE *argv) * With argument +exception+ not given, * argument +message+ and keyword argument +cause+ may be given, * but argument +backtrace+ may not be given. + * + * +cause+ can not be given as an only argument. + * */ static VALUE @@ -1162,12 +1144,11 @@ rb_protect(VALUE (* proc) (VALUE), VALUE data, int *pstate) } VALUE -rb_ensure(VALUE (*b_proc)(VALUE), VALUE data1, VALUE (*e_proc)(VALUE), VALUE data2) +rb_ec_ensure(rb_execution_context_t *ec, VALUE (*b_proc)(VALUE), VALUE data1, VALUE (*e_proc)(VALUE), VALUE data2) { enum ruby_tag_type state; volatile VALUE result = Qnil; VALUE errinfo; - rb_execution_context_t * volatile ec = GET_EC(); EC_PUSH_TAG(ec); if ((state = EC_EXEC_TAG()) == TAG_NONE) { result = (*b_proc) (data1); @@ -1184,6 +1165,12 @@ rb_ensure(VALUE (*b_proc)(VALUE), VALUE data1, VALUE (*e_proc)(VALUE), VALUE dat return result; } +VALUE +rb_ensure(VALUE (*b_proc)(VALUE), VALUE data1, VALUE (*e_proc)(VALUE), VALUE data2) +{ + return rb_ec_ensure(GET_EC(), b_proc, data1, e_proc, data2); +} + static ID frame_func_id(const rb_control_frame_t *cfp) { @@ -1450,6 +1437,8 @@ rb_using_refinement(rb_cref_t *cref, VALUE klass, VALUE module) RCLASS_WRITE_M_TBL(c, RCLASS_M_TBL(module)); + rb_class_subclass_add(klass, iclass); + rb_hash_aset(CREF_REFINEMENTS(cref), klass, iclass); } @@ -1550,10 +1539,12 @@ add_activated_refinement(VALUE activated_refinements, superclass = refinement_superclass(superclass); c = iclass = rb_include_class_new(refinement, superclass); RCLASS_SET_REFINED_CLASS(c, klass); + rb_class_subclass_add(klass, iclass); refinement = RCLASS_SUPER(refinement); while (refinement && refinement != klass) { c = rb_class_set_super(c, rb_include_class_new(refinement, RCLASS_SUPER(c))); RCLASS_SET_REFINED_CLASS(c, klass); + rb_class_subclass_add(klass, c); refinement = RCLASS_SUPER(refinement); } rb_hash_aset(activated_refinements, klass, iclass); @@ -2020,10 +2011,10 @@ errinfo_place(const rb_execution_context_t *ec) while (RUBY_VM_VALID_CONTROL_FRAME_P(cfp, end_cfp)) { if (VM_FRAME_RUBYFRAME_P(cfp)) { - if (ISEQ_BODY(cfp->iseq)->type == ISEQ_TYPE_RESCUE) { + if (ISEQ_BODY(CFP_ISEQ(cfp))->type == ISEQ_TYPE_RESCUE) { return &cfp->ep[VM_ENV_INDEX_LAST_LVAR]; } - else if (ISEQ_BODY(cfp->iseq)->type == ISEQ_TYPE_ENSURE && + else if (ISEQ_BODY(CFP_ISEQ(cfp))->type == ISEQ_TYPE_ENSURE && !THROW_DATA_P(cfp->ep[VM_ENV_INDEX_LAST_LVAR]) && !FIXNUM_P(cfp->ep[VM_ENV_INDEX_LAST_LVAR])) { return &cfp->ep[VM_ENV_INDEX_LAST_LVAR]; @@ -2233,6 +2224,9 @@ Init_eval(void) rb_gvar_ractor_local("$@"); rb_gvar_ractor_local("$!"); + rb_gvar_box_dynamic("$@"); + rb_gvar_box_dynamic("$!"); + rb_define_global_function("raise", f_raise, -1); rb_define_global_function("fail", f_raise, -1); |
