2009-07-15 20:37:25 -04:00
|
|
|
/**********************************************************************
|
|
|
|
|
|
|
|
method.h -
|
|
|
|
|
|
|
|
$Author$
|
|
|
|
created at: Wed Jul 15 20:02:33 2009
|
|
|
|
|
|
|
|
Copyright (C) 2009 Koichi Sasada
|
|
|
|
|
|
|
|
**********************************************************************/
|
|
|
|
#ifndef METHOD_H
|
|
|
|
#define METHOD_H
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
NOEX_PUBLIC = 0x00,
|
|
|
|
NOEX_NOSUPER = 0x01,
|
|
|
|
NOEX_PRIVATE = 0x02,
|
|
|
|
NOEX_PROTECTED = 0x04,
|
|
|
|
NOEX_MASK = 0x06,
|
|
|
|
NOEX_BASIC = 0x08,
|
|
|
|
NOEX_UNDEF = NOEX_NOSUPER,
|
|
|
|
NOEX_MODFUNC = 0x12,
|
|
|
|
NOEX_SUPER = 0x20,
|
2009-10-04 13:05:59 -04:00
|
|
|
NOEX_VCALL = 0x40,
|
|
|
|
NOEX_RESPONDS = 0x80
|
2009-07-15 20:37:25 -04:00
|
|
|
} rb_method_flag_t;
|
|
|
|
|
|
|
|
#define NOEX_SAFE(n) ((int)((n) >> 8) & 0x0F)
|
2011-01-19 16:03:36 -05:00
|
|
|
#define NOEX_WITH(n, s) (((s) << 8) | (n) | (ruby_running ? 0 : NOEX_BASIC))
|
|
|
|
#define NOEX_WITH_SAFE(n) NOEX_WITH((n), rb_safe_level())
|
2009-07-15 20:37:25 -04:00
|
|
|
|
|
|
|
/* method data type */
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
VM_METHOD_TYPE_ISEQ,
|
|
|
|
VM_METHOD_TYPE_CFUNC,
|
|
|
|
VM_METHOD_TYPE_ATTRSET,
|
|
|
|
VM_METHOD_TYPE_IVAR,
|
|
|
|
VM_METHOD_TYPE_BMETHOD,
|
|
|
|
VM_METHOD_TYPE_ZSUPER,
|
|
|
|
VM_METHOD_TYPE_UNDEF,
|
|
|
|
VM_METHOD_TYPE_NOTIMPLEMENTED,
|
2009-09-27 23:09:16 -04:00
|
|
|
VM_METHOD_TYPE_OPTIMIZED, /* Kernel#send, Proc#call, etc */
|
2012-10-15 17:24:08 -04:00
|
|
|
VM_METHOD_TYPE_MISSING, /* wrapper for method_missing(id) */
|
2012-10-18 01:22:13 -04:00
|
|
|
VM_METHOD_TYPE_CFUNC_FRAMELESS
|
2009-07-15 20:37:25 -04:00
|
|
|
} rb_method_type_t;
|
|
|
|
|
2012-10-19 06:38:30 -04:00
|
|
|
struct rb_call_info_struct;
|
|
|
|
|
2009-07-15 20:37:25 -04:00
|
|
|
typedef struct rb_method_cfunc_struct {
|
|
|
|
VALUE (*func)(ANYARGS);
|
* vm_core.h, vm_insnhelper.c, vm_eval.c (OPT_CALL_CFUNC_WITHOUT_FRAME):
add a new otpimization and its macro `OPT_CALL_CFUNC_WITHOUT_FRAME'.
This optimization makes all cfunc method calls `frameless', which
is fster than ordinal cfunc method call.
If `frame' is needed (for example, it calls another method with
`rb_funcall()'), then build a frame. In other words, this
optimization delays frame building.
However, to delay the frame building, we need additional overheads:
(1) Store the last call information.
(2) Check the delayed frame buidling before the frame is needed.
(3) Overhead to build a delayed frame.
rb_thread_t::passed_ci is storage of delayed cfunc call information.
(1) is lightweight because it is only 1 assignment to `passed_ci'.
To achieve (2), we modify GET_THREAD() to check `passed_ci' every
time. It causes 10% overhead on my envrionment.
This optimization only works for cfunc methods which do not need
their `frame'.
After evaluation on my environment, this optimization does not
effective every time. Because of this evaluation results, this
optimization is disabled at default.
* vm_insnhelper.c, vm.c: add VM_PROFILE* macros to measure behaviour
of VM internals. I will extend this feature.
* vm_method.c, method.h: change parameters of the `invoker' function.
Receive `func' pointer as the first parameter.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37293 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-23 00:22:31 -04:00
|
|
|
VALUE (*invoker)(VALUE (*func)(ANYARGS), const struct rb_call_info_struct *ci, const VALUE *argv);
|
2009-07-15 20:37:25 -04:00
|
|
|
int argc;
|
|
|
|
} rb_method_cfunc_t;
|
|
|
|
|
2010-03-22 07:44:01 -04:00
|
|
|
typedef struct rb_method_attr_struct {
|
|
|
|
ID id;
|
|
|
|
VALUE location;
|
|
|
|
} rb_method_attr_t;
|
|
|
|
|
2009-07-15 20:37:25 -04:00
|
|
|
typedef struct rb_iseq_struct rb_iseq_t;
|
|
|
|
|
2009-08-27 22:45:41 -04:00
|
|
|
typedef struct rb_method_definition_struct {
|
2009-07-15 20:37:25 -04:00
|
|
|
rb_method_type_t type; /* method type */
|
|
|
|
ID original_id;
|
|
|
|
union {
|
|
|
|
rb_iseq_t *iseq; /* should be mark */
|
|
|
|
rb_method_cfunc_t cfunc;
|
2010-03-22 07:44:01 -04:00
|
|
|
rb_method_attr_t attr;
|
2009-08-26 02:26:08 -04:00
|
|
|
VALUE proc; /* should be mark */
|
2009-07-15 20:37:25 -04:00
|
|
|
enum method_optimized_type {
|
|
|
|
OPTIMIZED_METHOD_TYPE_SEND,
|
2012-10-16 11:32:19 -04:00
|
|
|
OPTIMIZED_METHOD_TYPE_CALL
|
2009-07-15 20:37:25 -04:00
|
|
|
} optimize_type;
|
|
|
|
} body;
|
|
|
|
int alias_count;
|
2009-08-27 22:45:41 -04:00
|
|
|
} rb_method_definition_t;
|
|
|
|
|
|
|
|
typedef struct rb_method_entry_struct {
|
|
|
|
rb_method_flag_t flag;
|
2010-05-05 13:51:21 -04:00
|
|
|
char mark;
|
2009-08-27 22:45:41 -04:00
|
|
|
rb_method_definition_t *def;
|
|
|
|
ID called_id;
|
|
|
|
VALUE klass; /* should be mark */
|
2009-07-15 20:37:25 -04:00
|
|
|
} rb_method_entry_t;
|
|
|
|
|
2010-05-05 13:51:21 -04:00
|
|
|
struct unlinked_method_entry_list_entry {
|
|
|
|
struct unlinked_method_entry_list_entry *next;
|
|
|
|
rb_method_entry_t *me;
|
|
|
|
};
|
|
|
|
|
2009-08-27 22:45:41 -04:00
|
|
|
#define UNDEFINED_METHOD_ENTRY_P(me) (!(me) || !(me)->def || (me)->def->type == VM_METHOD_TYPE_UNDEF)
|
|
|
|
|
2009-07-15 20:37:25 -04:00
|
|
|
void rb_add_method_cfunc(VALUE klass, ID mid, VALUE (*func)(ANYARGS), int argc, rb_method_flag_t noex);
|
|
|
|
rb_method_entry_t *rb_add_method(VALUE klass, ID mid, rb_method_type_t type, void *option, rb_method_flag_t noex);
|
2012-08-02 07:08:44 -04:00
|
|
|
rb_method_entry_t *rb_method_entry(VALUE klass, ID id, VALUE *define_class_ptr);
|
2010-05-04 16:25:09 -04:00
|
|
|
|
2012-10-08 10:02:46 -04:00
|
|
|
rb_method_entry_t *rb_method_entry_get_with_refinements(VALUE refinements, VALUE klass, ID id, VALUE *define_class_ptr);
|
|
|
|
rb_method_entry_t *rb_method_entry_get_without_cache(VALUE klass, VALUE refinements, ID id, VALUE *define_class_ptr);
|
2010-05-04 16:25:09 -04:00
|
|
|
rb_method_entry_t *rb_method_entry_set(VALUE klass, ID mid, const rb_method_entry_t *, rb_method_flag_t noex);
|
|
|
|
|
2009-07-15 20:37:25 -04:00
|
|
|
int rb_method_entry_arity(const rb_method_entry_t *me);
|
* method.h, internal.h iseq.h: declare internal functions.
* compile.c, eval.c, iseq.c, object.c, parse.y, proc.c, process.c,
thread.c, vm.c, vm_eval.c, vm_insnhelper.c, vm_method.c: don't
declare internal functions.
Note that rb_method_entry_eq() is defined in vm_method.c but
there was a declaration in proc.c with different const-ness.
Now it is declared in method.h with same const-ness to the
definition.
* object.c (rb_mod_module_exec): don't declare functions declared in
include/ruby/intern.h.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32163 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-06-17 23:49:33 -04:00
|
|
|
int rb_method_entry_eq(const rb_method_entry_t *m1, const rb_method_entry_t *m2);
|
2012-02-20 19:13:44 -05:00
|
|
|
st_index_t rb_hash_method_entry(st_index_t hash, const rb_method_entry_t *me);
|
2010-05-04 16:25:09 -04:00
|
|
|
|
2010-05-04 18:27:18 -04:00
|
|
|
void rb_mark_method_entry(const rb_method_entry_t *me);
|
2009-08-27 22:45:41 -04:00
|
|
|
void rb_free_method_entry(rb_method_entry_t *me);
|
2010-05-05 13:51:21 -04:00
|
|
|
void rb_sweep_method_entry(void *vm);
|
2010-10-26 13:27:32 -04:00
|
|
|
void rb_free_m_table(st_table *tbl);
|
2009-07-15 20:37:25 -04:00
|
|
|
|
|
|
|
#endif /* METHOD_H */
|