summaryrefslogtreecommitdiff
path: root/include/ruby/internal/intern/eval.h
blob: 2230f7ab0c1f6899e799a91cfa9507508a5110be (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
#ifndef  RBIMPL_INTERN_EVAL_H                        /*-*-C++-*-vi:se ft=cpp:*/
#define  RBIMPL_INTERN_EVAL_H
/**
 * @file
 * @author     Ruby developers <ruby-core@ruby-lang.org>
 * @copyright  This  file  is   a  part  of  the   programming  language  Ruby.
 *             Permission  is hereby  granted,  to  either redistribute  and/or
 *             modify this file, provided that  the conditions mentioned in the
 *             file COPYING are met.  Consult the file for details.
 * @warning    Symbols   prefixed  with   either  `RBIMPL`   or  `rbimpl`   are
 *             implementation details.   Don't take  them as canon.  They could
 *             rapidly appear then vanish.  The name (path) of this header file
 *             is also an  implementation detail.  Do not expect  it to persist
 *             at the place it is now.  Developers are free to move it anywhere
 *             anytime at will.
 * @note       To  ruby-core:  remember  that   this  header  can  be  possibly
 *             recursively included  from extension  libraries written  in C++.
 *             Do not  expect for  instance `__VA_ARGS__` is  always available.
 *             We assume C99  for ruby itself but we don't  assume languages of
 *             extension libraries.  They could be written in C++98.
 * @brief      Pre-1.9 era evaluator APIs (now considered miscellaneous).
 */
#include "ruby/internal/attr/noreturn.h"
#include "ruby/internal/dllexport.h"
#include "ruby/internal/value.h"

RBIMPL_SYMBOL_EXPORT_BEGIN()

/* eval.c */
RBIMPL_ATTR_NORETURN()
/**
 * Identical to rb_raise(), except it  raises the passed exception instance as-
 * is instead of creating new one.
 *
 * @param[in]  exc            An instance of a subclass of ::rb_eException.
 * @exception  exc            What is passed.
 * @exception  rb_eTypeError  `exc` is not an exception.
 * @note       It never returns.
 *
 * @internal
 *
 * Wellll  actually, it  can  take more  than what  is  described above.   This
 * function tries  to call `exception`  method of  the passed object.   If that
 * function returns an exception object that is used instead.
 */
void rb_exc_raise(VALUE exc);

RBIMPL_ATTR_NORETURN()
/**
 * Identical to rb_fatal(), except it  raises the passed exception instance as-
 * is instead of creating new one.
 *
 * @param[in]  exc  An instance of a subclass of ::rb_eException.
 * @exception  exc  What is passed.
 * @note       It never returns.
 *
 * @internal
 *
 * You know  what...?  Using this API  you can make arbitrary  exceptions, like
 * `RuntimeError`, that doesn't  interface with `rescue` clause.   This is very
 * confusing.
 */
void rb_exc_fatal(VALUE exc);

/* process.c */

RBIMPL_ATTR_NORETURN()
/**
 * Identical to rb_exit(), except how arguments are passed.
 *
 * @param[in]  argc            Number of objects of `argv`.
 * @param[in]  argv            Contains at most one of the following:
 *                               - ::RUBY_Qtrue - means `EXIT_SUCCESS`.
 *                               - ::RUBY_Qfalse - means `EXIT_FAILURE`.
 *                               - Numerical value - takes that value.
 * @exception  rb_eArgError    Wrong `argc`.
 * @exception  rb_eSystemExit  Exception representing the exit status.
 * @note       It never returns.
 */
VALUE rb_f_exit(int argc, const VALUE *argv);

RBIMPL_ATTR_NORETURN()
/**
 * This is  similar to rb_f_exit().   In fact  on some situation  it internally
 * calls rb_exit().  But can be very esoteric on occasions.
 *
 * It takes up to one argument.  If  an argument is passed, it tries to display
 * that.   Otherwise if  there is  `$!`, displays  that exception  instead.  It
 * finally raise ::rb_eSystemExit in both cases.
 *
 * @param[in]  argc            Number of objects of `argv`.
 * @param[in]  argv            Contains at most one string-ish object.
 * @exception  rb_eArgError    Wrong `argc`.
 * @exception  rb_eTypeError   No conversion from `argv[0]` to String.
 * @exception  rb_eSystemExit  Exception representing `EXIT_FAILURE`.
 * @note       It never returns.
 */
VALUE rb_f_abort(int argc, const VALUE *argv);

/* eval.c*/

RBIMPL_ATTR_NORETURN()
/**
 * Raises an instance of ::rb_eInterrupt.
 *
 * @exception  rb_eInterrupt  Always raises this exception.
 * @note       It never returns.
 */
void rb_interrupt(void);

/**
 * Queries the  name of the  Ruby level method  that is calling  this function.
 * The "name" in this context is the one assigned to the function for the first
 * time (note that methods can have multiple names via aliases).
 *
 * @retval  0          There is no method (e.g. toplevel context).
 * @retval  otherwise  The name of the current method.
 */
ID rb_frame_this_func(void);

RBIMPL_ATTR_NORETURN()
/**
 * This function  is to re-throw  global escapes.  Such global  escapes include
 * exceptions, `throw`, `break`, for example.
 *
 * It makes  sense only  when used  in conjunction  with "protect"  series APIs
 * e.g.  rb_protect(),  rb_load_protect(), rb_eval_string_protect(),  etc.   In
 * case  these functions  experience  global escapes,  they  fill their  opaque
 * `state` return  buffer.  You  can ignore  such escapes.   But if  you decide
 * otherwise, you have to somehow escape globally again.  This function is used
 * for that purpose.
 *
 * @param[in]  state  Opaque state of execution.
 * @note       It never returns.
 *
 * @internal
 *
 * Though  not  a  part  of  our  public  API,  `state`  is  in  fact  an  enum
 * ruby_tag_type.  You can see the potential values by looking at vm_core.h.
 */
void rb_jump_tag(int state);

/**
 * Calls `initialize`  method of the  passed object with the  passed arguments.
 * It also forwards the implicitly passed block to the method.
 *
 * @param[in]  obj            Receiver object.
 * @param[in]  argc           Number of objects of `argv`.
 * @param[in]  argv           Passed as-is to `obj.initialize`.
 * @exception  rb_eException  Any exceptions happen inside.
 */
void rb_obj_call_init(VALUE obj, int argc, const VALUE *argv);

/**
 * Identical to  rb_obj_call_init(), except you  can specify how to  handle the
 * last element of the given array.
 *
 * @param[in]  obj                Receiver object.
 * @param[in]  argc               Number of objects of `argv`.
 * @param[in]  argv               Passed as-is to `obj.initialize`.
 * @param[in]  kw_splat           Handling of keyword parameters:
 *   - RB_NO_KEYWORDS             `argv`'s last is not a keyword argument.
 *   - RB_PASS_KEYWORDS           `argv`'s last is a keyword argument.
 *   - RB_PASS_CALLED_KEYWORDS    it depends if there is a passed block.
 * @exception  rb_eNoMethodError  No such method.
 * @exception  rb_eException      Any exceptions happen inside.
 */
void rb_obj_call_init_kw(VALUE, int, const VALUE*, int);

/**
 * Identical to rb_frame_this_func(), except it  returns the named used to call
 * the method.
 *
 * @retval  0          There is no method (e.g. toplevel context).
 * @retval  otherwise  The name of the current method.
 */
ID rb_frame_callee(void);

/**
 * Constructs  an exception  object from  the list  of arguments,  in a  manner
 * similar to Ruby's `raise`.  This function can take:
 *
 *   - No arguments  at all,  i.e. `argc  == 0`.   This is  not a  failure.  It
 *     returns ::RUBY_Qnil then.
 *
 *   - An  object, which  is  an instance  of ::rb_cString.   In  this case  an
 *     instance of  ::rb_eRuntimeError whose  message is  the passed  string is
 *     created then returned.
 *
 *   - An  object, which  responds to  `exception` method,  and optionally  its
 *     argument,  and  optionally  its  backtrace.  For  example  instances  of
 *     subclasses of ::rb_eException  have this method.  What  is returned from
 *     the method is returned.
 *
 * @param[in]  argc           Number of objects of `argv`.
 * @param[in]  argv           0 up to 3 objects.
 * @exception  rb_eArgError   Wrong `argc`.
 * @exception  rb_eTypeError  `argv[0].exception` returned non-exception.
 * @return     An instance of a subclass of ::rb_eException.
 *
 * @internal
 *
 * Historically  this was  _the_  way  `raise` converted  its  arguments to  an
 * exception.  However they diverged.
 */
VALUE rb_make_exception(int argc, const VALUE *argv);

/* eval_jump.c */

/**
 * Registers a function  that shall run on process  exit.  Registered functions
 * run in  reverse-chronological order,  mixed with  syntactic `END`  block and
 * `Kernel#at_exit`.
 *
 * @param[in]  func  Function to run at process exit.
 * @param[in]  arg   Passed as-is to `func`.
 */
void rb_set_end_proc(void (*func)(VALUE arg), VALUE arg);

RBIMPL_SYMBOL_EXPORT_END()

#endif /* RBIMPL_INTERN_EVAL_H */