Ruby 1.9.2p136(2010-12-25revision30365)

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

# method.h

Go to the documentation of this file.

    00001 /**********************************************************************
    00002
    00003   method.h -
    00004
    00005   $Author: ko1 $
    00006   created at: Wed Jul 15 20:02:33 2009
    00007
    00008   Copyright (C) 2009 Koichi Sasada
    00009
    00010 **********************************************************************/
    00011 #ifndef METHOD_H
    00012 #define METHOD_H
    00013
    00014 typedef enum {
    00015     NOEX_PUBLIC    = 0x00,
    00016     NOEX_NOSUPER   = 0x01,
    00017     NOEX_PRIVATE   = 0x02,
    00018     NOEX_PROTECTED = 0x04,
    00019     NOEX_MASK      = 0x06,
    00020     NOEX_BASIC     = 0x08,
    00021     NOEX_UNDEF     = NOEX_NOSUPER,
    00022     NOEX_MODFUNC   = 0x12,
    00023     NOEX_SUPER     = 0x20,
    00024     NOEX_VCALL     = 0x40,
    00025     NOEX_RESPONDS  = 0x80
    00026 } rb_method_flag_t;
    00027
    00028 #define NOEX_SAFE(n) ((int)((n) >> 8) & 0x0F)
    00029 #define NOEX_WITH(n, s) ((s << 8) | (n) | (ruby_running ? 0 : NOEX_BASIC))
    00030 #define NOEX_WITH_SAFE(n) NOEX_WITH(n, rb_safe_level())
    00031
    00032 /* method data type */
    00033
    00034 typedef enum {
    00035     VM_METHOD_TYPE_ISEQ,
    00036     VM_METHOD_TYPE_CFUNC,
    00037     VM_METHOD_TYPE_ATTRSET,
    00038     VM_METHOD_TYPE_IVAR,
    00039     VM_METHOD_TYPE_BMETHOD,
    00040     VM_METHOD_TYPE_ZSUPER,
    00041     VM_METHOD_TYPE_UNDEF,
    00042     VM_METHOD_TYPE_NOTIMPLEMENTED,
    00043     VM_METHOD_TYPE_OPTIMIZED, /* Kernel#send, Proc#call, etc */
    00044     VM_METHOD_TYPE_MISSING   /* wrapper for method_missing(id) */
    00045 } rb_method_type_t;
    00046
    00047 typedef struct rb_method_cfunc_struct {
    00048     VALUE (*func)(ANYARGS);
    00049     int argc;
    00050 } rb_method_cfunc_t;
    00051
    00052 typedef struct rb_method_attr_struct {
    00053     ID id;
    00054     VALUE location;
    00055 } rb_method_attr_t;
    00056
    00057 typedef struct rb_iseq_struct rb_iseq_t;
    00058
    00059 typedef struct rb_method_definition_struct {
    00060     rb_method_type_t type; /* method type */
    00061     ID original_id;
    00062     union {
    00063         rb_iseq_t *iseq;            /* should be mark */
    00064         rb_method_cfunc_t cfunc;
    00065         rb_method_attr_t attr;
    00066         VALUE proc;                 /* should be mark */
    00067         enum method_optimized_type {
    00068             OPTIMIZED_METHOD_TYPE_SEND,
    00069             OPTIMIZED_METHOD_TYPE_CALL
    00070         } optimize_type;
    00071     } body;
    00072     int alias_count;
    00073 } rb_method_definition_t;
    00074
    00075 typedef struct rb_method_entry_struct {
    00076     rb_method_flag_t flag;
    00077     char mark;
    00078     rb_method_definition_t *def;
    00079     ID called_id;
    00080     VALUE klass;                    /* should be mark */
    00081 } rb_method_entry_t;
    00082
    00083 struct unlinked_method_entry_list_entry {
    00084     struct unlinked_method_entry_list_entry *next;
    00085     rb_method_entry_t *me;
    00086 };
    00087
    00088 #define UNDEFINED_METHOD_ENTRY_P(me) (!(me) || !(me)->def || (me)->def->type == VM_METHOD_TYPE_UNDEF)
    00089
    00090 void rb_add_method_cfunc(VALUE klass, ID mid, VALUE (*func)(ANYARGS), int argc, rb_method_flag_t noex);
    00091 rb_method_entry_t *rb_add_method(VALUE klass, ID mid, rb_method_type_t type, void *option, rb_method_flag_t noex);
    00092 rb_method_entry_t *rb_method_entry(VALUE klass, ID id);
    00093
    00094 rb_method_entry_t *rb_method_entry_get_without_cache(VALUE klass, ID id);
    00095 rb_method_entry_t *rb_method_entry_set(VALUE klass, ID mid, const rb_method_entry_t *, rb_method_flag_t noex);
    00096
    00097 int rb_method_entry_arity(const rb_method_entry_t *me);
    00098
    00099 void rb_mark_method_entry(const rb_method_entry_t *me);
    00100 void rb_free_method_entry(rb_method_entry_t *me);
    00101 void rb_sweep_method_entry(void *vm);
    00102
    00103 #endif /* METHOD_H */
    00104