| 1 |
#ifndef RBIMPL_INTERN_EVAL_H /*-*-C++-*-vi:se ft=cpp:*/ |
| 2 |
#define RBIMPL_INTERN_EVAL_H |
| 3 |
/** |
| 4 |
* @file |
| 5 |
* @author Ruby developers <[email protected]> |
| 6 |
* @copyright This file is a part of the programming language Ruby. |
| 7 |
* Permission is hereby granted, to either redistribute and/or |
| 8 |
* modify this file, provided that the conditions mentioned in the |
| 9 |
* file COPYING are met. Consult the file for details. |
| 10 |
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are |
| 11 |
* implementation details. Don't take them as canon. They could |
| 12 |
* rapidly appear then vanish. The name (path) of this header file |
| 13 |
* is also an implementation detail. Do not expect it to persist |
| 14 |
* at the place it is now. Developers are free to move it anywhere |
| 15 |
* anytime at will. |
| 16 |
* @note To ruby-core: remember that this header can be possibly |
| 17 |
* recursively included from extension libraries written in C++. |
| 18 |
* Do not expect for instance `__VA_ARGS__` is always available. |
| 19 |
* We assume C99 for ruby itself but we don't assume languages of |
| 20 |
* extension libraries. They could be written in C++98. |
| 21 |
* @brief Pre-1.9 era evaluator APIs (now considered miscellaneous). |
| 22 |
*/ |
| 23 |
#include "ruby/internal/attr/noreturn.h" |
| 24 |
#include "ruby/internal/dllexport.h" |
| 25 |
#include "ruby/internal/value.h" |
| 26 |
|
| 27 |
RBIMPL_SYMBOL_EXPORT_BEGIN() |
| 28 |
|
| 29 |
/* eval.c */ |
| 30 |
RBIMPL_ATTR_NORETURN() |
| 31 |
/** |
| 32 |
* Identical to rb_raise(), except it raises the passed exception instance as- |
| 33 |
* is instead of creating new one. |
| 34 |
* |
| 35 |
* @param[in] exc An instance of a subclass of ::rb_eException. |
| 36 |
* @exception exc What is passed. |
| 37 |
* @exception rb_eTypeError `exc` is not an exception. |
| 38 |
* @note It never returns. |
| 39 |
* |
| 40 |
* @internal |
| 41 |
* |
| 42 |
* Wellll actually, it can take more than what is described above. This |
| 43 |
* function tries to call `exception` method of the passed object. If that |
| 44 |
* function returns an exception object that is used instead. |
| 45 |
*/ |
| 46 |
void rb_exc_raise(VALUE exc); |
| 47 |
|
| 48 |
RBIMPL_ATTR_NORETURN() |
| 49 |
/** |
| 50 |
* Identical to rb_fatal(), except it raises the passed exception instance as- |
| 51 |
* is instead of creating new one. |
| 52 |
* |
| 53 |
* @param[in] exc An instance of a subclass of ::rb_eException. |
| 54 |
* @exception exc What is passed. |
| 55 |
* @note It never returns. |
| 56 |
* |
| 57 |
* @internal |
| 58 |
* |
| 59 |
* You know what...? Using this API you can make arbitrary exceptions, like |
| 60 |
* `RuntimeError`, that doesn't interface with `rescue` clause. This is very |
| 61 |
* confusing. |
| 62 |
*/ |
| 63 |
void rb_exc_fatal(VALUE exc); |
| 64 |
|
| 65 |
/* process.c */ |
| 66 |
|
| 67 |
RBIMPL_ATTR_NORETURN() |
| 68 |
/** |
| 69 |
* Identical to rb_exit(), except how arguments are passed. |
| 70 |
* |
| 71 |
* @param[in] argc Number of objects of `argv`. |
| 72 |
* @param[in] argv Contains at most one of the following: |
| 73 |
* - ::RUBY_Qtrue - means `EXIT_SUCCESS`. |
| 74 |
* - ::RUBY_Qfalse - means `EXIT_FAILURE`. |
| 75 |
* - Numerical value - takes that value. |
| 76 |
* @exception rb_eArgError Wrong `argc`. |
| 77 |
* @exception rb_eSystemExit Exception representing the exit status. |
| 78 |
* @note It never returns. |
| 79 |
*/ |
| 80 |
VALUE rb_f_exit(int argc, const VALUE *argv); |
| 81 |
|
| 82 |
RBIMPL_ATTR_NORETURN() |
| 83 |
/** |
| 84 |
* This is similar to rb_f_exit(). In fact on some situation it internally |
| 85 |
* calls rb_exit(). But can be very esoteric on occasions. |
| 86 |
* |
| 87 |
* It takes up to one argument. If an argument is passed, it tries to display |
| 88 |
* that. Otherwise if there is `$!`, displays that exception instead. It |
| 89 |
* finally raise ::rb_eSystemExit in both cases. |
| 90 |
* |
| 91 |
* @param[in] argc Number of objects of `argv`. |
| 92 |
* @param[in] argv Contains at most one string-ish object. |
| 93 |
* @exception rb_eArgError Wrong `argc`. |
| 94 |
* @exception rb_eTypeError No conversion from `argv[0]` to String. |
| 95 |
* @exception rb_eSystemExit Exception representing `EXIT_FAILURE`. |
| 96 |
* @note It never returns. |
| 97 |
*/ |
| 98 |
VALUE rb_f_abort(int argc, const VALUE *argv); |
| 99 |
|
| 100 |
/* eval.c*/ |
| 101 |
|
| 102 |
RBIMPL_ATTR_NORETURN() |
| 103 |
/** |
| 104 |
* Raises an instance of ::rb_eInterrupt. |
| 105 |
* |
| 106 |
* @exception rb_eInterrupt Always raises this exception. |
| 107 |
* @note It never returns. |
| 108 |
*/ |
| 109 |
void rb_interrupt(void); |
| 110 |
|
| 111 |
/** |
| 112 |
* Queries the name of the Ruby level method that is calling this function. |
| 113 |
* The "name" in this context is the one assigned to the function for the first |
| 114 |
* time (note that methods can have multiple names via aliases). |
| 115 |
* |
| 116 |
* @retval 0 There is no method (e.g. toplevel context). |
| 117 |
* @retval otherwise The name of the current method. |
| 118 |
*/ |
| 119 |
ID rb_frame_this_func(void); |
| 120 |
|
| 121 |
RBIMPL_ATTR_NORETURN() |
| 122 |
/** |
| 123 |
* This function is to re-throw global escapes. Such global escapes include |
| 124 |
* exceptions, `throw`, `break`, for example. |
| 125 |
* |
| 126 |
* It makes sense only when used in conjunction with "protect" series APIs |
| 127 |
* e.g. rb_protect(), rb_load_protect(), rb_eval_string_protect(), etc. In |
| 128 |
* case these functions experience global escapes, they fill their opaque |
| 129 |
* `state` return buffer. You can ignore such escapes. But if you decide |
| 130 |
* otherwise, you have to somehow escape globally again. This function is used |
| 131 |
* for that purpose. |
| 132 |
* |
| 133 |
* @param[in] state Opaque state of execution. |
| 134 |
* @note It never returns. |
| 135 |
* |
| 136 |
* @internal |
| 137 |
* |
| 138 |
* Though not a part of our public API, `state` is in fact an enum |
| 139 |
* ruby_tag_type. You can see the potential values by looking at vm_core.h. |
| 140 |
*/ |
| 141 |
void rb_jump_tag(int state); |
| 142 |
|
| 143 |
/** |
| 144 |
* Calls `initialize` method of the passed object with the passed arguments. |
| 145 |
* It also forwards the implicitly passed block to the method. |
| 146 |
* |
| 147 |
* @param[in] obj Receiver object. |
| 148 |
* @param[in] argc Number of objects of `argv`. |
| 149 |
* @param[in] argv Passed as-is to `obj.initialize`. |
| 150 |
* @exception rb_eException Any exceptions happen inside. |
| 151 |
*/ |
| 152 |
void rb_obj_call_init(VALUE obj, int argc, const VALUE *argv); |
| 153 |
|
| 154 |
/** |
| 155 |
* Identical to rb_obj_call_init(), except you can specify how to handle the |
| 156 |
* last element of the given array. |
| 157 |
* |
| 158 |
* @param[in] obj Receiver object. |
| 159 |
* @param[in] argc Number of objects of `argv`. |
| 160 |
* @param[in] argv Passed as-is to `obj.initialize`. |
| 161 |
* @param[in] kw_splat Handling of keyword parameters: |
| 162 |
* - RB_NO_KEYWORDS `argv`'s last is not a keyword argument. |
| 163 |
* - RB_PASS_KEYWORDS `argv`'s last is a keyword argument. |
| 164 |
* - RB_PASS_CALLED_KEYWORDS it depends if there is a passed block. |
| 165 |
* @exception rb_eNoMethodError No such method. |
| 166 |
* @exception rb_eException Any exceptions happen inside. |
| 167 |
*/ |
| 168 |
void rb_obj_call_init_kw(VALUE, int, const VALUE*, int); |
| 169 |
|
| 170 |
/** |
| 171 |
* Identical to rb_frame_this_func(), except it returns the named used to call |
| 172 |
* the method. |
| 173 |
* |
| 174 |
* @retval 0 There is no method (e.g. toplevel context). |
| 175 |
* @retval otherwise The name of the current method. |
| 176 |
*/ |
| 177 |
ID rb_frame_callee(void); |
| 178 |
|
| 179 |
/** |
| 180 |
* Constructs an exception object from the list of arguments, in a manner |
| 181 |
* similar to Ruby's `raise`. This function can take: |
| 182 |
* |
| 183 |
* - No arguments at all, i.e. `argc == 0`. This is not a failure. It |
| 184 |
* returns ::RUBY_Qnil then. |
| 185 |
* |
| 186 |
* - An object, which is an instance of ::rb_cString. In this case an |
| 187 |
* instance of ::rb_eRuntimeError whose message is the passed string is |
| 188 |
* created then returned. |
| 189 |
* |
| 190 |
* - An object, which responds to `exception` method, and optionally its |
| 191 |
* argument, and optionally its backtrace. For example instances of |
| 192 |
* subclasses of ::rb_eException have this method. What is returned from |
| 193 |
* the method is returned. |
| 194 |
* |
| 195 |
* @param[in] argc Number of objects of `argv`. |
| 196 |
* @param[in] argv 0 up to 3 objects. |
| 197 |
* @exception rb_eArgError Wrong `argc`. |
| 198 |
* @exception rb_eTypeError `argv[0].exception` returned non-exception. |
| 199 |
* @return An instance of a subclass of ::rb_eException. |
| 200 |
* |
| 201 |
* @internal |
| 202 |
* |
| 203 |
* Historically this was _the_ way `raise` converted its arguments to an |
| 204 |
* exception. However they diverged. |
| 205 |
*/ |
| 206 |
VALUE rb_make_exception(int argc, const VALUE *argv); |
| 207 |
|
| 208 |
/* eval_jump.c */ |
| 209 |
|
| 210 |
/** |
| 211 |
* Registers a function that shall run on process exit. Registered functions |
| 212 |
* run in reverse-chronological order, mixed with syntactic `END` block and |
| 213 |
* `Kernel#at_exit`. |
| 214 |
* |
| 215 |
* @param[in] func Function to run at process exit. |
| 216 |
* @param[in] arg Passed as-is to `func`. |
| 217 |
*/ |
| 218 |
void rb_set_end_proc(void (*func)(VALUE arg), VALUE arg); |
| 219 |
|
| 220 |
RBIMPL_SYMBOL_EXPORT_END() |
| 221 |
|
| 222 |
#endif /* RBIMPL_INTERN_EVAL_H */ |