Ignore:
Timestamp:
Jan 21, 2018, 12:10:09 AM (6 years ago)
Author:
coas-nagasima
Message:

prototoolに関連するプロジェクトをnewlibからmuslを使うよう変更・更新
ntshellをnewlibの下位の実装から、muslのsyscallの実装に変更・更新
以下のOSSをアップデート
・mruby-1.3.0
・musl-1.1.18
・onigmo-6.1.3
・tcc-0.9.27
以下のOSSを追加
・openssl-1.1.0e
・curl-7.57.0
・zlib-1.2.11
以下のmrbgemsを追加
・iij/mruby-digest
・iij/mruby-env
・iij/mruby-errno
・iij/mruby-iijson
・iij/mruby-ipaddr
・iij/mruby-mock
・iij/mruby-require
・iij/mruby-tls-openssl

Location:
EcnlProtoTool/trunk/mruby-1.3.0
Files:
1 added
27 edited
1 moved

Legend:

Unmodified
Added
Removed
  • EcnlProtoTool/trunk/mruby-1.3.0/include/mrbconf.h

    r321 r331  
    88#define MRUBYCONF_H
    99
     10#include <limits.h>
     11#include <stdint.h>
     12
     13/* architecture selection: */
     14/* specify -DMRB_32BIT or -DMRB_64BIT to override */
     15#if !defined(MRB_32BIT) && !defined(MRB_64BIT)
     16#if UINT64_MAX == SIZE_MAX
     17#define MRB_64BIT
     18#else
     19#define MRB_32BIT
     20#endif
     21#endif
     22
     23#if defined(MRB_32BIT) && defined(MRB_64BIT)
     24#error Cannot build for 32 and 64 bit architecture at the same time
     25#endif
     26
    1027/* configuration options: */
    1128/* add -DMRB_USE_FLOAT to use float instead of double for floating point numbers */
    1229//#define MRB_USE_FLOAT
    13 #define MRB_USE_FLOAT
    1430
    1531/* add -DMRB_INT16 to use 16bit integer for mrb_int; conflict with MRB_INT64 */
     
    3349/* argv max size in mrb_funcall */
    3450//#define MRB_FUNCALL_ARGC_MAX 16
    35 #define MRB_FUNCALL_ARGC_MAX 8
    3651
    3752/* number of object per heap page */
    3853//#define MRB_HEAP_PAGE_SIZE 1024
    39 #define MRB_HEAP_PAGE_SIZE 64
    4054
    4155/* use segmented list for IV table */
    4256//#define MRB_USE_IV_SEGLIST
    43 #define MRB_USE_IV_SEGLIST
    4457
    4558/* initial size for IV khash; ignored when MRB_USE_IV_SEGLIST is set */
     
    5871/* default size of khash table bucket */
    5972//#define KHASH_DEFAULT_SIZE 32
    60 #define KHASH_DEFAULT_SIZE 8
    6173
    6274/* allocated memory address alignment */
     
    6577/* page size of memory pool */
    6678//#define POOL_PAGE_SIZE 16000
    67 #define POOL_PAGE_SIZE 4096
    6879
    6980/* initial minimum size for string buffer */
    7081//#define MRB_STR_BUF_MIN_SIZE 128
    71 #define MRB_STR_BUF_MIN_SIZE 20
    7282
    7383/* arena size */
     
    7686/* fixed size GC arena */
    7787//#define MRB_GC_FIXED_ARENA
    78 #define MRB_GC_FIXED_ARENA
    7988
    8089/* state atexit stack size */
  • EcnlProtoTool/trunk/mruby-1.3.0/include/mruby.h

    r321 r331  
    22** mruby - An embeddable Ruby implementation
    33**
    4 ** Copyright (c) mruby developers 2010-2015
     4** Copyright (c) mruby developers 2010-2017
    55**
    66** Permission is hereby granted, free of charge, to any person obtaining
     
    2929#define MRUBY_H
    3030
     31#ifdef __cplusplus
     32#define __STDC_LIMIT_MACROS
     33#define __STDC_CONSTANT_MACROS
     34#define __STDC_FORMAT_MACROS
     35#endif
     36
    3137#include <stdint.h>
    3238#include <stddef.h>
    3339#include <limits.h>
    3440
     41#ifdef __cplusplus
     42#ifndef SIZE_MAX
     43#ifdef __SIZE_MAX__
     44#define SIZE_MAX __SIZE_MAX__
     45#else
     46#define SIZE_MAX std::numeric_limits<size_t>::max()
     47#endif
     48#endif
     49#endif
     50
     51#ifdef MRB_DEBUG
     52#include <assert.h>
     53#define mrb_assert(p) assert(p)
     54#define mrb_assert_int_fit(t1,n,t2,max) assert((n)>=0 && ((sizeof(n)<=sizeof(t2))||(n<=(t1)(max))))
     55#else
     56#define mrb_assert(p) ((void)0)
     57#define mrb_assert_int_fit(t1,n,t2,max) ((void)0)
     58#endif
     59
     60#if __STDC_VERSION__ >= 201112L
     61#define mrb_static_assert(exp, str) _Static_assert(exp, str)
     62#else
     63#define mrb_static_assert(exp, str) mrb_assert(exp)
     64#endif
     65
    3566#include "mrbconf.h"
     67
     68#ifdef MRB_USE_FLOAT
     69#define MRB_FLOAT_EPSILON FLT_EPSILON
     70#else
     71#define MRB_FLOAT_EPSILON DBL_EPSILON
     72#endif
     73
    3674#include "mruby/common.h"
    37 #include "mruby/value.h"
    38 #include "mruby/gc.h"
    39 #include "mruby/version.h"
     75#include <mruby/value.h>
     76#include <mruby/gc.h>
     77#include <mruby/version.h>
    4078
    4179/**
     
    76114  int nregs;
    77115  int ridx;
    78   int eidx;
     116  int epos;
    79117  struct REnv *env;
    80118  mrb_code *pc;                 /* return address */
     
    88126  MRB_FIBER_CREATED = 0,
    89127  MRB_FIBER_RUNNING,
    90   MRB_FIBER_RESUMING,
     128  MRB_FIBER_RESUMED,
    91129  MRB_FIBER_SUSPENDED,
    92130  MRB_FIBER_TRANSFERRED,
     
    106144  int rsize;
    107145  struct RProc **ensure;                  /* ensure handler stack */
    108   int esize;
     146  int esize, eidx;
    109147
    110148  enum mrb_fiber_state status;
     149  mrb_bool vmexec;
    111150  struct RFiber *fib;
    112151};
     
    116155typedef void (*mrb_atexit_func)(struct mrb_state*);
    117156
     157#define MRB_STATE_NO_REGEXP 1
     158#define MRB_STATE_REGEXP    2
     159
    118160typedef struct mrb_state {
    119161  struct mrb_jmpbuf *jmp;
    120162
     163  uint32_t flags;
    121164  mrb_allocf allocf;                      /* memory allocation function */
    122165  void *allocf_ud;                        /* auxiliary data of allocf */
     
    124167  struct mrb_context *c;
    125168  struct mrb_context *root_c;
     169  struct iv_tbl *globals;                 /* global variable table */
    126170
    127171  struct RObject *exc;                    /* exception */
    128   struct iv_tbl *globals;                 /* global variable table */
    129172
    130173  struct RObject *top_self;
     
    158201#endif
    159202
     203#ifdef MRB_BYTECODE_DECODE_OPTION
     204  mrb_code (*bytecode_decoder)(struct mrb_state* mrb, mrb_code code);
     205#endif
     206
    160207  struct RClass *eException_class;
    161208  struct RClass *eStandardError_class;
    162209  struct RObject *nomem_err;              /* pre-allocated NoMemoryError */
     210  struct RObject *stack_err;              /* pre-allocated SysStackError */
     211#ifdef MRB_GC_FIXED_ARENA
     212  struct RObject *arena_err;              /* pre-allocated arena overfow error */
     213#endif
    163214
    164215  void *ud; /* auxiliary data */
     
    182233 *      !!!c
    183234 *      void mrb_example_gem_init(mrb_state* mrb) {
    184  *              struct RClass *example_class;
    185  *              example_class = mrb_define_class(mrb, "Example_Class", mrb->object_class);
     235 *          struct RClass *example_class;
     236 *          example_class = mrb_define_class(mrb, "Example_Class", mrb->object_class);
    186237 *      }
    187238 *
    188239 *      void mrb_example_gem_final(mrb_state* mrb) {
    189  *              //free(TheAnimals);
     240 *          //free(TheAnimals);
    190241 *      }
    191242 *
     
    200251/**
    201252 * Defines a new module.
     253 *
    202254 * @param [mrb_state *] mrb_state* The current mruby state.
    203255 * @param [const char *] char* The name of the module.
     
    209261/**
    210262 * Include a module in another class or module.
    211  * Equivalent to: 
    212  *
    213  *   module B                                                                                                         
    214  *     include A                                                                                                     
    215  *   end 
     263 * Equivalent to:
     264 *
     265 *   module B
     266 *     include A
     267 *   end
    216268 * @param [mrb_state *] mrb_state* The current mruby state.
    217269 * @param [struct RClass *] RClass* A reference to module or a class.
     
    230282 * @param [struct RClass *] RClass* A reference to module or a class.
    231283 * @param [struct RClass *] RClass* A reference to the module to be prepended.
    232  */ 
     284 */
    233285MRB_API void mrb_prepend_module(mrb_state*, struct RClass*, struct RClass*);
    234286
     
    264316 *
    265317 * Example:
    266  *   # Ruby style
    267  *   class Foo
    268  *
    269  *     def Foo.bar
     318 *
     319 *     # Ruby style
     320 *     class Foo
     321 *       def Foo.bar
     322 *       end
    270323 *     end
    271  *
    272  *   end
    273  *   // C style
    274  *   mrb_value bar_method(mrb_state* mrb, mrb_value self){
    275  *
    276  *     return mrb_nil_value();
    277  *
    278  *   }
    279  *   void mrb_example_gem_init(mrb_state* mrb){
    280  *
    281  *     struct RClass *foo;
    282  *
    283  *     foo = mrb_define_class(mrb, "Foo", mrb->object_class);
    284  *
    285  *     mrb_define_class_method(mrb, foo, "bar", bar_method, MRB_ARGS_NONE());
    286  *
    287  *   }
    288  * @param [mrb_state *] mrb_state* The MRuby state reference.
     324 *     // C style
     325 *     mrb_value bar_method(mrb_state* mrb, mrb_value self){
     326 *       return mrb_nil_value();
     327 *     }
     328 *     void mrb_example_gem_init(mrb_state* mrb){
     329 *       struct RClass *foo;
     330 *       foo = mrb_define_class(mrb, "Foo", mrb->object_class);
     331 *       mrb_define_class_method(mrb, foo, "bar", bar_method, MRB_ARGS_NONE());
     332 *     }
     333 * @param [mrb_state *] mrb_state* The MRuby state reference.
    289334 * @param [struct RClass *] RClass* The class where the class method will be defined.
    290335 * @param [const char *] char* The name of the class method being defined.
     
    299344 *
    300345 * Example:
    301  *   # Ruby style
    302  *   module Foo
    303  *                                                                                                     
    304  *     def Foo.bar                                                                                                    *     end
    305  *
    306  *   end                                                                                                             
    307  *   // C style                                                                                                     
    308  *   mrb_value bar_method(mrb_state* mrb, mrb_value self){
    309  *                                                         
    310  *     return mrb_nil_value();                                                                                        *               
    311  *   }                                                                                                               
    312  *   void mrb_example_gem_init(mrb_state* mrb){
    313  *                                                                     
    314  *     struct RClass *foo;
    315  *                                                                                           
    316  *     foo = mrb_define_module(mrb, "Foo");
    317  *                                                       
    318  *     mrb_define_module_function(mrb, foo, "bar", bar_method, MRB_ARGS_NONE());
    319  *
    320  *   }   
     346 *
     347 *        # Ruby style
     348 *        module Foo
     349 *          def Foo.bar
     350 *          end
     351 *        end
     352 *        // C style
     353 *        mrb_value bar_method(mrb_state* mrb, mrb_value self){
     354 *          return mrb_nil_value();
     355 *        }
     356 *        void mrb_example_gem_init(mrb_state* mrb){
     357 *          struct RClass *foo;
     358 *          foo = mrb_define_module(mrb, "Foo");
     359 *          mrb_define_module_function(mrb, foo, "bar", bar_method, MRB_ARGS_NONE());
     360 *        }
    321361 *  @param [mrb_state *] mrb_state* The MRuby state reference.
    322362 *  @param [struct RClass *] RClass* The module where the module function will be defined.
    323363 *  @param [const char *] char* The name of the module function being defined.
    324  *  @param [mrb_func_t] mrb_func_t The function pointer to the module function definition. 
     364 *  @param [mrb_func_t] mrb_func_t The function pointer to the module function definition.
    325365 *  @param [mrb_aspec] mrb_aspec The method parameters declaration.
    326366 */
     
    331371 *
    332372 * Example:
    333  *    # Ruby style
    334  *
    335  *    class ExampleClass
    336  *   
    337  *    AGE = 22
    338  *
    339  *    end
    340  *
    341  *    // C style
    342  *    #include <stdio.h>
    343  *    #include <mruby.h>
    344  *
    345  *    void
    346  *    mrb_example_gem_init(mrb_state* mrb){
    347  *
    348  *      mrb_define_const(mrb, mrb->kernel_module, "AGE", mrb_fixnum_value(22));
    349  *
    350  *    }
    351  *
    352  *    mrb_value
    353  *    mrb_example_gem_final(mrb_state* mrb){
    354  *
    355  *    }
     373 *
     374 *          # Ruby style
     375 *          class ExampleClass
     376 *            AGE = 22
     377 *          end
     378 *          // C style
     379 *          #include <stdio.h>
     380 *          #include <mruby.h>
     381 *
     382 *          void
     383 *          mrb_example_gem_init(mrb_state* mrb){
     384 *            mrb_define_const(mrb, mrb->kernel_module, "AGE", mrb_fixnum_value(22));
     385 *          }
     386 *
     387 *          mrb_value
     388 *          mrb_example_gem_final(mrb_state* mrb){
     389 *          }
    356390 *  @param [mrb_state *] mrb_state* The MRuby state reference.
    357391 *  @param [struct RClass *] RClass* A class or module the constant is defined in.
     
    365399 *
    366400 * Example:
    367  *   # Ruby style
    368  *
    369  *   class ExampleClassA
    370  *
    371  *     def example_method
    372  *       "example"
     401 *
     402 *     # Ruby style
     403 *
     404 *     class ExampleClassA
     405 *       def example_method
     406 *         "example"
     407 *       end
    373408 *     end
    374  *
    375  *   end
    376  *
    377  *   ExampleClassA.new.example_method # => example
    378  *
    379  *   class ExampleClassB < ExampleClassA
    380  *
    381  *     undef_method :example_method
    382  *
    383  *   end
    384  *
    385  *   ExampleClassB.new.example_method # => undefined method 'example_method' for ExampleClassB (NoMethodError)
    386  *
    387  *   // C style
    388  *   #include <stdio.h>
    389  *   #include <mruby.h>
    390  * 
    391  *   mrb_value
    392  *   mrb_example_method(mrb_state *mrb){
    393  *
    394  *     return mrb_str_new_cstr(mrb, "example");
    395  *
    396  *   }
    397  *
    398  *   void
    399  *   mrb_example_gem_init(mrb_state* mrb){
    400  *     struct RClass *example_class_a;
    401  *     struct RClass *example_class_b;
    402  *     struct RClass *example_class_c;
    403  *
    404  *     example_class_a = mrb_define_class(mrb, "ExampleClassA", mrb->object_class);
    405  *
    406  *     mrb_define_method(mrb, example_class_a, "example_method", mrb_example_method, MRB_ARGS_NONE());
    407  *
    408  *     example_class_b = mrb_define_class(mrb, "ExampleClassB", example_class_a);
    409  *
    410  *     example_class_c = mrb_define_class(mrb, "ExampleClassC", example_class_b);
    411  *
    412  *     mrb_undef_method(mrb, example_class_c, "example_method");
    413  *
    414  *   }
    415  *
    416  *   mrb_example_gem_final(mrb_state* mrb){
    417  *
    418  *   }
    419  *
     409 *     ExampleClassA.new.example_method # => example
     410 *
     411 *     class ExampleClassB < ExampleClassA
     412 *       undef_method :example_method
     413 *     end
     414 *
     415 *     ExampleClassB.new.example_method # => undefined method 'example_method' for ExampleClassB (NoMethodError)
     416 *
     417 *     // C style
     418 *     #include <stdio.h>
     419 *     #include <mruby.h>
     420 *
     421 *     mrb_value
     422 *     mrb_example_method(mrb_state *mrb){
     423 *       return mrb_str_new_lit(mrb, "example");
     424 *     }
     425 *
     426 *     void
     427 *     mrb_example_gem_init(mrb_state* mrb){
     428 *       struct RClass *example_class_a;
     429 *       struct RClass *example_class_b;
     430 *       struct RClass *example_class_c;
     431 *
     432 *       example_class_a = mrb_define_class(mrb, "ExampleClassA", mrb->object_class);
     433 *       mrb_define_method(mrb, example_class_a, "example_method", mrb_example_method, MRB_ARGS_NONE());
     434 *       example_class_b = mrb_define_class(mrb, "ExampleClassB", example_class_a);
     435 *       example_class_c = mrb_define_class(mrb, "ExampleClassC", example_class_b);
     436 *       mrb_undef_method(mrb, example_class_c, "example_method");
     437 *     }
     438 *
     439 *     mrb_example_gem_final(mrb_state* mrb){
     440 *     }
    420441 * @param [mrb_state*] mrb_state* The mruby state reference.
    421442 * @param [struct RClass*] RClass* A class the method will be undefined from.
     
    426447/**
    427448 * Undefine a class method.
    428  *
    429449 * Example:
    430  *   # Ruby style
    431  *
    432  *   class ExampleClass
    433  *     def self.example_method
    434  *       "example"
    435  *     end
    436  *
    437  *   end
    438  *
    439  *   ExampleClass.example_method
    440  *   
    441  *   // C style
    442  *   #include <stdio.h>
    443  *   #include <mruby.h>
    444  *
    445  *   mrb_value
    446  *   mrb_example_method(mrb_state *mrb){
    447  *
    448  *     return mrb_str_new_cstr(mrb, "example");
    449  *     
    450  *   }
    451  *
    452  *   void
    453  *   mrb_example_gem_init(mrb_state* mrb){
    454  *
    455  *     struct RClass *example_class;
    456  *     
    457  *     example_class = mrb_define_class(mrb, "ExampleClass", mrb->object_class);
    458  *
    459  *     mrb_define_class_method(mrb, example_class, "example_method", mrb_example_method, MRB_ARGS_NONE());
    460  *
    461  *     mrb_undef_class_method(mrb, example_class, "example_method");
    462  *
    463  *   }
    464  *
    465  *   void
    466  *   mrb_example_gem_final(mrb_state* mrb){
    467  *
    468  *   }
     450 *
     451 *      # Ruby style
     452 *      class ExampleClass
     453 *        def self.example_method
     454 *          "example"
     455 *        end
     456 *      end
     457 *
     458 *     ExampleClass.example_method
     459 *
     460 *     // C style
     461 *     #include <stdio.h>
     462 *     #include <mruby.h>
     463 *
     464 *     mrb_value
     465 *     mrb_example_method(mrb_state *mrb){
     466 *       return mrb_str_new_lit(mrb, "example");
     467 *     }
     468 *
     469 *     void
     470 *     mrb_example_gem_init(mrb_state* mrb){
     471 *       struct RClass *example_class;
     472 *       example_class = mrb_define_class(mrb, "ExampleClass", mrb->object_class);
     473 *       mrb_define_class_method(mrb, example_class, "example_method", mrb_example_method, MRB_ARGS_NONE());
     474 *       mrb_undef_class_method(mrb, example_class, "example_method");
     475 *      }
     476 *
     477 *      void
     478 *      mrb_example_gem_final(mrb_state* mrb){
     479 *      }
    469480 * @param [mrb_state*] mrb_state* The mruby state reference.
    470481 * @param [RClass*] RClass* A class the class method will be undefined from.
     
    478489 * Example:
    479490 *
    480  *   # Ruby style
    481  *   class ExampleClass
    482  *   end
    483  *
    484  *   p ExampleClass # => #<ExampleClass:0x9958588>
    485  *   // C style
    486  *   #include <stdio.h>
    487  *   #include <mruby.h>
    488  *
    489  *   void
    490  *   mrb_example_gem_init(mrb_state* mrb) {
    491  *     struct RClass *example_class;
    492  *     mrb_value obj;
    493  *
    494  *     example_class = mrb_define_class(mrb, "ExampleClass", mrb->object_class); # => class ExampleClass; end
    495  *     obj = mrb_obj_new(mrb, example_class, 0, NULL); # => ExampleClass.new
    496  *     mrb_p(mrb, obj); // => Kernel#p
    497  *   } 
     491 *     # Ruby style
     492 *     class ExampleClass
     493 *     end
     494 *
     495 *     p ExampleClass # => #<ExampleClass:0x9958588>
     496 *     // C style
     497 *     #include <stdio.h>
     498 *     #include <mruby.h>
     499 *
     500 *     void
     501 *     mrb_example_gem_init(mrb_state* mrb) {
     502 *       struct RClass *example_class;
     503 *       mrb_value obj;
     504 *       example_class = mrb_define_class(mrb, "ExampleClass", mrb->object_class); # => class ExampleClass; end
     505 *       obj = mrb_obj_new(mrb, example_class, 0, NULL); # => ExampleClass.new
     506 *       mrb_p(mrb, obj); // => Kernel#p
     507 *      }
    498508 * @param [mrb_state*] mrb The current mruby state.
    499509 * @param [RClass*] c Reference to the class of the new object.
     
    517527 * Example:
    518528 *
    519  *   void
    520  *   mrb_example_gem_init(mrb_state* mrb) {
    521  *      struct RClass *example_class;
    522  *      mrb_value obj;
    523  *
    524  *      example_class = mrb_class_new(mrb, mrb->object_class);
    525  *      obj = mrb_obj_new(mrb, example_class, 0, NULL); // => #<#<Class:0x9a945b8>:0x9a94588>
    526  *      mrb_p(mrb, obj); // => Kernel#p
    527  *   }
     529 *      void
     530 *      mrb_example_gem_init(mrb_state* mrb) {
     531 *        struct RClass *example_class;
     532 *
     533 *        mrb_value obj;
     534 *        example_class = mrb_class_new(mrb, mrb->object_class);
     535 *        obj = mrb_obj_new(mrb, example_class, 0, NULL); // => #<#<Class:0x9a945b8>:0x9a94588>
     536 *        mrb_p(mrb, obj); // => Kernel#p
     537 *       }
    528538 *
    529539 * @param [mrb_state*] mrb The current mruby state.
     
    537547 *
    538548 * Example:
    539  *   void
    540  *   mrb_example_gem_init(mrb_state* mrb) {
    541  *      struct RClass *example_module;
    542  *
    543  *      example_module = mrb_module_new(mrb);
    544  *   }
     549 *      void
     550 *      mrb_example_gem_init(mrb_state* mrb) {
     551 *        struct RClass *example_module;
     552 *
     553 *        example_module = mrb_module_new(mrb);
     554 *      }
    545555 *
    546556 * @param [mrb_state*] mrb The current mruby state.
     
    553563 *
    554564 * Example:
    555  *   void
    556  *   mrb_example_gem_init(mrb_state* mrb) {
    557  *      struct RClass *example_class;
    558  *      mrb_bool cd;
    559  *
    560  *      example_class = mrb_define_class(mrb, "ExampleClass", mrb->object_class);
    561  *      cd = mrb_class_defined(mrb, "ExampleClass");
    562  *     
    563  *      // If mrb_class_defined returns 1 then puts "True"
    564  *      // If mrb_class_defined returns 0 then puts "False"
    565  *      if (cd == 1){
    566  *        puts("True");
     565 *     void
     566 *     mrb_example_gem_init(mrb_state* mrb) {
     567 *       struct RClass *example_class;
     568 *       mrb_bool cd;
     569 *
     570 *       example_class = mrb_define_class(mrb, "ExampleClass", mrb->object_class);
     571 *       cd = mrb_class_defined(mrb, "ExampleClass");
     572 *
     573 *       // If mrb_class_defined returns 1 then puts "True"
     574 *       // If mrb_class_defined returns 0 then puts "False"
     575 *       if (cd == 1){
     576 *         puts("True");
     577 *       }
     578 *       else {
     579 *         puts("False");
     580 *       }
    567581 *      }
    568  *      else {
    569  *        puts("False");
    570  *      }
    571  *   }
    572582 *
    573583 * @param [mrb_state*] mrb The current mruby state.
     
    584594*/
    585595MRB_API struct RClass * mrb_class_get(mrb_state *mrb, const char *name);
     596
     597/**
     598 * Gets a exception class.
     599 * @param [mrb_state*] mrb The current mruby state.
     600 * @param [const char *] name The name of the class.
     601 * @return [struct RClass *] A reference to the class.
     602*/
     603MRB_API struct RClass * mrb_exc_get(mrb_state *mrb, const char *name);
     604
     605/**
     606 * Returns an mrb_bool. True if inner class was defined, and false if the inner class was not defined.
     607 *
     608 * Example:
     609 *     void
     610 *     mrb_example_gem_init(mrb_state* mrb) {
     611 *       struct RClass *example_outer, *example_inner;
     612 *       mrb_bool cd;
     613 *
     614 *       example_outer = mrb_define_module(mrb, "ExampleOuter");
     615 *
     616 *       example_inner = mrb_define_class_under(mrb, example_outer, "ExampleInner", mrb->object_class);
     617 *       cd = mrb_class_defined_under(mrb, example_outer, "ExampleInner");
     618 *
     619 *       // If mrb_class_defined_under returns 1 then puts "True"
     620 *       // If mrb_class_defined_under returns 0 then puts "False"
     621 *       if (cd == 1){
     622 *         puts("True");
     623 *       }
     624 *       else {
     625 *         puts("False");
     626 *       }
     627 *      }
     628 *
     629 * @param [mrb_state*] mrb The current mruby state.
     630 * @param [struct RClass *] outer The name of the outer class.
     631 * @param [const char *] name A string representing the name of the inner class.
     632 * @return [mrb_bool] A boolean value.
     633 */
     634MRB_API mrb_bool mrb_class_defined_under(mrb_state *mrb, struct RClass *outer, const char *name);
    586635
    587636/**
     
    616665 *
    617666 * Equivalent to:
    618  *   Object#dup   
     667 *   Object#dup
    619668 * @param [mrb_state*] mrb The current mruby state.
    620669 * @param [mrb_value] obj Object to be duplicate.
     
    628677 * class it returns true, it returns false otherwise.
    629678 *
    630  * Example:
    631  *   # Ruby style
    632  *   class ExampleClass
    633  *      def example_method
     679 *      Example:
     680 *      # Ruby style
     681 *      class ExampleClass
     682 *        def example_method
     683 *        end
    634684 *      end
    635  *   end
    636  *
    637  *   ExampleClass.new.respond_to?(:example_method) # => true
    638  *
    639  *   // C style
    640  *   void
    641  *   mrb_example_gem_init(mrb_state* mrb) {
    642  *      struct RClass *example_class;
    643  *      mrb_sym mid;
    644  *      mrb_bool obj_resp;
    645  *
    646  *      example_class = mrb_define_class(mrb, "ExampleClass", mrb->object_class);
    647  *      mrb_define_method(mrb, example_class, "example_method", exampleMethod, MRB_ARGS_NONE());
    648  *      mid = mrb_intern_str(mrb, mrb_str_new_cstr(mrb, "example_method" ));
    649  *      obj_resp = mrb_obj_respond_to(mrb, example_class, mid); // => 1(true in Ruby world)
    650  *     
    651  *      // If mrb_obj_respond_to returns 1 then puts "True"
    652  *      // If mrb_obj_respond_to returns 0 then puts "False"
    653  *      if (obj_resp == 1) {
    654  *        puts("True");
     685 *
     686 *      ExampleClass.new.respond_to?(:example_method) # => true
     687 *
     688 *      // C style
     689 *      void
     690 *      mrb_example_gem_init(mrb_state* mrb) {
     691 *        struct RClass *example_class;
     692 *        mrb_sym mid;
     693 *        mrb_bool obj_resp;
     694 *
     695 *        example_class = mrb_define_class(mrb, "ExampleClass", mrb->object_class);
     696 *        mrb_define_method(mrb, example_class, "example_method", exampleMethod, MRB_ARGS_NONE());
     697 *        mid = mrb_intern_str(mrb, mrb_str_new_lit(mrb, "example_method" ));
     698 *        obj_resp = mrb_obj_respond_to(mrb, example_class, mid); // => 1(true in Ruby world)
     699 *
     700 *        // If mrb_obj_respond_to returns 1 then puts "True"
     701 *        // If mrb_obj_respond_to returns 0 then puts "False"
     702 *        if (obj_resp == 1) {
     703 *          puts("True");
     704 *        }
     705 *        else if (obj_resp == 0) {
     706 *          puts("False");
     707 *        }
    655708 *      }
    656  *      else if (obj_resp == 0) {
    657  *        puts("False");
    658  *      }
    659  *   }
    660709 *
    661710 * @param [mrb_state*] mrb The current mruby state.
     
    795844/**
    796845 * Call existing ruby functions.
     846 *
     847 *      #include <stdio.h>
     848 *      #include <mruby.h>
     849 *      #include "mruby/compile.h"
     850 *
     851 *      int
     852 *      main()
     853 *      {
     854 *        mrb_int i = 99;
     855 *        mrb_state *mrb = mrb_open();
     856 *
     857 *        if (!mrb) { }
     858 *        FILE *fp = fopen("test.rb","r");
     859 *        mrb_value obj = mrb_load_file(mrb,fp);
     860 *        mrb_funcall(mrb, obj, "method_name", 1, mrb_fixnum_value(i));
     861 *        fclose(fp);
     862 *        mrb_close(mrb);
     863 *       }
     864 * @param [mrb_state*] mrb_state* The current mruby state.
     865 * @param [mrb_value] mrb_value A reference to an mruby value.
     866 * @param [const char*] const char* The name of the method.
     867 * @param [mrb_int] mrb_int The number of arguments the method has.
     868 * @param [...] ... Variadic values(not type safe!).
     869 * @return [mrb_value] mrb_value mruby function value.
    797870 */
    798871MRB_API mrb_value mrb_funcall(mrb_state*, mrb_value, const char*, mrb_int,...);
     872/**
     873 * Call existing ruby functions. This is basically the type safe version of mrb_funcall.
     874 *
     875 *      #include <stdio.h>
     876 *      #include <mruby.h>
     877 *      #include "mruby/compile.h"
     878 *      int
     879 *      main()
     880 *      {
     881 *        mrb_int i = 99;
     882 *        mrb_state *mrb = mrb_open();
     883 *
     884 *        if (!mrb) { }
     885 *        mrb_sym m_sym = mrb_intern_lit(mrb, "method_name"); // Symbol for method.
     886 *
     887 *        FILE *fp = fopen("test.rb","r");
     888 *        mrb_value obj = mrb_load_file(mrb,fp);
     889 *        mrb_funcall_argv(mrb, obj, m_sym, 1, &obj); // Calling ruby function from test.rb.
     890 *        fclose(fp);
     891 *        mrb_close(mrb);
     892 *       }
     893 * @param [mrb_state*] mrb_state* The current mruby state.
     894 * @param [mrb_value] mrb_value A reference to an mruby value.
     895 * @param [mrb_sym] mrb_sym The symbol representing the method.
     896 * @param [mrb_int] mrb_int The number of arguments the method has.
     897 * @param [const mrb_value*] mrb_value* Pointer to the object.
     898 * @return [mrb_value] mrb_value mruby function value.
     899 * @see mrb_funcall
     900 */
    799901MRB_API mrb_value mrb_funcall_argv(mrb_state*, mrb_value, mrb_sym, mrb_int, const mrb_value*);
     902/**
     903 * Call existing ruby functions with a block.
     904 */
    800905MRB_API mrb_value mrb_funcall_with_block(mrb_state*, mrb_value, mrb_sym, mrb_int, const mrb_value*, mrb_value);
     906/**
     907 * Create a symbol
     908 *
     909 *     # Ruby style:
     910 *     :pizza # => :pizza
     911 *
     912 *     // C style:
     913 *     mrb_sym m_sym = mrb_intern_lit(mrb, "pizza"); //  => :pizza
     914 * @param [mrb_state*] mrb_state* The current mruby state.
     915 * @param [const char*] const char* The name of the method.
     916 * @return [mrb_sym] mrb_sym A symbol.
     917 */
    801918MRB_API mrb_sym mrb_intern_cstr(mrb_state*,const char*);
    802919MRB_API mrb_sym mrb_intern(mrb_state*,const char*,size_t);
     
    8921009MRB_API mrb_value mrb_top_self(mrb_state *);
    8931010MRB_API mrb_value mrb_run(mrb_state*, struct RProc*, mrb_value);
    894 MRB_API mrb_value mrb_toplevel_run(mrb_state*, struct RProc*);
    895 MRB_API mrb_value mrb_context_run(mrb_state*, struct RProc*, mrb_value, unsigned int);
     1011MRB_API mrb_value mrb_top_run(mrb_state*, struct RProc*, mrb_value, unsigned int);
     1012MRB_API mrb_value mrb_vm_run(mrb_state*, struct RProc*, mrb_value, unsigned int);
     1013MRB_API mrb_value mrb_vm_exec(mrb_state*, struct RProc*, mrb_code*);
     1014/* compatibility macros */
     1015#define mrb_toplevel_run_keep(m,p,k) mrb_top_run((m),(p),mrb_top_self(m),(k))
     1016#define mrb_toplevel_run(m,p) mrb_toplevel_run_keep((m),(p),0)
     1017#define mrb_context_run(m,p,s,k) mrb_vm_run((m),(p),(s),(k))
    8961018
    8971019MRB_API void mrb_p(mrb_state*, mrb_value);
     
    9651087   + exception objects obtained from those macros are local to mrb
    9661088*/
    967 #define E_RUNTIME_ERROR             (mrb_class_get(mrb, "RuntimeError"))
    968 #define E_TYPE_ERROR                (mrb_class_get(mrb, "TypeError"))
    969 #define E_ARGUMENT_ERROR            (mrb_class_get(mrb, "ArgumentError"))
    970 #define E_INDEX_ERROR               (mrb_class_get(mrb, "IndexError"))
    971 #define E_RANGE_ERROR               (mrb_class_get(mrb, "RangeError"))
    972 #define E_NAME_ERROR                (mrb_class_get(mrb, "NameError"))
    973 #define E_NOMETHOD_ERROR            (mrb_class_get(mrb, "NoMethodError"))
    974 #define E_SCRIPT_ERROR              (mrb_class_get(mrb, "ScriptError"))
    975 #define E_SYNTAX_ERROR              (mrb_class_get(mrb, "SyntaxError"))
    976 #define E_LOCALJUMP_ERROR           (mrb_class_get(mrb, "LocalJumpError"))
    977 #define E_REGEXP_ERROR              (mrb_class_get(mrb, "RegexpError"))
    978 #define E_SYSSTACK_ERROR            (mrb_class_get(mrb, "SystemStackError"))
    979 
    980 #define E_NOTIMP_ERROR              (mrb_class_get(mrb, "NotImplementedError"))
    981 #define E_FLOATDOMAIN_ERROR         (mrb_class_get(mrb, "FloatDomainError"))
    982 
    983 #define E_KEY_ERROR                 (mrb_class_get(mrb, "KeyError"))
     1089#define E_RUNTIME_ERROR             (mrb_exc_get(mrb, "RuntimeError"))
     1090#define E_TYPE_ERROR                (mrb_exc_get(mrb, "TypeError"))
     1091#define E_ARGUMENT_ERROR            (mrb_exc_get(mrb, "ArgumentError"))
     1092#define E_INDEX_ERROR               (mrb_exc_get(mrb, "IndexError"))
     1093#define E_RANGE_ERROR               (mrb_exc_get(mrb, "RangeError"))
     1094#define E_NAME_ERROR                (mrb_exc_get(mrb, "NameError"))
     1095#define E_NOMETHOD_ERROR            (mrb_exc_get(mrb, "NoMethodError"))
     1096#define E_SCRIPT_ERROR              (mrb_exc_get(mrb, "ScriptError"))
     1097#define E_SYNTAX_ERROR              (mrb_exc_get(mrb, "SyntaxError"))
     1098#define E_LOCALJUMP_ERROR           (mrb_exc_get(mrb, "LocalJumpError"))
     1099#define E_REGEXP_ERROR              (mrb_exc_get(mrb, "RegexpError"))
     1100
     1101#define E_NOTIMP_ERROR              (mrb_exc_get(mrb, "NotImplementedError"))
     1102#define E_FLOATDOMAIN_ERROR         (mrb_exc_get(mrb, "FloatDomainError"))
     1103
     1104#define E_KEY_ERROR                 (mrb_exc_get(mrb, "KeyError"))
    9841105
    9851106MRB_API mrb_value mrb_yield(mrb_state *mrb, mrb_value b, mrb_value arg);
    9861107MRB_API mrb_value mrb_yield_argv(mrb_state *mrb, mrb_value b, mrb_int argc, const mrb_value *argv);
    9871108MRB_API mrb_value mrb_yield_with_class(mrb_state *mrb, mrb_value b, mrb_int argc, const mrb_value *argv, mrb_value self, struct RClass *c);
     1109
     1110/* continue execution to the proc */
     1111/* this function should always be called as the last function of a method */
     1112/* e.g. return mrb_yield_cont(mrb, proc, self, argc, argv); */
     1113mrb_value mrb_yield_cont(mrb_state *mrb, mrb_value b, mrb_value self, mrb_int argc, const mrb_value *argv);
    9881114
    9891115/* mrb_gc_protect() leaves the object in the arena */
     
    10131139MRB_API mrb_bool mrb_respond_to(mrb_state *mrb, mrb_value obj, mrb_sym mid);
    10141140MRB_API mrb_bool mrb_obj_is_instance_of(mrb_state *mrb, mrb_value obj, struct RClass* c);
     1141MRB_API mrb_bool mrb_func_basic_p(mrb_state *mrb, mrb_value obj, mrb_sym mid, mrb_func_t func);
    10151142
    10161143
     
    10341161 * @mrbgem mruby-fiber
    10351162 */
    1036 #define E_FIBER_ERROR (mrb_class_get(mrb, "FiberError"))
     1163#define E_FIBER_ERROR (mrb_exc_get(mrb, "FiberError"))
    10371164
    10381165/* memory pool implementation */
     
    10501177MRB_API void mrb_show_copyright(mrb_state *mrb);
    10511178
    1052 #ifdef MRB_DEBUG
    1053 #include <assert.h>
    1054 #define mrb_assert(p) assert(p)
    1055 #define mrb_assert_int_fit(t1,n,t2,max) assert((n)>=0 && ((sizeof(n)<=sizeof(t2))||(n<=(t1)(max))))
    1056 #else
    1057 #define mrb_assert(p) ((void)0)
    1058 #define mrb_assert_int_fit(t1,n,t2,max) ((void)0)
    1059 #endif
    1060 
    1061 #if __STDC_VERSION__ >= 201112L
    1062 #define mrb_static_assert(exp, str) _Static_assert(exp, str)
    1063 #else
    1064 #define mrb_static_assert(exp, str) mrb_assert(exp)
    1065 #endif
    1066 
    10671179MRB_API mrb_value mrb_format(mrb_state *mrb, const char *format, ...);
    10681180
     1181#if 0
     1182/* memcpy and memset does not work with gdb reverse-next on my box */
     1183/* use naive memcpy and memset instead */
     1184#undef memcpy
     1185#undef memset
     1186static inline void*
     1187mrbmemcpy(void *dst, const void *src, size_t n)
     1188{
     1189  char *d = dst;
     1190  const char *s = src;
     1191  while (n--)
     1192    *d++ = *s++;
     1193  return d;
     1194}
     1195#define memcpy(a,b,c) mrbmemcpy(a,b,c)
     1196
     1197static inline void*
     1198mrbmemset(void *s, int c, size_t n)
     1199{
     1200  char *t = s;
     1201  while (n--)
     1202    *t++ = c;
     1203  return s;
     1204}
     1205#define memset(a,b,c) mrbmemset(a,b,c)
     1206#endif
     1207
    10691208MRB_END_DECL
    10701209
  • EcnlProtoTool/trunk/mruby-1.3.0/include/mruby/array.h

    r321 r331  
    88#define MRUBY_ARRAY_H
    99
    10 #include "mruby/common.h"
     10#include "common.h"
    1111
    1212/*
     
    5555 *
    5656 * @param mrb The mruby state reference.
    57  * @return The initialized array
     57 * @return The initialized array.
    5858 */
    5959MRB_API mrb_value mrb_ary_new(mrb_state *mrb);
    6060
     61/*
     62 * Initializes a new array with initial values
     63 *
     64 * Equivalent to:
     65 *
     66 *      Array[value1, value2, ...]
     67 *
     68 * @param mrb The mruby state reference.
     69 * @param size The numer of values.
     70 * @param vals The actual values.
     71 * @return The initialized array.
     72 */
    6173MRB_API mrb_value mrb_ary_new_from_values(mrb_state *mrb, mrb_int size, const mrb_value *vals);
     74
     75/*
     76 * Initializes a new array with two initial values
     77 *
     78 * Equivalent to:
     79 *
     80 *      Array[car, cdr]
     81 *
     82 * @param mrb The mruby state reference.
     83 * @param car The first value.
     84 * @param cdr The second value.
     85 * @return The initialized array.
     86 */
    6287MRB_API mrb_value mrb_assoc_new(mrb_state *mrb, mrb_value car, mrb_value cdr);
    63 MRB_API void mrb_ary_concat(mrb_state*, mrb_value, mrb_value);
    64 MRB_API mrb_value mrb_ary_splat(mrb_state*, mrb_value);
     88
     89/*
     90 * Concatenate two arrays. The target array will be modified
     91 *
     92 * Equivalent to:
     93 *      ary.concat(other)
     94 *
     95 * @param mrb The mruby state reference.
     96 * @param self The target array.
     97 * @param other The array that will be concatenated to self.
     98 */
     99MRB_API void mrb_ary_concat(mrb_state *mrb, mrb_value self, mrb_value other);
     100
     101/*
     102 * Create an array from the input. It tries calling to_a on the
     103 * value. If value does not respond to that, it creates a new
     104 * array with just this value.
     105 *
     106 * @param mrb The mruby state reference.
     107 * @param value The value to change into an array.
     108 * @return An array representation of value.
     109 */
     110MRB_API mrb_value mrb_ary_splat(mrb_state *mrb, mrb_value value);
    65111
    66112/*
     
    85131 *
    86132 * @param mrb The mruby state reference.
    87  * @param ary The array from which the value will be poped.
    88  * @return The poped value.
     133 * @param ary The array from which the value will be popped.
     134 * @return The popped value.
    89135 */
    90136MRB_API mrb_value mrb_ary_pop(mrb_state *mrb, mrb_value ary);
     
    118164MRB_API void mrb_ary_set(mrb_state *mrb, mrb_value ary, mrb_int n, mrb_value val);
    119165
    120 MRB_API void mrb_ary_replace(mrb_state *mrb, mrb_value a, mrb_value b);
     166/*
     167 * Replace the array with another array
     168 *
     169 * Equivalent to:
     170 *
     171 *      ary.replace(other)
     172 *
     173 * @param mrb The mruby state reference
     174 * @param self The target array.
     175 * @param other The array to replace it with.
     176 */
     177MRB_API void mrb_ary_replace(mrb_state *mrb, mrb_value self, mrb_value other);
    121178MRB_API mrb_value mrb_check_array_type(mrb_state *mrb, mrb_value self);
     179
     180/*
     181 * Unshift an element into an array
     182 *
     183 * Equivalent to:
     184 *
     185 *     ary.unshift(item)
     186 *
     187 * @param mrb The mruby state reference.
     188 * @param self The target array.
     189 * @param item The item to unshift.
     190 */
    122191MRB_API mrb_value mrb_ary_unshift(mrb_state *mrb, mrb_value self, mrb_value item);
    123192MRB_API mrb_value mrb_ary_entry(mrb_value ary, mrb_int offset);
     193
     194/*
     195 * Shifts the first element from the array.
     196 *
     197 * Equivalent to:
     198 *
     199 *      ary.shift
     200 *
     201 * @param mrb The mruby state reference.
     202 * @param self The array from which the value will be shifted.
     203 * @return The shifted value.
     204 */
    124205MRB_API mrb_value mrb_ary_shift(mrb_state *mrb, mrb_value self);
     206
     207/*
     208 * Removes all elements from this array
     209 *
     210 * Equivalent to:
     211 *
     212 *      ary.clear
     213 *
     214 * @param mrb The mruby state reference.
     215 * @param self The target array.
     216 * @return self
     217 */
    125218MRB_API mrb_value mrb_ary_clear(mrb_state *mrb, mrb_value self);
     219
     220/*
     221 * Join the array elements together in a string
     222 *
     223 * Equivalent to:
     224 *
     225 *      ary.join(sep="")
     226 *
     227 * @param mrb The mruby state reference.
     228 * @param ary The target array
     229 * @param sep The separater, can be NULL
     230 */
    126231MRB_API mrb_value mrb_ary_join(mrb_state *mrb, mrb_value ary, mrb_value sep);
    127 MRB_API mrb_value mrb_ary_resize(mrb_state *mrb, mrb_value ary, mrb_int len);
     232
     233/*
     234 * Update the capacity of the array
     235 *
     236 * @param mrb The mruby state reference.
     237 * @param ary The target array.
     238 * @param new_len The new capacity of the array
     239 */
     240MRB_API mrb_value mrb_ary_resize(mrb_state *mrb, mrb_value ary, mrb_int new_len);
    128241
    129242static inline mrb_int
     
    135248}
    136249
     250static inline mrb_value
     251ary_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
    137259MRB_END_DECL
    138260
  • EcnlProtoTool/trunk/mruby-1.3.0/include/mruby/boxing_nan.h

    r321 r331  
    5454
    5555#define mrb_tt(o)       ((enum mrb_vtype)(((o).value.ttt & 0xfc000)>>14)-1)
    56 #define mrb_type(o)     ((uint32_t)0xfff00000 < (o).value.ttt ? mrb_tt(o) : MRB_TT_FLOAT)
     56#define mrb_type(o)     (enum mrb_vtype)((uint32_t)0xfff00000 < (o).value.ttt ? mrb_tt(o) : MRB_TT_FLOAT)
    5757#define mrb_ptr(o)      ((void*)((((uintptr_t)0x3fffffffffff)&((uintptr_t)((o).value.p)))<<2))
    5858#define mrb_float(o)    (o).f
     
    6161#define mrb_symbol(o)   (o).value.sym
    6262
     63#ifdef MRB_64BIT
     64#define BOXNAN_SHIFT_LONG_POINTER(v) (((uintptr_t)(v)>>34)&0x3fff)
     65#else
     66#define BOXNAN_SHIFT_LONG_POINTER(v) 0
     67#endif
     68
    6369#define BOXNAN_SET_VALUE(o, tt, attr, v) do {\
    64   switch (tt) {\
    65   case MRB_TT_FALSE:\
    66   case MRB_TT_TRUE:\
    67   case MRB_TT_UNDEF:\
    68   case MRB_TT_FIXNUM:\
    69   case MRB_TT_SYMBOL: (o).attr = (v); break;\
    70   default: (o).value.i = 0; (o).value.p = (void*)((uintptr_t)(o).value.p | (((uintptr_t)(v))>>2)); break;\
    71   }\
    72   (o).value.ttt = (0xfff00000|(((tt)+1)<<14));\
     70  (o).attr = (v);\
     71  (o).value.ttt = 0xfff00000 | (((tt)+1)<<14);\
     72} while (0)
     73
     74#define BOXNAN_SET_OBJ_VALUE(o, tt, v) do {\
     75  (o).value.p = (void*)((uintptr_t)(v)>>2);\
     76  (o).value.ttt = (0xfff00000|(((tt)+1)<<14)|BOXNAN_SHIFT_LONG_POINTER(v));\
    7377} while (0)
    7478
     
    7781    (r).value.ttt = 0x7ff80000; \
    7882    (r).value.i = 0; \
    79   } else { \
     83  } \
     84  else { \
    8085    (r).f = v; \
    8186  }} while(0)
     
    8792#define SET_INT_VALUE(r,n) BOXNAN_SET_VALUE(r, MRB_TT_FIXNUM, value.i, (n))
    8893#define SET_SYM_VALUE(r,v) BOXNAN_SET_VALUE(r, MRB_TT_SYMBOL, value.sym, (v))
    89 #define SET_OBJ_VALUE(r,v) BOXNAN_SET_VALUE(r, (((struct RObject*)(v))->tt), value.p, (v))
    90 #define SET_CPTR_VALUE(mrb,r,v) BOXNAN_SET_VALUE(r, MRB_TT_CPTR, value.p, v)
     94#define SET_OBJ_VALUE(r,v) BOXNAN_SET_OBJ_VALUE(r, (((struct RObject*)(v))->tt), (v))
     95#define SET_CPTR_VALUE(mrb,r,v) BOXNAN_SET_OBJ_VALUE(r, MRB_TT_CPTR, v)
    9196#define SET_UNDEF_VALUE(r) BOXNAN_SET_VALUE(r, MRB_TT_UNDEF, value.i, 0)
    9297
  • EcnlProtoTool/trunk/mruby-1.3.0/include/mruby/boxing_word.h

    r321 r331  
    1010#if defined(MRB_INT16)
    1111# error MRB_INT16 is too small for MRB_WORD_BOXING.
     12#endif
     13
     14#if defined(MRB_INT64) && !defined(MRB_64BIT)
     15#error MRB_INT64 cannot be used with MRB_WORD_BOXING in 32-bit mode.
    1216#endif
    1317
     
    6367#define mrb_cptr(o)    (o).value.vp->p
    6468#define mrb_float(o)   (o).value.fp->f
    65 #define mrb_fixnum(o)  (o).value.i
     69#define mrb_fixnum(o)  ((mrb_int)(o).value.i)
    6670#define mrb_symbol(o)  (o).value.sym
    6771
     
    9296#define mrb_nil_p(o)  ((o).w == MRB_Qnil)
    9397
    94 #define BOXWORD_SET_VALUE(o, ttt, attr, v) do {\
     98#define BOXWORD_SET_VALUE(o, ttt, attr, v) do { \
    9599  switch (ttt) {\
    96100  case MRB_TT_FALSE:  (o).w = (v) ? MRB_Qfalse : MRB_Qnil; break;\
    97101  case MRB_TT_TRUE:   (o).w = MRB_Qtrue; break;\
    98102  case MRB_TT_UNDEF:  (o).w = MRB_Qundef; break;\
    99   case MRB_TT_FIXNUM: (o).value.i_flag = MRB_FIXNUM_FLAG; (o).attr = (v); break;\
    100   case MRB_TT_SYMBOL: (o).value.sym_flag = MRB_SYMBOL_FLAG; (o).attr = (v); break;\
     103  case MRB_TT_FIXNUM: (o).w = 0;(o).value.i_flag = MRB_FIXNUM_FLAG; (o).attr = (v); break;\
     104  case MRB_TT_SYMBOL: (o).w = 0;(o).value.sym_flag = MRB_SYMBOL_FLAG; (o).attr = (v); break;\
    101105  default:            (o).w = 0; (o).attr = (v); if ((o).value.bp) (o).value.bp->tt = ttt; break;\
    102106  }\
  • EcnlProtoTool/trunk/mruby-1.3.0/include/mruby/class.h

    r321 r331  
    88#define MRUBY_CLASS_H
    99
    10 #include "mruby/common.h"
     10#include "common.h"
    1111
    1212/**
     
    5252}
    5353
    54 // TODO: figure out where to put user flags
     54/* TODO: figure out where to put user flags */
     55#define MRB_FLAG_IS_FROZEN (1 << 18)
    5556#define MRB_FLAG_IS_PREPENDED (1 << 19)
    5657#define MRB_FLAG_IS_ORIGIN (1 << 20)
  • EcnlProtoTool/trunk/mruby-1.3.0/include/mruby/common.h

    r321 r331  
    11/*
    2 ** mruby/common.h - mruby common platform definitions
     2**"common.h - mruby common platform definition"
    33**
    44** See Copyright Notice in mruby.h
     
    1010
    1111#ifdef __cplusplus
     12#ifdef MRB_ENABLE_CXX_ABI
     13#define MRB_BEGIN_DECL
     14#define MRB_END_DECL
     15#else
    1216# define MRB_BEGIN_DECL extern "C" {
    1317# define MRB_END_DECL   }
     18#endif
    1419#else
    1520/** Start declarations in C mode */
  • EcnlProtoTool/trunk/mruby-1.3.0/include/mruby/compile.h

    r321 r331  
    88#define MRUBY_COMPILE_H
    99
    10 #include "mruby/common.h"
     10#include "common.h"
    1111
    1212/**
     
    1515MRB_BEGIN_DECL
    1616
    17 #include "mruby.h"
     17#include <mruby.h>
    1818
    1919struct mrb_jmpbuf;
     
    4040MRB_API const char *mrbc_filename(mrb_state *mrb, mrbc_context *c, const char *s);
    4141MRB_API void mrbc_partial_hook(mrb_state *mrb, mrbc_context *c, int (*partial_hook)(struct mrb_parser_state*), void*data);
    42 
    43 MRB_API mrb_value mrb_toplevel_run_keep(mrb_state*, struct RProc*, unsigned int);
    4442
    4543/* AST node structure */
     
    105103};
    106104
    107 #define MRB_PARSER_BUF_SIZE 1024
     105#define MRB_PARSER_TOKBUF_MAX 65536
     106#define MRB_PARSER_TOKBUF_SIZE 256
    108107
    109108/* parser structure */
     
    133132
    134133  mrb_ast_node *pb;
    135   char buf[MRB_PARSER_BUF_SIZE];
    136   int bidx;
     134  char *tokbuf;
     135  char buf[MRB_PARSER_TOKBUF_SIZE];
     136  int tidx;
     137  int tsiz;
    137138
    138139  mrb_ast_node *all_heredocs;   /* list of mrb_parser_heredoc_info* */
     
    163164MRB_API void mrb_parser_free(struct mrb_parser_state*);
    164165MRB_API void mrb_parser_parse(struct mrb_parser_state*,mrbc_context*);
     166MRB_API double mrb_float_read(const char*, char**);
    165167
    166168MRB_API void mrb_parser_set_filename(struct mrb_parser_state*, char const*);
     
    174176MRB_API struct mrb_parser_state* mrb_parse_nstring(mrb_state*,const char*,int,mrbc_context*);
    175177MRB_API struct RProc* mrb_generate_code(mrb_state*, struct mrb_parser_state*);
     178MRB_API mrb_value mrb_load_exec(mrb_state *mrb, struct mrb_parser_state *p, mrbc_context *c);
    176179
    177180/* program load functions */
  • EcnlProtoTool/trunk/mruby-1.3.0/include/mruby/data.h

    r321 r331  
    88#define MRUBY_DATA_H
    99
    10 #include "mruby/common.h"
     10#include "common.h"
    1111
    1212/**
  • EcnlProtoTool/trunk/mruby-1.3.0/include/mruby/debug.h

    r321 r331  
    88#define MRUBY_DEBUG_H
    99
    10 #include "mruby/common.h"
     10#include "common.h"
    1111
    1212/**
  • EcnlProtoTool/trunk/mruby-1.3.0/include/mruby/dump.h

    r321 r331  
    88#define MRUBY_DUMP_H
    99
    10 #include "mruby.h"
    11 #include "mruby/irep.h"
    12 #include "mruby/common.h"
     10#include <mruby.h>
     11#include <mruby/irep.h>
     12#include "common.h"
    1313
    1414/**
     
    5353#define RITE_BINARY_IDENT              "RITE"
    5454#define RITE_BINARY_IDENT_LIL          "ETIR"
    55 #define RITE_BINARY_FORMAT_VER         "0003"
     55#define RITE_BINARY_FORMAT_VER         "0004"
    5656#define RITE_COMPILER_NAME             "MATZ"
    5757#define RITE_COMPILER_VERSION          "0000"
  • EcnlProtoTool/trunk/mruby-1.3.0/include/mruby/error.h

    r321 r331  
    88#define MRUBY_ERROR_H
    99
    10 #include "mruby/common.h"
     10#include "common.h"
    1111
    1212/**
     
    3232/* declaration for fail method */
    3333MRB_API mrb_value mrb_f_raise(mrb_state*, mrb_value);
     34
     35struct RBreak {
     36  MRB_OBJECT_HEADER;
     37  struct iv_tbl *iv;
     38  struct RProc *proc;
     39  mrb_value val;
     40};
    3441
    3542/**
  • EcnlProtoTool/trunk/mruby-1.3.0/include/mruby/gc.h

    r321 r331  
    88#define MRUBY_GC_H
    99
    10 #include "mruby/common.h"
     10#include "common.h"
    1111
    1212/**
     
    1818struct mrb_state;
    1919
    20 typedef void (mrb_each_object_callback)(struct mrb_state *mrb, struct RBasic *obj, void *data);
     20#define MRB_EACH_OBJ_OK 0
     21#define MRB_EACH_OBJ_BREAK 1
     22typedef int (mrb_each_object_callback)(struct mrb_state *mrb, struct RBasic *obj, void *data);
    2123void mrb_objspace_each_objects(struct mrb_state *mrb, mrb_each_object_callback *callback, void *data);
    2224MRB_API void mrb_free_context(struct mrb_state *mrb, struct mrb_context *c);
     
    6365  int interval_ratio;
    6466  int step_ratio;
     67  mrb_bool iterating     :1;
    6568  mrb_bool disabled      :1;
    6669  mrb_bool full          :1;
  • EcnlProtoTool/trunk/mruby-1.3.0/include/mruby/hash.h

    r321 r331  
    88#define MRUBY_HASH_H
    99
    10 #include "mruby/common.h"
     10#include "common.h"
     11#include <mruby/khash.h>
    1112
    1213/**
     
    2425#define mrb_hash_value(p)  mrb_obj_value((void*)(p))
    2526
    26 MRB_API mrb_value mrb_hash_new_capa(mrb_state*, int);
     27MRB_API mrb_value mrb_hash_new_capa(mrb_state*, mrb_int);
    2728
    2829/*
    2930 * Initializes a new hash.
     31 *
     32 * Equivalent to:
     33 *
     34 *      Hash.new
     35 *
     36 * @param mrb The mruby state reference.
     37 * @return The initialized hash.
    3038 */
    3139MRB_API mrb_value mrb_hash_new(mrb_state *mrb);
     
    3341/*
    3442 * Sets a keys and values to hashes.
     43 *
     44 * Equivalent to:
     45 *
     46 *      hash[key] = val
     47 *
     48 * @param mrb The mruby state reference.
     49 * @param hash The target hash.
     50 * @param key The key to set.
     51 * @param val The value to set.
     52 * @return The value.
    3553 */
    3654MRB_API void mrb_hash_set(mrb_state *mrb, mrb_value hash, mrb_value key, mrb_value val);
    3755
    3856/*
    39  * Gets a value from a key.
     57 * Gets a value from a key. If the key is not found, the default of the
     58 * hash is used.
     59 *
     60 * Equivalent to:
     61 *
     62 *     hash[key]
     63 *
     64 * @param mrb The mruby state reference.
     65 * @param hash The target hash.
     66 * @param key The key to get.
     67 * @return The found value.
    4068 */
    4169MRB_API mrb_value mrb_hash_get(mrb_state *mrb, mrb_value hash, mrb_value key);
    4270
     71/*
     72 * Gets a value from a key. If the key is not found, the default parameter is
     73 * used.
     74 *
     75 * Equivalent to:
     76 *
     77 *     hash.hash_key?(key) ? hash[key] : def
     78 *
     79 * @param mrb The mruby state reference.
     80 * @param hash The target hash.
     81 * @param key The key to get.
     82 * @param def The default value.
     83 * @return The found value.
     84 */
    4385MRB_API mrb_value mrb_hash_fetch(mrb_state *mrb, mrb_value hash, mrb_value key, mrb_value def);
    4486
    4587/*
    4688 * Deletes hash key and value pair.
     89 *
     90 * Equivalent to:
     91 *
     92 *     hash.delete(key)
     93 *
     94 * @param mrb The mruby state reference.
     95 * @param hash The target hash.
     96 * @param key The key to delete.
     97 * @return The deleted value.
    4798 */
    4899MRB_API mrb_value mrb_hash_delete_key(mrb_state *mrb, mrb_value hash, mrb_value key);
     
    50101/*
    51102 * Gets an array of keys.
     103 *
     104 * Equivalent to:
     105 *
     106 *     hash.keys
     107 *
     108 * @param mrb The mruby state reference.
     109 * @param hash The target hash.
     110 * @return An array with the keys of the hash.
    52111 */
    53112MRB_API mrb_value mrb_hash_keys(mrb_state *mrb, mrb_value hash);
    54113MRB_API mrb_value mrb_check_hash_type(mrb_state *mrb, mrb_value hash);
     114
     115/*
     116 * Check if the hash is empty
     117 *
     118 * Equivalent to:
     119 *
     120 *     hash.empty?
     121 *
     122 * @param mrb The mruby state reference.
     123 * @param self The target hash.
     124 * @return True if the hash is empty, false otherwise.
     125 */
    55126MRB_API mrb_value mrb_hash_empty_p(mrb_state *mrb, mrb_value self);
    56127
    57128/*
     129 * Gets an array of values.
     130 *
     131 * Equivalent to:
     132 *
     133 *     hash.values
     134 *
     135 * @param mrb The mruby state reference.
     136 * @param hash The target hash.
     137 * @return An array with the values of the hash.
     138 */
     139MRB_API mrb_value mrb_hash_values(mrb_state *mrb, mrb_value hash);
     140
     141/*
    58142 * Clears the hash.
     143 *
     144 * Equivalent to:
     145 *
     146 *     hash.clear
     147 *
     148 * @param mrb The mruby state reference.
     149 * @param hash The target hash.
     150 * @return The hash
    59151 */
    60152MRB_API mrb_value mrb_hash_clear(mrb_state *mrb, mrb_value hash);
     153
     154/* declaration of struct kh_ht */
     155/* be careful when you touch the internal */
     156typedef struct {
     157  mrb_value v;
     158  mrb_int n;
     159} mrb_hash_value;
     160
     161KHASH_DECLARE(ht, mrb_value, mrb_hash_value, TRUE)
    61162
    62163/* RHASH_TBL allocates st_table if not available. */
     
    67168MRB_API struct kh_ht * mrb_hash_tbl(mrb_state *mrb, mrb_value hash);
    68169
    69 #define MRB_HASH_PROC_DEFAULT 256
     170#define MRB_HASH_DEFAULT      1
     171#define MRB_HASH_PROC_DEFAULT 2
     172#define MRB_RHASH_DEFAULT_P(h) (RHASH(h)->flags & MRB_HASH_DEFAULT)
    70173#define MRB_RHASH_PROCDEFAULT_P(h) (RHASH(h)->flags & MRB_HASH_PROC_DEFAULT)
    71174
  • EcnlProtoTool/trunk/mruby-1.3.0/include/mruby/irep.h

    r321 r331  
    88#define MRUBY_IREP_H
    99
    10 #include "mruby/common.h"
    11 #include "mruby/compile.h"
     10#include "common.h"
     11#include <mruby/compile.h>
    1212
    1313/**
     
    4040  struct mrb_locals *lv;
    4141  /* debug info */
     42  mrb_bool own_filename;
    4243  const char *filename;
    4344  uint16_t *lines;
  • EcnlProtoTool/trunk/mruby-1.3.0/include/mruby/khash.h

    r321 r331  
    1010#include <string.h>
    1111
    12 #include "mruby.h"
    13 #include "mruby/common.h"
     12#include <mruby.h>
     13#include "common.h"
    1414
    1515/**
  • EcnlProtoTool/trunk/mruby-1.3.0/include/mruby/numeric.h

    r321 r331  
    88#define MRUBY_NUMERIC_H
    99
    10 #include "mruby/common.h"
     10#include "common.h"
    1111
    1212/**
     
    2121#define FIXABLE(f) (POSFIXABLE(f) && NEGFIXABLE(f))
    2222
     23#ifdef MRB_INT64
     24#define FIXABLE_FLOAT(f) FIXABLE((mrb_int)(f))
     25#else
     26#define FIXABLE_FLOAT(f) FIXABLE(f)
     27#endif
     28
    2329MRB_API mrb_value mrb_flo_to_fixnum(mrb_state *mrb, mrb_value val);
    2430MRB_API mrb_value mrb_fixnum_to_str(mrb_state *mrb, mrb_value x, int base);
     
    3238mrb_value mrb_num_div(mrb_state *mrb, mrb_value x, mrb_value y);
    3339
     40#ifndef __has_builtin
     41  #define __has_builtin(x) 0
     42#endif
     43
     44#if (defined(__GNUC__) && __GNUC__ >= 5) ||   \
     45    (__has_builtin(__builtin_add_overflow) && \
     46     __has_builtin(__builtin_sub_overflow) && \
     47     __has_builtin(__builtin_mul_overflow))
     48# define MRB_HAVE_TYPE_GENERIC_CHECKED_ARITHMETIC_BUILTINS
     49#endif
     50
     51/*
     52// Clang 3.8 and 3.9 have problem compiling mruby in 32-bit mode, when MRB_INT64 is set
     53// because of missing __mulodi4 and similar functions in its runtime. We need to use custom
     54// implementation for them.
     55*/
     56#ifdef MRB_HAVE_TYPE_GENERIC_CHECKED_ARITHMETIC_BUILTINS
     57#if defined(__clang__) && (__clang_major__ == 3) && (__clang_minor__ >= 8) && \
     58    defined(MRB_32BIT) && defined(MRB_INT64)
     59#undef MRB_HAVE_TYPE_GENERIC_CHECKED_ARITHMETIC_BUILTINS
     60#endif
     61#endif
     62
     63#ifdef MRB_HAVE_TYPE_GENERIC_CHECKED_ARITHMETIC_BUILTINS
     64
     65#ifndef MRB_WORD_BOXING
     66# define WBCHK(x) 0
     67#else
     68# define WBCHK(x) !FIXABLE(x)
     69#endif
     70
     71static inline mrb_bool
     72mrb_int_add_overflow(mrb_int augend, mrb_int addend, mrb_int *sum)
     73{
     74  return __builtin_add_overflow(augend, addend, sum) || WBCHK(*sum);
     75}
     76
     77static inline mrb_bool
     78mrb_int_sub_overflow(mrb_int minuend, mrb_int subtrahend, mrb_int *difference)
     79{
     80  return __builtin_sub_overflow(minuend, subtrahend, difference) || WBCHK(*difference);
     81}
     82
     83static inline mrb_bool
     84mrb_int_mul_overflow(mrb_int multiplier, mrb_int multiplicand, mrb_int *product)
     85{
     86  return __builtin_mul_overflow(multiplier, multiplicand, product) || WBCHK(*product);
     87}
     88
     89#undef WBCHK
     90
     91#else
     92
    3493#define MRB_UINT_MAKE2(n) uint ## n ## _t
    3594#define MRB_UINT_MAKE(n) MRB_UINT_MAKE2(n)
     
    3796
    3897#define MRB_INT_OVERFLOW_MASK ((mrb_uint)1 << (MRB_INT_BIT - 1 - MRB_FIXNUM_SHIFT))
    39 
    40 /* Idea from Potion: https://github.com/perl11/potion (MIT) */
    41 #if (defined(__clang__) && ((__clang_major__ > 3) || (__clang_major__ == 3 && __clang_minor__ >= 4))) \
    42     || (defined(__GNUC__) && __GNUC__ >= 5)
    43 
    44 static inline mrb_bool
    45 mrb_int_add_overflow(mrb_int augend, mrb_int addend, mrb_int *sum)
    46 {
    47   mrb_bool of;
    48 
    49 #ifdef MRB_INT64
    50   long long val;
    51   of = __builtin_saddll_overflow(augend, addend, &val) ||
    52 #else
    53   int val;
    54   of = __builtin_sadd_overflow(augend, addend, &val) ||
    55 #endif
    56   (val > MRB_INT_MAX) || (val < MRB_INT_MIN);
    57 
    58   *sum = (mrb_int) val;
    59   return of;
    60 }
    61 
    62 static inline mrb_bool
    63 mrb_int_sub_overflow(mrb_int minuend, mrb_int subtrahend, mrb_int *difference)
    64 {
    65   mrb_bool of;
    66 
    67 #ifdef MRB_INT64
    68   long long val;
    69   of = __builtin_ssubll_overflow(minuend, subtrahend, &val) ||
    70 #else
    71   int val;
    72   of = __builtin_ssub_overflow(minuend, subtrahend, &val) ||
    73 #endif
    74   (val > MRB_INT_MAX) || (val < MRB_INT_MIN);
    75 
    76   *difference = (mrb_int) val;
    77   return of;
    78 }
    79 #else
    8098
    8199static inline mrb_bool
     
    99117}
    100118
     119static inline mrb_bool
     120mrb_int_mul_overflow(mrb_int multiplier, mrb_int multiplicand, mrb_int *product)
     121{
     122#if MRB_INT_BIT == 32
     123  int64_t n = (int64_t)multiplier * multiplicand;
     124  *product = (mrb_int)n;
     125  return !FIXABLE(n);
     126#else
     127  if (multiplier > 0) {
     128    if (multiplicand > 0) {
     129      if (multiplier > MRB_INT_MAX / multiplicand) return TRUE;
     130    }
     131    else {
     132      if (multiplicand < MRB_INT_MAX / multiplier) return TRUE;
     133    }
     134  }
     135  else {
     136    if (multiplicand > 0) {
     137      if (multiplier < MRB_INT_MAX / multiplicand) return TRUE;
     138    }
     139    else {
     140      if (multiplier != 0 && multiplicand < MRB_INT_MAX / multiplier) return TRUE;
     141    }
     142  }
     143  *product = multiplier * multiplicand;
     144  return FALSE;
    101145#endif
     146}
    102147
    103148#undef MRB_INT_OVERFLOW_MASK
     
    106151#undef MRB_UINT_MAKE2
    107152
     153#endif
     154
    108155MRB_END_DECL
    109156
  • EcnlProtoTool/trunk/mruby-1.3.0/include/mruby/object.h

    r321 r331  
    2323#define mrb_basic_ptr(v) ((struct RBasic*)(mrb_ptr(v)))
    2424
     25#define MRB_FROZEN_P(o) ((o)->flags & MRB_FLAG_IS_FROZEN)
     26#define MRB_SET_FROZEN_FLAG(o) ((o)->flags |= MRB_FLAG_IS_FROZEN)
     27#define MRB_UNSET_FROZEN_FLAG(o) ((o)->flags &= ~MRB_FLAG_IS_FROZEN)
     28
    2529struct RObject {
    2630  MRB_OBJECT_HEADER;
  • EcnlProtoTool/trunk/mruby-1.3.0/include/mruby/opcode.h

    r321 r331  
    8383  OP_JMPNOT,/*    A sBx   if !R(A) pc+=sBx                                */
    8484  OP_ONERR,/*     sBx     rescue_push(pc+sBx)                             */
    85   OP_RESCUE,/*    A       clear(exc); R(A) := exception (ignore when A=0) */
     85  OP_RESCUE,/*    A B C   if A (if C exc=R(A) else R(A) := exc);
     86                          if B R(B) := exc.isa?(R(B)); clear(exc)         */
    8687  OP_POPERR,/*    A       A.times{rescue_pop()}                           */
    8788  OP_RAISE,/*     A       raise(R(A))                                     */
  • EcnlProtoTool/trunk/mruby-1.3.0/include/mruby/proc.h

    r321 r331  
    88#define MRUBY_PROC_H
    99
    10 #include "mruby/common.h"
    11 #include "mruby/irep.h"
     10#include "common.h"
     11#include <mruby/irep.h>
    1212
    1313/**
     
    1919  MRB_OBJECT_HEADER;
    2020  mrb_value *stack;
    21   mrb_sym mid;
    2221  ptrdiff_t cioff;
     22  union {
     23    mrb_sym mid;
     24    struct mrb_context *c;
     25  } cxt;
    2326};
    2427
     
    2730#define MRB_ENV_UNSHARE_STACK(e) ((e)->cioff = -1)
    2831#define MRB_ENV_STACK_SHARED_P(e) ((e)->cioff >= 0)
     32
     33MRB_API void mrb_env_unshare(mrb_state*, struct REnv*);
    2934
    3035struct RProc {
     
    5156#define MRB_PROC_STRICT 256
    5257#define MRB_PROC_STRICT_P(p) (((p)->flags & MRB_PROC_STRICT) != 0)
     58#define MRB_PROC_ORPHAN 512
     59#define MRB_PROC_ORPHAN_P(p) (((p)->flags & MRB_PROC_ORPHAN) != 0)
    5360
    5461#define mrb_proc_ptr(v)    ((struct RProc*)(mrb_ptr(v)))
     
    6976#define mrb_cfunc_env_get(mrb, idx) mrb_proc_cfunc_env_get(mrb, idx)
    7077
    71 #include "mruby/khash.h"
     78#include <mruby/khash.h>
    7279KHASH_DECLARE(mt, mrb_sym, struct RProc*, TRUE)
    7380
  • EcnlProtoTool/trunk/mruby-1.3.0/include/mruby/range.h

    r321 r331  
    88#define MRUBY_RANGE_H
    99
    10 #include "mruby/common.h"
     10#include "common.h"
    1111
    1212/**
     
    2626};
    2727
    28 #define mrb_range_ptr(v)    ((struct RRange*)(mrb_ptr(v)))
     28MRB_API struct RRange* mrb_range_ptr(mrb_state *mrb, mrb_value v);
     29#define mrb_range_raw_ptr(v) ((struct RRange*)mrb_ptr(v))
    2930#define mrb_range_value(p)  mrb_obj_value((void*)(p))
    3031
     
    4142MRB_API mrb_value mrb_range_new(mrb_state *mrb, mrb_value start, mrb_value end, mrb_bool exclude);
    4243
    43 MRB_API mrb_bool mrb_range_beg_len(mrb_state *mrb, mrb_value range, mrb_int *begp, mrb_int *lenp, mrb_int len);
     44MRB_API mrb_int mrb_range_beg_len(mrb_state *mrb, mrb_value range, mrb_int *begp, mrb_int *lenp, mrb_int len, mrb_bool trunc);
    4445mrb_value mrb_get_values_at(mrb_state *mrb, mrb_value obj, mrb_int olen, mrb_int argc, const mrb_value *argv, mrb_value (*func)(mrb_state*, mrb_value, mrb_int));
    4546
  • EcnlProtoTool/trunk/mruby-1.3.0/include/mruby/re.h

    r321 r331  
    88#define MRUBY_RE_H
    99
    10 #ifdef __cplusplus
    11 extern "C" {
    12 #endif
     10MRB_BEGIN_DECL
    1311
    1412#define REGEXP_CLASS          "Regexp"
    1513
    16 #ifdef __cplusplus
    17 }
    18 #endif
     14MRB_END_DECL
    1915
    2016#endif  /* RE_H */
  • EcnlProtoTool/trunk/mruby-1.3.0/include/mruby/string.h

    r321 r331  
    88#define MRUBY_STRING_H
    99
    10 #include "mruby/common.h"
     10#include "common.h"
    1111
    1212/**
     
    4545  if (RSTR_EMBED_P(s)) {\
    4646    RSTR_SET_EMBED_LEN((s),(n));\
    47   } else {\
     47  }\
     48  else {\
    4849    s->as.heap.len = (mrb_int)(n);\
    4950  }\
     
    6364#define RSTR_UNSET_NOFREE_FLAG(s) ((s)->flags &= ~MRB_STR_NOFREE)
    6465
    65 #define RSTR_FROZEN_P(s) ((s)->flags & MRB_STR_FROZEN)
    66 #define RSTR_SET_FROZEN_FLAG(s) ((s)->flags |= MRB_STR_FROZEN)
    67 #define RSTR_UNSET_FROZEN_FLAG(s) ((s)->flags &= ~MRB_STR_FROZEN)
    68 
    6966/*
    7067 * Returns a pointer from a Ruby string
     
    7370#define RSTRING(s)           mrb_str_ptr(s)
    7471#define RSTRING_PTR(s)       RSTR_PTR(RSTRING(s))
    75 #define RSTRING_EMBED_LEN(s) RSTR_ENBED_LEN(RSTRING(s))
     72#define RSTRING_EMBED_LEN(s) RSTR_EMBED_LEN(RSTRING(s))
    7673#define RSTRING_LEN(s)       RSTR_LEN(RSTRING(s))
    7774#define RSTRING_CAPA(s)      RSTR_CAPA(RSTRING(s))
    7875#define RSTRING_END(s)       (RSTRING_PTR(s) + RSTRING_LEN(s))
    79 mrb_int mrb_str_strlen(mrb_state*, struct RString*);
     76MRB_API mrb_int mrb_str_strlen(mrb_state*, struct RString*);
    8077
    8178#define MRB_STR_SHARED    1
    8279#define MRB_STR_NOFREE    2
    83 #define MRB_STR_FROZEN    4
    84 #define MRB_STR_EMBED     8
    85 #define MRB_STR_EMBED_LEN_MASK 0x1f0
    86 #define MRB_STR_EMBED_LEN_SHIFT 4
     80#define MRB_STR_NO_UTF    8
     81#define MRB_STR_EMBED    16
     82#define MRB_STR_EMBED_LEN_MASK 0x3e0
     83#define MRB_STR_EMBED_LEN_SHIFT 5
    8784
    8885void mrb_gc_free_str(mrb_state*, struct RString*);
    8986MRB_API void mrb_str_modify(mrb_state*, struct RString*);
     87/*
     88 * Appends self to other. Returns self as a concatnated string.
     89 *
     90 *
     91 *  Example:
     92 *
     93 *     !!!c
     94 *     int
     95 *     main(int argc,
     96 *          char **argv)
     97 *     {
     98 *       // Variable declarations.
     99 *       mrb_value str1;
     100 *       mrb_value str2;
     101 *
     102 *       mrb_state *mrb = mrb_open();
     103 *       if (!mrb)
     104 *       {
     105 *          // handle error
     106 *       }
     107 *
     108 *       // Creates new Ruby strings.
     109 *       str1 = mrb_str_new_lit(mrb, "abc");
     110 *       str2 = mrb_str_new_lit(mrb, "def");
     111 *
     112 *       // Concatnates str2 to str1.
     113 *       mrb_str_concat(mrb, str1, str2);
     114 *
     115 *      // Prints new Concatnated Ruby string.
     116 *      mrb_p(mrb, str1);
     117 *
     118 *      mrb_close(mrb);
     119 *      return 0;
     120 *    }
     121 *
     122 *
     123 *  Result:
     124 *
     125 *     => "abcdef"
     126 *
     127 * @param [mrb_state] mrb The current mruby state.
     128 * @param [mrb_value] self String to concatenate.
     129 * @param [mrb_value] other String to append to self.
     130 * @return [mrb_value] Returns a new String appending other to self.
     131 */
    90132MRB_API void mrb_str_concat(mrb_state*, mrb_value, mrb_value);
    91133
    92134/*
    93135 * Adds two strings together.
     136 *
     137 *
     138 *  Example:
     139 *
     140 *     !!!c
     141 *     int
     142 *     main(int argc,
     143 *          char **argv)
     144 *     {
     145 *       // Variable declarations.
     146 *       mrb_value a;
     147 *       mrb_value b;
     148 *       mrb_value c;
     149 *
     150 *       mrb_state *mrb = mrb_open();
     151 *       if (!mrb)
     152 *       {
     153 *          // handle error
     154 *       }
     155 *
     156 *       // Creates two Ruby strings from the passed in C strings.
     157 *       a = mrb_str_new_lit(mrb, "abc");
     158 *       b = mrb_str_new_lit(mrb, "def");
     159 *
     160 *       // Prints both C strings.
     161 *       mrb_p(mrb, a);
     162 *       mrb_p(mrb, b);
     163 *
     164 *       // Concatnates both Ruby strings.
     165 *       c = mrb_str_plus(mrb, a, b);
     166 *
     167 *      // Prints new Concatnated Ruby string.
     168 *      mrb_p(mrb, c);
     169 *
     170 *      mrb_close(mrb);
     171 *      return 0;
     172 *    }
     173 *
     174 *
     175 *  Result:
     176 *
     177 *     => "abc"  # First string
     178 *     => "def"  # Second string
     179 *     => "abcdef" # First & Second concatnated.
     180 *
     181 * @param [mrb_state] mrb The current mruby state.
     182 * @param [mrb_value] a First string to concatenate.
     183 * @param [mrb_value] b Second string to concatenate.
     184 * @return [mrb_value] Returns a new String containing a concatenated to b.
    94185 */
    95186MRB_API mrb_value mrb_str_plus(mrb_state*, mrb_value, mrb_value);
     
    97188/*
    98189 * Converts pointer into a Ruby string.
     190 *
     191 * @param [mrb_state] mrb The current mruby state.
     192 * @param [void*] p The pointer to convert to Ruby string.
     193 * @return [mrb_value] Returns a new Ruby String.
    99194 */
    100195MRB_API mrb_value mrb_ptr_to_str(mrb_state *, void*);
     
    102197/*
    103198 * Returns an object as a Ruby string.
     199 *
     200 * @param [mrb_state] mrb The current mruby state.
     201 * @param [mrb_value] obj An object to return as a Ruby string.
     202 * @return [mrb_value] An object as a Ruby string.
    104203 */
    105204MRB_API mrb_value mrb_obj_as_string(mrb_state *mrb, mrb_value obj);
    106205
    107206/*
    108  * Resizes the string's length.
     207 * Resizes the string's length. Returns the amount of characters
     208 * in the specified by len.
     209 *
     210 * Example:
     211 *
     212 *     !!!c
     213 *     int
     214 *     main(int argc,
     215 *          char **argv)
     216 *     {
     217 *         // Variable declaration.
     218 *         mrb_value str;
     219 *
     220 *         mrb_state *mrb = mrb_open();
     221 *         if (!mrb)
     222 *         {
     223 *            // handle error
     224 *         }
     225 *         // Creates a new string.
     226 *         str = mrb_str_new_lit(mrb, "Hello, world!");
     227 *         // Returns 5 characters of
     228 *         mrb_str_resize(mrb, str, 5);
     229 *         mrb_p(mrb, str);
     230 *
     231 *         mrb_close(mrb);
     232 *         return 0;
     233 *      }
     234 *
     235 * Result:
     236 *
     237 *     => "Hello"
     238 *
     239 * @param [mrb_state] mrb The current mruby state.
     240 * @param [mrb_value] str The Ruby string to resize.
     241 * @param [mrb_value] len The length.
     242 * @return [mrb_value] An object as a Ruby string.
    109243 */
    110244MRB_API mrb_value mrb_str_resize(mrb_state *mrb, mrb_value str, mrb_int len);
     
    112246/*
    113247 * Returns a sub string.
     248 *
     249 *  Example:
     250 *
     251 *     !!!c
     252 *     int
     253 *     main(int argc,
     254 *     char const **argv)
     255 *     {
     256 *       // Variable declarations.
     257 *       mrb_value str1;
     258 *       mrb_value str2;
     259 *
     260 *       mrb_state *mrb = mrb_open();
     261 *       if (!mrb)
     262 *       {
     263 *         // handle error
     264 *       }
     265 *       // Creates new string.
     266 *       str1 = mrb_str_new_lit(mrb, "Hello, world!");
     267 *       // Returns a sub-string within the range of 0..2
     268 *       str2 = mrb_str_substr(mrb, str1, 0, 2);
     269 *
     270 *       // Prints sub-string.
     271 *       mrb_p(mrb, str2);
     272 *
     273 *       mrb_close(mrb);
     274 *       return 0;
     275 *     }
     276 *
     277 *  Result:
     278 *
     279 *     => "He"
     280 *
     281 * @param [mrb_state] mrb The current mruby state.
     282 * @param [mrb_value] str Ruby string.
     283 * @param [mrb_int] beg The beginning point of the sub-string.
     284 * @param [mrb_int] len The end point of the sub-string.
     285 * @return [mrb_value] An object as a Ruby sub-string.
    114286 */
    115287MRB_API mrb_value mrb_str_substr(mrb_state *mrb, mrb_value str, mrb_int beg, mrb_int len);
     
    117289/*
    118290 * Returns a Ruby string type.
     291 *
     292 *
     293 * @param [mrb_state] mrb The current mruby state.
     294 * @param [mrb_value] str Ruby string.
     295 * @return [mrb_value] A Ruby string.
    119296 */
    120297MRB_API mrb_value mrb_string_type(mrb_state *mrb, mrb_value str);
     
    124301
    125302MRB_API const char *mrb_string_value_cstr(mrb_state *mrb, mrb_value *ptr);
    126 MRB_API const char *mrb_string_value_ptr(mrb_state *mrb, mrb_value ptr);
     303MRB_API const char *mrb_string_value_ptr(mrb_state *mrb, mrb_value str);
     304/*
     305 * Returns the length of the Ruby string.
     306 *
     307 *
     308 * @param [mrb_state] mrb The current mruby state.
     309 * @param [mrb_value] str Ruby string.
     310 * @return [mrb_int] The length of the passed in Ruby string.
     311 */
     312MRB_API mrb_int mrb_string_value_len(mrb_state *mrb, mrb_value str);
    127313
    128314/*
    129315 * Duplicates a string object.
     316 *
     317 *
     318 * @param [mrb_state] mrb The current mruby state.
     319 * @param [mrb_value] str Ruby string.
     320 * @return [mrb_value] Duplicated Ruby string.
    130321 */
    131322MRB_API mrb_value mrb_str_dup(mrb_state *mrb, mrb_value str);
    132323
    133324/*
    134  * Returns a symbol from a passed in string.
     325 * Returns a symbol from a passed in Ruby string.
     326 *
     327 * @param [mrb_state] mrb The current mruby state.
     328 * @param [mrb_value] self Ruby string.
     329 * @return [mrb_value] A symbol.
    135330 */
    136331MRB_API mrb_value mrb_str_intern(mrb_state *mrb, mrb_value self);
     
    146341/*
    147342 * Returns true if the strings match and false if the strings don't match.
     343 *
     344 * @param [mrb_state] mrb The current mruby state.
     345 * @param [mrb_value] str1 Ruby string to compare.
     346 * @param [mrb_value] str2 Ruby string to compare.
     347 * @return [mrb_value] boolean value.
    148348 */
    149349MRB_API mrb_bool mrb_str_equal(mrb_state *mrb, mrb_value str1, mrb_value str2);
     
    152352 * Returns a concated string comprised of a Ruby string and a C string.
    153353 *
     354 * @param [mrb_state] mrb The current mruby state.
     355 * @param [mrb_value] str Ruby string.
     356 * @param [const char *] ptr A C string.
     357 * @param [size_t] len length of C string.
     358 * @return [mrb_value] A Ruby string.
    154359 * @see mrb_str_cat_cstr
    155360 */
     
    159364 * Returns a concated string comprised of a Ruby string and a C string.
    160365 *
     366 * @param [mrb_state] mrb The current mruby state.
     367 * @param [mrb_value] str Ruby string.
     368 * @param [const char *] ptr A C string.
     369 * @return [mrb_value] A Ruby string.
    161370 * @see mrb_str_cat
    162371 */
     
    176385
    177386/*
    178  * Returns a C string from a Ruby string.
     387 * Returns a newly allocated C string from a Ruby string.
     388 * This is an utility function to pass a Ruby string to C library functions.
     389 *
     390 * - Returned string does not contain any NUL characters (but terminator).
     391 * - It raises an ArgumentError exception if Ruby string contains
     392 *   NUL characters.
     393 * - Retured string will be freed automatically on next GC.
     394 * - Caller can modify returned string without affecting Ruby string
     395 *   (e.g. it can be used for mkstemp(3)).
     396 *
     397 * @param [mrb_state *] mrb The current mruby state.
     398 * @param [mrb_value] str Ruby string. Must be an instance of String.
     399 * @return [char *] A newly allocated C string.
    179400 */
    180401MRB_API char *mrb_str_to_cstr(mrb_state *mrb, mrb_value str);
  • EcnlProtoTool/trunk/mruby-1.3.0/include/mruby/throw.h

    r321 r331  
    88#define MRB_THROW_H
    99
    10 #ifdef MRB_ENABLE_CXX_EXCEPTION
     10#if defined(MRB_ENABLE_CXX_ABI)
     11# if !defined(__cplusplus)
     12#  error Trying to use C++ exception handling in C code
     13# endif
     14#endif
     15
     16#if defined(MRB_ENABLE_CXX_EXCEPTION) && defined(__cplusplus)
    1117
    1218#define MRB_TRY(buf) do { try {
     
    2127#include <setjmp.h>
    2228
    23 #define MRB_TRY(buf) do { if (setjmp((buf)->impl) == 0) {
     29#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
     30#define MRB_SETJMP _setjmp
     31#define MRB_LONGJMP _longjmp
     32#else
     33#define MRB_SETJMP setjmp
     34#define MRB_LONGJMP longjmp
     35#endif
     36
     37#define MRB_TRY(buf) do { if (MRB_SETJMP((buf)->impl) == 0) {
    2438#define MRB_CATCH(buf) } else {
    2539#define MRB_END_EXC(buf) } } while(0)
    2640
    27 #define MRB_THROW(buf) longjmp((buf)->impl, 1);
     41#define MRB_THROW(buf) MRB_LONGJMP((buf)->impl, 1);
    2842#define mrb_jmpbuf_impl jmp_buf
    2943
     
    3347  mrb_jmpbuf_impl impl;
    3448
    35 #ifdef MRB_ENABLE_CXX_EXCEPTION
     49#if defined(MRB_ENABLE_CXX_EXCEPTION) && defined(__cplusplus)
    3650  static mrb_int jmpbuf_id;
    3751  mrb_jmpbuf() : impl(jmpbuf_id++) {}
  • EcnlProtoTool/trunk/mruby-1.3.0/include/mruby/value.h

    r321 r331  
    88#define MRUBY_VALUE_H
    99
    10 #include "mruby/common.h"
     10#include "common.h"
    1111
    1212/**
     
    2121#if defined(MRB_INT16) && defined(MRB_INT64)
    2222# error "You can't define MRB_INT16 and MRB_INT64 at the same time."
     23#endif
     24
     25#if defined _MSC_VER && _MSC_VER < 1800
     26# define PRIo64 "llo"
     27# define PRId64 "lld"
     28# define PRIx64 "llx"
     29# define PRIo16 "ho"
     30# define PRId16 "hd"
     31# define PRIx16 "hx"
     32# define PRIo32 "o"
     33# define PRId32 "d"
     34# define PRIx32 "x"
     35#else
     36# include <inttypes.h>
    2337#endif
    2438
     
    2842# define MRB_INT_MIN (INT64_MIN>>MRB_FIXNUM_SHIFT)
    2943# define MRB_INT_MAX (INT64_MAX>>MRB_FIXNUM_SHIFT)
     44# define MRB_PRIo PRIo64
     45# define MRB_PRId PRId64
     46# define MRB_PRIx PRIx64
    3047#elif defined(MRB_INT16)
    3148  typedef int16_t mrb_int;
     
    3350# define MRB_INT_MIN (INT16_MIN>>MRB_FIXNUM_SHIFT)
    3451# define MRB_INT_MAX (INT16_MAX>>MRB_FIXNUM_SHIFT)
     52# define MRB_PRIo PRIo16
     53# define MRB_PRId PRId16
     54# define MRB_PRIx PRIx16
    3555#else
    3656  typedef int32_t mrb_int;
     
    3858# define MRB_INT_MIN (INT32_MIN>>MRB_FIXNUM_SHIFT)
    3959# define MRB_INT_MAX (INT32_MAX>>MRB_FIXNUM_SHIFT)
    40 #endif
    41 
     60# define MRB_PRIo PRIo32
     61# define MRB_PRId PRId32
     62# define MRB_PRIx PRIx32
     63#endif
     64
     65
     66MRB_API double mrb_float_read(const char*, char**);
    4267#ifdef MRB_USE_FLOAT
    4368  typedef float mrb_float;
    44 # define str_to_mrb_float(buf) strtof(buf, NULL)
    4569#else
    4670  typedef double mrb_float;
    47 # define str_to_mrb_float(buf) strtod(buf, NULL)
    4871#endif
    4972
     
    6386#  define isinf(n) (!_finite(n) && !_isnan(n))
    6487#  define signbit(n) (_copysign(1.0, (n)) < 0.0)
    65 #  define strtof (float)strtod
    6688static const unsigned int IEEE754_INFINITY_BITS_SINGLE = 0x7F800000;
    6789#  define INFINITY (*(float *)&IEEE754_INFINITY_BITS_SINGLE)
     
    94116  MRB_TT_DATA,        /*  21 */
    95117  MRB_TT_FIBER,       /*  22 */
    96   MRB_TT_MAXDEFINE    /*  23 */
     118  MRB_TT_ISTRUCT,     /*  23 */
     119  MRB_TT_BREAK,       /*  24 */
     120  MRB_TT_MAXDEFINE    /*  25 */
    97121};
    98122
    99 #include "mruby/object.h"
     123#include <mruby/object.h>
    100124
    101125#ifdef MRB_DOCUMENTATION_BLOCK
     
    188212  mrb_value v;
    189213  SET_OBJ_VALUE(v, (struct RBasic*)p);
     214  mrb_assert(p == mrb_ptr(v));
     215  mrb_assert(((struct RBasic*)p)->tt == mrb_type(v));
    190216  return v;
    191217}
     
    242268
    243269#ifdef MRB_USE_ETEXT_EDATA
     270#if (defined(__APPLE__) && defined(__MACH__))
     271#include <mach-o/getsect.h>
     272static inline mrb_bool
     273mrb_ro_data_p(const char *p)
     274{
     275  return (const char*)get_etext() < p && p < (const char*)get_edata();
     276}
     277#else
    244278extern char _etext[];
    245279#ifdef MRB_NO_INIT_ARRAY_START
     
    260294}
    261295#endif
     296#endif
    262297#else
    263298# define mrb_ro_data_p(p) FALSE
  • EcnlProtoTool/trunk/mruby-1.3.0/include/mruby/variable.h

    r321 r331  
    88#define MRUBY_VARIABLE_H
    99
    10 #include "mruby/common.h"
     10#include "common.h"
    1111
    1212/**
     
    5555MRB_API void mrb_iv_copy(mrb_state *mrb, mrb_value dst, mrb_value src);
    5656MRB_API mrb_bool mrb_const_defined_at(mrb_state *mrb, mrb_value mod, mrb_sym id);
     57
     58/**
     59 * Get a global variable. Will return nil if the var does not exist
     60 *
     61 * Example:
     62 *
     63 *     !!!ruby
     64 *     # Ruby style
     65 *     var = $value
     66 *
     67 *     !!!c
     68 *     // C style
     69 *     mrb_sym sym = mrb_intern_lit(mrb, "$value");
     70 *     mrb_value var = mrb_gv_get(mrb, sym);
     71 *
     72 * @param mrb The mruby state reference
     73 * @param sym The name of the global variable
     74 * @return The value of that global variable. May be nil
     75 */
    5776MRB_API mrb_value mrb_gv_get(mrb_state *mrb, mrb_sym sym);
     77
     78/**
     79 * Set a global variable
     80 *
     81 * Example:
     82 *
     83 *     !!!ruby
     84 *     # Ruby style
     85 *     $value = "foo"
     86 *
     87 *     !!!c
     88 *     // C style
     89 *     mrb_sym sym = mrb_intern_lit(mrb, "$value");
     90 *     mrb_gv_set(mrb, sym, mrb_str_new_lit("foo"));
     91 *
     92 * @param mrb The mruby state reference
     93 * @param sym The name of the global variable
     94 * @param val The value of the global variable
     95 */
    5896MRB_API void mrb_gv_set(mrb_state *mrb, mrb_sym sym, mrb_value val);
     97
     98/**
     99 * Remove a global variable.
     100 *
     101 * Example:
     102 *
     103 *     !!!ruby
     104 *     # Ruby style
     105 *     $value = nil
     106 *
     107 *     !!!c
     108 *     // C style
     109 *     mrb_sym sym = mrb_intern_lit(mrb, "$value");
     110 *     mrb_gv_remove(mrb, sym);
     111 *
     112 * @param mrb The mruby state reference
     113 * @param sym The name of the global variable
     114 * @param val The value of the global variable
     115 */
    59116MRB_API void mrb_gv_remove(mrb_state *mrb, mrb_sym sym);
     117
    60118MRB_API mrb_value mrb_cv_get(mrb_state *mrb, mrb_value mod, mrb_sym sym);
    61119MRB_API void mrb_mod_cv_set(mrb_state *mrb, struct RClass * c, mrb_sym sym, mrb_value v);
  • EcnlProtoTool/trunk/mruby-1.3.0/include/mruby/version.h

    r321 r331  
    88#define MRUBY_VERSION_H
    99
    10 #include "mruby/common.h"
     10#include "common.h"
    1111
    1212/**
     
    4343 * Minor release version number.
    4444 */
    45 #define MRUBY_RELEASE_MINOR 2
     45#define MRUBY_RELEASE_MINOR 3
    4646
    4747/*
     
    6363 * Release year.
    6464 */
    65 #define MRUBY_RELEASE_YEAR 2015
     65#define MRUBY_RELEASE_YEAR 2017
    6666
    6767/*
    6868 * Release month.
    6969 */
    70 #define MRUBY_RELEASE_MONTH 11
     70#define MRUBY_RELEASE_MONTH 7
    7171
    7272/*
    7373 * Release day.
    7474 */
    75 #define MRUBY_RELEASE_DAY 17
     75#define MRUBY_RELEASE_DAY 4
    7676
    7777/*
Note: See TracChangeset for help on using the changeset viewer.