Ruby: eval.c File Reference

Ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c52d4d35cc6a173c89eda98ceffa2dcf)

Macros | Enumerations | Functions | Variables
eval.c File Reference
`#include "ruby/internal/config.h"`
`#include "eval_intern.h"`
`#include "gc.h"`
`#include "internal.h"`
`#include "internal/class.h"`
`#include "internal/error.h"`
`#include "internal/eval.h"`
`#include "internal/hash.h"`
`#include "internal/inits.h"`
`#include "internal/io.h"`
`#include "internal/object.h"`
`#include "internal/thread.h"`
`#include "internal/variable.h"`
`#include "internal/scheduler.h"`
`#include "iseq.h"`
`#include "mjit.h"`
`#include "probes.h"`
`#include "probes_helper.h"`
`#include "ruby/vm.h"`
`#include "vm_core.h"`
`#include "ractor_core.h"`
`#include "eval_error.c"`
`#include "eval_jump.c"`

Go to the source code of this file.

## Macros
#define | id_cause ruby_static_id_cause
#define | exception_error GET_VM()->special_exceptions[ruby_error_reenter]
#define | CLASS_OR_MODULE_P(obj)
#define | get_ec_errinfo(ec) rb_ec_get_errinfo(ec)

## Enumerations
enum | { raise_opt_cause , raise_max_opt }

## Functions
void | rb_raise_jump (VALUE mesg, VALUE cause)
void | rb_ec_clear_current_thread_trace_func (const rb_execution_context_t *ec)
void | rb_ec_clear_all_trace_func (const rb_execution_context_t *ec)
int | ruby_setup (void)
| Initializes the VM and builtin libraries. More...
void | ruby_init (void)
| Calls ruby_setup() and check error. More...
void * | ruby_options (int argc, char **argv)
| Processes command line arguments and compiles the Ruby source to execute. More...
void | ruby_finalize (void)
| Runs the VM finalization processes. More...
int | ruby_cleanup (volatile int ex)
| Destructs the VM. More...
void | ruby_stop (int ex)
| Calls ruby_cleanup() and exits the process. More...
int | ruby_executable_node (void *n, int *status)
| Checks the return value of ruby_options(). More...
int | ruby_run_node (void *n)
| Runs the given compiled source and exits this process. More...
int | ruby_exec_node (void *n)
| Runs the given compiled source. More...
void | rb_class_modify_check (VALUE klass)
| Asserts that klass is not a frozen class. More...
void | rb_exc_raise (VALUE mesg)
| Raises an exception in the current thread. More...
void | rb_exc_fatal (VALUE mesg)
| Raises a fatal error in the current thread. More...
void | rb_interrupt (void)
| Raises an `Interrupt` exception. More...
VALUE | rb_f_raise (int argc, VALUE *argv)
VALUE | rb_make_exception (int argc, const VALUE *argv)
| Make an `Exception` object from the list of arguments in a manner similar to `Kernel#raise`. More...
void | rb_jump_tag (int tag)
| Continues the exception caught by rb_protect() and rb_eval_string_protect(). More...
int | rb_block_given_p (void)
| Determines if the current method is given a block. More...
int | rb_vm_cframe_keyword_p (const rb_control_frame_t *cfp)
int | rb_keyword_given_p (void)
void | rb_need_block (void)
| Declares that the current method needs a block. More...
VALUE | rb_rescue2 (VALUE(*b_proc)(VALUE), VALUE data1, VALUE(*r_proc)(VALUE, VALUE), VALUE data2,...)
| An equivalent of `rescue` clause. More...
VALUE | rb_vrescue2 (VALUE(*b_proc)(VALUE), VALUE data1, VALUE(*r_proc)(VALUE, VALUE), VALUE data2, va_list args)
| An equivalent of `rescue` clause. More...
VALUE | rb_rescue (VALUE(*b_proc)(VALUE), VALUE data1, VALUE(*r_proc)(VALUE, VALUE), VALUE data2)
| An equivalent of `rescue` clause. More...
VALUE | rb_protect (VALUE(*proc)(VALUE), VALUE data, int *pstate)
| Protects a function call from potential global escapes from the function. More...
VALUE | rb_ensure (VALUE(*b_proc)(VALUE), VALUE data1, VALUE(*e_proc)(VALUE), VALUE data2)
| An equivalent to `ensure` clause. More...
ID | rb_frame_this_func (void)
| The original name of the current method. More...
ID | rb_frame_callee (void)
| The name of the current method. More...
void | rb_obj_call_init (VALUE obj, int argc, const VALUE *argv)
| Calls `initialize` method of obj with the given arguments. More...
void | rb_obj_call_init_kw (VALUE obj, int argc, const VALUE *argv, int kw_splat)
void | rb_extend_object (VALUE obj, VALUE module)
| Extend the object with the module. More...
VALUE | rb_ec_get_errinfo (const rb_execution_context_t *ec)
VALUE | rb_errinfo (void)
| The current exception in the current thread. More...
void | rb_set_errinfo (VALUE err)
| Sets the current exception (`$!`) to the given value. More...
void | Init_eval (void)

## Variables
VALUE | rb_eLocalJumpError
VALUE | rb_eSysStackError
ID | ruby_static_id_signo
ID | ruby_static_id_status
ID | ruby_static_id_cause
VALUE | rb_eThreadError

## Macro Definition Documentation

## ◆ CLASS_OR_MODULE_P

#define CLASS_OR_MODULE_P | ( |  | obj | ) |

Value:
(!SPECIAL_CONST_P(obj) && \
(BUILTIN_TYPE(obj) == T_CLASS || BUILTIN_TYPE(obj) == T_MODULE))
SPECIAL_CONST_P
#define SPECIAL_CONST_P
Definition: special_consts.h:47
T_MODULE
#define T_MODULE
Definition: value_type.h:69
T_CLASS
#define T_CLASS
Definition: value_type.h:57
BUILTIN_TYPE
#define BUILTIN_TYPE
Definition: value_type.h:84

Definition at line 60 of file eval.c.

## ◆ exception_error

#define exception_error GET_VM()->special_exceptions[ruby_error_reenter]

Definition at line 55 of file eval.c.

## ◆ get_ec_errinfo

#define get_ec_errinfo | ( |  | ec | ) | rb_ec_get_errinfo(ec)

Definition at line 522 of file eval.c.

## ◆ id_cause

#define id_cause ruby_static_id_cause

Definition at line 53 of file eval.c.

## Enumeration Type Documentation

## ◆ anonymous enum

anonymous enum

Enumerator
raise_opt_cause |
raise_max_opt |

Definition at line 746 of file eval.c.

## Function Documentation

## ◆ Init_eval()

void Init_eval | ( | void |  | ) |

Definition at line 2085 of file eval.c.

References id_signo, id_status, Init_eval_method(), Init_vm_eval(), rb_cClass, rb_cModule, rb_define_global_function, rb_define_method, rb_define_private_method, rb_define_singleton_method, ruby::backward::cxxanyargs::rb_define_virtual_variable(), rb_eFatal, rb_gvar_ractor_local(), rb_mKernel, rb_singleton_class(), rb_undef_method(), rb_vm_register_special_exception, rb_vm_top_self(), ruby_error_reenter, and ruby_error_stackfatal.

## ◆ rb_ec_clear_all_trace_func()

void rb_ec_clear_all_trace_func | ( | const rb_execution_context_t * | ec | ) |

Definition at line 283 of file vm_trace.c.

References MATCH_ANY_FILTER_TH, and Qundef.

## ◆ rb_ec_clear_current_thread_trace_func()

void rb_ec_clear_current_thread_trace_func | ( | const rb_execution_context_t * | ec | ) |

Definition at line 277 of file vm_trace.c.

References Qundef.

Referenced by ruby_options().

## ◆ rb_ec_get_errinfo()

VALUE rb_ec_get_errinfo | ( | const rb_execution_context_t * | ec | ) |

Definition at line 1881 of file eval.c.

References rb_execution_context_struct::errinfo, and ptr.

Referenced by rb_f_abort().

## ◆ rb_f_raise()

VALUE rb_f_raise | ( | int | argc,
|  | VALUE * | argv
| ) |  |

Definition at line 771 of file eval.c.

References argc, argv, err, NIL_P, Qnil, Qundef, raise_max_opt, raise_opt_cause, rb_eArgError, rb_make_exception(), rb_raise(), rb_raise_jump(), and UNREACHABLE_RETURN.

## ◆ rb_keyword_given_p()

int rb_keyword_given_p | ( | void |  | ) |

Definition at line 948 of file eval.c.

References rb_vm_cframe_keyword_p().

Referenced by rb_arith_seq_new(), rb_enumeratorize_with_size(), and rb_yield_block().

## ◆ rb_obj_call_init_kw()

void rb_obj_call_init_kw | ( | VALUE | obj,
|  | int | argc,
|  | const VALUE * | argv,
|  | int | kw_splat
| ) |  |

Definition at line 1717 of file eval.c.

References argc, argv, PASS_PASSED_BLOCK_HANDLER, and rb_funcallv_kw().

Referenced by rb_class_new_instance(), rb_class_new_instance_kw(), and rb_class_new_instance_pass_kw().

## ◆ rb_raise_jump()

void rb_raise_jump | ( | VALUE | mesg,
|  | VALUE | cause
| ) |  |

Todo:
  can be static?

Definition at line 897 of file eval.c.

References rb_callable_method_entry_struct::called_id, rb_execution_context_struct::cfp, rb_callable_method_entry_struct::def, EXEC_EVENT_HOOK, rb_method_definition_struct::original_id, rb_callable_method_entry_struct::owner, Qnil, rb_vm_frame_method_entry(), rb_vm_pop_frame(), RUBY_EVENT_C_RETURN, rb_control_frame_struct::self, and TAG_RAISE.

Referenced by rb_f_raise().

## ◆ rb_vm_cframe_keyword_p()

int rb_vm_cframe_keyword_p | ( | const rb_control_frame_t * | cfp | ) |

Definition at line 120 of file vm.c.

Referenced by rb_keyword_given_p().

## ◆ rb_vrescue2()

VALUE rb_vrescue2 | ( | VALUE(*)(VALUE) | b_proc,
|  | VALUE | data1,
|  | VALUE(*)(VALUE, VALUE) | r_proc,
|  | VALUE | data2,
|  | va_list | args
| ) |  |

An equivalent of `rescue` clause.

Equivalent to `begin .. rescue err_type .. end`

Parameters

  [in] | b_proc | a function which potentially raises an exception.
  [in] | data1 | the argument of b_proc
  [in] | r_proc | a function which rescues an exception in b_proc.
  [in] | data2 | the first argument of r_proc
  [in] | ... | 1 or more exception classes. Must be terminated by ``(VALUE)0.

First it calls the function b_proc, with data1 as the argument. When b_proc raises an exception, it calls r_proc with data2 and the exception object if the exception is a kind of one of the given exception classes.

Returns
  the return value of b_proc if no exception occurs, or the return value of r_proc if otherwise.

See also
  rb_rescue
  rb_ensure
  rb_protect

Parameters

  [in] | args | exception classes, terminated by (VALUE)0.

Definition at line 1006 of file eval.c.

References rb_execution_context_struct::cfp, EC_EXEC_TAG, EC_JUMP_TAG, EC_POP_TAG, EC_PUSH_TAG, rb_execution_context_struct::errinfo, FALSE, Qfalse, Qnil, rb_obj_is_kind_of(), rb_vm_rewind_cfp(), TAG_NONE, TAG_RAISE, TAG_RETRY, and TRUE.

Referenced by ruby::backward::cxxanyargs::rb_rescue2(), and rb_rescue2().

## Variable Documentation

## ◆ rb_eLocalJumpError

VALUE rb_eLocalJumpError

Definition at line 48 of file eval.c.

Referenced by Init_Proc().

## ◆ rb_eSysStackError

VALUE rb_eSysStackError

Definition at line 49 of file eval.c.

Referenced by Init_Proc().

## ◆ rb_eThreadError

VALUE rb_eThreadError

Definition at line 953 of file eval.c.

Referenced by Init_Thread(), rb_mutex_unlock(), rb_thread_stop(), and rb_thread_wakeup().

## ◆ ruby_static_id_signo

ID ruby_static_id_signo

Definition at line 51 of file eval.c.

## ◆ ruby_static_id_status

ID ruby_static_id_status

Definition at line 51 of file eval.c.