Changeset 439 for EcnlProtoTool/trunk/mruby-2.1.1/include
- Timestamp:
- Jul 9, 2020, 8:51:43 AM (4 years ago)
- Location:
- EcnlProtoTool/trunk/mruby-2.1.1
- Files:
-
- 1 added
- 29 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
EcnlProtoTool/trunk/mruby-2.1.1/include/mrbconf.h
r331 r439 29 29 //#define MRB_USE_FLOAT 30 30 31 /* add -DMRB_INT16 to use 16bit integer for mrb_int; conflict with MRB_INT64 */ 32 //#define MRB_INT16 33 34 /* add -DMRB_INT64 to use 64bit integer for mrb_int; conflict with MRB_INT16 */ 31 /* exclude floating point numbers */ 32 //#define MRB_WITHOUT_FLOAT 33 34 /* add -DMRB_METHOD_CACHE to use method cache to improve performance */ 35 //#define MRB_METHOD_CACHE 36 /* size of the method cache (need to be the power of 2) */ 37 //#define MRB_METHOD_CACHE_SIZE (1<<7) 38 39 /* add -DMRB_METHOD_T_STRUCT on machines that use higher bits of pointers */ 40 /* no MRB_METHOD_T_STRUCT requires highest 2 bits of function pointers to be zero */ 41 #ifndef MRB_METHOD_T_STRUCT 42 // can't use highest 2 bits of function pointers on 32bit Windows. 43 # if defined(_WIN32) && !defined(_WIN64) 44 # define MRB_METHOD_T_STRUCT 45 # endif 46 #endif 47 48 /* add -DMRB_INT32 to use 32bit integer for mrb_int; conflict with MRB_INT64; 49 Default for 32-bit CPU mode. */ 50 //#define MRB_INT32 51 52 /* add -DMRB_INT64 to use 64bit integer for mrb_int; conflict with MRB_INT32; 53 Default for 64-bit CPU mode. */ 35 54 //#define MRB_INT64 36 55 37 /* represent mrb_value in boxed double; conflict with MRB_USE_FLOAT */ 56 /* if no specific integer type is chosen */ 57 #if !defined(MRB_INT32) && !defined(MRB_INT64) 58 # if defined(MRB_64BIT) && !defined(MRB_NAN_BOXING) 59 /* Use 64bit integers on 64bit architecture (without MRB_NAN_BOXING) */ 60 # define MRB_INT64 61 # else 62 /* Otherwise use 32bit integers */ 63 # define MRB_INT32 64 # endif 65 #endif 66 67 /* define on big endian machines; used by MRB_NAN_BOXING, etc. */ 68 #ifndef MRB_ENDIAN_BIG 69 # if (defined(BYTE_ORDER) && defined(BIG_ENDIAN) && BYTE_ORDER == BIG_ENDIAN) || \ 70 (defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) 71 # define MRB_ENDIAN_BIG 72 # endif 73 #endif 74 75 /* represent mrb_value in boxed double; conflict with MRB_USE_FLOAT and MRB_WITHOUT_FLOAT */ 38 76 //#define MRB_NAN_BOXING 39 40 /* define on big endian machines; used by MRB_NAN_BOXING */41 //#define MRB_ENDIAN_BIG42 77 43 78 /* represent mrb_value as a word (natural unit of data for the processor) */ … … 53 88 //#define MRB_HEAP_PAGE_SIZE 1024 54 89 55 /* use segmented list for IV table */ 56 //#define MRB_USE_IV_SEGLIST 57 58 /* initial size for IV khash; ignored when MRB_USE_IV_SEGLIST is set */ 59 //#define MRB_IVHASH_INIT_SIZE 8 60 61 /* if _etext and _edata available, mruby can reduce memory used by symbols */ 62 //#define MRB_USE_ETEXT_EDATA 63 64 /* do not use __init_array_start to determine readonly data section; 65 effective only when MRB_USE_ETEXT_EDATA is defined */ 66 //#define MRB_NO_INIT_ARRAY_START 90 /* if __ehdr_start is available, mruby can reduce memory used by symbols */ 91 //#define MRB_USE_LINK_TIME_RO_DATA_P 92 93 /* if MRB_USE_LINK_TIME_RO_DATA_P does not work, 94 you can try mrb_ro_data_p() that you have implemented yourself in any file; 95 prototype is `mrb_bool mrb_ro_data_p(const char *ptr)` */ 96 //#define MRB_USE_CUSTOM_RO_DATA_P 67 97 68 98 /* turn off generational GC by default */ … … 94 124 95 125 /* -DMRB_DISABLE_XXXX to drop following features */ 96 //#define MRB_DISABLE_STDIO 126 //#define MRB_DISABLE_STDIO /* use of stdio */ 97 127 98 128 /* -DMRB_ENABLE_XXXX to enable following features */ 99 //#define MRB_ENABLE_DEBUG_HOOK /* hooks for debugger */ 129 //#define MRB_ENABLE_DEBUG_HOOK /* hooks for debugger */ 130 //#define MRB_ENABLE_ALL_SYMBOLS /* Symbols.all_symbols */ 100 131 101 132 /* end of configuration */ … … 123 154 #endif 124 155 156 /* 157 ** mruby tuning profiles 158 **/ 159 160 /* A profile for micro controllers */ 161 #if defined(MRB_CONSTRAINED_BASELINE_PROFILE) 162 # ifndef KHASH_DEFAULT_SIZE 163 # define KHASH_DEFAULT_SIZE 16 164 # endif 165 166 # ifndef MRB_STR_BUF_MIN_SIZE 167 # define MRB_STR_BUF_MIN_SIZE 32 168 # endif 169 170 # ifndef MRB_HEAP_PAGE_SIZE 171 # define MRB_HEAP_PAGE_SIZE 256 172 # endif 173 174 /* A profile for default mruby */ 175 #elif defined(MRB_BASELINE_PROFILE) 176 177 /* A profile for desktop computers or workstations; rich memory! */ 178 #elif defined(MRB_MAIN_PROFILE) 179 # ifndef MRB_METHOD_CACHE 180 # define MRB_METHOD_CACHE 181 # endif 182 183 # ifndef MRB_METHOD_CACHE_SIZE 184 # define MRB_METHOD_CACHE_SIZE (1<<10) 185 # endif 186 187 # ifndef MRB_IV_SEGMENT_SIZE 188 # define MRB_IV_SEGMENT_SIZE 32 189 # endif 190 191 # ifndef MRB_HEAP_PAGE_SIZE 192 # define MRB_HEAP_PAGE_SIZE 4096 193 # endif 194 195 /* A profile for server; mruby vm is long life */ 196 #elif defined(MRB_HIGH_PROFILE) 197 # ifndef MRB_METHOD_CACHE 198 # define MRB_METHOD_CACHE 199 # endif 200 201 # ifndef MRB_METHOD_CACHE_SIZE 202 # define MRB_METHOD_CACHE_SIZE (1<<12) 203 # endif 204 205 # ifndef MRB_IV_SEGMENT_SIZE 206 # define MRB_IV_SEGMENT_SIZE 64 207 # endif 208 209 # ifndef MRB_HEAP_PAGE_SIZE 210 # define MRB_HEAP_PAGE_SIZE 4096 211 # endif 212 #endif 213 125 214 #endif /* MRUBYCONF_H */ -
EcnlProtoTool/trunk/mruby-2.1.1/include/mruby.h
r331 r439 2 2 ** mruby - An embeddable Ruby implementation 3 3 ** 4 ** Copyright (c) mruby developers 2010-20 174 ** Copyright (c) mruby developers 2010-2020 5 5 ** 6 6 ** Permission is hereby granted, free of charge, to any person obtaining … … 26 26 */ 27 27 28 /** 29 * @file mruby.h 30 */ 31 28 32 #ifndef MRUBY_H 29 33 #define MRUBY_H … … 35 39 #endif 36 40 41 #include <stdarg.h> 37 42 #include <stdint.h> 38 43 #include <stddef.h> … … 58 63 #endif 59 64 60 #if __STDC_VERSION__ >= 201112L65 #if defined __STDC_VERSION__ && __STDC_VERSION__ >= 201112L 61 66 #define mrb_static_assert(exp, str) _Static_assert(exp, str) 62 67 #else … … 65 70 66 71 #include "mrbconf.h" 72 73 #include <mruby/common.h> 74 #include <mruby/value.h> 75 #include <mruby/gc.h> 76 #include <mruby/version.h> 77 78 #ifdef _MSC_VER 79 #include <float.h> 80 #endif 81 82 #ifndef MRB_WITHOUT_FLOAT 83 #ifndef FLT_EPSILON 84 #define FLT_EPSILON (1.19209290e-07f) 85 #endif 86 #ifndef DBL_EPSILON 87 #define DBL_EPSILON ((double)2.22044604925031308085e-16L) 88 #endif 89 #ifndef LDBL_EPSILON 90 #define LDBL_EPSILON (1.08420217248550443401e-19L) 91 #endif 67 92 68 93 #ifdef MRB_USE_FLOAT … … 71 96 #define MRB_FLOAT_EPSILON DBL_EPSILON 72 97 #endif 73 74 #include "mruby/common.h" 75 #include <mruby/value.h> 76 #include <mruby/gc.h> 77 #include <mruby/version.h> 98 #endif 78 99 79 100 /** … … 82 103 MRB_BEGIN_DECL 83 104 84 typedef uint32_t mrb_code; 85 86 /** 87 * Required arguments signature type. 105 typedef uint8_t mrb_code; 106 107 /** 108 * \class mrb_aspec 109 * 110 * Specifies the number of arguments a function takes 111 * 112 * Example: `MRB_ARGS_REQ(2) | MRB_ARGS_OPT(1)` for a method that expects 2..3 arguments 88 113 */ 89 114 typedef uint32_t mrb_aspec; 90 91 115 92 116 struct mrb_irep; … … 112 136 struct RProc *proc; 113 137 mrb_value *stackent; 114 int nregs; 115 int ridx; 116 int epos; 138 uint16_t ridx; 139 uint16_t epos; 117 140 struct REnv *env; 118 mrb_code *pc;/* return address */119 mrb_code *err;/* error position */141 const mrb_code *pc; /* return address */ 142 const mrb_code *err; /* error position */ 120 143 int argc; 121 144 int acc; … … 141 164 mrb_callinfo *cibase, *ciend; 142 165 143 mrb_code **rescue;/* exception handler stack */144 int rsize;166 uint16_t *rescue; /* exception handler stack */ 167 uint16_t rsize; 145 168 struct RProc **ensure; /* ensure handler stack */ 146 int esize, eidx;169 uint16_t esize, eidx; 147 170 148 171 enum mrb_fiber_state status; … … 151 174 }; 152 175 176 #ifdef MRB_METHOD_CACHE_SIZE 177 # define MRB_METHOD_CACHE 178 #else 179 /* default method cache size: 128 */ 180 /* cache size needs to be power of 2 */ 181 # define MRB_METHOD_CACHE_SIZE (1<<7) 182 #endif 183 184 /** 185 * Function pointer type for a function callable by mruby. 186 * 187 * The arguments to the function are stored on the mrb_state. To get them see mrb_get_args 188 * 189 * @param mrb The mruby state 190 * @param self The self object 191 * @return [mrb_value] The function's return value 192 */ 193 typedef mrb_value (*mrb_func_t)(struct mrb_state *mrb, mrb_value self); 194 195 #ifndef MRB_METHOD_T_STRUCT 196 typedef uintptr_t mrb_method_t; 197 #else 198 typedef struct { 199 uint8_t flags; 200 union { 201 struct RProc *proc; 202 mrb_func_t func; 203 }; 204 } mrb_method_t; 205 #endif 206 207 #ifdef MRB_METHOD_CACHE 208 struct mrb_cache_entry { 209 struct RClass *c, *c0; 210 mrb_sym mid; 211 mrb_method_t m; 212 }; 213 #endif 214 153 215 struct mrb_jmpbuf; 154 216 155 217 typedef void (*mrb_atexit_func)(struct mrb_state*); 156 157 #define MRB_STATE_NO_REGEXP 1158 #define MRB_STATE_REGEXP 2159 218 160 219 typedef struct mrb_state { 161 220 struct mrb_jmpbuf *jmp; 162 221 163 uint32_t flags;164 222 mrb_allocf allocf; /* memory allocation function */ 165 223 void *allocf_ud; /* auxiliary data of allocf */ … … 179 237 struct RClass *array_class; 180 238 struct RClass *hash_class; 181 239 struct RClass *range_class; 240 241 #ifndef MRB_WITHOUT_FLOAT 182 242 struct RClass *float_class; 243 #endif 183 244 struct RClass *fixnum_class; 184 245 struct RClass *true_class; … … 188 249 struct RClass *kernel_module; 189 250 190 struct alloca_header *mems;191 251 mrb_gc gc; 192 252 253 #ifdef MRB_METHOD_CACHE 254 struct mrb_cache_entry cache[MRB_METHOD_CACHE_SIZE]; 255 #endif 256 193 257 mrb_sym symidx; 194 struct kh_n2s *name2sym; /* symbol hash */195 258 struct symbol_name *symtbl; /* symbol table */ 259 mrb_sym symhash[256]; 196 260 size_t symcapa; 261 #ifndef MRB_ENABLE_SYMBOLL_ALL 262 char symbuf[8]; /* buffer for small symbol names */ 263 #endif 197 264 198 265 #ifdef MRB_ENABLE_DEBUG_HOOK 199 void (*code_fetch_hook)(struct mrb_state* mrb, struct mrb_irep *irep, mrb_code *pc, mrb_value *regs);200 void (*debug_op_hook)(struct mrb_state* mrb, struct mrb_irep *irep, mrb_code *pc, mrb_value *regs);266 void (*code_fetch_hook)(struct mrb_state* mrb, struct mrb_irep *irep, const mrb_code *pc, mrb_value *regs); 267 void (*debug_op_hook)(struct mrb_state* mrb, struct mrb_irep *irep, const mrb_code *pc, mrb_value *regs); 201 268 #endif 202 269 … … 220 287 mrb_atexit_func *atexit_stack; 221 288 #endif 222 mrb_int atexit_stack_len; 289 uint16_t atexit_stack_len; 290 uint16_t ecall_nest; /* prevent infinite recursive ecall() */ 223 291 } mrb_state; 224 225 226 typedef mrb_value (*mrb_func_t)(mrb_state *mrb, mrb_value);227 292 228 293 /** … … 241 306 * } 242 307 * 243 * @param [mrb_state *]mrb The current mruby state.244 * @param [const char *]name The name of the defined class.245 * @param [struct RClass *]super The new class parent.308 * @param mrb The current mruby state. 309 * @param name The name of the defined class. 310 * @param super The new class parent. 246 311 * @return [struct RClass *] Reference to the newly defined class. 247 312 * @see mrb_define_class_under … … 252 317 * Defines a new module. 253 318 * 254 * @param [mrb_state *] mrb_state*The current mruby state.255 * @param [const char *] char*The name of the module.319 * @param mrb The current mruby state. 320 * @param name The name of the module. 256 321 * @return [struct RClass *] Reference to the newly defined module. 257 322 */ 258 MRB_API struct RClass *mrb_define_module(mrb_state * , const char*);259 MRB_API mrb_value mrb_singleton_class(mrb_state *, mrb_value);323 MRB_API struct RClass *mrb_define_module(mrb_state *mrb, const char *name); 324 MRB_API mrb_value mrb_singleton_class(mrb_state *mrb, mrb_value val); 260 325 261 326 /** … … 266 331 * include A 267 332 * end 268 * @param [mrb_state *] mrb_state*The current mruby state.269 * @param [struct RClass *] RClass*A reference to module or a class.270 * @param [struct RClass *] RClass*A reference to the module to be included.271 */ 272 MRB_API void mrb_include_module(mrb_state *, struct RClass*, struct RClass*);333 * @param mrb The current mruby state. 334 * @param cla A reference to module or a class. 335 * @param included A reference to the module to be included. 336 */ 337 MRB_API void mrb_include_module(mrb_state *mrb, struct RClass *cla, struct RClass *included); 273 338 274 339 /** … … 279 344 * prepend A 280 345 * end 281 * @param [mrb_state *] mrb_state*The current mruby state.282 * @param [struct RClass *] RClass*A reference to module or a class.283 * @param [struct RClass *] RClass*A reference to the module to be prepended.284 */ 285 MRB_API void mrb_prepend_module(mrb_state *, struct RClass*, struct RClass*);346 * @param mrb The current mruby state. 347 * @param cla A reference to module or a class. 348 * @param prepended A reference to the module to be prepended. 349 */ 350 MRB_API void mrb_prepend_module(mrb_state *mrb, struct RClass *cla, struct RClass *prepended); 286 351 287 352 /** … … 292 357 * Example: 293 358 * 294 * !!!c295 359 * mrb_value example_method(mrb_state* mrb, mrb_value self) 296 360 * { … … 304 368 * } 305 369 * 306 * @param [mrb_state *]mrb The MRuby state reference.307 * @param [struct RClass *]cla The class pointer where the method will be defined.308 * @param [const char *]name The name of the method being defined.309 * @param [mrb_func_t]func The function pointer to the method definition.310 * @param [mrb_aspec]aspec The method parameters declaration.370 * @param mrb The MRuby state reference. 371 * @param cla The class pointer where the method will be defined. 372 * @param name The name of the method being defined. 373 * @param func The function pointer to the method definition. 374 * @param aspec The method parameters declaration. 311 375 */ 312 376 MRB_API void mrb_define_method(mrb_state *mrb, struct RClass *cla, const char *name, mrb_func_t func, mrb_aspec aspec); … … 331 395 * mrb_define_class_method(mrb, foo, "bar", bar_method, MRB_ARGS_NONE()); 332 396 * } 333 * @param [mrb_state *] mrb_state* The MRuby state reference. 334 * @param [struct RClass *] RClass* The class where the class method will be defined. 335 * @param [const char *] char* The name of the class method being defined. 336 * @param [mrb_func_t] mrb_func_t The function pointer to the class method definition. 337 * @param [mrb_aspec] mrb_aspec The method parameters declaration. 338 */ 339 MRB_API void mrb_define_class_method(mrb_state *, struct RClass *, const char *, mrb_func_t, mrb_aspec); 340 MRB_API void mrb_define_singleton_method(mrb_state*, struct RObject*, const char*, mrb_func_t, mrb_aspec); 341 342 /** 343 * Defines a module fuction. 397 * @param mrb The MRuby state reference. 398 * @param cla The class where the class method will be defined. 399 * @param name The name of the class method being defined. 400 * @param fun The function pointer to the class method definition. 401 * @param aspec The method parameters declaration. 402 */ 403 MRB_API void mrb_define_class_method(mrb_state *mrb, struct RClass *cla, const char *name, mrb_func_t fun, mrb_aspec aspec); 404 405 /** 406 * Defines a singleton method 407 * 408 * @see mrb_define_class_method 409 */ 410 MRB_API void mrb_define_singleton_method(mrb_state *mrb, struct RObject *cla, const char *name, mrb_func_t fun, mrb_aspec aspec); 411 412 /** 413 * Defines a module function. 344 414 * 345 415 * Example: … … 359 429 * mrb_define_module_function(mrb, foo, "bar", bar_method, MRB_ARGS_NONE()); 360 430 * } 361 * @param [mrb_state *] mrb_state*The MRuby state reference.362 * @param [struct RClass *] RClass*The module where the module function will be defined.363 * @param [const char *] char*The name of the module function being defined.364 * @param [mrb_func_t] mrb_func_tThe function pointer to the module function definition.365 * @param [mrb_aspec] mrb_aspec The method parameters declaration.366 */ 367 MRB_API void mrb_define_module_function(mrb_state *, struct RClass*, const char*, mrb_func_t, mrb_aspec);431 * @param mrb The MRuby state reference. 432 * @param cla The module where the module function will be defined. 433 * @param name The name of the module function being defined. 434 * @param fun The function pointer to the module function definition. 435 * @param aspec The method parameters declaration. 436 */ 437 MRB_API void mrb_define_module_function(mrb_state *mrb, struct RClass *cla, const char *name, mrb_func_t fun, mrb_aspec aspec); 368 438 369 439 /** … … 388 458 * mrb_example_gem_final(mrb_state* mrb){ 389 459 * } 390 * @param [mrb_state *] mrb_state*The MRuby state reference.391 * @param [struct RClass *] RClass*A class or module the constant is defined in.392 * @param [const char *]name The name of the constant being defined.393 * @param [mrb_value] mrb_valueThe value for the constant.394 */ 395 MRB_API void mrb_define_const(mrb_state* , struct RClass*, const char *name, mrb_value);460 * @param mrb The MRuby state reference. 461 * @param cla A class or module the constant is defined in. 462 * @param name The name of the constant being defined. 463 * @param val The value for the constant. 464 */ 465 MRB_API void mrb_define_const(mrb_state* mrb, struct RClass* cla, const char *name, mrb_value val); 396 466 397 467 /** … … 439 509 * mrb_example_gem_final(mrb_state* mrb){ 440 510 * } 441 * @param [mrb_state*] mrb_state* The mruby state reference. 442 * @param [struct RClass*] RClass* A class the method will be undefined from. 443 * @param [const char*] constchar* The name of the method to be undefined. 444 */ 445 MRB_API void mrb_undef_method(mrb_state*, struct RClass*, const char*); 511 * @param mrb The mruby state reference. 512 * @param cla The class the method will be undefined from. 513 * @param name The name of the method to be undefined. 514 */ 515 MRB_API void mrb_undef_method(mrb_state *mrb, struct RClass *cla, const char *name); 516 MRB_API void mrb_undef_method_id(mrb_state*, struct RClass*, mrb_sym); 446 517 447 518 /** … … 478 549 * mrb_example_gem_final(mrb_state* mrb){ 479 550 * } 480 * @param [mrb_state*] mrb_state*The mruby state reference.481 * @param [RClass*] RClass*A class the class method will be undefined from.482 * @param [constchar*] constchar*The name of the class method to be undefined.483 */ 484 MRB_API void mrb_undef_class_method(mrb_state *, struct RClass*, const char*);485 486 /** 487 * Initialize a new object insta ce of c class.551 * @param mrb The mruby state reference. 552 * @param cls A class the class method will be undefined from. 553 * @param name The name of the class method to be undefined. 554 */ 555 MRB_API void mrb_undef_class_method(mrb_state *mrb, struct RClass *cls, const char *name); 556 557 /** 558 * Initialize a new object instance of c class. 488 559 * 489 560 * Example: … … 506 577 * mrb_p(mrb, obj); // => Kernel#p 507 578 * } 508 * @param [mrb_state*]mrb The current mruby state.509 * @param [RClass*]c Reference to the class of the new object.510 * @param [mrb_int]argc Number of arguments in argv511 * @param [const mrb_value *]argv Array of mrb_value to initialize the object579 * @param mrb The current mruby state. 580 * @param c Reference to the class of the new object. 581 * @param argc Number of arguments in argv 582 * @param argv Array of mrb_value to initialize the object 512 583 * @return [mrb_value] The newly initialized object 513 584 */ … … 520 591 } 521 592 522 MRB_API mrb_value mrb_instance_new(mrb_state *mrb, mrb_value cv);523 524 593 /** 525 594 * Creates a new instance of Class, Class. … … 537 606 * } 538 607 * 539 * @param [mrb_state*]mrb The current mruby state.540 * @param [struct RClass *]super The super class or parent.608 * @param mrb The current mruby state. 609 * @param super The super class or parent. 541 610 * @return [struct RClass *] Reference to the new class. 542 611 */ … … 554 623 * } 555 624 * 556 * @param [mrb_state*]mrb The current mruby state.625 * @param mrb The current mruby state. 557 626 * @return [struct RClass *] Reference to the new module. 558 627 */ … … 581 650 * } 582 651 * 583 * @param [mrb_state*]mrb The current mruby state.584 * @param [const char *]name A string representing the name of the class.652 * @param mrb The current mruby state. 653 * @param name A string representing the name of the class. 585 654 * @return [mrb_bool] A boolean value. 586 655 */ … … 589 658 /** 590 659 * Gets a class. 591 * @param [mrb_state*]mrb The current mruby state.592 * @param [const char *]name The name of the class.660 * @param mrb The current mruby state. 661 * @param name The name of the class. 593 662 * @return [struct RClass *] A reference to the class. 594 663 */ … … 597 666 /** 598 667 * Gets a exception class. 599 * @param [mrb_state*]mrb The current mruby state.600 * @param [const char *]name The name of the class.668 * @param mrb The current mruby state. 669 * @param name The name of the class. 601 670 * @return [struct RClass *] A reference to the class. 602 671 */ … … 627 696 * } 628 697 * 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.698 * @param mrb The current mruby state. 699 * @param outer The name of the outer class. 700 * @param name A string representing the name of the inner class. 632 701 * @return [mrb_bool] A boolean value. 633 702 */ … … 636 705 /** 637 706 * Gets a child class. 638 * @param [mrb_state*]mrb The current mruby state.639 * @param [struct RClass *]outer The name of the parent class.640 * @param [const char *]name The name of the class.707 * @param mrb The current mruby state. 708 * @param outer The name of the parent class. 709 * @param name The name of the class. 641 710 * @return [struct RClass *] A reference to the class. 642 711 */ … … 645 714 /** 646 715 * Gets a module. 647 * @param [mrb_state*]mrb The current mruby state.648 * @param [const char *]name The name of the module.716 * @param mrb The current mruby state. 717 * @param name The name of the module. 649 718 * @return [struct RClass *] A reference to the module. 650 719 */ … … 653 722 /** 654 723 * Gets a module defined under another module. 655 * @param [mrb_state*]mrb The current mruby state.656 * @param [struct RClass *]outer The name of the outer module.657 * @param [const char *]name The name of the module.724 * @param mrb The current mruby state. 725 * @param outer The name of the outer module. 726 * @param name The name of the module. 658 727 * @return [struct RClass *] A reference to the module. 659 728 */ 660 729 MRB_API struct RClass * mrb_module_get_under(mrb_state *mrb, struct RClass *outer, const char *name); 730 /* a function to raise NotImplementedError with current method name */ 731 MRB_API void mrb_notimplement(mrb_state*); 732 /* a function to be replacement of unimplemented method */ 661 733 MRB_API mrb_value mrb_notimplement_m(mrb_state*, mrb_value); 662 734 … … 666 738 * Equivalent to: 667 739 * Object#dup 668 * @param [mrb_state*]mrb The current mruby state.669 * @param [mrb_value]obj Object to be duplicate.740 * @param mrb The current mruby state. 741 * @param obj Object to be duplicate. 670 742 * @return [mrb_value] The newly duplicated object. 671 743 */ 672 744 MRB_API mrb_value mrb_obj_dup(mrb_state *mrb, mrb_value obj); 673 MRB_API mrb_value mrb_check_to_integer(mrb_state *mrb, mrb_value val, const char *method);674 745 675 746 /** … … 708 779 * } 709 780 * 710 * @param [mrb_state*]mrb The current mruby state.711 * @param [struct RClass *]c A reference to a class.712 * @param [mrb_sym]mid A symbol referencing a method id.781 * @param mrb The current mruby state. 782 * @param c A reference to a class. 783 * @param mid A symbol referencing a method id. 713 784 * @return [mrb_bool] A boolean value. 714 785 */ … … 718 789 * Defines a new class under a given module 719 790 * 720 * @param [mrb_state*]mrb The current mruby state.721 * @param [struct RClass *]outer Reference to the module under which the new class will be defined722 * @param [const char *]name The name of the defined class723 * @param [struct RClass *]super The new class parent791 * @param mrb The current mruby state. 792 * @param outer Reference to the module under which the new class will be defined 793 * @param name The name of the defined class 794 * @param super The new class parent 724 795 * @return [struct RClass *] Reference to the newly defined class 725 796 * @see mrb_define_class … … 738 809 739 810 /** 740 * Fun tion takes n optional arguments811 * Function takes n optional arguments 741 812 * 742 813 * @param n … … 746 817 747 818 /** 748 * Fun tion takes n1 mandatory arguments and n2 optional arguments819 * Function takes n1 mandatory arguments and n2 optional arguments 749 820 * 750 821 * @param n1 … … 784 855 * Must be a C string composed of the following format specifiers: 785 856 * 786 * | char | Ruby type | C types | Notes 857 * | char | Ruby type | C types | Notes | 787 858 * |:----:|----------------|-------------------|----------------------------------------------------| 788 859 * | `o` | {Object} | {mrb_value} | Could be used to retrieve any type of argument | … … 791 862 * | `A` | {Array} | {mrb_value} | when `!` follows, the value may be `nil` | 792 863 * | `H` | {Hash} | {mrb_value} | when `!` follows, the value may be `nil` | 793 * | `s` | {String} | char *, {mrb_int} | Receive two arguments; `s!` gives (`NULL`,`0`) for `nil`|864 * | `s` | {String} | char *, {mrb_int} | Receive two arguments; `s!` gives (`NULL`,`0`) for `nil` | 794 865 * | `z` | {String} | char * | `NULL` terminated string; `z!` gives `NULL` for `nil` | 795 866 * | `a` | {Array} | {mrb_value} *, {mrb_int} | Receive two arguments; `a!` gives (`NULL`,`0`) for `nil` | 796 * | `f` | {F loat}| {mrb_float} | |797 * | `i` | { Integer}| {mrb_int} | |867 * | `f` | {Fixnum}/{Float} | {mrb_float} | | 868 * | `i` | {Fixnum}/{Float} | {mrb_int} | | 798 869 * | `b` | boolean | {mrb_bool} | | 799 * | `n` | {Symbol} | {mrb_sym} | | 800 * | `&` | block | {mrb_value} | | 801 * | `*` | rest arguments | {mrb_value} *, {mrb_int} | Receive the rest of arguments as an array. | 802 * | | | optional | | After this spec following specs would be optional. | 870 * | `n` | {String}/{Symbol} | {mrb_sym} | | 871 * | `d` | data | void *, {mrb_data_type} const | 2nd argument will be used to check data type so it won't be modified; when `!` follows, the value may be `nil` | 872 * | `I` | inline struct | void * | | 873 * | `&` | block | {mrb_value} | &! raises exception if no block given. | 874 * | `*` | rest arguments | {mrb_value} *, {mrb_int} | Receive the rest of arguments as an array; `*!` avoid copy of the stack. | 875 * | <code>\|</code> | optional | | After this spec following specs would be optional. | 803 876 * | `?` | optional given | {mrb_bool} | `TRUE` if preceding argument is given. Used to check optional argument is given. | 877 * | `:` | keyword args | {mrb_kwargs} const | Get keyword arguments. @see mrb_kwargs | 804 878 * 805 879 * @see mrb_get_args … … 808 882 809 883 /** 884 * Get keyword arguments by `mrb_get_args()` with `:` specifier. 885 * 886 * `mrb_kwargs::num` indicates that the number of keyword values. 887 * 888 * `mrb_kwargs::values` is an object array, and the keyword argument corresponding to the string array is assigned. 889 * Note that `undef` is assigned if there is no keyword argument corresponding to `mrb_kwargs::optional`. 890 * 891 * `mrb_kwargs::table` accepts a string array. 892 * 893 * `mrb_kwargs::required` indicates that the specified number of keywords starting from the beginning of the string array are required. 894 * 895 * `mrb_kwargs::rest` is the remaining keyword argument that can be accepted as `**rest` in Ruby. 896 * If `NULL` is specified, `ArgumentError` is raised when there is an undefined keyword. 897 * 898 * Examples: 899 * 900 * // def method(a: 1, b: 2) 901 * 902 * uint32_t kw_num = 2; 903 * const char *kw_names[kw_num] = { "a", "b" }; 904 * uint32_t kw_required = 0; 905 * mrb_value kw_values[kw_num]; 906 * const mrb_kwargs kwargs = { kw_num, kw_values, kw_names, kw_required, NULL }; 907 * 908 * mrb_get_args(mrb, ":", &kwargs); 909 * if (mrb_undef_p(kw_values[0])) { kw_values[0] = mrb_fixnum_value(1); } 910 * if (mrb_undef_p(kw_values[1])) { kw_values[1] = mrb_fixnum_value(2); } 911 * 912 * 913 * // def method(str, x:, y: 2, z: "default string", **opts) 914 * 915 * mrb_value str, kw_rest; 916 * uint32_t kw_num = 3; 917 * const char *kw_names[kw_num] = { "x", "y", "z" }; 918 * uint32_t kw_required = 1; 919 * mrb_value kw_values[kw_num]; 920 * const mrb_kwargs kwargs = { kw_num, kw_values, kw_names, kw_required, &kw_rest }; 921 * 922 * mrb_get_args(mrb, "S:", &str, &kwargs); 923 * // or: mrb_get_args(mrb, ":S", &kwargs, &str); 924 * if (mrb_undef_p(kw_values[1])) { kw_values[1] = mrb_fixnum_value(2); } 925 * if (mrb_undef_p(kw_values[2])) { kw_values[2] = mrb_str_new_cstr(mrb, "default string"); } 926 */ 927 typedef struct mrb_kwargs mrb_kwargs; 928 929 struct mrb_kwargs 930 { 931 uint32_t num; 932 mrb_value *values; 933 const char *const *table; 934 uint32_t required; 935 mrb_value *rest; 936 }; 937 938 /** 810 939 * Retrieve arguments from mrb_state. 811 940 * 812 * When applicable, implicit conversions (such as `to_str`, `to_ary`, `to_hash`) are813 * applied to received arguments.814 * Used inside a function of mrb_func_t type.815 *816 941 * @param mrb The current MRuby state. 817 * @param format [mrb_args_format]is a list of format specifiers942 * @param format is a list of format specifiers 818 943 * @param ... The passing variadic arguments must be a pointer of retrieving type. 819 944 * @return the number of arguments retrieved. 820 945 * @see mrb_args_format 946 * @see mrb_kwargs 821 947 */ 822 948 MRB_API mrb_int mrb_get_args(mrb_state *mrb, mrb_args_format format, ...); 823 949 824 static inlinemrb_sym950 MRB_INLINE mrb_sym 825 951 mrb_get_mid(mrb_state *mrb) /* get method symbol */ 826 952 { … … 828 954 } 829 955 830 static inline int 831 mrb_get_argc(mrb_state *mrb) /* get argc */ 832 { 833 return mrb->c->ci->argc; 834 } 956 /** 957 * Retrieve number of arguments from mrb_state. 958 * 959 * Correctly handles *splat arguments. 960 */ 961 MRB_API mrb_int mrb_get_argc(mrb_state *mrb); 962 963 MRB_API mrb_value* mrb_get_argv(mrb_state *mrb); 835 964 836 965 /* `strlen` for character string literals (use with caution or `strlen` instead) … … 845 974 * Call existing ruby functions. 846 975 * 976 * Example: 977 * 847 978 * #include <stdio.h> 848 979 * #include <mruby.h> … … 861 992 * fclose(fp); 862 993 * 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. 870 */ 871 MRB_API mrb_value mrb_funcall(mrb_state*, mrb_value, const char*, mrb_int,...); 994 * } 995 * 996 * @param mrb The current mruby state. 997 * @param val A reference to an mruby value. 998 * @param name The name of the method. 999 * @param argc The number of arguments the method has. 1000 * @param ... Variadic values(not type safe!). 1001 * @return [mrb_value] mruby function value. 1002 */ 1003 MRB_API mrb_value mrb_funcall(mrb_state *mrb, mrb_value val, const char *name, mrb_int argc, ...); 872 1004 /** 873 1005 * Call existing ruby functions. This is basically the type safe version of mrb_funcall. … … 891 1023 * mrb_close(mrb); 892 1024 * } 893 * @param [mrb_state*] mrb_state*The current mruby state.894 * @param [mrb_value] mrb_valueA reference to an mruby value.895 * @param [mrb_sym] mrb_sym The symbol representing the method.896 * @param [mrb_int] mrb_intThe number of arguments the method has.897 * @param [const mrb_value*] mrb_value*Pointer to the object.1025 * @param mrb The current mruby state. 1026 * @param val A reference to an mruby value. 1027 * @param name_sym The symbol representing the method. 1028 * @param argc The number of arguments the method has. 1029 * @param obj Pointer to the object. 898 1030 * @return [mrb_value] mrb_value mruby function value. 899 1031 * @see mrb_funcall 900 1032 */ 901 MRB_API mrb_value mrb_funcall_argv(mrb_state *, mrb_value, mrb_sym, mrb_int, const mrb_value*);1033 MRB_API mrb_value mrb_funcall_argv(mrb_state *mrb, mrb_value val, mrb_sym name, mrb_int argc, const mrb_value *argv); 902 1034 /** 903 1035 * Call existing ruby functions with a block. 904 1036 */ 905 MRB_API mrb_value mrb_funcall_with_block(mrb_state *, mrb_value, mrb_sym, mrb_int, const mrb_value*, mrb_value);1037 MRB_API mrb_value mrb_funcall_with_block(mrb_state *mrb, mrb_value val, mrb_sym name, mrb_int argc, const mrb_value *argv, mrb_value block); 906 1038 /** 907 1039 * Create a symbol 1040 * 1041 * Example: 908 1042 * 909 1043 * # Ruby style: … … 912 1046 * // C style: 913 1047 * 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. 1048 * 1049 * @param mrb The current mruby state. 1050 * @param str The string to be symbolized 916 1051 * @return [mrb_sym] mrb_sym A symbol. 917 1052 */ 918 MRB_API mrb_sym mrb_intern_cstr(mrb_state *,const char*);1053 MRB_API mrb_sym mrb_intern_cstr(mrb_state *mrb, const char* str); 919 1054 MRB_API mrb_sym mrb_intern(mrb_state*,const char*,size_t); 920 1055 MRB_API mrb_sym mrb_intern_static(mrb_state*,const char*,size_t); … … 924 1059 MRB_API mrb_value mrb_check_intern(mrb_state*,const char*,size_t); 925 1060 MRB_API mrb_value mrb_check_intern_str(mrb_state*,mrb_value); 926 MRB_API const char *mrb_sym2name(mrb_state*,mrb_sym); 927 MRB_API const char *mrb_sym2name_len(mrb_state*,mrb_sym,mrb_int*); 928 MRB_API mrb_value mrb_sym2str(mrb_state*,mrb_sym); 1061 MRB_API const char *mrb_sym_name(mrb_state*,mrb_sym); 1062 MRB_API const char *mrb_sym_name_len(mrb_state*,mrb_sym,mrb_int*); 1063 MRB_API const char *mrb_sym_dump(mrb_state*,mrb_sym); 1064 MRB_API mrb_value mrb_sym_str(mrb_state*,mrb_sym); 1065 #define mrb_sym2name(mrb,sym) mrb_sym_name(mrb,sym) 1066 #define mrb_sym2name_len(mrb,sym,len) mrb_sym_name_len(mrb,sym,len) 1067 #define mrb_sym2str(mrb,sym) mrb_sym_str(mrb,sym) 929 1068 930 1069 MRB_API void *mrb_malloc(mrb_state*, size_t); /* raise RuntimeError if no mem */ … … 945 1084 #define mrb_str_new_lit(mrb, lit) mrb_str_new_static(mrb, (lit), mrb_strlen_lit(lit)) 946 1085 1086 MRB_API mrb_value mrb_obj_freeze(mrb_state*, mrb_value); 1087 #define mrb_str_new_frozen(mrb,p,len) mrb_obj_freeze(mrb,mrb_str_new(mrb,p,len)) 1088 #define mrb_str_new_cstr_frozen(mrb,p) mrb_obj_freeze(mrb,mrb_str_new_cstr(mrb,p)) 1089 #define mrb_str_new_static_frozen(mrb,p,len) mrb_obj_freeze(mrb,mrb_str_new_static(mrb,p,len)) 1090 #define mrb_str_new_lit_frozen(mrb,lit) mrb_obj_freeze(mrb,mrb_str_new_lit(mrb,lit)) 1091 947 1092 #ifdef _WIN32 948 char* mrb_utf8_from_locale(const char *p, size_t len);949 char* mrb_locale_from_utf8(const char *p, size_t len);1093 MRB_API char* mrb_utf8_from_locale(const char *p, int len); 1094 MRB_API char* mrb_locale_from_utf8(const char *p, int len); 950 1095 #define mrb_locale_free(p) free(p) 951 1096 #define mrb_utf8_free(p) free(p) 952 1097 #else 953 #define mrb_utf8_from_locale(p, l) ( p)954 #define mrb_locale_from_utf8(p, l) ( p)1098 #define mrb_utf8_from_locale(p, l) ((char*)(p)) 1099 #define mrb_locale_from_utf8(p, l) ((char*)(p)) 955 1100 #define mrb_locale_free(p) 956 1101 #define mrb_utf8_free(p) … … 1007 1152 MRB_API void* mrb_default_allocf(mrb_state*, void*, size_t, void*); 1008 1153 1009 MRB_API mrb_value mrb_top_self(mrb_state * );1010 MRB_API mrb_value mrb_run(mrb_state *, struct RProc*, mrb_value);1011 MRB_API mrb_value mrb_top_run(mrb_state *, struct RProc*, mrb_value, unsigned int);1012 MRB_API mrb_value mrb_vm_run(mrb_state *, struct RProc*, mrb_value, unsigned int);1013 MRB_API mrb_value mrb_vm_exec(mrb_state *, struct RProc*, mrb_code*);1154 MRB_API mrb_value mrb_top_self(mrb_state *mrb); 1155 MRB_API mrb_value mrb_run(mrb_state *mrb, struct RProc* proc, mrb_value self); 1156 MRB_API mrb_value mrb_top_run(mrb_state *mrb, struct RProc *proc, mrb_value self, unsigned int stack_keep); 1157 MRB_API mrb_value mrb_vm_run(mrb_state *mrb, struct RProc *proc, mrb_value self, unsigned int stack_keep); 1158 MRB_API mrb_value mrb_vm_exec(mrb_state *mrb, struct RProc *proc, const mrb_code *iseq); 1014 1159 /* compatibility macros */ 1015 1160 #define mrb_toplevel_run_keep(m,p,k) mrb_top_run((m),(p),mrb_top_self(m),(k)) … … 1021 1166 MRB_API mrb_sym mrb_obj_to_sym(mrb_state *mrb, mrb_value name); 1022 1167 1023 MRB_API mrb_bool mrb_obj_eq(mrb_state *, mrb_value, mrb_value);1024 MRB_API mrb_bool mrb_obj_equal(mrb_state *, mrb_value, mrb_value);1168 MRB_API mrb_bool mrb_obj_eq(mrb_state *mrb, mrb_value a, mrb_value b); 1169 MRB_API mrb_bool mrb_obj_equal(mrb_state *mrb, mrb_value a, mrb_value b); 1025 1170 MRB_API mrb_bool mrb_equal(mrb_state *mrb, mrb_value obj1, mrb_value obj2); 1026 MRB_API mrb_value mrb_convert_to_integer(mrb_state *mrb, mrb_value val, int base);1171 MRB_API mrb_value mrb_convert_to_integer(mrb_state *mrb, mrb_value val, mrb_int base); 1027 1172 MRB_API mrb_value mrb_Integer(mrb_state *mrb, mrb_value val); 1173 #ifndef MRB_WITHOUT_FLOAT 1028 1174 MRB_API mrb_value mrb_Float(mrb_state *mrb, mrb_value val); 1175 #endif 1029 1176 MRB_API mrb_value mrb_inspect(mrb_state *mrb, mrb_value obj); 1030 1177 MRB_API mrb_bool mrb_eql(mrb_state *mrb, mrb_value obj1, mrb_value obj2); 1178 /* mrb_cmp(mrb, obj1, obj2): 1:0:-1; -2 for error */ 1179 MRB_API mrb_int mrb_cmp(mrb_state *mrb, mrb_value obj1, mrb_value obj2); 1180 1181 MRB_INLINE int 1182 mrb_gc_arena_save(mrb_state *mrb) 1183 { 1184 return mrb->gc.arena_idx; 1185 } 1186 1187 MRB_INLINE void 1188 mrb_gc_arena_restore(mrb_state *mrb, int idx) 1189 { 1190 mrb->gc.arena_idx = idx; 1191 } 1031 1192 1032 1193 MRB_API void mrb_garbage_collect(mrb_state*); 1033 1194 MRB_API void mrb_full_gc(mrb_state*); 1034 1195 MRB_API void mrb_incremental_gc(mrb_state *); 1035 MRB_API int mrb_gc_arena_save(mrb_state*);1036 MRB_API void mrb_gc_arena_restore(mrb_state*,int);1037 1196 MRB_API void mrb_gc_mark(mrb_state*,struct RBasic*); 1038 1197 #define mrb_gc_mark_value(mrb,val) do {\ … … 1077 1236 MRB_API mrb_noreturn void mrb_raisef(mrb_state *mrb, struct RClass *c, const char *fmt, ...); 1078 1237 MRB_API mrb_noreturn void mrb_name_error(mrb_state *mrb, mrb_sym id, const char *fmt, ...); 1238 MRB_API mrb_noreturn void mrb_frozen_error(mrb_state *mrb, void *frozen_obj); 1239 MRB_API mrb_noreturn void mrb_argnum_error(mrb_state *mrb, mrb_int argc, int min, int max); 1079 1240 MRB_API void mrb_warn(mrb_state *mrb, const char *fmt, ...); 1080 1241 MRB_API mrb_noreturn void mrb_bug(mrb_state *mrb, const char *fmt, ...); 1081 1242 MRB_API void mrb_print_backtrace(mrb_state *mrb); 1082 1243 MRB_API void mrb_print_error(mrb_state *mrb); 1244 /* function for `raisef` formatting */ 1245 MRB_API mrb_value mrb_vformat(mrb_state *mrb, const char *format, va_list ap); 1083 1246 1084 1247 /* macros to get typical exception objects … … 1098 1261 #define E_LOCALJUMP_ERROR (mrb_exc_get(mrb, "LocalJumpError")) 1099 1262 #define E_REGEXP_ERROR (mrb_exc_get(mrb, "RegexpError")) 1263 #define E_FROZEN_ERROR (mrb_exc_get(mrb, "FrozenError")) 1100 1264 1101 1265 #define E_NOTIMP_ERROR (mrb_exc_get(mrb, "NotImplementedError")) 1266 #ifndef MRB_WITHOUT_FLOAT 1102 1267 #define E_FLOATDOMAIN_ERROR (mrb_exc_get(mrb, "FloatDomainError")) 1268 #endif 1103 1269 1104 1270 #define E_KEY_ERROR (mrb_exc_get(mrb, "KeyError")) … … 1122 1288 MRB_API mrb_value mrb_to_int(mrb_state *mrb, mrb_value val); 1123 1289 #define mrb_int(mrb, val) mrb_fixnum(mrb_to_int(mrb, val)) 1290 /* string type checking (contrary to the name, it doesn't convert) */ 1291 MRB_API mrb_value mrb_to_str(mrb_state *mrb, mrb_value val); 1124 1292 MRB_API void mrb_check_type(mrb_state *mrb, mrb_value x, enum mrb_vtype t); 1293 1294 MRB_INLINE void mrb_check_frozen(mrb_state *mrb, void *o) 1295 { 1296 if (mrb_frozen_p((struct RBasic*)o)) mrb_frozen_error(mrb, o); 1297 } 1125 1298 1126 1299 typedef enum call_type { … … 1131 1304 } call_type; 1132 1305 1133 MRB_API void mrb_define_alias(mrb_state *mrb, struct RClass * klass, const char *name1, const char *name2);1306 MRB_API void mrb_define_alias(mrb_state *mrb, struct RClass *c, const char *a, const char *b); 1134 1307 MRB_API const char *mrb_class_name(mrb_state *mrb, struct RClass* klass); 1135 1308 MRB_API void mrb_define_global_const(mrb_state *mrb, const char *name, mrb_value val); … … 1142 1315 1143 1316 1144 /* 1317 /** 1145 1318 * Resume a Fiber 1146 1319 * 1147 * @mrbgemmruby-fiber1320 * Implemented in mruby-fiber 1148 1321 */ 1149 1322 MRB_API mrb_value mrb_fiber_resume(mrb_state *mrb, mrb_value fib, mrb_int argc, const mrb_value *argv); 1150 1323 1151 /* 1324 /** 1152 1325 * Yield a Fiber 1153 1326 * 1154 * @mrbgemmruby-fiber1327 * Implemented in mruby-fiber 1155 1328 */ 1156 1329 MRB_API mrb_value mrb_fiber_yield(mrb_state *mrb, mrb_int argc, const mrb_value *argv); 1157 1330 1158 /* 1331 /** 1332 * Check if a Fiber is alive 1333 * 1334 * Implemented in mruby-fiber 1335 */ 1336 MRB_API mrb_value mrb_fiber_alive_p(mrb_state *mrb, mrb_value fib); 1337 1338 /** 1159 1339 * FiberError reference 1160 1340 * 1161 * @mrbgemmruby-fiber1341 * Implemented in mruby-fiber 1162 1342 */ 1163 1343 #define E_FIBER_ERROR (mrb_exc_get(mrb, "FiberError")) 1344 MRB_API void mrb_stack_extend(mrb_state*, mrb_int); 1164 1345 1165 1346 /* memory pool implementation */ … … 1170 1351 MRB_API void* mrb_pool_realloc(struct mrb_pool*, void*, size_t oldlen, size_t newlen); 1171 1352 MRB_API mrb_bool mrb_pool_can_realloc(struct mrb_pool*, void*, size_t); 1353 /* temporary memory allocation, only effective while GC arena is kept */ 1172 1354 MRB_API void* mrb_alloca(mrb_state *mrb, size_t); 1173 1355 … … 1184 1366 #undef memcpy 1185 1367 #undef memset 1186 static inlinevoid*1368 static void* 1187 1369 mrbmemcpy(void *dst, const void *src, size_t n) 1188 1370 { 1189 char *d = dst;1190 const char *s = src;1371 char *d = (char*)dst; 1372 const char *s = (const char*)src; 1191 1373 while (n--) 1192 1374 *d++ = *s++; … … 1195 1377 #define memcpy(a,b,c) mrbmemcpy(a,b,c) 1196 1378 1197 static inlinevoid*1379 static void* 1198 1380 mrbmemset(void *s, int c, size_t n) 1199 1381 { 1200 char *t = s;1382 char *t = (char*)s; 1201 1383 while (n--) 1202 1384 *t++ = c; -
EcnlProtoTool/trunk/mruby-2.1.1/include/mruby/array.h
r331 r439 1 /* 2 ** mruby/array.h - Array class1 /** 2 ** @file mruby/array.h - Array class 3 3 ** 4 4 ** See Copyright Notice in mruby.h … … 18 18 typedef struct mrb_shared_array { 19 19 int refcnt; 20 mrb_ intlen;20 mrb_ssize len; 21 21 mrb_value *ptr; 22 22 } mrb_shared_array; 23 23 24 #define MRB_ARY_EMBED_LEN_MAX ((mrb_int)(sizeof(void*)*3/sizeof(mrb_value))) 24 25 struct RArray { 25 26 MRB_OBJECT_HEADER; 26 mrb_int len;27 27 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; 32 38 }; 33 39 … … 36 42 #define RARRAY(v) ((struct RArray*)(mrb_ptr(v))) 37 43 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) 40 64 #define MRB_ARY_SHARED 256 41 65 #define ARY_SHARED_P(a) ((a)->flags & MRB_ARY_SHARED) … … 176 200 */ 177 201 MRB_API void mrb_ary_replace(mrb_state *mrb, mrb_value self, mrb_value other); 202 MRB_API mrb_value mrb_ensure_array_type(mrb_state *mrb, mrb_value self); 178 203 MRB_API mrb_value mrb_check_array_type(mrb_state *mrb, mrb_value self); 179 204 180 205 /* 181 * Unshift an element into anarray206 * Unshift an element into the array 182 207 * 183 208 * Equivalent to: … … 190 215 */ 191 216 MRB_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 */ 192 228 MRB_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 */ 244 MRB_API mrb_value mrb_ary_splice(mrb_state *mrb, mrb_value self, mrb_int head, mrb_int len, mrb_value rpl); 193 245 194 246 /* … … 206 258 207 259 /* 208 * Removes all elements from th isarray260 * Removes all elements from the array 209 261 * 210 262 * Equivalent to: … … 240 292 MRB_API mrb_value mrb_ary_resize(mrb_state *mrb, mrb_value ary, mrb_int new_len); 241 293 242 static inline mrb_int243 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_value251 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 259 294 MRB_END_DECL 260 295 -
EcnlProtoTool/trunk/mruby-2.1.1/include/mruby/boxing_nan.h
r331 r439 1 /* 2 ** mruby/boxing_nan.h - nan boxing mrb_value definition1 /** 2 ** @file mruby/boxing_nan.h - nan boxing mrb_value definition 3 3 ** 4 4 ** See Copyright Notice in mruby.h … … 12 12 #endif 13 13 14 #ifdef MRB_WITHOUT_FLOAT 15 # error ---->> MRB_NAN_BOXING and MRB_WITHOUT_FLOAT conflict <<---- 16 #endif 17 14 18 #ifdef MRB_INT64 15 19 # error ---->> MRB_NAN_BOXING and MRB_INT64 conflict <<---- … … 17 21 18 22 #define MRB_FIXNUM_SHIFT 0 19 #define MRB_TT_HAS_BASIC MRB_TT_OBJECT 20 21 #ifdef MRB_ENDIAN_BIG 22 #define MRB_ENDIAN_LOHI(a,b) a b 23 #else 24 #define MRB_ENDIAN_LOHI(a,b) b a 25 #endif 23 #define MRB_SYMBOL_SHIFT 0 26 24 27 25 /* value representation by nan-boxing: … … 78 76 79 77 #define SET_FLOAT_VALUE(mrb,r,v) do { \ 80 if ( v != v) { \78 if ((v) != (v)) { \ 81 79 (r).value.ttt = 0x7ff80000; \ 82 80 (r).value.i = 0; \ -
EcnlProtoTool/trunk/mruby-2.1.1/include/mruby/boxing_no.h
r321 r439 1 /* 2 ** mruby/boxing_no.h - unboxed mrb_value definition1 /** 2 ** @file mruby/boxing_no.h - unboxed mrb_value definition 3 3 ** 4 4 ** See Copyright Notice in mruby.h … … 9 9 10 10 #define MRB_FIXNUM_SHIFT 0 11 #define MRB_TT_HAS_BASIC MRB_TT_OBJECT 11 #define MRB_SYMBOL_SHIFT 0 12 13 union mrb_value_union { 14 #ifndef MRB_WITHOUT_FLOAT 15 mrb_float f; 16 #endif 17 void *p; 18 mrb_int i; 19 mrb_sym sym; 20 }; 12 21 13 22 typedef struct mrb_value { 14 union { 15 mrb_float f; 16 void *p; 17 mrb_int i; 18 mrb_sym sym; 19 } value; 23 union mrb_value_union value; 20 24 enum mrb_vtype tt; 21 25 } mrb_value; 22 26 27 #ifndef MRB_WITHOUT_FLOAT 23 28 #define mrb_float_pool(mrb,f) mrb_float_value(mrb,f) 29 #endif 24 30 25 31 #define mrb_ptr(o) (o).value.p 26 32 #define mrb_cptr(o) mrb_ptr(o) 33 #ifndef MRB_WITHOUT_FLOAT 27 34 #define mrb_float(o) (o).value.f 35 #endif 28 36 #define mrb_fixnum(o) (o).value.i 29 37 #define mrb_symbol(o) (o).value.sym … … 40 48 #define SET_BOOL_VALUE(r,b) BOXNIX_SET_VALUE(r, b ? MRB_TT_TRUE : MRB_TT_FALSE, value.i, 1) 41 49 #define SET_INT_VALUE(r,n) BOXNIX_SET_VALUE(r, MRB_TT_FIXNUM, value.i, (n)) 50 #ifndef MRB_WITHOUT_FLOAT 42 51 #define SET_FLOAT_VALUE(mrb,r,v) BOXNIX_SET_VALUE(r, MRB_TT_FLOAT, value.f, (v)) 52 #endif 43 53 #define SET_SYM_VALUE(r,v) BOXNIX_SET_VALUE(r, MRB_TT_SYMBOL, value.sym, (v)) 44 54 #define SET_OBJ_VALUE(r,v) BOXNIX_SET_VALUE(r, (((struct RObject*)(v))->tt), value.p, (v)) -
EcnlProtoTool/trunk/mruby-2.1.1/include/mruby/boxing_word.h
r331 r439 1 /* 2 ** mruby/boxing_word.h - word boxing mrb_value definition1 /** 2 ** @file mruby/boxing_word.h - word boxing mrb_value definition 3 3 ** 4 4 ** See Copyright Notice in mruby.h … … 8 8 #define MRUBY_BOXING_WORD_H 9 9 10 #if defined(MRB_INT16)11 # error MRB_INT16 is too small for MRB_WORD_BOXING.12 #endif13 14 10 #if defined(MRB_INT64) && !defined(MRB_64BIT) 15 11 #error MRB_INT64 cannot be used with MRB_WORD_BOXING in 32-bit mode. 16 12 #endif 17 13 14 #ifndef MRB_WITHOUT_FLOAT 18 15 struct RFloat { 19 16 MRB_OBJECT_HEADER; 20 17 mrb_float f; 21 18 }; 19 #endif 22 20 23 21 struct RCptr { … … 26 24 }; 27 25 28 #define MRB_FIXNUM_SHIFT 129 #define MRB_TT_HAS_BASIC MRB_TT_FLOAT30 31 26 enum mrb_special_consts { 32 MRB_Qnil = 0,33 MRB_Qfalse = 2,34 MRB_Qtrue = 4,35 MRB_Qundef = 6,27 MRB_Qnil = 0, 28 MRB_Qfalse = 4, 29 MRB_Qtrue = 12, 30 MRB_Qundef = 20, 36 31 }; 37 32 38 #define MRB_FIXNUM_FLAG 0x01 39 #define MRB_SYMBOL_FLAG 0x0e 40 #define MRB_SPECIAL_SHIFT 8 33 #if defined(MRB_64BIT) && defined(MRB_INT32) 34 #define MRB_FIXNUM_SHIFT 0 35 #else 36 #define MRB_FIXNUM_SHIFT BOXWORD_FIXNUM_SHIFT 37 #endif 38 #define MRB_SYMBOL_SHIFT BOXWORD_SYMBOL_SHIFT 41 39 40 #define BOXWORD_FIXNUM_BIT_POS 1 41 #define BOXWORD_SYMBOL_BIT_POS 2 42 #define BOXWORD_FIXNUM_SHIFT BOXWORD_FIXNUM_BIT_POS 43 #ifdef MRB_64BIT 44 #define BOXWORD_SYMBOL_SHIFT 0 45 #else 46 #define BOXWORD_SYMBOL_SHIFT BOXWORD_SYMBOL_BIT_POS 47 #endif 48 #define BOXWORD_FIXNUM_FLAG (1 << (BOXWORD_FIXNUM_BIT_POS - 1)) 49 #define BOXWORD_SYMBOL_FLAG (1 << (BOXWORD_SYMBOL_BIT_POS - 1)) 50 #define BOXWORD_FIXNUM_MASK ((1 << BOXWORD_FIXNUM_BIT_POS) - 1) 51 #define BOXWORD_SYMBOL_MASK ((1 << BOXWORD_SYMBOL_BIT_POS) - 1) 52 #define BOXWORD_IMMEDIATE_MASK 0x07 53 54 #define BOXWORD_SHIFT_VALUE(o,n,t) \ 55 (t)(((long)(o).w) >> BOXWORD_##n##_SHIFT) 56 #define BOXWORD_SET_SHIFT_VALUE(o,n,v) \ 57 ((o).w = (((unsigned long)(v)) << BOXWORD_##n##_SHIFT) | BOXWORD_##n##_FLAG) 58 #define BOXWORD_SHIFT_VALUE_P(o,n) \ 59 (((o).w & BOXWORD_##n##_MASK) == BOXWORD_##n##_FLAG) 60 #define BOXWORD_OBJ_TYPE_P(o,n) \ 61 (!mrb_immediate_p(o) && (o).value.bp->tt == MRB_TT_##n) 62 63 /* 64 * mrb_value representation: 65 * 66 * nil : ...0000 0000 (all bits are 0) 67 * false : ...0000 0100 (mrb_fixnum(v) != 0) 68 * true : ...0000 1100 69 * undef : ...0001 0100 70 * fixnum: ...IIII III1 71 * symbol: ...SSSS SS10 (use only upper 32-bit as symbol value on 64-bit CPU) 72 * object: ...PPPP P000 (any bits are 1) 73 */ 42 74 typedef union mrb_value { 43 75 union { 44 76 void *p; 77 #ifdef MRB_64BIT 78 /* use struct to avoid bit shift. */ 45 79 struct { 46 unsigned int i_flag : MRB_FIXNUM_SHIFT; 47 mrb_int i : (MRB_INT_BIT - MRB_FIXNUM_SHIFT); 80 MRB_ENDIAN_LOHI( 81 mrb_sym sym; 82 ,uint32_t sym_flag; 83 ) 48 84 }; 49 struct { 50 unsigned int sym_flag : MRB_SPECIAL_SHIFT; 51 mrb_sym sym : (sizeof(mrb_sym) * CHAR_BIT); 52 }; 85 #endif 53 86 struct RBasic *bp; 87 #ifndef MRB_WITHOUT_FLOAT 54 88 struct RFloat *fp; 89 #endif 55 90 struct RCptr *vp; 56 91 } value; … … 59 94 60 95 MRB_API mrb_value mrb_word_boxing_cptr_value(struct mrb_state*, void*); 96 #ifndef MRB_WITHOUT_FLOAT 61 97 MRB_API mrb_value mrb_word_boxing_float_value(struct mrb_state*, mrb_float); 62 98 MRB_API mrb_value mrb_word_boxing_float_pool(struct mrb_state*, mrb_float); 99 #endif 63 100 101 #ifndef MRB_WITHOUT_FLOAT 64 102 #define mrb_float_pool(mrb,f) mrb_word_boxing_float_pool(mrb,f) 103 #endif 65 104 66 105 #define mrb_ptr(o) (o).value.p 67 106 #define mrb_cptr(o) (o).value.vp->p 107 #ifndef MRB_WITHOUT_FLOAT 68 108 #define mrb_float(o) (o).value.fp->f 69 #define mrb_fixnum(o) ((mrb_int)(o).value.i) 109 #endif 110 #define mrb_fixnum(o) BOXWORD_SHIFT_VALUE(o, FIXNUM, mrb_int) 111 #ifdef MRB_64BIT 70 112 #define mrb_symbol(o) (o).value.sym 113 #else 114 #define mrb_symbol(o) BOXWORD_SHIFT_VALUE(o, SYMBOL, mrb_sym) 115 #endif 116 #define mrb_bool(o) (((o).w & ~(unsigned long)MRB_Qfalse) != 0) 71 117 72 static inline enum mrb_vtype 118 #define mrb_immediate_p(o) ((o).w & BOXWORD_IMMEDIATE_MASK || (o).w == MRB_Qnil) 119 #define mrb_fixnum_p(o) BOXWORD_SHIFT_VALUE_P(o, FIXNUM) 120 #ifdef MRB_64BIT 121 #define mrb_symbol_p(o) ((o).value.sym_flag == BOXWORD_SYMBOL_FLAG) 122 #else 123 #define mrb_symbol_p(o) BOXWORD_SHIFT_VALUE_P(o, SYMBOL) 124 #endif 125 #define mrb_undef_p(o) ((o).w == MRB_Qundef) 126 #define mrb_nil_p(o) ((o).w == MRB_Qnil) 127 #define mrb_false_p(o) ((o).w == MRB_Qfalse) 128 #define mrb_true_p(o) ((o).w == MRB_Qtrue) 129 #ifndef MRB_WITHOUT_FLOAT 130 #define mrb_float_p(o) BOXWORD_OBJ_TYPE_P(o, FLOAT) 131 #endif 132 #define mrb_array_p(o) BOXWORD_OBJ_TYPE_P(o, ARRAY) 133 #define mrb_string_p(o) BOXWORD_OBJ_TYPE_P(o, STRING) 134 #define mrb_hash_p(o) BOXWORD_OBJ_TYPE_P(o, HASH) 135 #define mrb_cptr_p(o) BOXWORD_OBJ_TYPE_P(o, CPTR) 136 #define mrb_exception_p(o) BOXWORD_OBJ_TYPE_P(o, EXCEPTION) 137 #define mrb_free_p(o) BOXWORD_OBJ_TYPE_P(o, FREE) 138 #define mrb_object_p(o) BOXWORD_OBJ_TYPE_P(o, OBJECT) 139 #define mrb_class_p(o) BOXWORD_OBJ_TYPE_P(o, CLASS) 140 #define mrb_module_p(o) BOXWORD_OBJ_TYPE_P(o, MODULE) 141 #define mrb_iclass_p(o) BOXWORD_OBJ_TYPE_P(o, ICLASS) 142 #define mrb_sclass_p(o) BOXWORD_OBJ_TYPE_P(o, SCLASS) 143 #define mrb_proc_p(o) BOXWORD_OBJ_TYPE_P(o, PROC) 144 #define mrb_range_p(o) BOXWORD_OBJ_TYPE_P(o, RANGE) 145 #define mrb_file_p(o) BOXWORD_OBJ_TYPE_P(o, FILE) 146 #define mrb_env_p(o) BOXWORD_OBJ_TYPE_P(o, ENV) 147 #define mrb_data_p(o) BOXWORD_OBJ_TYPE_P(o, DATA) 148 #define mrb_fiber_p(o) BOXWORD_OBJ_TYPE_P(o, FIBER) 149 #define mrb_istruct_p(o) BOXWORD_OBJ_TYPE_P(o, ISTRUCT) 150 #define mrb_break_p(o) BOXWORD_OBJ_TYPE_P(o, BREAK) 151 152 #ifndef MRB_WITHOUT_FLOAT 153 #define SET_FLOAT_VALUE(mrb,r,v) ((r) = mrb_word_boxing_float_value(mrb, v)) 154 #endif 155 #define SET_CPTR_VALUE(mrb,r,v) ((r) = mrb_word_boxing_cptr_value(mrb, v)) 156 #define SET_UNDEF_VALUE(r) ((r).w = MRB_Qundef) 157 #define SET_NIL_VALUE(r) ((r).w = MRB_Qnil) 158 #define SET_FALSE_VALUE(r) ((r).w = MRB_Qfalse) 159 #define SET_TRUE_VALUE(r) ((r).w = MRB_Qtrue) 160 #define SET_BOOL_VALUE(r,b) ((b) ? SET_TRUE_VALUE(r) : SET_FALSE_VALUE(r)) 161 #define SET_INT_VALUE(r,n) BOXWORD_SET_SHIFT_VALUE(r, FIXNUM, n) 162 #ifdef MRB_64BIT 163 #define SET_SYM_VALUE(r,v) ((r).value.sym = v, (r).value.sym_flag = BOXWORD_SYMBOL_FLAG) 164 #else 165 #define SET_SYM_VALUE(r,n) BOXWORD_SET_SHIFT_VALUE(r, SYMBOL, n) 166 #endif 167 #define SET_OBJ_VALUE(r,v) ((r).value.p = v) 168 169 MRB_INLINE enum mrb_vtype 73 170 mrb_type(mrb_value o) 74 171 { 75 switch (o.w) { 76 case MRB_Qfalse: 77 case MRB_Qnil: 78 return MRB_TT_FALSE; 79 case MRB_Qtrue: 80 return MRB_TT_TRUE; 81 case MRB_Qundef: 82 return MRB_TT_UNDEF; 83 } 84 if (o.value.i_flag == MRB_FIXNUM_FLAG) { 85 return MRB_TT_FIXNUM; 86 } 87 if (o.value.sym_flag == MRB_SYMBOL_FLAG) { 88 return MRB_TT_SYMBOL; 89 } 90 return o.value.bp->tt; 172 return !mrb_bool(o) ? MRB_TT_FALSE : 173 mrb_true_p(o) ? MRB_TT_TRUE : 174 mrb_fixnum_p(o) ? MRB_TT_FIXNUM : 175 mrb_symbol_p(o) ? MRB_TT_SYMBOL : 176 mrb_undef_p(o) ? MRB_TT_UNDEF : 177 o.value.bp->tt; 91 178 } 92 179 93 #define mrb_bool(o) ((o).w != MRB_Qnil && (o).w != MRB_Qfalse)94 #define mrb_fixnum_p(o) ((o).value.i_flag == MRB_FIXNUM_FLAG)95 #define mrb_undef_p(o) ((o).w == MRB_Qundef)96 #define mrb_nil_p(o) ((o).w == MRB_Qnil)97 98 #define BOXWORD_SET_VALUE(o, ttt, attr, v) do { \99 switch (ttt) {\100 case MRB_TT_FALSE: (o).w = (v) ? MRB_Qfalse : MRB_Qnil; break;\101 case MRB_TT_TRUE: (o).w = MRB_Qtrue; break;\102 case MRB_TT_UNDEF: (o).w = MRB_Qundef; 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;\105 default: (o).w = 0; (o).attr = (v); if ((o).value.bp) (o).value.bp->tt = ttt; break;\106 }\107 } while (0)108 109 #define SET_FLOAT_VALUE(mrb,r,v) r = mrb_word_boxing_float_value(mrb, v)110 #define SET_CPTR_VALUE(mrb,r,v) r = mrb_word_boxing_cptr_value(mrb, v)111 #define SET_NIL_VALUE(r) BOXWORD_SET_VALUE(r, MRB_TT_FALSE, value.i, 0)112 #define SET_FALSE_VALUE(r) BOXWORD_SET_VALUE(r, MRB_TT_FALSE, value.i, 1)113 #define SET_TRUE_VALUE(r) BOXWORD_SET_VALUE(r, MRB_TT_TRUE, value.i, 1)114 #define SET_BOOL_VALUE(r,b) BOXWORD_SET_VALUE(r, b ? MRB_TT_TRUE : MRB_TT_FALSE, value.i, 1)115 #define SET_INT_VALUE(r,n) BOXWORD_SET_VALUE(r, MRB_TT_FIXNUM, value.i, (n))116 #define SET_SYM_VALUE(r,v) BOXWORD_SET_VALUE(r, MRB_TT_SYMBOL, value.sym, (v))117 #define SET_OBJ_VALUE(r,v) BOXWORD_SET_VALUE(r, (((struct RObject*)(v))->tt), value.p, (v))118 #define SET_UNDEF_VALUE(r) BOXWORD_SET_VALUE(r, MRB_TT_UNDEF, value.i, 0)119 120 180 #endif /* MRUBY_BOXING_WORD_H */ -
EcnlProtoTool/trunk/mruby-2.1.1/include/mruby/class.h
r331 r439 1 /* 2 ** mruby/class.h - Class class1 /** 2 ** @file mruby/class.h - Class class 3 3 ** 4 4 ** See Copyright Notice in mruby.h … … 23 23 24 24 #define mrb_class_ptr(v) ((struct RClass*)(mrb_ptr(v))) 25 #define RCLASS_SUPER(v) (((struct RClass*)(mrb_ptr(v)))->super)26 #define RCLASS_IV_TBL(v) (((struct RClass*)(mrb_ptr(v)))->iv)27 #define RCLASS_M_TBL(v) (((struct RClass*)(mrb_ptr(v)))->mt)28 25 29 static inlinestruct RClass*26 MRB_INLINE struct RClass* 30 27 mrb_class(mrb_state *mrb, mrb_value v) 31 28 { … … 41 38 case MRB_TT_FIXNUM: 42 39 return mrb->fixnum_class; 40 #ifndef MRB_WITHOUT_FLOAT 43 41 case MRB_TT_FLOAT: 44 42 return mrb->float_class; 43 #endif 45 44 case MRB_TT_CPTR: 46 45 return mrb->object_class; … … 52 51 } 53 52 54 /* TODO: figure out where to put user flags */ 55 #define MRB_FLAG_IS_FROZEN (1 << 18) 56 #define MRB_FLAG_IS_PREPENDED (1 << 19) 57 #define MRB_FLAG_IS_ORIGIN (1 << 20) 53 /* flags: 54 20: frozen 55 19: is_prepended 56 18: is_origin 57 17: is_inherited (used by method cache) 58 16: unused 59 0-15: instance type 60 */ 61 #define MRB_FL_CLASS_IS_PREPENDED (1 << 19) 62 #define MRB_FL_CLASS_IS_ORIGIN (1 << 18) 58 63 #define MRB_CLASS_ORIGIN(c) do {\ 59 if ( c->flags & MRB_FLAG_IS_PREPENDED) {\60 c = c->super;\61 while (!( c->flags & MRB_FLAG_IS_ORIGIN)) {\62 c = c->super;\64 if ((c)->flags & MRB_FL_CLASS_IS_PREPENDED) {\ 65 (c) = (c)->super;\ 66 while (!((c)->flags & MRB_FL_CLASS_IS_ORIGIN)) {\ 67 (c) = (c)->super;\ 63 68 }\ 64 69 }\ 65 70 } while (0) 71 #define MRB_FL_CLASS_IS_INHERITED (1 << 17) 66 72 #define MRB_INSTANCE_TT_MASK (0xFF) 67 #define MRB_SET_INSTANCE_TT(c, tt) c->flags = ((c->flags & ~MRB_INSTANCE_TT_MASK) | (char)tt)68 #define MRB_INSTANCE_TT(c) (enum mrb_vtype)( c->flags & MRB_INSTANCE_TT_MASK)73 #define MRB_SET_INSTANCE_TT(c, tt) ((c)->flags = (((c)->flags & ~MRB_INSTANCE_TT_MASK) | (char)(tt))) 74 #define MRB_INSTANCE_TT(c) (enum mrb_vtype)((c)->flags & MRB_INSTANCE_TT_MASK) 69 75 70 76 MRB_API struct RClass* mrb_define_class_id(mrb_state*, mrb_sym, struct RClass*); 71 77 MRB_API struct RClass* mrb_define_module_id(mrb_state*, mrb_sym); 72 MRB_APIstruct RClass *mrb_vm_define_class(mrb_state*, mrb_value, mrb_value, mrb_sym);73 MRB_APIstruct RClass *mrb_vm_define_module(mrb_state*, mrb_value, mrb_sym);74 MRB_API void mrb_define_method_raw(mrb_state*, struct RClass*, mrb_sym, struct RProc *);78 struct RClass *mrb_vm_define_class(mrb_state*, mrb_value, mrb_value, mrb_sym); 79 struct RClass *mrb_vm_define_module(mrb_state*, mrb_value, mrb_sym); 80 MRB_API void mrb_define_method_raw(mrb_state*, struct RClass*, mrb_sym, mrb_method_t); 75 81 MRB_API void mrb_define_method_id(mrb_state *mrb, struct RClass *c, mrb_sym mid, mrb_func_t func, mrb_aspec aspec); 76 MRB_API void mrb_alias_method(mrb_state *mrb, struct RClass *c, mrb_sym a, mrb_sym b);82 MRB_API void mrb_alias_method(mrb_state*, struct RClass *c, mrb_sym a, mrb_sym b); 77 83 78 MRB_API struct RClass *mrb_class_outer_module(mrb_state*, struct RClass *); 79 MRB_API struct RProc *mrb_method_search_vm(mrb_state*, struct RClass**, mrb_sym); 80 MRB_API struct RProc *mrb_method_search(mrb_state*, struct RClass*, mrb_sym); 84 MRB_API mrb_method_t mrb_method_search_vm(mrb_state*, struct RClass**, mrb_sym); 85 MRB_API mrb_method_t mrb_method_search(mrb_state*, struct RClass*, mrb_sym); 81 86 82 87 MRB_API struct RClass* mrb_class_real(struct RClass* cl); 88 mrb_value mrb_instance_new(mrb_state *mrb, mrb_value cv); 83 89 90 void mrb_class_name_class(mrb_state*, struct RClass*, struct RClass*, mrb_sym); 91 mrb_bool mrb_const_name_p(mrb_state*, const char*, mrb_int); 92 mrb_value mrb_class_find_path(mrb_state*, struct RClass*); 93 mrb_value mrb_mod_to_s(mrb_state*, mrb_value); 84 94 void mrb_gc_mark_mt(mrb_state*, struct RClass*); 85 95 size_t mrb_gc_mark_mt_size(mrb_state*, struct RClass*); 86 96 void mrb_gc_free_mt(mrb_state*, struct RClass*); 87 97 98 #ifdef MRB_METHOD_CACHE 99 void mrb_mc_clear_by_class(mrb_state *mrb, struct RClass* c); 100 #else 101 #define mrb_mc_clear_by_class(mrb,c) 102 #endif 103 88 104 MRB_END_DECL 89 105 -
EcnlProtoTool/trunk/mruby-2.1.1/include/mruby/common.h
r331 r439 1 /* 2 ** "common.h - mruby common platform definition"1 /** 2 ** @file common.h - mruby common platform definition" 3 3 ** 4 4 ** See Copyright Notice in mruby.h … … 8 8 #define MRUBY_COMMON_H 9 9 10 #ifdef __APPLE__ 11 #ifndef __TARGETCONDITIONALS__ 12 #include "TargetConditionals.h" 13 #endif 14 #endif 10 15 11 16 #ifdef __cplusplus … … 15 20 #else 16 21 # define MRB_BEGIN_DECL extern "C" { 17 # define MRB_END_DECL 22 # define MRB_END_DECL } 18 23 #endif 19 24 #else … … 30 35 31 36 /** Declare a function that never returns. */ 32 #if __STDC_VERSION__ >= 201112L37 #if defined __STDC_VERSION__ && __STDC_VERSION__ >= 201112L 33 38 # define mrb_noreturn _Noreturn 34 39 #elif defined __GNUC__ && !defined __STRICT_ANSI__ … … 50 55 51 56 /** Declare a function as always inlined. */ 52 #if defined (_MSC_VER)53 # define MRB_INLINE static __inline54 # else55 # define MRB_INLINE static inline57 #if defined _MSC_VER && _MSC_VER < 1900 58 # ifndef __cplusplus 59 # define inline __inline 60 # endif 56 61 #endif 57 62 #define MRB_INLINE static inline 58 63 59 64 /** Declare a public MRuby API function. */ 65 #ifndef MRB_API 60 66 #if defined(MRB_BUILD_AS_DLL) 61 67 #if defined(MRB_CORE) || defined(MRB_LIB) … … 67 73 # define MRB_API extern 68 74 #endif 75 #endif 76 77 /** Declare mingw versions */ 78 #if defined(__MINGW32__) || defined(__MINGW64__) 79 # include <_mingw.h> 80 # if defined(__MINGW64_VERSION_MAJOR) 81 # define MRB_MINGW64_VERSION (__MINGW64_VERSION_MAJOR * 1000 + __MINGW64_VERSION_MINOR) 82 # elif defined(__MINGW32_MAJOR_VERSION) 83 # define MRB_MINGW32_VERSION (__MINGW32_MAJOR_VERSION * 1000 + __MINGW32_MINOR_VERSION) 84 # endif 85 #endif 69 86 70 87 MRB_END_DECL -
EcnlProtoTool/trunk/mruby-2.1.1/include/mruby/compile.h
r331 r439 1 /* 2 ** mruby/compile.h - mruby parser1 /** 2 ** @file mruby/compile.h - mruby parser 3 3 ** 4 4 ** See Copyright Notice in mruby.h … … 25 25 int slen; 26 26 char *filename; 27 short lineno;27 uint16_t lineno; 28 28 int (*partial_hook)(struct mrb_parser_state*); 29 29 void *partial_data; … … 34 34 mrb_bool keep_lv:1; 35 35 mrb_bool no_optimize:1; 36 mrb_bool on_eval:1; 37 38 size_t parser_nerr; 36 39 } mrbc_context; 37 40 … … 65 68 /* saved error message */ 66 69 struct mrb_parser_message { 67 int lineno;70 uint16_t lineno; 68 71 int column; 69 72 char* message; … … 103 106 }; 104 107 105 #define MRB_PARSER_TOKBUF_MAX 65536108 #define MRB_PARSER_TOKBUF_MAX (UINT16_MAX-1) 106 109 #define MRB_PARSER_TOKBUF_SIZE 256 107 110 … … 116 119 #endif 117 120 mrbc_context *cxt; 118 char const *filename;119 int lineno;121 mrb_sym filename_sym; 122 uint16_t lineno; 120 123 int column; 121 124 … … 137 140 int tsiz; 138 141 139 mrb_ast_node *all_heredocs; 142 mrb_ast_node *all_heredocs; /* list of mrb_parser_heredoc_info* */ 140 143 mrb_ast_node *heredocs_from_nextline; 141 144 mrb_ast_node *parsing_heredoc; 142 145 mrb_ast_node *lex_strterm_before_heredoc; 143 mrb_bool heredoc_end_now:1; /* for mirb */144 146 145 147 void *ylval; … … 150 152 151 153 mrb_bool no_optimize:1; 154 mrb_bool on_eval:1; 152 155 mrb_bool capture_errors:1; 153 156 struct mrb_parser_message error_buffer[10]; … … 155 158 156 159 mrb_sym* filename_table; 157 size_t filename_table_length;158 int current_filename_index;160 uint16_t filename_table_length; 161 uint16_t current_filename_index; 159 162 160 163 struct mrb_jmpbuf* jmp; 164 mrb_ast_node *nvars; 161 165 }; 162 166 … … 164 168 MRB_API void mrb_parser_free(struct mrb_parser_state*); 165 169 MRB_API void mrb_parser_parse(struct mrb_parser_state*,mrbc_context*); 166 MRB_API double mrb_float_read(const char*, char**);167 170 168 171 MRB_API void mrb_parser_set_filename(struct mrb_parser_state*, char const*); 169 MRB_API char const*mrb_parser_get_filename(struct mrb_parser_state*, uint16_t idx);172 MRB_API mrb_sym mrb_parser_get_filename(struct mrb_parser_state*, uint16_t idx); 170 173 171 174 /* utility functions */ … … 174 177 #endif 175 178 MRB_API struct mrb_parser_state* mrb_parse_string(mrb_state*,const char*,mrbc_context*); 176 MRB_API struct mrb_parser_state* mrb_parse_nstring(mrb_state*,const char*, int,mrbc_context*);179 MRB_API struct mrb_parser_state* mrb_parse_nstring(mrb_state*,const char*,size_t,mrbc_context*); 177 180 MRB_API struct RProc* mrb_generate_code(mrb_state*, struct mrb_parser_state*); 178 181 MRB_API mrb_value mrb_load_exec(mrb_state *mrb, struct mrb_parser_state *p, mrbc_context *c); … … 184 187 #endif 185 188 MRB_API mrb_value mrb_load_string(mrb_state *mrb, const char *s); 186 MRB_API mrb_value mrb_load_nstring(mrb_state *mrb, const char *s, int len);189 MRB_API mrb_value mrb_load_nstring(mrb_state *mrb, const char *s, size_t len); 187 190 MRB_API mrb_value mrb_load_string_cxt(mrb_state *mrb, const char *s, mrbc_context *cxt); 188 MRB_API mrb_value mrb_load_nstring_cxt(mrb_state *mrb, const char *s, int len, mrbc_context *cxt);191 MRB_API mrb_value mrb_load_nstring_cxt(mrb_state *mrb, const char *s, size_t len, mrbc_context *cxt); 189 192 190 193 /** @} */ -
EcnlProtoTool/trunk/mruby-2.1.1/include/mruby/data.h
r331 r439 1 /* 2 ** mruby/data.h - Data class1 /** 2 ** @file mruby/data.h - Data class 3 3 ** 4 4 ** See Copyright Notice in mruby.h … … 40 40 mrb_data_object_alloc(mrb,klass,ptr,type) 41 41 42 #define Data_Make_Struct(mrb,klass,strct,type,sval,data) do { \ 43 sval = mrb_malloc(mrb, sizeof(strct)); \ 44 { static const strct zero = { 0 }; *sval = zero; };\ 45 data = Data_Wrap_Struct(mrb,klass,type,sval);\ 42 #define Data_Make_Struct(mrb,klass,strct,type,sval,data_obj) do { \ 43 (data_obj) = Data_Wrap_Struct(mrb,klass,type,NULL);\ 44 (sval) = (strct *)mrb_malloc(mrb, sizeof(strct)); \ 45 { static const strct zero = { 0 }; *(sval) = zero; };\ 46 (data_obj)->data = (sval);\ 46 47 } while (0) 47 48 … … 63 64 } while (0) 64 65 65 static inlinevoid66 MRB_INLINE void 66 67 mrb_data_init(mrb_value v, void *ptr, const mrb_data_type *type) 67 68 { 68 mrb_assert(mrb_ type(v) == MRB_TT_DATA);69 mrb_assert(mrb_data_p(v)); 69 70 DATA_PTR(v) = ptr; 70 71 DATA_TYPE(v) = type; -
EcnlProtoTool/trunk/mruby-2.1.1/include/mruby/debug.h
r331 r439 1 /* 2 ** mruby/debug.h - mruby debug info1 /** 2 ** @file mruby/debug.h - mruby debug info 3 3 ** 4 4 ** See Copyright Notice in mruby.h … … 27 27 typedef struct mrb_irep_debug_info_file { 28 28 uint32_t start_pos; 29 const char *filename;30 29 mrb_sym filename_sym; 31 30 uint32_t line_entry_count; … … 48 47 * @return returns NULL if not found 49 48 */ 50 MRB_API const char *mrb_debug_get_filename(mrb_ irep *irep, uint32_t pc);49 MRB_API const char *mrb_debug_get_filename(mrb_state *mrb, mrb_irep *irep, ptrdiff_t pc); 51 50 52 51 /* … … 54 53 * @return returns -1 if not found 55 54 */ 56 MRB_API int32_t mrb_debug_get_line(mrb_ irep *irep, uint32_t pc);55 MRB_API int32_t mrb_debug_get_line(mrb_state *mrb, mrb_irep *irep, ptrdiff_t pc); 57 56 57 MRB_API mrb_irep_debug_info *mrb_debug_info_alloc(mrb_state *mrb, mrb_irep *irep); 58 58 MRB_API mrb_irep_debug_info_file *mrb_debug_info_append_file( 59 mrb_state *mrb, mrb_irep *irep, 59 mrb_state *mrb, mrb_irep_debug_info *info, 60 const char *filename, uint16_t *lines, 60 61 uint32_t start_pos, uint32_t end_pos); 61 MRB_API mrb_irep_debug_info *mrb_debug_info_alloc(mrb_state *mrb, mrb_irep *irep);62 62 MRB_API void mrb_debug_info_free(mrb_state *mrb, mrb_irep_debug_info *d); 63 63 -
EcnlProtoTool/trunk/mruby-2.1.1/include/mruby/dump.h
r331 r439 1 /* 2 ** mruby/dump.h - mruby binary dumper (mrbc binary format)1 /** 2 ** @file mruby/dump.h - mruby binary dumper (mrbc binary format) 3 3 ** 4 4 ** See Copyright Notice in mruby.h … … 32 32 #endif 33 33 MRB_API mrb_irep *mrb_read_irep(mrb_state*, const uint8_t*); 34 MRB_API mrb_irep *mrb_read_irep_buf(mrb_state*, const void*, size_t); 34 35 35 36 /* dump/load error code … … 53 54 #define RITE_BINARY_IDENT "RITE" 54 55 #define RITE_BINARY_IDENT_LIL "ETIR" 55 #define RITE_BINARY_FORMAT_VER "000 4"56 #define RITE_BINARY_FORMAT_VER "0006" 56 57 #define RITE_COMPILER_NAME "MATZ" 57 58 #define RITE_COMPILER_VERSION "0000" 58 59 59 #define RITE_VM_VER "000 0"60 #define RITE_VM_VER "0002" 60 61 61 62 #define RITE_BINARY_EOF "END\0" 62 63 #define RITE_SECTION_IREP_IDENT "IREP" 63 #define RITE_SECTION_LINENO_IDENT "LINE"64 64 #define RITE_SECTION_DEBUG_IDENT "DBG\0" 65 65 #define RITE_SECTION_LV_IDENT "LVAR" … … 67 67 #define MRB_DUMP_DEFAULT_STR_LEN 128 68 68 #define MRB_DUMP_ALIGNMENT sizeof(uint32_t) 69 70 #ifdef __CA850__71 #pragma pack(1)72 #elif __RX73 #pragma pack74 #elif _MSC_VER75 #pragma pack(push, 1)76 #endif77 #ifndef __GNUC__78 #define __attribute__(x)79 #endif // !__GNUC__80 69 81 70 /* binary header */ … … 87 76 uint8_t compiler_name[4]; /* Compiler name */ 88 77 uint8_t compiler_version[4]; 89 } __attribute__((packed));78 }; 90 79 91 80 /* section header */ … … 96 85 struct rite_section_header { 97 86 RITE_SECTION_HEADER; 98 } __attribute__((packed));87 }; 99 88 100 89 struct rite_section_irep_header { … … 102 91 103 92 uint8_t rite_version[4]; /* Rite Instruction Specification Version */ 104 } __attribute__((packed)); 105 106 struct rite_section_lineno_header { 107 RITE_SECTION_HEADER; 108 } __attribute__((packed)); 93 }; 109 94 110 95 struct rite_section_debug_header { 111 96 RITE_SECTION_HEADER; 112 } __attribute__((packed));97 }; 113 98 114 99 struct rite_section_lv_header { 115 100 RITE_SECTION_HEADER; 116 } __attribute__((packed));101 }; 117 102 118 103 #define RITE_LV_NULL_MARK UINT16_MAX … … 120 105 struct rite_binary_footer { 121 106 RITE_SECTION_HEADER; 122 } __attribute__((packed)); 123 124 #ifdef __CA850__ 125 #pragma pack(8) 126 #elif __RX 127 #pragma unpack 128 #elif _MSC_VER 129 #pragma pack(pop) 130 #endif 107 }; 131 108 132 109 static inline int -
EcnlProtoTool/trunk/mruby-2.1.1/include/mruby/error.h
r331 r439 1 /* 2 ** mruby/error.h - Exception class1 /** 2 ** @file mruby/error.h - Exception class 3 3 ** 4 4 ** See Copyright Notice in mruby.h … … 25 25 MRB_API mrb_value mrb_exc_new_str(mrb_state *mrb, struct RClass* c, mrb_value str); 26 26 #define mrb_exc_new_str_lit(mrb, c, lit) mrb_exc_new_str(mrb, c, mrb_str_new_lit(mrb, lit)) 27 MRB_API mrb_value mrb_make_exception(mrb_state *mrb, int argc, const mrb_value *argv);27 MRB_API mrb_value mrb_make_exception(mrb_state *mrb, mrb_int argc, const mrb_value *argv); 28 28 MRB_API mrb_value mrb_exc_backtrace(mrb_state *mrb, mrb_value exc); 29 29 MRB_API mrb_value mrb_get_backtrace(mrb_state *mrb); 30 30 MRB_API mrb_noreturn void mrb_no_method_error(mrb_state *mrb, mrb_sym id, mrb_value args, const char *fmt, ...); 31 31 32 /* declaration for failmethod */32 /* declaration for `fail` method */ 33 33 MRB_API mrb_value mrb_f_raise(mrb_state*, mrb_value); 34 34 35 #if defined(MRB_64BIT) || defined(MRB_USE_FLOAT) || defined(MRB_NAN_BOXING) || defined(MRB_WORD_BOXING) 35 36 struct RBreak { 36 37 MRB_OBJECT_HEADER; 37 struct iv_tbl *iv;38 38 struct RProc *proc; 39 39 mrb_value val; 40 40 }; 41 #define mrb_break_value_get(brk) ((brk)->val) 42 #define mrb_break_value_set(brk, v) ((brk)->val = v) 43 #else 44 struct RBreak { 45 MRB_OBJECT_HEADER; 46 struct RProc *proc; 47 union mrb_value_union value; 48 }; 49 #define RBREAK_VALUE_TT_MASK ((1 << 8) - 1) 50 static inline mrb_value 51 mrb_break_value_get(struct RBreak *brk) 52 { 53 mrb_value val; 54 val.value = brk->value; 55 val.tt = (enum mrb_vtype)(brk->flags & RBREAK_VALUE_TT_MASK); 56 return val; 57 } 58 static inline void 59 mrb_break_value_set(struct RBreak *brk, mrb_value val) 60 { 61 brk->value = val.value; 62 brk->flags &= ~RBREAK_VALUE_TT_MASK; 63 brk->flags |= val.tt; 64 } 65 #endif /* MRB_64BIT || MRB_USE_FLOAT || MRB_NAN_BOXING || MRB_WORD_BOXING */ 66 #define mrb_break_proc_get(brk) ((brk)->proc) 67 #define mrb_break_proc_set(brk, p) ((brk)->proc = p) 41 68 42 69 /** 43 70 * Protect 44 71 * 45 * @mrbgem mruby-error72 * Implemented in the mruby-error mrbgem 46 73 */ 47 74 MRB_API mrb_value mrb_protect(mrb_state *mrb, mrb_func_t body, mrb_value data, mrb_bool *state); … … 50 77 * Ensure 51 78 * 52 * @mrbgem mruby-error79 * Implemented in the mruby-error mrbgem 53 80 */ 54 81 MRB_API mrb_value mrb_ensure(mrb_state *mrb, mrb_func_t body, mrb_value b_data, … … 58 85 * Rescue 59 86 * 60 * @mrbgem mruby-error87 * Implemented in the mruby-error mrbgem 61 88 */ 62 89 MRB_API mrb_value mrb_rescue(mrb_state *mrb, mrb_func_t body, mrb_value b_data, … … 66 93 * Rescue exception 67 94 * 68 * @mrbgem mruby-error95 * Implemented in the mruby-error mrbgem 69 96 */ 70 97 MRB_API mrb_value mrb_rescue_exceptions(mrb_state *mrb, mrb_func_t body, mrb_value b_data, -
EcnlProtoTool/trunk/mruby-2.1.1/include/mruby/gc.h
r331 r439 1 /* 2 ** mruby/gc.h - garbage collector for mruby1 /** 2 ** @file mruby/gc.h - garbage collector for mruby 3 3 ** 4 4 ** See Copyright Notice in mruby.h … … 34 34 } mrb_gc_state; 35 35 36 /* Disable MSVC warning "C4200: nonstandard extension used: zero-sized array 37 * in struct/union" when in C++ mode */ 38 #ifdef _MSC_VER 39 #pragma warning(push) 40 #pragma warning(disable : 4200) 41 #endif 42 36 43 typedef struct mrb_heap_page { 37 44 struct RBasic *freelist; … … 43 50 void *objects[]; 44 51 } mrb_heap_page; 52 53 #ifdef _MSC_VER 54 #pragma warning(pop) 55 #endif 45 56 46 57 typedef struct mrb_gc { -
EcnlProtoTool/trunk/mruby-2.1.1/include/mruby/hash.h
r331 r439 1 /* 2 ** mruby/hash.h - Hash class1 /** 2 ** @file mruby/hash.h - Hash class 3 3 ** 4 4 ** See Copyright Notice in mruby.h … … 9 9 10 10 #include "common.h" 11 #include <mruby/khash.h>12 11 13 12 /** … … 19 18 MRB_OBJECT_HEADER; 20 19 struct iv_tbl *iv; 21 struct kh_ht*ht;20 struct htable *ht; 22 21 }; 23 22 … … 25 24 #define mrb_hash_value(p) mrb_obj_value((void*)(p)) 26 25 27 MRB_API mrb_value mrb_hash_new_capa(mrb_state*, mrb_int); 26 MRB_API mrb_value mrb_hash_new_capa(mrb_state *mrb, mrb_int capa); 27 MRB_API mrb_value mrb_ensure_hash_type(mrb_state *mrb, mrb_value hash); 28 MRB_API mrb_value mrb_check_hash_type(mrb_state *mrb, mrb_value hash); 28 29 29 30 /* … … 75 76 * Equivalent to: 76 77 * 77 * hash. hash_key?(key) ? hash[key] : def78 * hash.key?(key) ? hash[key] : def 78 79 * 79 80 * @param mrb The mruby state reference. … … 95 96 * @param hash The target hash. 96 97 * @param key The key to delete. 97 * @return The deleted value. 98 * @return The deleted value. This value is not protected from GC. Use `mrb_gc_protect()` if necessary. 98 99 */ 99 100 MRB_API mrb_value mrb_hash_delete_key(mrb_state *mrb, mrb_value hash, mrb_value key); … … 111 112 */ 112 113 MRB_API mrb_value mrb_hash_keys(mrb_state *mrb, mrb_value hash); 113 MRB_API mrb_value mrb_check_hash_type(mrb_state *mrb, mrb_value hash); 114 /* 115 * Check if the hash has the key. 116 * 117 * Equivalent to: 118 * 119 * hash.key?(key) 120 * 121 * @param mrb The mruby state reference. 122 * @param hash The target hash. 123 * @param key The key to check existence. 124 * @return True if the hash has the key 125 */ 126 MRB_API mrb_bool mrb_hash_key_p(mrb_state *mrb, mrb_value hash, mrb_value key); 114 127 115 128 /* … … 124 137 * @return True if the hash is empty, false otherwise. 125 138 */ 126 MRB_API mrb_ valuemrb_hash_empty_p(mrb_state *mrb, mrb_value self);139 MRB_API mrb_bool mrb_hash_empty_p(mrb_state *mrb, mrb_value self); 127 140 128 141 /* … … 152 165 MRB_API mrb_value mrb_hash_clear(mrb_state *mrb, mrb_value hash); 153 166 154 /* declaration of struct kh_ht */ 155 /* be careful when you touch the internal */ 156 typedef struct { 157 mrb_value v; 158 mrb_int n; 159 } mrb_hash_value; 160 161 KHASH_DECLARE(ht, mrb_value, mrb_hash_value, TRUE) 167 /* 168 * Get hash size. 169 * 170 * Equivalent to: 171 * 172 * hash.size 173 * 174 * @param mrb The mruby state reference. 175 * @param hash The target hash. 176 * @return The hash size. 177 */ 178 MRB_API mrb_int mrb_hash_size(mrb_state *mrb, mrb_value hash); 179 180 /* 181 * Copies the hash. 182 * 183 * 184 * @param mrb The mruby state reference. 185 * @param hash The target hash. 186 * @return The copy of the hash 187 */ 188 MRB_API mrb_value mrb_hash_dup(mrb_state *mrb, mrb_value hash); 189 190 /* 191 * Merges two hashes. The first hash will be modified by the 192 * second hash. 193 * 194 * @param mrb The mruby state reference. 195 * @param hash1 The target hash. 196 * @param hash2 Updating hash 197 */ 198 MRB_API void mrb_hash_merge(mrb_state *mrb, mrb_value hash1, mrb_value hash2); 162 199 163 200 /* RHASH_TBL allocates st_table if not available. */ … … 166 203 #define RHASH_IFNONE(h) mrb_iv_get(mrb, (h), mrb_intern_lit(mrb, "ifnone")) 167 204 #define RHASH_PROCDEFAULT(h) RHASH_IFNONE(h) 168 MRB_API struct kh_ht * mrb_hash_tbl(mrb_state *mrb, mrb_value hash);169 205 170 206 #define MRB_HASH_DEFAULT 1 … … 178 214 void mrb_gc_free_hash(mrb_state*, struct RHash*); 179 215 216 /* return non zero to break the loop */ 217 typedef int (mrb_hash_foreach_func)(mrb_state *mrb, mrb_value key, mrb_value val, void *data); 218 MRB_API void mrb_hash_foreach(mrb_state *mrb, struct RHash *hash, mrb_hash_foreach_func *func, void *p); 219 180 220 MRB_END_DECL 181 221 -
EcnlProtoTool/trunk/mruby-2.1.1/include/mruby/irep.h
r331 r439 1 /* 2 ** mruby/irep.h - mrb_irep structure1 /** 2 ** @file mruby/irep.h - mrb_irep structure 3 3 ** 4 4 ** See Copyright Notice in mruby.h … … 33 33 uint8_t flags; 34 34 35 mrb_code *iseq;35 const mrb_code *iseq; 36 36 mrb_value *pool; 37 37 mrb_sym *syms; … … 40 40 struct mrb_locals *lv; 41 41 /* debug info */ 42 mrb_bool own_filename;43 const char *filename;44 uint16_t *lines;45 42 struct mrb_irep_debug_info* debug_info; 46 43 47 size_t ilen, plen, slen, rlen, refcnt; 44 uint16_t ilen, plen, slen, rlen; 45 uint32_t refcnt; 48 46 } mrb_irep; 49 47 … … 51 49 52 50 MRB_API mrb_irep *mrb_add_irep(mrb_state *mrb); 51 52 /* @param [const uint8_t*] irep code, expected as a literal */ 53 53 MRB_API mrb_value mrb_load_irep(mrb_state*, const uint8_t*); 54 55 /* 56 * @param [const void*] irep code 57 * @param [size_t] size of irep buffer. If -1 is given, it is considered unrestricted. 58 */ 59 MRB_API mrb_value mrb_load_irep_buf(mrb_state*, const void*, size_t); 60 61 /* @param [const uint8_t*] irep code, expected as a literal */ 54 62 MRB_API mrb_value mrb_load_irep_cxt(mrb_state*, const uint8_t*, mrbc_context*); 63 64 /* 65 * @param [const void*] irep code 66 * @param [size_t] size of irep buffer. If -1 is given, it is considered unrestricted. 67 */ 68 MRB_API mrb_value mrb_load_irep_buf_cxt(mrb_state*, const void*, size_t, mrbc_context*); 69 55 70 void mrb_irep_free(mrb_state*, struct mrb_irep*); 56 71 void mrb_irep_incref(mrb_state*, struct mrb_irep*); 57 72 void mrb_irep_decref(mrb_state*, struct mrb_irep*); 73 void mrb_irep_cutref(mrb_state*, struct mrb_irep*); 74 void mrb_irep_remove_lv(mrb_state *mrb, mrb_irep *irep); 75 76 struct mrb_insn_data { 77 uint8_t insn; 78 uint16_t a; 79 uint16_t b; 80 uint8_t c; 81 }; 82 83 struct mrb_insn_data mrb_decode_insn(const mrb_code *pc); 58 84 59 85 MRB_END_DECL -
EcnlProtoTool/trunk/mruby-2.1.1/include/mruby/istruct.h
r331 r439 1 /* 2 ** mruby/istruct.h - Inline structures1 /** 2 ** @file mruby/istruct.h - Inline structures 3 3 ** 4 4 ** See Copyright Notice in mruby.h … … 20 20 #define ISTRUCT_DATA_SIZE (sizeof(void*) * 3) 21 21 22 struct RI struct {22 struct RIStruct { 23 23 MRB_OBJECT_HEADER; 24 24 char inline_data[ISTRUCT_DATA_SIZE]; 25 25 }; 26 26 27 #define RISTRUCT(obj) ((struct RI struct*)(mrb_ptr(obj)))27 #define RISTRUCT(obj) ((struct RIStruct*)(mrb_ptr(obj))) 28 28 #define ISTRUCT_PTR(obj) (RISTRUCT(obj)->inline_data) 29 29 -
EcnlProtoTool/trunk/mruby-2.1.1/include/mruby/khash.h
r331 r439 1 /* 2 ** mruby/khash.c- Hash for mruby1 /** 2 ** @file mruby/khash.h - Hash for mruby 3 3 ** 4 4 ** See Copyright Notice in mruby.h -
EcnlProtoTool/trunk/mruby-2.1.1/include/mruby/numeric.h
r331 r439 1 /* 2 ** mruby/numeric.h - Numeric, Integer, Float, Fixnum class1 /** 2 ** @file mruby/numeric.h - Numeric, Integer, Float, Fixnum class 3 3 ** 4 4 ** See Copyright Notice in mruby.h … … 17 17 MRB_BEGIN_DECL 18 18 19 #define POSFIXABLE(f) ((f) <= MRB_INT_MAX) 20 #define NEGFIXABLE(f) ((f) >= MRB_INT_MIN) 21 #define FIXABLE(f) (POSFIXABLE(f) && NEGFIXABLE(f)) 22 19 #define TYPED_POSFIXABLE(f,t) ((f) <= (t)MRB_INT_MAX) 20 #define TYPED_NEGFIXABLE(f,t) ((f) >= (t)MRB_INT_MIN) 21 #define TYPED_FIXABLE(f,t) (TYPED_POSFIXABLE(f,t) && TYPED_NEGFIXABLE(f,t)) 22 #define POSFIXABLE(f) TYPED_POSFIXABLE(f,mrb_int) 23 #define NEGFIXABLE(f) TYPED_NEGFIXABLE(f,mrb_int) 24 #define FIXABLE(f) TYPED_FIXABLE(f,mrb_int) 25 #ifndef MRB_WITHOUT_FLOAT 23 26 #ifdef MRB_INT64 24 #define FIXABLE_FLOAT(f) FIXABLE((mrb_int)(f))27 #define FIXABLE_FLOAT(f) ((f)>=-9223372036854775808.0 && (f)<9223372036854775808.0) 25 28 #else 26 #define FIXABLE_FLOAT(f) FIXABLE(f) 29 #define FIXABLE_FLOAT(f) TYPED_FIXABLE(f,mrb_float) 30 #endif 27 31 #endif 28 32 33 #ifndef MRB_WITHOUT_FLOAT 29 34 MRB_API mrb_value mrb_flo_to_fixnum(mrb_state *mrb, mrb_value val); 30 MRB_API mrb_value mrb_fixnum_to_str(mrb_state *mrb, mrb_value x, int base); 35 #endif 36 MRB_API mrb_value mrb_fixnum_to_str(mrb_state *mrb, mrb_value x, mrb_int base); 31 37 /* ArgumentError if format string doesn't match /%(\.[0-9]+)?[aAeEfFgG]/ */ 38 #ifndef MRB_WITHOUT_FLOAT 32 39 MRB_API mrb_value mrb_float_to_str(mrb_state *mrb, mrb_value x, const char *fmt); 33 40 MRB_API mrb_float mrb_to_flo(mrb_state *mrb, mrb_value x); 41 MRB_API mrb_value mrb_int_value(mrb_state *mrb, mrb_float f); 42 #endif 34 43 35 mrb_value mrb_fixnum_plus(mrb_state *mrb, mrb_value x, mrb_value y); 36 mrb_value mrb_fixnum_minus(mrb_state *mrb, mrb_value x, mrb_value y); 37 mrb_value mrb_fixnum_mul(mrb_state *mrb, mrb_value x, mrb_value y); 38 mrb_value mrb_num_div(mrb_state *mrb, mrb_value x, mrb_value y); 44 MRB_API mrb_value mrb_num_plus(mrb_state *mrb, mrb_value x, mrb_value y); 45 MRB_API mrb_value mrb_num_minus(mrb_state *mrb, mrb_value x, mrb_value y); 46 MRB_API mrb_value mrb_num_mul(mrb_state *mrb, mrb_value x, mrb_value y); 39 47 40 48 #ifndef __has_builtin … … 153 161 #endif 154 162 163 #ifndef MRB_WITHOUT_FLOAT 164 # include <stdint.h> 165 # include <float.h> 166 167 # define MRB_FLT_RADIX FLT_RADIX 168 169 # ifdef MRB_USE_FLOAT 170 # define MRB_FLT_MANT_DIG FLT_MANT_DIG 171 # define MRB_FLT_EPSILON FLT_EPSILON 172 # define MRB_FLT_DIG FLT_DIG 173 # define MRB_FLT_MIN_EXP FLT_MIN_EXP 174 # define MRB_FLT_MIN FLT_MIN 175 # define MRB_FLT_MIN_10_EXP FLT_MIN_10_EXP 176 # define MRB_FLT_MAX_EXP FLT_MAX_EXP 177 # define MRB_FLT_MAX FLT_MAX 178 # define MRB_FLT_MAX_10_EXP FLT_MAX_10_EXP 179 180 # else /* not MRB_USE_FLOAT */ 181 # define MRB_FLT_MANT_DIG DBL_MANT_DIG 182 # define MRB_FLT_EPSILON DBL_EPSILON 183 # define MRB_FLT_DIG DBL_DIG 184 # define MRB_FLT_MIN_EXP DBL_MIN_EXP 185 # define MRB_FLT_MIN DBL_MIN 186 # define MRB_FLT_MIN_10_EXP DBL_MIN_10_EXP 187 # define MRB_FLT_MAX_EXP DBL_MAX_EXP 188 # define MRB_FLT_MAX DBL_MAX 189 # define MRB_FLT_MAX_10_EXP DBL_MAX_10_EXP 190 # endif /* MRB_USE_FLOAT */ 191 #endif /* MRB_WITHOUT_FLOAT */ 192 155 193 MRB_END_DECL 156 194 -
EcnlProtoTool/trunk/mruby-2.1.1/include/mruby/object.h
r331 r439 1 /* 2 ** mruby/object.h - mruby object definition1 /** 2 ** @file mruby/object.h - mruby object definition 3 3 ** 4 4 ** See Copyright Notice in mruby.h … … 9 9 10 10 #define MRB_OBJECT_HEADER \ 11 enum mrb_vtype tt:8;\12 uint32_t color:3;\13 uint32_t flags:21;\14 struct RClass *c;\15 struct RBasic *gcnext11 struct RClass *c; \ 12 struct RBasic *gcnext; \ 13 enum mrb_vtype tt:8; \ 14 uint32_t color:3; \ 15 uint32_t flags:21 16 16 17 #define MRB_FLAG_TEST(obj, flag) ((obj)->flags & flag) 18 17 #define MRB_FLAG_TEST(obj, flag) ((obj)->flags & (flag)) 19 18 20 19 struct RBasic { … … 23 22 #define mrb_basic_ptr(v) ((struct RBasic*)(mrb_ptr(v))) 24 23 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) 24 #define MRB_FL_OBJ_IS_FROZEN (1 << 20) 25 #define MRB_FROZEN_P(o) ((o)->flags & MRB_FL_OBJ_IS_FROZEN) 26 #define MRB_SET_FROZEN_FLAG(o) ((o)->flags |= MRB_FL_OBJ_IS_FROZEN) 27 #define MRB_UNSET_FROZEN_FLAG(o) ((o)->flags &= ~MRB_FL_OBJ_IS_FROZEN) 28 #define mrb_frozen_p(o) MRB_FROZEN_P(o) 28 29 29 30 struct RObject { … … 33 34 #define mrb_obj_ptr(v) ((struct RObject*)(mrb_ptr(v))) 34 35 35 #define mrb_immediate_p(x) (mrb_type(x) < MRB_TT_HAS_BASIC)36 36 #define mrb_special_const_p(x) mrb_immediate_p(x) 37 37 -
EcnlProtoTool/trunk/mruby-2.1.1/include/mruby/opcode.h
r331 r439 1 /* 2 ** mruby/opcode.h - RiteVM operation codes1 /** 2 ** @file mruby/opcode.h - RiteVM operation codes 3 3 ** 4 4 ** See Copyright Notice in mruby.h … … 8 8 #define MRUBY_OPCODE_H 9 9 10 #define MAXARG_Bx (0xffff) 11 #define MAXARG_sBx (MAXARG_Bx>>1) /* 'sBx' is signed */ 12 13 /* instructions: packed 32 bit */ 14 /* ------------------------------- */ 15 /* A:B:C:OP = 9: 9: 7: 7 */ 16 /* A:Bx:OP = 9:16: 7 */ 17 /* Ax:OP = 25: 7 */ 18 /* A:Bz:Cz:OP = 9:14: 2: 7 */ 19 20 #define GET_OPCODE(i) ((int)(((mrb_code)(i)) & 0x7f)) 21 #define GETARG_A(i) ((int)((((mrb_code)(i)) >> 23) & 0x1ff)) 22 #define GETARG_B(i) ((int)((((mrb_code)(i)) >> 14) & 0x1ff)) 23 #define GETARG_C(i) ((int)((((mrb_code)(i)) >> 7) & 0x7f)) 24 #define GETARG_Bx(i) ((int)((((mrb_code)(i)) >> 7) & 0xffff)) 25 #define GETARG_sBx(i) ((int)(GETARG_Bx(i)-MAXARG_sBx)) 26 #define GETARG_Ax(i) ((int32_t)((((mrb_code)(i)) >> 7) & 0x1ffffff)) 27 #define GETARG_UNPACK_b(i,n1,n2) ((int)((((mrb_code)(i)) >> (7+(n2))) & (((1<<(n1))-1)))) 28 #define GETARG_UNPACK_c(i,n1,n2) ((int)((((mrb_code)(i)) >> 7) & (((1<<(n2))-1)))) 29 #define GETARG_b(i) GETARG_UNPACK_b(i,14,2) 30 #define GETARG_c(i) GETARG_UNPACK_c(i,14,2) 31 32 #define MKOPCODE(op) ((op) & 0x7f) 33 #define MKARG_A(c) ((mrb_code)((c) & 0x1ff) << 23) 34 #define MKARG_B(c) ((mrb_code)((c) & 0x1ff) << 14) 35 #define MKARG_C(c) (((c) & 0x7f) << 7) 36 #define MKARG_Bx(v) ((mrb_code)((v) & 0xffff) << 7) 37 #define MKARG_sBx(v) MKARG_Bx((v)+MAXARG_sBx) 38 #define MKARG_Ax(v) ((mrb_code)((v) & 0x1ffffff) << 7) 39 #define MKARG_PACK(b,n1,c,n2) ((((b) & ((1<<n1)-1)) << (7+n2))|(((c) & ((1<<n2)-1)) << 7)) 40 #define MKARG_bc(b,c) MKARG_PACK(b,14,c,2) 41 42 #define MKOP_A(op,a) (MKOPCODE(op)|MKARG_A(a)) 43 #define MKOP_AB(op,a,b) (MKOP_A(op,a)|MKARG_B(b)) 44 #define MKOP_ABC(op,a,b,c) (MKOP_AB(op,a,b)|MKARG_C(c)) 45 #define MKOP_ABx(op,a,bx) (MKOP_A(op,a)|MKARG_Bx(bx)) 46 #define MKOP_Bx(op,bx) (MKOPCODE(op)|MKARG_Bx(bx)) 47 #define MKOP_sBx(op,sbx) (MKOPCODE(op)|MKARG_sBx(sbx)) 48 #define MKOP_AsBx(op,a,sbx) (MKOP_A(op,a)|MKARG_sBx(sbx)) 49 #define MKOP_Ax(op,ax) (MKOPCODE(op)|MKARG_Ax(ax)) 50 #define MKOP_Abc(op,a,b,c) (MKOP_A(op,a)|MKARG_bc(b,c)) 51 52 enum { 53 /*----------------------------------------------------------------------- 54 operation code operand description 55 ------------------------------------------------------------------------*/ 56 OP_NOP=0,/* */ 57 OP_MOVE,/* A B R(A) := R(B) */ 58 OP_LOADL,/* A Bx R(A) := Pool(Bx) */ 59 OP_LOADI,/* A sBx R(A) := sBx */ 60 OP_LOADSYM,/* A Bx R(A) := Syms(Bx) */ 61 OP_LOADNIL,/* A R(A) := nil */ 62 OP_LOADSELF,/* A R(A) := self */ 63 OP_LOADT,/* A R(A) := true */ 64 OP_LOADF,/* A R(A) := false */ 65 66 OP_GETGLOBAL,/* A Bx R(A) := getglobal(Syms(Bx)) */ 67 OP_SETGLOBAL,/* A Bx setglobal(Syms(Bx), R(A)) */ 68 OP_GETSPECIAL,/*A Bx R(A) := Special[Bx] */ 69 OP_SETSPECIAL,/*A Bx Special[Bx] := R(A) */ 70 OP_GETIV,/* A Bx R(A) := ivget(Syms(Bx)) */ 71 OP_SETIV,/* A Bx ivset(Syms(Bx),R(A)) */ 72 OP_GETCV,/* A Bx R(A) := cvget(Syms(Bx)) */ 73 OP_SETCV,/* A Bx cvset(Syms(Bx),R(A)) */ 74 OP_GETCONST,/* A Bx R(A) := constget(Syms(Bx)) */ 75 OP_SETCONST,/* A Bx constset(Syms(Bx),R(A)) */ 76 OP_GETMCNST,/* A Bx R(A) := R(A)::Syms(Bx) */ 77 OP_SETMCNST,/* A Bx R(A+1)::Syms(Bx) := R(A) */ 78 OP_GETUPVAR,/* A B C R(A) := uvget(B,C) */ 79 OP_SETUPVAR,/* A B C uvset(B,C,R(A)) */ 80 81 OP_JMP,/* sBx pc+=sBx */ 82 OP_JMPIF,/* A sBx if R(A) pc+=sBx */ 83 OP_JMPNOT,/* A sBx if !R(A) pc+=sBx */ 84 OP_ONERR,/* sBx rescue_push(pc+sBx) */ 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) */ 87 OP_POPERR,/* A A.times{rescue_pop()} */ 88 OP_RAISE,/* A raise(R(A)) */ 89 OP_EPUSH,/* Bx ensure_push(SEQ[Bx]) */ 90 OP_EPOP,/* A A.times{ensure_pop().call} */ 91 92 OP_SEND,/* A B C R(A) := call(R(A),Syms(B),R(A+1),...,R(A+C)) */ 93 OP_SENDB,/* A B C R(A) := call(R(A),Syms(B),R(A+1),...,R(A+C),&R(A+C+1))*/ 94 OP_FSEND,/* A B C R(A) := fcall(R(A),Syms(B),R(A+1),...,R(A+C-1)) */ 95 OP_CALL,/* A R(A) := self.call(frame.argc, frame.argv) */ 96 OP_SUPER,/* A C R(A) := super(R(A+1),... ,R(A+C+1)) */ 97 OP_ARGARY,/* A Bx R(A) := argument array (16=6:1:5:4) */ 98 OP_ENTER,/* Ax arg setup according to flags (23=5:5:1:5:5:1:1) */ 99 OP_KARG,/* A B C R(A) := kdict[Syms(B)]; if C kdict.rm(Syms(B)) */ 100 OP_KDICT,/* A C R(A) := kdict */ 101 102 OP_RETURN,/* A B return R(A) (B=normal,in-block return/break) */ 103 OP_TAILCALL,/* A B C return call(R(A),Syms(B),*R(C)) */ 104 OP_BLKPUSH,/* A Bx R(A) := block (16=6:1:5:4) */ 105 106 OP_ADD,/* A B C R(A) := R(A)+R(A+1) (Syms[B]=:+,C=1) */ 107 OP_ADDI,/* A B C R(A) := R(A)+C (Syms[B]=:+) */ 108 OP_SUB,/* A B C R(A) := R(A)-R(A+1) (Syms[B]=:-,C=1) */ 109 OP_SUBI,/* A B C R(A) := R(A)-C (Syms[B]=:-) */ 110 OP_MUL,/* A B C R(A) := R(A)*R(A+1) (Syms[B]=:*,C=1) */ 111 OP_DIV,/* A B C R(A) := R(A)/R(A+1) (Syms[B]=:/,C=1) */ 112 OP_EQ,/* A B C R(A) := R(A)==R(A+1) (Syms[B]=:==,C=1) */ 113 OP_LT,/* A B C R(A) := R(A)<R(A+1) (Syms[B]=:<,C=1) */ 114 OP_LE,/* A B C R(A) := R(A)<=R(A+1) (Syms[B]=:<=,C=1) */ 115 OP_GT,/* A B C R(A) := R(A)>R(A+1) (Syms[B]=:>,C=1) */ 116 OP_GE,/* A B C R(A) := R(A)>=R(A+1) (Syms[B]=:>=,C=1) */ 117 118 OP_ARRAY,/* A B C R(A) := ary_new(R(B),R(B+1)..R(B+C)) */ 119 OP_ARYCAT,/* A B ary_cat(R(A),R(B)) */ 120 OP_ARYPUSH,/* A B ary_push(R(A),R(B)) */ 121 OP_AREF,/* A B C R(A) := R(B)[C] */ 122 OP_ASET,/* A B C R(B)[C] := R(A) */ 123 OP_APOST,/* A B C *R(A),R(A+1)..R(A+C) := R(A) */ 124 125 OP_STRING,/* A Bx R(A) := str_dup(Lit(Bx)) */ 126 OP_STRCAT,/* A B str_cat(R(A),R(B)) */ 127 128 OP_HASH,/* A B C R(A) := hash_new(R(B),R(B+1)..R(B+C)) */ 129 OP_LAMBDA,/* A Bz Cz R(A) := lambda(SEQ[Bz],Cz) */ 130 OP_RANGE,/* A B C R(A) := range_new(R(B),R(B+1),C) */ 131 132 OP_OCLASS,/* A R(A) := ::Object */ 133 OP_CLASS,/* A B R(A) := newclass(R(A),Syms(B),R(A+1)) */ 134 OP_MODULE,/* A B R(A) := newmodule(R(A),Syms(B)) */ 135 OP_EXEC,/* A Bx R(A) := blockexec(R(A),SEQ[Bx]) */ 136 OP_METHOD,/* A B R(A).newmethod(Syms(B),R(A+1)) */ 137 OP_SCLASS,/* A B R(A) := R(B).singleton_class */ 138 OP_TCLASS,/* A R(A) := target_class */ 139 140 OP_DEBUG,/* A B C print R(A),R(B),R(C) */ 141 OP_STOP,/* stop VM */ 142 OP_ERR,/* Bx raise RuntimeError with message Lit(Bx) */ 143 144 OP_RSVD1,/* reserved instruction #1 */ 145 OP_RSVD2,/* reserved instruction #2 */ 146 OP_RSVD3,/* reserved instruction #3 */ 147 OP_RSVD4,/* reserved instruction #4 */ 148 OP_RSVD5,/* reserved instruction #5 */ 10 enum mrb_insn { 11 #define OPCODE(x,_) OP_ ## x, 12 #include "mruby/ops.h" 13 #undef OPCODE 149 14 }; 150 15 … … 159 24 #define OP_R_RETURN 2 160 25 26 #define PEEK_B(pc) (*(pc)) 27 #define PEEK_S(pc) ((pc)[0]<<8|(pc)[1]) 28 #define PEEK_W(pc) ((pc)[0]<<16|(pc)[1]<<8|(pc)[2]) 29 30 #define READ_B() PEEK_B(pc++) 31 #define READ_S() (pc+=2, PEEK_S(pc-2)) 32 #define READ_W() (pc+=3, PEEK_W(pc-3)) 33 34 #define FETCH_Z() /* nothing */ 35 #define FETCH_B() do {a=READ_B();} while (0) 36 #define FETCH_BB() do {a=READ_B(); b=READ_B();} while (0) 37 #define FETCH_BBB() do {a=READ_B(); b=READ_B(); c=READ_B();} while (0) 38 #define FETCH_BS() do {a=READ_B(); b=READ_S();} while (0) 39 #define FETCH_S() do {a=READ_S();} while (0) 40 #define FETCH_W() do {a=READ_W();} while (0) 41 42 /* with OP_EXT1 (1st 16bit) */ 43 #define FETCH_Z_1() FETCH_Z() 44 #define FETCH_B_1() FETCH_S() 45 #define FETCH_BB_1() do {a=READ_S(); b=READ_B();} while (0) 46 #define FETCH_BBB_1() do {a=READ_S(); b=READ_B(); c=READ_B();} while (0) 47 #define FETCH_BS_1() do {a=READ_S(); b=READ_S();} while (0) 48 #define FETCH_S_1() FETCH_S() 49 #define FETCH_W_1() FETCH_W() 50 51 /* with OP_EXT2 (2nd 16bit) */ 52 #define FETCH_Z_2() FETCH_Z() 53 #define FETCH_B_2() FETCH_B() 54 #define FETCH_BB_2() do {a=READ_B(); b=READ_S();} while (0) 55 #define FETCH_BBB_2() do {a=READ_B(); b=READ_S(); c=READ_B();} while (0) 56 #define FETCH_BS_2() FETCH_BS() 57 #define FETCH_S_2() FETCH_S() 58 #define FETCH_W_2() FETCH_W() 59 60 /* with OP_EXT3 (1st & 2nd 16bit) */ 61 #define FETCH_Z_3() FETCH_Z() 62 #define FETCH_B_3() FETCH_B() 63 #define FETCH_BB_3() do {a=READ_S(); b=READ_S();} while (0) 64 #define FETCH_BBB_3() do {a=READ_S(); b=READ_S(); c=READ_B();} while (0) 65 #define FETCH_BS_3() do {a=READ_S(); b=READ_S();} while (0) 66 #define FETCH_S_3() FETCH_S() 67 #define FETCH_W_3() FETCH_W() 68 161 69 #endif /* MRUBY_OPCODE_H */ -
EcnlProtoTool/trunk/mruby-2.1.1/include/mruby/proc.h
r331 r439 1 /* 2 ** mruby/proc.h - Proc class1 /** 2 ** @file mruby/proc.h - Proc class 3 3 ** 4 4 ** See Copyright Notice in mruby.h … … 19 19 MRB_OBJECT_HEADER; 20 20 mrb_value *stack; 21 ptrdiff_t cioff; 22 union { 23 mrb_sym mid; 24 struct mrb_context *c; 25 } cxt; 21 struct mrb_context *cxt; 22 mrb_sym mid; 26 23 }; 27 24 28 #define MRB_SET_ENV_STACK_LEN(e,len) (e)->flags = (unsigned int)(len) 29 #define MRB_ENV_STACK_LEN(e) ((mrb_int)(e)->flags) 30 #define MRB_ENV_UNSHARE_STACK(e) ((e)->cioff = -1) 31 #define MRB_ENV_STACK_SHARED_P(e) ((e)->cioff >= 0) 25 /* flags (21bits): 1(shared flag):10(cioff/bidx):10(stack_len) */ 26 #define MRB_ENV_SET_STACK_LEN(e,len) ((e)->flags = (((e)->flags & ~0x3ff)|((unsigned int)(len) & 0x3ff))) 27 #define MRB_ENV_STACK_LEN(e) ((mrb_int)((e)->flags & 0x3ff)) 28 #define MRB_ENV_STACK_UNSHARED (1<<20) 29 #define MRB_ENV_UNSHARE_STACK(e) ((e)->flags |= MRB_ENV_STACK_UNSHARED) 30 #define MRB_ENV_STACK_SHARED_P(e) (((e)->flags & MRB_ENV_STACK_UNSHARED) == 0) 31 #define MRB_ENV_BIDX(e) (((e)->flags >> 10) & 0x3ff) 32 #define MRB_ENV_SET_BIDX(e,idx) ((e)->flags = (((e)->flags & ~(0x3ff<<10))|((unsigned int)(idx) & 0x3ff)<<10)) 32 33 33 MRB_APIvoid mrb_env_unshare(mrb_state*, struct REnv*);34 void mrb_env_unshare(mrb_state*, struct REnv*); 34 35 35 36 struct RProc { … … 39 40 mrb_func_t func; 40 41 } body; 41 struct RClass *target_class; 42 struct REnv *env; 42 struct RProc *upper; 43 union { 44 struct RClass *target_class; 45 struct REnv *env; 46 } e; 43 47 }; 44 48 … … 52 56 #define MRB_ASPEC_BLOCK(a) ((a) & 1) 53 57 54 #define MRB_PROC_CFUNC 128 55 #define MRB_PROC_CFUNC_P(p) (((p)->flags & MRB_PROC_CFUNC) != 0) 58 #define MRB_PROC_CFUNC_FL 128 59 #define MRB_PROC_CFUNC_P(p) (((p)->flags & MRB_PROC_CFUNC_FL) != 0) 60 #define MRB_PROC_CFUNC(p) (p)->body.func 56 61 #define MRB_PROC_STRICT 256 57 62 #define MRB_PROC_STRICT_P(p) (((p)->flags & MRB_PROC_STRICT) != 0) 58 63 #define MRB_PROC_ORPHAN 512 59 64 #define MRB_PROC_ORPHAN_P(p) (((p)->flags & MRB_PROC_ORPHAN) != 0) 65 #define MRB_PROC_ENVSET 1024 66 #define MRB_PROC_ENV_P(p) (((p)->flags & MRB_PROC_ENVSET) != 0) 67 #define MRB_PROC_ENV(p) (MRB_PROC_ENV_P(p) ? (p)->e.env : NULL) 68 #define MRB_PROC_TARGET_CLASS(p) (MRB_PROC_ENV_P(p) ? (p)->e.env->c : (p)->e.target_class) 69 #define MRB_PROC_SET_TARGET_CLASS(p,tc) do {\ 70 if (MRB_PROC_ENV_P(p)) {\ 71 (p)->e.env->c = (tc);\ 72 mrb_field_write_barrier(mrb, (struct RBasic*)(p)->e.env, (struct RBasic*)(tc));\ 73 }\ 74 else {\ 75 (p)->e.target_class = (tc);\ 76 mrb_field_write_barrier(mrb, (struct RBasic*)p, (struct RBasic*)(tc));\ 77 }\ 78 } while (0) 79 #define MRB_PROC_SCOPE 2048 80 #define MRB_PROC_SCOPE_P(p) (((p)->flags & MRB_PROC_SCOPE) != 0) 60 81 61 82 #define mrb_proc_ptr(v) ((struct RProc*)(mrb_ptr(v))) … … 66 87 MRB_API struct RProc *mrb_closure_new_cfunc(mrb_state *mrb, mrb_func_t func, int nlocals); 67 88 void mrb_proc_copy(struct RProc *a, struct RProc *b); 89 mrb_int mrb_proc_arity(const struct RProc *p); 68 90 69 91 /* implementation of #send method */ 70 MRB_APImrb_value mrb_f_send(mrb_state *mrb, mrb_value self);92 mrb_value mrb_f_send(mrb_state *mrb, mrb_value self); 71 93 72 94 /* following functions are defined in mruby-proc-ext so please include it when using */ 73 MRB_API struct RProc *mrb_proc_new_cfunc_with_env(mrb_state *, mrb_func_t, mrb_int, const mrb_value*);74 MRB_API mrb_value mrb_proc_cfunc_env_get(mrb_state *, mrb_int);95 MRB_API struct RProc *mrb_proc_new_cfunc_with_env(mrb_state *mrb, mrb_func_t func, mrb_int argc, const mrb_value *argv); 96 MRB_API mrb_value mrb_proc_cfunc_env_get(mrb_state *mrb, mrb_int idx); 75 97 /* old name */ 76 98 #define mrb_cfunc_env_get(mrb, idx) mrb_proc_cfunc_env_get(mrb, idx) 77 99 100 #define MRB_METHOD_FUNC_FL 1 101 #define MRB_METHOD_NOARG_FL 2 102 #ifndef MRB_METHOD_T_STRUCT 103 104 #define MRB_METHOD_FUNC_P(m) (((uintptr_t)(m))&MRB_METHOD_FUNC_FL) 105 #define MRB_METHOD_NOARG_P(m) (((uintptr_t)(m))&MRB_METHOD_NOARG_FL) 106 #define MRB_METHOD_NOARG_SET(m) ((m)=(mrb_method_t)(((uintptr_t)(m))|MRB_METHOD_NOARG_FL)) 107 #define MRB_METHOD_FUNC(m) ((mrb_func_t)((uintptr_t)(m)&(~(MRB_METHOD_NOARG_FL|MRB_METHOD_FUNC_FL)))) 108 #define MRB_METHOD_FROM_FUNC(m,fn) ((m)=(mrb_method_t)((((uintptr_t)(fn))|MRB_METHOD_FUNC_FL))) 109 #define MRB_METHOD_FROM_PROC(m,pr) ((m)=(mrb_method_t)(pr)) 110 #define MRB_METHOD_PROC_P(m) (!MRB_METHOD_FUNC_P(m)) 111 #define MRB_METHOD_PROC(m) ((struct RProc*)(m)) 112 #define MRB_METHOD_UNDEF_P(m) ((m)==0) 113 114 #else 115 116 #define MRB_METHOD_FUNC_P(m) ((m).flags&MRB_METHOD_FUNC_FL) 117 #define MRB_METHOD_NOARG_P(m) ((m).flags&MRB_METHOD_NOARG_FL) 118 #define MRB_METHOD_FUNC(m) ((m).func) 119 #define MRB_METHOD_NOARG_SET(m) do{(m).flags|=MRB_METHOD_NOARG_FL;}while(0) 120 #define MRB_METHOD_FROM_FUNC(m,fn) do{(m).flags=MRB_METHOD_FUNC_FL;(m).func=(fn);}while(0) 121 #define MRB_METHOD_FROM_PROC(m,pr) do{(m).flags=0;(m).proc=(pr);}while(0) 122 #define MRB_METHOD_PROC_P(m) (!MRB_METHOD_FUNC_P(m)) 123 #define MRB_METHOD_PROC(m) ((m).proc) 124 #define MRB_METHOD_UNDEF_P(m) ((m).proc==NULL) 125 126 #endif /* MRB_METHOD_T_STRUCT */ 127 128 #define MRB_METHOD_CFUNC_P(m) (MRB_METHOD_FUNC_P(m)?TRUE:(MRB_METHOD_PROC(m)?(MRB_PROC_CFUNC_P(MRB_METHOD_PROC(m))):FALSE)) 129 #define MRB_METHOD_CFUNC(m) (MRB_METHOD_FUNC_P(m)?MRB_METHOD_FUNC(m):((MRB_METHOD_PROC(m)&&MRB_PROC_CFUNC_P(MRB_METHOD_PROC(m)))?MRB_PROC_CFUNC(MRB_METHOD_PROC(m)):NULL)) 130 131 78 132 #include <mruby/khash.h> 79 KHASH_DECLARE(mt, mrb_sym, struct RProc*, TRUE)133 KHASH_DECLARE(mt, mrb_sym, mrb_method_t, TRUE) 80 134 81 135 MRB_END_DECL -
EcnlProtoTool/trunk/mruby-2.1.1/include/mruby/range.h
r331 r439 1 /* 2 ** mruby/range.h - Range class1 /** 2 ** @file mruby/range.h - Range class 3 3 ** 4 4 ** See Copyright Notice in mruby.h … … 15 15 MRB_BEGIN_DECL 16 16 17 #if defined(MRB_NAN_BOXING) && defined(MRB_64BIT) || defined(MRB_WORD_BOXING) 18 # define MRB_RANGE_EMBED 19 #endif 20 21 #ifdef MRB_RANGE_EMBED 22 struct RRange { 23 MRB_OBJECT_HEADER; 24 mrb_value beg; 25 mrb_value end; 26 mrb_bool excl; 27 }; 28 # define mrb_gc_free_range(mrb, p) ((void)0) 29 # define RANGE_BEG(p) ((p)->beg) 30 # define RANGE_END(p) ((p)->end) 31 #else 17 32 typedef struct mrb_range_edges { 18 33 mrb_value beg; 19 34 mrb_value end; 20 35 } mrb_range_edges; 21 22 36 struct RRange { 23 37 MRB_OBJECT_HEADER; 24 38 mrb_range_edges *edges; 25 mrb_bool excl : 1;39 mrb_bool excl; 26 40 }; 41 # define mrb_gc_free_range(mrb, p) mrb_free(mrb, (p)->edges) 42 # define RANGE_BEG(p) ((p)->edges->beg) 43 # define RANGE_END(p) ((p)->edges->end) 44 #endif 27 45 28 MRB_API struct RRange* mrb_range_ptr(mrb_state *mrb, mrb_value v); 29 #define mrb_range_raw_ptr(v) ((struct RRange*)mrb_ptr(v)) 30 #define mrb_range_value(p) mrb_obj_value((void*)(p)) 46 #define mrb_range_beg(mrb, r) RANGE_BEG(mrb_range_ptr(mrb, r)) 47 #define mrb_range_end(mrb, r) RANGE_END(mrb_range_ptr(mrb, r)) 48 #define mrb_range_excl_p(mrb, r) RANGE_EXCL(mrb_range_ptr(mrb, r)) 49 #define mrb_range_raw_ptr(r) ((struct RRange*)mrb_ptr(r)) 50 #define mrb_range_value(p) mrb_obj_value((void*)(p)) 51 #define RANGE_EXCL(p) ((p)->excl) 52 53 MRB_API struct RRange* mrb_range_ptr(mrb_state *mrb, mrb_value range); 31 54 32 55 /* … … 42 65 MRB_API mrb_value mrb_range_new(mrb_state *mrb, mrb_value start, mrb_value end, mrb_bool exclude); 43 66 44 MRB_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); 67 enum mrb_range_beg_len { 68 MRB_RANGE_TYPE_MISMATCH = 0, /* (failure) not range */ 69 MRB_RANGE_OK = 1, /* (success) range */ 70 MRB_RANGE_OUT = 2 /* (failure) out of range */ 71 }; 72 73 MRB_API enum mrb_range_beg_len mrb_range_beg_len(mrb_state *mrb, mrb_value range, mrb_int *begp, mrb_int *lenp, mrb_int len, mrb_bool trunc); 45 74 mrb_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)); 75 void mrb_gc_mark_range(mrb_state *mrb, struct RRange *r); 46 76 47 77 MRB_END_DECL -
EcnlProtoTool/trunk/mruby-2.1.1/include/mruby/re.h
r331 r439 1 /* 2 ** mruby/re.h - Regexp class1 /** 2 ** @file mruby/re.h - Regexp class 3 3 ** 4 4 ** See Copyright Notice in mruby.h -
EcnlProtoTool/trunk/mruby-2.1.1/include/mruby/string.h
r331 r439 1 /* 2 ** mruby/string.h - String class1 /** 2 ** @file mruby/string.h - String class 3 3 ** 4 4 ** See Copyright Notice in mruby.h … … 17 17 extern const char mrb_digitmap[]; 18 18 19 #define RSTRING_EMBED_LEN_MAX ((mrb_int)(sizeof(void*) * 3 - 1)) 19 #define RSTRING_EMBED_LEN_MAX \ 20 ((mrb_int)(sizeof(void*) * 3 + sizeof(void*) - 32 / CHAR_BIT - 1)) 20 21 21 22 struct RString { … … 23 24 union { 24 25 struct { 25 mrb_ intlen;26 mrb_ssize len; 26 27 union { 27 mrb_ intcapa;28 mrb_ssize capa; 28 29 struct mrb_shared_string *shared; 30 struct RString *fshared; 29 31 } aux; 30 32 char *ptr; 31 33 } heap; 32 char ary[RSTRING_EMBED_LEN_MAX + 1];33 34 } as; 34 35 }; 36 struct RStringEmbed { 37 MRB_OBJECT_HEADER; 38 char ary[]; 39 }; 40 41 #define RSTR_SET_TYPE_FLAG(s, type) (RSTR_UNSET_TYPE_FLAG(s), (s)->flags |= MRB_STR_##type) 42 #define RSTR_UNSET_TYPE_FLAG(s) ((s)->flags &= ~(MRB_STR_TYPE_MASK|MRB_STR_EMBED_LEN_MASK)) 35 43 36 44 #define RSTR_EMBED_P(s) ((s)->flags & MRB_STR_EMBED) … … 39 47 #define RSTR_SET_EMBED_LEN(s, n) do {\ 40 48 size_t tmp_n = (n);\ 41 s->flags &= ~MRB_STR_EMBED_LEN_MASK;\42 s->flags |= (tmp_n) << MRB_STR_EMBED_LEN_SHIFT;\49 (s)->flags &= ~MRB_STR_EMBED_LEN_MASK;\ 50 (s)->flags |= (tmp_n) << MRB_STR_EMBED_LEN_SHIFT;\ 43 51 } while (0) 44 52 #define RSTR_SET_LEN(s, n) do {\ … … 47 55 }\ 48 56 else {\ 49 s->as.heap.len = (mrb_int)(n);\57 (s)->as.heap.len = (mrb_ssize)(n);\ 50 58 }\ 51 59 } while (0) 60 #define RSTR_EMBED_PTR(s) (((struct RStringEmbed*)(s))->ary) 52 61 #define RSTR_EMBED_LEN(s)\ 53 62 (mrb_int)(((s)->flags & MRB_STR_EMBED_LEN_MASK) >> MRB_STR_EMBED_LEN_SHIFT) 54 #define RSTR_PTR(s) ((RSTR_EMBED_P(s)) ? (s)->as.ary : (s)->as.heap.ptr) 63 #define RSTR_EMBEDDABLE_P(len) ((len) <= RSTRING_EMBED_LEN_MAX) 64 65 #define RSTR_PTR(s) ((RSTR_EMBED_P(s)) ? RSTR_EMBED_PTR(s) : (s)->as.heap.ptr) 55 66 #define RSTR_LEN(s) ((RSTR_EMBED_P(s)) ? RSTR_EMBED_LEN(s) : (s)->as.heap.len) 56 67 #define RSTR_CAPA(s) (RSTR_EMBED_P(s) ? RSTRING_EMBED_LEN_MAX : (s)->as.heap.aux.capa) … … 60 71 #define RSTR_UNSET_SHARED_FLAG(s) ((s)->flags &= ~MRB_STR_SHARED) 61 72 73 #define RSTR_FSHARED_P(s) ((s)->flags & MRB_STR_FSHARED) 74 #define RSTR_SET_FSHARED_FLAG(s) ((s)->flags |= MRB_STR_FSHARED) 75 #define RSTR_UNSET_FSHARED_FLAG(s) ((s)->flags &= ~MRB_STR_FSHARED) 76 62 77 #define RSTR_NOFREE_P(s) ((s)->flags & MRB_STR_NOFREE) 63 78 #define RSTR_SET_NOFREE_FLAG(s) ((s)->flags |= MRB_STR_NOFREE) 64 79 #define RSTR_UNSET_NOFREE_FLAG(s) ((s)->flags &= ~MRB_STR_NOFREE) 65 80 66 /* 81 #ifdef MRB_UTF8_STRING 82 # define RSTR_ASCII_P(s) ((s)->flags & MRB_STR_ASCII) 83 # define RSTR_SET_ASCII_FLAG(s) ((s)->flags |= MRB_STR_ASCII) 84 # define RSTR_UNSET_ASCII_FLAG(s) ((s)->flags &= ~MRB_STR_ASCII) 85 # define RSTR_WRITE_ASCII_FLAG(s, v) (RSTR_UNSET_ASCII_FLAG(s), (s)->flags |= v) 86 # define RSTR_COPY_ASCII_FLAG(dst, src) RSTR_WRITE_ASCII_FLAG(dst, RSTR_ASCII_P(src)) 87 #else 88 # define RSTR_ASCII_P(s) (void)0 89 # define RSTR_SET_ASCII_FLAG(s) (void)0 90 # define RSTR_UNSET_ASCII_FLAG(s) (void)0 91 # define RSTR_WRITE_ASCII_FLAG(s, v) (void)0 92 # define RSTR_COPY_ASCII_FLAG(dst, src) (void)0 93 #endif 94 95 #define RSTR_POOL_P(s) ((s)->flags & MRB_STR_POOL) 96 #define RSTR_SET_POOL_FLAG(s) ((s)->flags |= MRB_STR_POOL) 97 98 /** 67 99 * Returns a pointer from a Ruby string 68 100 */ … … 75 107 #define RSTRING_END(s) (RSTRING_PTR(s) + RSTRING_LEN(s)) 76 108 MRB_API mrb_int mrb_str_strlen(mrb_state*, struct RString*); 109 #define RSTRING_CSTR(mrb,s) mrb_string_cstr(mrb, s) 77 110 78 111 #define MRB_STR_SHARED 1 79 #define MRB_STR_NOFREE 2 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 112 #define MRB_STR_FSHARED 2 113 #define MRB_STR_NOFREE 4 114 #define MRB_STR_EMBED 8 /* type flags up to here */ 115 #define MRB_STR_POOL 16 /* status flags from here */ 116 #define MRB_STR_ASCII 32 117 #define MRB_STR_EMBED_LEN_SHIFT 6 118 #define MRB_STR_EMBED_LEN_BIT 5 119 #define MRB_STR_EMBED_LEN_MASK (((1 << MRB_STR_EMBED_LEN_BIT) - 1) << MRB_STR_EMBED_LEN_SHIFT) 120 #define MRB_STR_TYPE_MASK (MRB_STR_POOL - 1) 121 84 122 85 123 void mrb_gc_free_str(mrb_state*, struct RString*); 86 MRB_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 124 125 MRB_API void mrb_str_modify(mrb_state *mrb, struct RString *s); 126 /* mrb_str_modify() with keeping ASCII flag if set */ 127 MRB_API void mrb_str_modify_keep_ascii(mrb_state *mrb, struct RString *s); 128 129 /** 130 * Finds the index of a substring in a string 131 */ 132 MRB_API mrb_int mrb_str_index(mrb_state *mrb, mrb_value str, const char *p, mrb_int len, mrb_int offset); 133 #define mrb_str_index_lit(mrb, str, lit, off) mrb_str_index(mrb, str, lit, mrb_strlen_lit(lit), off); 134 135 /** 136 * Appends self to other. Returns self as a concatenated string. 137 * 138 * 139 * Example: 140 * 94 141 * int 95 142 * main(int argc, … … 110 157 * str2 = mrb_str_new_lit(mrb, "def"); 111 158 * 112 * // Concat nates str2 to str1.159 * // Concatenates str2 to str1. 113 160 * mrb_str_concat(mrb, str1, str2); 114 161 * 115 * // Prints new Concatnated Ruby string. 116 * mrb_p(mrb, str1); 117 * 118 * mrb_close(mrb); 119 * return 0; 120 * } 121 * 122 * 123 * Result: 162 * // Prints new Concatenated Ruby string. 163 * mrb_p(mrb, str1); 164 * 165 * mrb_close(mrb); 166 * return 0; 167 * } 168 * 169 * Result: 124 170 * 125 171 * => "abcdef" 126 172 * 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.173 * @param mrb The current mruby state. 174 * @param self String to concatenate. 175 * @param other String to append to self. 130 176 * @return [mrb_value] Returns a new String appending other to self. 131 177 */ 132 MRB_API void mrb_str_concat(mrb_state *, mrb_value, mrb_value);133 134 /* 178 MRB_API void mrb_str_concat(mrb_state *mrb, mrb_value self, mrb_value other); 179 180 /** 135 181 * Adds two strings together. 136 182 * 137 183 * 138 * Example: 139 * 140 * !!!c 184 * Example: 185 * 141 186 * int 142 187 * main(int argc, … … 162 207 * mrb_p(mrb, b); 163 208 * 164 * // Concat nates both Ruby strings.209 * // Concatenates both Ruby strings. 165 210 * c = mrb_str_plus(mrb, a, b); 166 211 * 167 * // Prints new Concatnated Ruby string.168 * mrb_p(mrb, c);169 * 170 * mrb_close(mrb);171 * return 0;172 * }173 * 174 * 175 * 212 * // Prints new Concatenated Ruby string. 213 * mrb_p(mrb, c); 214 * 215 * mrb_close(mrb); 216 * return 0; 217 * } 218 * 219 * 220 * Result: 176 221 * 177 222 * => "abc" # First string 178 223 * => "def" # Second string 179 * => "abcdef" # First & Second concat nated.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.224 * => "abcdef" # First & Second concatenated. 225 * 226 * @param mrb The current mruby state. 227 * @param a First string to concatenate. 228 * @param b Second string to concatenate. 184 229 * @return [mrb_value] Returns a new String containing a concatenated to b. 185 230 */ 186 MRB_API mrb_value mrb_str_plus(mrb_state *, mrb_value, mrb_value);187 188 /* 231 MRB_API mrb_value mrb_str_plus(mrb_state *mrb, mrb_value a, mrb_value b); 232 233 /** 189 234 * Converts pointer into a Ruby string. 190 235 * 191 * @param [mrb_state]mrb The current mruby state.192 * @param [void*]p The pointer to convert to Ruby string.236 * @param mrb The current mruby state. 237 * @param p The pointer to convert to Ruby string. 193 238 * @return [mrb_value] Returns a new Ruby String. 194 239 */ 195 MRB_API mrb_value mrb_ptr_to_str(mrb_state * , void*);196 197 /* 240 MRB_API mrb_value mrb_ptr_to_str(mrb_state *mrb, void *p); 241 242 /** 198 243 * Returns an object as a Ruby string. 199 244 * 200 * @param [mrb_state]mrb The current mruby state.201 * @param [mrb_value]obj An object to return as a Ruby string.245 * @param mrb The current mruby state. 246 * @param obj An object to return as a Ruby string. 202 247 * @return [mrb_value] An object as a Ruby string. 203 248 */ 204 249 MRB_API mrb_value mrb_obj_as_string(mrb_state *mrb, mrb_value obj); 205 250 206 /* 251 /** 207 252 * Resizes the string's length. Returns the amount of characters 208 253 * in the specified by len. … … 210 255 * Example: 211 256 * 212 * !!!c213 257 * int 214 258 * main(int argc, … … 235 279 * Result: 236 280 * 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.281 * => "Hello" 282 * 283 * @param mrb The current mruby state. 284 * @param str The Ruby string to resize. 285 * @param len The length. 242 286 * @return [mrb_value] An object as a Ruby string. 243 287 */ 244 288 MRB_API mrb_value mrb_str_resize(mrb_state *mrb, mrb_value str, mrb_int len); 245 289 246 /* 290 /** 247 291 * Returns a sub string. 248 292 * 249 * Example: 250 * 251 * !!!c 293 * Example: 294 * 252 295 * int 253 296 * main(int argc, … … 275 318 * } 276 319 * 277 * 320 * Result: 278 321 * 279 322 * => "He" 280 323 * 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.324 * @param mrb The current mruby state. 325 * @param str Ruby string. 326 * @param beg The beginning point of the sub-string. 327 * @param len The end point of the sub-string. 285 328 * @return [mrb_value] An object as a Ruby sub-string. 286 329 */ 287 330 MRB_API mrb_value mrb_str_substr(mrb_state *mrb, mrb_value str, mrb_int beg, mrb_int len); 288 331 289 /* 332 /** 290 333 * Returns a Ruby string type. 291 334 * 292 335 * 293 * @param [mrb_state]mrb The current mruby state.294 * @param [mrb_value]str Ruby string.336 * @param mrb The current mruby state. 337 * @param str Ruby string. 295 338 * @return [mrb_value] A Ruby string. 296 339 */ 340 MRB_API mrb_value mrb_ensure_string_type(mrb_state *mrb, mrb_value str); 341 MRB_API mrb_value mrb_check_string_type(mrb_state *mrb, mrb_value str); 342 /* obsolete: use mrb_ensure_string_type() instead */ 297 343 MRB_API mrb_value mrb_string_type(mrb_state *mrb, mrb_value str); 298 344 299 MRB_API mrb_value mrb_check_string_type(mrb_state *mrb, mrb_value str); 345 346 MRB_API mrb_value mrb_str_new_capa(mrb_state *mrb, size_t capa); 300 347 MRB_API mrb_value mrb_str_buf_new(mrb_state *mrb, size_t capa); 301 348 302 MRB_API const char *mrb_string_value_cstr(mrb_state *mrb, mrb_value *ptr); 349 /* NULL terminated C string from mrb_value */ 350 MRB_API const char *mrb_string_cstr(mrb_state *mrb, mrb_value str); 351 /* NULL terminated C string from mrb_value; `str` will be updated */ 352 MRB_API const char *mrb_string_value_cstr(mrb_state *mrb, mrb_value *str); 353 /* obslete: use RSTRING_PTR() */ 303 354 MRB_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 */ 355 /* obslete: use RSTRING_LEN() */ 312 356 MRB_API mrb_int mrb_string_value_len(mrb_state *mrb, mrb_value str); 313 357 314 /* 358 /** 315 359 * Duplicates a string object. 316 360 * 317 361 * 318 * @param [mrb_state]mrb The current mruby state.319 * @param [mrb_value]str Ruby string.362 * @param mrb The current mruby state. 363 * @param str Ruby string. 320 364 * @return [mrb_value] Duplicated Ruby string. 321 365 */ 322 366 MRB_API mrb_value mrb_str_dup(mrb_state *mrb, mrb_value str); 323 367 324 /* 368 /** 325 369 * Returns a symbol from a passed in Ruby string. 326 370 * 327 * @param [mrb_state]mrb The current mruby state.328 * @param [mrb_value]self Ruby string.371 * @param mrb The current mruby state. 372 * @param self Ruby string. 329 373 * @return [mrb_value] A symbol. 330 374 */ … … 332 376 333 377 MRB_API mrb_value mrb_str_to_inum(mrb_state *mrb, mrb_value str, mrb_int base, mrb_bool badcheck); 378 MRB_API mrb_value mrb_cstr_to_inum(mrb_state *mrb, const char *s, mrb_int base, mrb_bool badcheck); 334 379 MRB_API double mrb_str_to_dbl(mrb_state *mrb, mrb_value str, mrb_bool badcheck); 335 336 /* 380 MRB_API double mrb_cstr_to_dbl(mrb_state *mrb, const char *s, mrb_bool badcheck); 381 382 /** 337 383 * Returns a converted string type. 384 * For type checking, non converting `mrb_to_str` is recommended. 338 385 */ 339 386 MRB_API mrb_value mrb_str_to_str(mrb_state *mrb, mrb_value str); 340 387 341 /* 388 /** 342 389 * Returns true if the strings match and false if the strings don't match. 343 390 * 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.391 * @param mrb The current mruby state. 392 * @param str1 Ruby string to compare. 393 * @param str2 Ruby string to compare. 347 394 * @return [mrb_value] boolean value. 348 395 */ 349 396 MRB_API mrb_bool mrb_str_equal(mrb_state *mrb, mrb_value str1, mrb_value str2); 350 397 351 /* 352 * Returns a concate d string comprised of a Ruby string and a C string.353 * 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.398 /** 399 * Returns a concatenated string comprised of a Ruby string and a C string. 400 * 401 * @param mrb The current mruby state. 402 * @param str Ruby string. 403 * @param ptr A C string. 404 * @param len length of C string. 358 405 * @return [mrb_value] A Ruby string. 359 406 * @see mrb_str_cat_cstr … … 361 408 MRB_API mrb_value mrb_str_cat(mrb_state *mrb, mrb_value str, const char *ptr, size_t len); 362 409 363 /* 364 * Returns a concate d string comprised of a Ruby string and a C string.365 * 366 * @param [mrb_state]mrb The current mruby state.367 * @param [mrb_value]str Ruby string.368 * @param [const char *]ptr A C string.410 /** 411 * Returns a concatenated string comprised of a Ruby string and a C string. 412 * 413 * @param mrb The current mruby state. 414 * @param str Ruby string. 415 * @param ptr A C string. 369 416 * @return [mrb_value] A Ruby string. 370 417 * @see mrb_str_cat … … 374 421 #define mrb_str_cat_lit(mrb, str, lit) mrb_str_cat(mrb, str, lit, mrb_strlen_lit(lit)) 375 422 376 /* 423 /** 377 424 * Adds str2 to the end of str1. 378 425 */ 379 426 MRB_API mrb_value mrb_str_append(mrb_state *mrb, mrb_value str, mrb_value str2); 380 427 381 /* 428 /** 382 429 * Returns 0 if both Ruby strings are equal. Returns a value < 0 if Ruby str1 is less than Ruby str2. Returns a value > 0 if Ruby str2 is greater than Ruby str1. 383 430 */ 384 431 MRB_API int mrb_str_cmp(mrb_state *mrb, mrb_value str1, mrb_value str2); 385 432 386 /* 433 /** 387 434 * Returns a newly allocated C string from a Ruby string. 388 435 * This is an utility function to pass a Ruby string to C library functions. … … 395 442 * (e.g. it can be used for mkstemp(3)). 396 443 * 397 * @param [mrb_state *]mrb The current mruby state.398 * @param [mrb_value]str Ruby string. Must be an instance of String.444 * @param mrb The current mruby state. 445 * @param str Ruby string. Must be an instance of String. 399 446 * @return [char *] A newly allocated C string. 400 447 */ 401 448 MRB_API char *mrb_str_to_cstr(mrb_state *mrb, mrb_value str); 402 449 403 mrb_value mrb_str_pool(mrb_state *mrb, mrb_value str);404 mrb_int mrb_str_hash(mrb_state *mrb, mrb_value str);450 mrb_value mrb_str_pool(mrb_state *mrb, const char *s, mrb_int len, mrb_bool nofree); 451 uint32_t mrb_str_hash(mrb_state *mrb, mrb_value str); 405 452 mrb_value mrb_str_dump(mrb_state *mrb, mrb_value str); 406 453 407 /* 454 /** 408 455 * Returns a printable version of str, surrounded by quote marks, with special characters escaped. 409 456 */ 410 457 mrb_value mrb_str_inspect(mrb_state *mrb, mrb_value str); 411 412 void mrb_noregexp(mrb_state *mrb, mrb_value self);413 void mrb_regexp_check(mrb_state *mrb, mrb_value obj);414 458 415 459 /* For backward compatibility */ … … 418 462 #define mrb_str_buf_append(mrb, str, str2) mrb_str_cat_str(mrb, str, str2) 419 463 464 mrb_bool mrb_str_beg_len(mrb_int str_len, mrb_int *begp, mrb_int *lenp); 465 mrb_value mrb_str_byte_subseq(mrb_state *mrb, mrb_value str, mrb_int beg, mrb_int len); 466 467 #ifdef MRB_UTF8_STRING 468 mrb_int mrb_utf8len(const char *str, const char *end); 469 mrb_int mrb_utf8_strlen(const char *str, mrb_int byte_len); 470 #endif 471 420 472 MRB_END_DECL 421 473 -
EcnlProtoTool/trunk/mruby-2.1.1/include/mruby/throw.h
r331 r439 1 /* 2 ** mruby/throw.h - mruby exception throwing handler1 /** 2 ** @file mruby/throw.h - mruby exception throwing handler 3 3 ** 4 4 ** See Copyright Notice in mruby.h … … 16 16 #if defined(MRB_ENABLE_CXX_EXCEPTION) && defined(__cplusplus) 17 17 18 #define MRB_TRY(buf) do {try {18 #define MRB_TRY(buf) try { 19 19 #define MRB_CATCH(buf) } catch(mrb_jmpbuf_impl e) { if (e != (buf)->impl) { throw e; } 20 #define MRB_END_EXC(buf) } } while(0)20 #define MRB_END_EXC(buf) } 21 21 22 22 #define MRB_THROW(buf) throw((buf)->impl) … … 35 35 #endif 36 36 37 #define MRB_TRY(buf) do {if (MRB_SETJMP((buf)->impl) == 0) {37 #define MRB_TRY(buf) if (MRB_SETJMP((buf)->impl) == 0) { 38 38 #define MRB_CATCH(buf) } else { 39 #define MRB_END_EXC(buf) } } while(0)39 #define MRB_END_EXC(buf) } 40 40 41 41 #define MRB_THROW(buf) MRB_LONGJMP((buf)->impl, 1); -
EcnlProtoTool/trunk/mruby-2.1.1/include/mruby/value.h
r331 r439 1 /* 2 ** mruby/value.h - mruby value definitions1 /** 2 ** @file mruby/value.h - mruby value definitions 3 3 ** 4 4 ** See Copyright Notice in mruby.h … … 10 10 #include "common.h" 11 11 12 /* *12 /* 13 13 * MRuby Value definition functions and macros. 14 14 */ 15 15 MRB_BEGIN_DECL 16 16 17 /** 18 * mruby Symbol. 19 * @class mrb_sym 20 * 21 * You can create an mrb_sym by simply using mrb_str_intern() or mrb_intern_cstr() 22 */ 17 23 typedef uint32_t mrb_sym; 24 25 /** 26 * mruby Boolean. 27 * @class mrb_bool 28 * 29 * 30 * Used internally to represent boolean. Can be TRUE or FALSE. 31 * Not to be confused with Ruby's boolean classes, which can be 32 * obtained using mrb_false_value() and mrb_true_value() 33 */ 18 34 typedef uint8_t mrb_bool; 19 35 struct mrb_state; 20 21 #if defined(MRB_INT16) && defined(MRB_INT64)22 # error "You can't define MRB_INT16 and MRB_INT64 at the same time."23 #endif24 36 25 37 #if defined _MSC_VER && _MSC_VER < 1800 26 38 # define PRIo64 "llo" 27 39 # define PRId64 "lld" 40 # define PRIu64 "llu" 28 41 # define PRIx64 "llx" 29 42 # define PRIo16 "ho" 30 43 # define PRId16 "hd" 44 # define PRIu16 "hu" 31 45 # define PRIx16 "hx" 32 46 # define PRIo32 "o" 33 47 # define PRId32 "d" 48 # define PRIu32 "u" 34 49 # define PRIx32 "x" 35 50 #else … … 45 60 # define MRB_PRId PRId64 46 61 # define MRB_PRIx PRIx64 47 #elif defined(MRB_INT16)48 typedef int16_t mrb_int;49 # define MRB_INT_BIT 1650 # define MRB_INT_MIN (INT16_MIN>>MRB_FIXNUM_SHIFT)51 # define MRB_INT_MAX (INT16_MAX>>MRB_FIXNUM_SHIFT)52 # define MRB_PRIo PRIo1653 # define MRB_PRId PRId1654 # define MRB_PRIx PRIx1655 62 #else 56 63 typedef int32_t mrb_int; … … 63 70 #endif 64 71 65 72 #ifdef MRB_ENDIAN_BIG 73 # define MRB_ENDIAN_LOHI(a,b) a b 74 #else 75 # define MRB_ENDIAN_LOHI(a,b) b a 76 #endif 77 78 #ifndef MRB_WITHOUT_FLOAT 66 79 MRB_API double mrb_float_read(const char*, char**); 67 80 #ifdef MRB_USE_FLOAT … … 70 83 typedef double mrb_float; 71 84 #endif 85 #endif 72 86 73 87 #if defined _MSC_VER && _MSC_VER < 1900 74 # ifndef __cplusplus75 # define inline __inline76 # endif77 88 # include <stdarg.h> 78 89 MRB_API int mrb_msvc_vsnprintf(char *s, size_t n, const char *format, va_list arg); … … 80 91 # define vsnprintf(s, n, format, arg) mrb_msvc_vsnprintf(s, n, format, arg) 81 92 # define snprintf(s, n, format, ...) mrb_msvc_snprintf(s, n, format, __VA_ARGS__) 82 # if _MSC_VER < 1800 93 # if _MSC_VER < 1800 && !defined MRB_WITHOUT_FLOAT 83 94 # include <float.h> 84 95 # define isfinite(n) _finite(n) … … 94 105 enum mrb_vtype { 95 106 MRB_TT_FALSE = 0, /* 0 */ 96 MRB_TT_ FREE, /* 1 */97 MRB_TT_ TRUE,/* 2 */107 MRB_TT_TRUE, /* 1 */ 108 MRB_TT_FLOAT, /* 2 */ 98 109 MRB_TT_FIXNUM, /* 3 */ 99 110 MRB_TT_SYMBOL, /* 4 */ 100 111 MRB_TT_UNDEF, /* 5 */ 101 MRB_TT_ FLOAT,/* 6 */102 MRB_TT_ CPTR, /* 7 */112 MRB_TT_CPTR, /* 6 */ 113 MRB_TT_FREE, /* 7 */ 103 114 MRB_TT_OBJECT, /* 8 */ 104 115 MRB_TT_CLASS, /* 9 */ … … 147 158 #endif 148 159 160 #define MRB_SYMBOL_BIT (sizeof(mrb_sym) * CHAR_BIT - MRB_SYMBOL_SHIFT) 161 #define MRB_SYMBOL_MAX (UINT32_MAX >> MRB_SYMBOL_SHIFT) 162 163 #if INTPTR_MAX < MRB_INT_MAX 164 typedef intptr_t mrb_ssize; 165 # define MRB_SSIZE_MAX (INTPTR_MAX>>MRB_FIXNUM_SHIFT) 166 #else 167 typedef mrb_int mrb_ssize; 168 # define MRB_SSIZE_MAX MRB_INT_MAX 169 #endif 170 171 #ifndef mrb_immediate_p 172 #define mrb_immediate_p(o) (mrb_type(o) < MRB_TT_FREE) 173 #endif 149 174 #ifndef mrb_fixnum_p 150 175 #define mrb_fixnum_p(o) (mrb_type(o) == MRB_TT_FIXNUM) 151 176 #endif 177 #ifndef mrb_symbol_p 178 #define mrb_symbol_p(o) (mrb_type(o) == MRB_TT_SYMBOL) 179 #endif 152 180 #ifndef mrb_undef_p 153 181 #define mrb_undef_p(o) (mrb_type(o) == MRB_TT_UNDEF) … … 156 184 #define mrb_nil_p(o) (mrb_type(o) == MRB_TT_FALSE && !mrb_fixnum(o)) 157 185 #endif 186 #ifndef mrb_false_p 187 #define mrb_false_p(o) (mrb_type(o) == MRB_TT_FALSE && !!mrb_fixnum(o)) 188 #endif 189 #ifndef mrb_true_p 190 #define mrb_true_p(o) (mrb_type(o) == MRB_TT_TRUE) 191 #endif 192 #ifndef MRB_WITHOUT_FLOAT 193 #ifndef mrb_float_p 194 #define mrb_float_p(o) (mrb_type(o) == MRB_TT_FLOAT) 195 #endif 196 #endif 197 #ifndef mrb_array_p 198 #define mrb_array_p(o) (mrb_type(o) == MRB_TT_ARRAY) 199 #endif 200 #ifndef mrb_string_p 201 #define mrb_string_p(o) (mrb_type(o) == MRB_TT_STRING) 202 #endif 203 #ifndef mrb_hash_p 204 #define mrb_hash_p(o) (mrb_type(o) == MRB_TT_HASH) 205 #endif 206 #ifndef mrb_cptr_p 207 #define mrb_cptr_p(o) (mrb_type(o) == MRB_TT_CPTR) 208 #endif 209 #ifndef mrb_exception_p 210 #define mrb_exception_p(o) (mrb_type(o) == MRB_TT_EXCEPTION) 211 #endif 212 #ifndef mrb_free_p 213 #define mrb_free_p(o) (mrb_type(o) == MRB_TT_FREE) 214 #endif 215 #ifndef mrb_object_p 216 #define mrb_object_p(o) (mrb_type(o) == MRB_TT_OBJECT) 217 #endif 218 #ifndef mrb_class_p 219 #define mrb_class_p(o) (mrb_type(o) == MRB_TT_CLASS) 220 #endif 221 #ifndef mrb_module_p 222 #define mrb_module_p(o) (mrb_type(o) == MRB_TT_MODULE) 223 #endif 224 #ifndef mrb_iclass_p 225 #define mrb_iclass_p(o) (mrb_type(o) == MRB_TT_ICLASS) 226 #endif 227 #ifndef mrb_sclass_p 228 #define mrb_sclass_p(o) (mrb_type(o) == MRB_TT_SCLASS) 229 #endif 230 #ifndef mrb_proc_p 231 #define mrb_proc_p(o) (mrb_type(o) == MRB_TT_PROC) 232 #endif 233 #ifndef mrb_range_p 234 #define mrb_range_p(o) (mrb_type(o) == MRB_TT_RANGE) 235 #endif 236 #ifndef mrb_file_p 237 #define mrb_file_p(o) (mrb_type(o) == MRB_TT_FILE) 238 #endif 239 #ifndef mrb_env_p 240 #define mrb_env_p(o) (mrb_type(o) == MRB_TT_ENV) 241 #endif 242 #ifndef mrb_data_p 243 #define mrb_data_p(o) (mrb_type(o) == MRB_TT_DATA) 244 #endif 245 #ifndef mrb_fiber_p 246 #define mrb_fiber_p(o) (mrb_type(o) == MRB_TT_FIBER) 247 #endif 248 #ifndef mrb_istruct_p 249 #define mrb_istruct_p(o) (mrb_type(o) == MRB_TT_ISTRUCT) 250 #endif 251 #ifndef mrb_break_p 252 #define mrb_break_p(o) (mrb_type(o) == MRB_TT_BREAK) 253 #endif 158 254 #ifndef mrb_bool 159 255 #define mrb_bool(o) (mrb_type(o) != MRB_TT_FALSE) 160 256 #endif 161 #define mrb_float_p(o) (mrb_type(o) == MRB_TT_FLOAT)162 #define mrb_symbol_p(o) (mrb_type(o) == MRB_TT_SYMBOL)163 #define mrb_array_p(o) (mrb_type(o) == MRB_TT_ARRAY)164 #define mrb_string_p(o) (mrb_type(o) == MRB_TT_STRING)165 #define mrb_hash_p(o) (mrb_type(o) == MRB_TT_HASH)166 #define mrb_cptr_p(o) (mrb_type(o) == MRB_TT_CPTR)167 #define mrb_exception_p(o) (mrb_type(o) == MRB_TT_EXCEPTION)168 257 #define mrb_test(o) mrb_bool(o) 169 MRB_API mrb_bool mrb_regexp_p(struct mrb_state*, mrb_value); 170 171 /* 258 259 /** 172 260 * Returns a float in Ruby. 173 */ 261 * 262 * Takes a float and boxes it into an mrb_value 263 */ 264 #ifndef MRB_WITHOUT_FLOAT 174 265 MRB_INLINE mrb_value mrb_float_value(struct mrb_state *mrb, mrb_float f) 175 266 { … … 179 270 return v; 180 271 } 181 182 static inline mrb_value 272 #endif 273 274 MRB_INLINE mrb_value 183 275 mrb_cptr_value(struct mrb_state *mrb, void *p) 184 276 { … … 189 281 } 190 282 191 /* 283 /** 192 284 * Returns a fixnum in Ruby. 285 * 286 * Takes an integer and boxes it into an mrb_value 193 287 */ 194 288 MRB_INLINE mrb_value mrb_fixnum_value(mrb_int i) … … 199 293 } 200 294 201 static inlinemrb_value295 MRB_INLINE mrb_value 202 296 mrb_symbol_value(mrb_sym i) 203 297 { … … 207 301 } 208 302 209 static inlinemrb_value303 MRB_INLINE mrb_value 210 304 mrb_obj_value(void *p) 211 305 { … … 217 311 } 218 312 219 220 /* 313 /** 221 314 * Get a nil mrb_value object. 222 315 * … … 231 324 } 232 325 233 /* 326 /** 234 327 * Returns false in Ruby. 235 328 */ … … 241 334 } 242 335 243 /* 336 /** 244 337 * Returns true in Ruby. 245 338 */ … … 251 344 } 252 345 253 static inlinemrb_value346 MRB_INLINE mrb_value 254 347 mrb_bool_value(mrb_bool boolean) 255 348 { … … 259 352 } 260 353 261 static inlinemrb_value354 MRB_INLINE mrb_value 262 355 mrb_undef_value(void) 263 356 { … … 267 360 } 268 361 269 #ifdef MRB_USE_ETEXT_EDATA 270 #if (defined(__APPLE__) && defined(__MACH__)) 271 #include <mach-o/getsect.h> 362 #if defined(MRB_USE_ETEXT_EDATA) && !defined(MRB_USE_LINK_TIME_RO_DATA_P) 363 # ifdef __GNUC__ 364 # warning MRB_USE_ETEXT_EDATA is deprecated. Define MRB_USE_LINK_TIME_RO_DATA_P instead. 365 # endif 366 # define MRB_USE_LINK_TIME_RO_DATA_P 367 #endif 368 369 #if defined(MRB_USE_CUSTOM_RO_DATA_P) 370 /* If you define `MRB_USE_CUSTOM_RO_DATA_P`, you must implement `mrb_ro_data_p()`. */ 371 mrb_bool mrb_ro_data_p(const char *p); 372 #elif defined(MRB_USE_LINK_TIME_RO_DATA_P) 373 extern char __ehdr_start[]; 374 extern char __init_array_start[]; 375 272 376 static inline mrb_bool 273 377 mrb_ro_data_p(const char *p) 274 378 { 275 return (const char*)get_etext() < p && p < (const char*)get_edata(); 276 } 277 #else 278 extern char _etext[]; 279 #ifdef MRB_NO_INIT_ARRAY_START 280 extern char _edata[]; 281 282 static inline mrb_bool 283 mrb_ro_data_p(const char *p) 284 { 285 return _etext < p && p < _edata; 286 } 287 #else 288 extern char __init_array_start[]; 289 290 static inline mrb_bool 291 mrb_ro_data_p(const char *p) 292 { 293 return _etext < p && p < (char*)&__init_array_start; 294 } 295 #endif 296 #endif 379 return __ehdr_start < p && p < __init_array_start; 380 } 297 381 #else 298 382 # define mrb_ro_data_p(p) FALSE -
EcnlProtoTool/trunk/mruby-2.1.1/include/mruby/variable.h
r331 r439 1 /* 2 ** mruby/variable.h - mruby variables1 /** 2 ** @file mruby/variable.h - mruby variables 3 3 ** 4 4 ** See Copyright Notice in mruby.h … … 32 32 mrb_value mrb_vm_special_get(mrb_state*, mrb_sym); 33 33 void mrb_vm_special_set(mrb_state*, mrb_sym, mrb_value); 34 mrb_value mrb_vm_iv_get(mrb_state*, mrb_sym);35 void mrb_vm_iv_set(mrb_state*, mrb_sym, mrb_value);36 34 mrb_value mrb_vm_cv_get(mrb_state*, mrb_sym); 37 35 void mrb_vm_cv_set(mrb_state*, mrb_sym, mrb_value); … … 43 41 MRB_API void mrb_const_remove(mrb_state*, mrb_value, mrb_sym); 44 42 45 MRB_API mrb_bool mrb_iv_ p(mrb_state *mrb, mrb_sym sym);46 MRB_API void mrb_iv_ check(mrb_state *mrb, mrb_sym sym);43 MRB_API mrb_bool mrb_iv_name_sym_p(mrb_state *mrb, mrb_sym sym); 44 MRB_API void mrb_iv_name_sym_check(mrb_state *mrb, mrb_sym sym); 47 45 MRB_API mrb_value mrb_obj_iv_get(mrb_state *mrb, struct RObject *obj, mrb_sym sym); 48 46 MRB_API void mrb_obj_iv_set(mrb_state *mrb, struct RObject *obj, mrb_sym sym, mrb_value v); 49 47 MRB_API mrb_bool mrb_obj_iv_defined(mrb_state *mrb, struct RObject *obj, mrb_sym sym); 50 MRB_API void mrb_obj_iv_ifnone(mrb_state *mrb, struct RObject *obj, mrb_sym sym, mrb_value v);51 48 MRB_API mrb_value mrb_iv_get(mrb_state *mrb, mrb_value obj, mrb_sym sym); 52 49 MRB_API void mrb_iv_set(mrb_state *mrb, mrb_value obj, mrb_sym sym, mrb_value v); … … 101 98 * Example: 102 99 * 103 * !!!ruby104 100 * # Ruby style 105 101 * $value = nil 106 102 * 107 * !!!c108 103 * // C style 109 104 * mrb_sym sym = mrb_intern_lit(mrb, "$value"); … … 112 107 * @param mrb The mruby state reference 113 108 * @param sym The name of the global variable 114 * @param val The value of the global variable115 109 */ 116 110 MRB_API void mrb_gv_remove(mrb_state *mrb, mrb_sym sym); … … 121 115 MRB_API mrb_bool mrb_cv_defined(mrb_state *mrb, mrb_value mod, mrb_sym sym); 122 116 mrb_value mrb_obj_iv_inspect(mrb_state*, struct RObject*); 117 void mrb_obj_iv_set_force(mrb_state *mrb, struct RObject *obj, mrb_sym sym, mrb_value v); 123 118 mrb_value mrb_mod_constants(mrb_state *mrb, mrb_value mod); 124 119 mrb_value mrb_f_global_variables(mrb_state *mrb, mrb_value self); … … 127 122 mrb_value mrb_mod_cv_get(mrb_state *mrb, struct RClass * c, mrb_sym sym); 128 123 mrb_bool mrb_mod_cv_defined(mrb_state *mrb, struct RClass * c, mrb_sym sym); 129 mrb_ sym mrb_class_sym(mrb_state *mrb, struct RClass *c, struct RClass *outer);124 mrb_bool mrb_ident_p(const char *s, mrb_int len); 130 125 131 126 /* GC functions */ … … 136 131 void mrb_gc_free_iv(mrb_state*, struct RObject*); 137 132 133 /* return non zero to break the loop */ 134 typedef int (mrb_iv_foreach_func)(mrb_state*,mrb_sym,mrb_value,void*); 135 MRB_API void mrb_iv_foreach(mrb_state *mrb, mrb_value obj, mrb_iv_foreach_func *func, void *p); 136 138 137 MRB_END_DECL 139 138 -
EcnlProtoTool/trunk/mruby-2.1.1/include/mruby/version.h
r331 r439 1 /* 2 ** mruby/version.h - mruby version definition1 /** 2 ** @file mruby/version.h - mruby version definition 3 3 ** 4 4 ** See Copyright Notice in mruby.h … … 28 28 * The version of Ruby used by mruby. 29 29 */ 30 #define MRUBY_RUBY_VERSION " 1.9"30 #define MRUBY_RUBY_VERSION "2.0" 31 31 32 32 /* … … 38 38 * Major release version number. 39 39 */ 40 #define MRUBY_RELEASE_MAJOR 140 #define MRUBY_RELEASE_MAJOR 2 41 41 42 42 /* 43 43 * Minor release version number. 44 44 */ 45 #define MRUBY_RELEASE_MINOR 345 #define MRUBY_RELEASE_MINOR 1 46 46 47 47 /* 48 48 * Tiny release version number. 49 49 */ 50 #define MRUBY_RELEASE_TEENY 050 #define MRUBY_RELEASE_TEENY 1 51 51 52 52 /* … … 63 63 * Release year. 64 64 */ 65 #define MRUBY_RELEASE_YEAR 20 1765 #define MRUBY_RELEASE_YEAR 2020 66 66 67 67 /* 68 68 * Release month. 69 69 */ 70 #define MRUBY_RELEASE_MONTH 770 #define MRUBY_RELEASE_MONTH 6 71 71 72 72 /* … … 78 78 * Release date as a string. 79 79 */ 80 #define MRUBY_RELEASE_DATE MRB_STRINGIZE(MRUBY_RELEASE_YEAR) "-" MRB_STRINGIZE(MRUBY_RELEASE_MONTH) "-" MRB_STRINGIZE(MRUBY_RELEASE_DAY) 80 #define MRUBY_RELEASE_DATE \ 81 MRUBY_RELEASE_YEAR_STR "-" \ 82 MRUBY_RELEASE_MONTH_STR "-" \ 83 MRUBY_RELEASE_DAY_STR 84 #define MRUBY_RELEASE_YEAR_STR MRB_STRINGIZE(MRUBY_RELEASE_YEAR) 85 #if MRUBY_RELEASE_MONTH < 10 86 #define MRUBY_RELEASE_MONTH_STR "0" MRB_STRINGIZE(MRUBY_RELEASE_MONTH) 87 #else 88 #define MRUBY_RELEASE_MONTH_STR MRB_STRINGIZE(MRUBY_RELEASE_MONTH) 89 #endif 90 #if MRUBY_RELEASE_DAY < 10 91 #define MRUBY_RELEASE_DAY_STR "0" MRB_STRINGIZE(MRUBY_RELEASE_DAY) 92 #else 93 #define MRUBY_RELEASE_DAY_STR MRB_STRINGIZE(MRUBY_RELEASE_DAY) 94 #endif 81 95 82 96 /* … … 93 107 * mruby's version, and release date. 94 108 */ 95 #define MRUBY_DESCRIPTION 96 "mruby " MRUBY_VERSION 97 " (" MRUBY_RELEASE_DATE ") 109 #define MRUBY_DESCRIPTION \ 110 "mruby " MRUBY_VERSION \ 111 " (" MRUBY_RELEASE_DATE ")" \ 98 112 99 113 /*
Note:
See TracChangeset
for help on using the changeset viewer.