Ignore:
Timestamp:
Jul 9, 2020, 8:51:43 AM (4 years ago)
Author:
coas-nagasima
Message:

mrubyを2.1.1に更新

Location:
EcnlProtoTool/trunk/mruby-2.1.1
Files:
1 edited
1 moved

Legend:

Unmodified
Added
Removed
  • EcnlProtoTool/trunk/mruby-2.1.1/include/mruby/array.h

    r331 r439  
    1 /*
    2 ** mruby/array.h - Array class
     1/**
     2** @file mruby/array.h - Array class
    33**
    44** See Copyright Notice in mruby.h
     
    1818typedef struct mrb_shared_array {
    1919  int refcnt;
    20   mrb_int len;
     20  mrb_ssize len;
    2121  mrb_value *ptr;
    2222} mrb_shared_array;
    2323
     24#define MRB_ARY_EMBED_LEN_MAX ((mrb_int)(sizeof(void*)*3/sizeof(mrb_value)))
    2425struct RArray {
    2526  MRB_OBJECT_HEADER;
    26   mrb_int len;
    2727  union {
    28     mrb_int capa;
    29     mrb_shared_array *shared;
    30   } aux;
    31   mrb_value *ptr;
     28    struct {
     29      mrb_ssize len;
     30      union {
     31        mrb_ssize capa;
     32        mrb_shared_array *shared;
     33      } aux;
     34      mrb_value *ptr;
     35    } heap;
     36    void *ary[3];
     37  } as;
    3238};
    3339
     
    3642#define RARRAY(v)  ((struct RArray*)(mrb_ptr(v)))
    3743
    38 #define RARRAY_LEN(a) (RARRAY(a)->len)
    39 #define RARRAY_PTR(a) ((const mrb_value*)RARRAY(a)->ptr)
     44#define MRB_ARY_EMBED_MASK  7
     45#define ARY_EMBED_P(a) ((a)->flags & MRB_ARY_EMBED_MASK)
     46#define ARY_UNSET_EMBED_FLAG(a) ((a)->flags &= ~(MRB_ARY_EMBED_MASK))
     47#define ARY_EMBED_LEN(a) ((mrb_int)(((a)->flags & MRB_ARY_EMBED_MASK) - 1))
     48#define ARY_SET_EMBED_LEN(a,len) ((a)->flags = ((a)->flags&~MRB_ARY_EMBED_MASK) | ((uint32_t)(len) + 1))
     49#define ARY_EMBED_PTR(a) ((mrb_value*)(&(a)->as.ary))
     50
     51#define ARY_LEN(a) (ARY_EMBED_P(a)?ARY_EMBED_LEN(a):(a)->as.heap.len)
     52#define ARY_PTR(a) (ARY_EMBED_P(a)?ARY_EMBED_PTR(a):(a)->as.heap.ptr)
     53#define RARRAY_LEN(a) ARY_LEN(RARRAY(a))
     54#define RARRAY_PTR(a) ARY_PTR(RARRAY(a))
     55#define ARY_SET_LEN(a,n) do {\
     56  if (ARY_EMBED_P(a)) {\
     57    mrb_assert((n) <= MRB_ARY_EMBED_LEN_MAX); \
     58    ARY_SET_EMBED_LEN(a,n);\
     59  }\
     60  else\
     61    (a)->as.heap.len = (n);\
     62} while (0)
     63#define ARY_CAPA(a) (ARY_EMBED_P(a)?MRB_ARY_EMBED_LEN_MAX:(a)->as.heap.aux.capa)
    4064#define MRB_ARY_SHARED      256
    4165#define ARY_SHARED_P(a) ((a)->flags & MRB_ARY_SHARED)
     
    176200 */
    177201MRB_API void mrb_ary_replace(mrb_state *mrb, mrb_value self, mrb_value other);
     202MRB_API mrb_value mrb_ensure_array_type(mrb_state *mrb, mrb_value self);
    178203MRB_API mrb_value mrb_check_array_type(mrb_state *mrb, mrb_value self);
    179204
    180205/*
    181  * Unshift an element into an array
     206 * Unshift an element into the array
    182207 *
    183208 * Equivalent to:
     
    190215 */
    191216MRB_API mrb_value mrb_ary_unshift(mrb_state *mrb, mrb_value self, mrb_value item);
     217
     218/*
     219 * Get nth element in the array
     220 *
     221 * Equivalent to:
     222 *
     223 *     ary[offset]
     224 *
     225 * @param ary The target array.
     226 * @param offset The element position (negative counts from the tail).
     227 */
    192228MRB_API mrb_value mrb_ary_entry(mrb_value ary, mrb_int offset);
     229
     230/*
     231 * Replace subsequence of an array.
     232 *
     233 * Equivalent to:
     234 *
     235 *      ary.shift
     236 *
     237 * @param mrb The mruby state reference.
     238 * @param self The array from which the value will be shifted.
     239 * @param head Beginning position of a replacement subsequence.
     240 * @param len Length of a replacement subsequence.
     241 * @param rpl The array of replacement elements.
     242 * @return The receiver array.
     243 */
     244MRB_API mrb_value mrb_ary_splice(mrb_state *mrb, mrb_value self, mrb_int head, mrb_int len, mrb_value rpl);
    193245
    194246/*
     
    206258
    207259/*
    208  * Removes all elements from this array
     260 * Removes all elements from the array
    209261 *
    210262 * Equivalent to:
     
    240292MRB_API mrb_value mrb_ary_resize(mrb_state *mrb, mrb_value ary, mrb_int new_len);
    241293
    242 static inline mrb_int
    243 mrb_ary_len(mrb_state *mrb, mrb_value ary)
    244 {
    245   (void)mrb;
    246   mrb_assert(mrb_array_p(ary));
    247   return RARRAY_LEN(ary);
    248 }
    249 
    250 static inline mrb_value
    251 ary_elt(mrb_value ary, mrb_int offset)
    252 {
    253   if (offset < 0 || RARRAY_LEN(ary) <= offset) {
    254     return mrb_nil_value();
    255   }
    256   return RARRAY_PTR(ary)[offset];
    257 }
    258 
    259294MRB_END_DECL
    260295
Note: See TracChangeset for help on using the changeset viewer.