Changeset 331 for EcnlProtoTool/trunk/mruby-1.3.0/include
- Timestamp:
- Jan 21, 2018, 12:10:09 AM (6 years ago)
- Location:
- EcnlProtoTool/trunk/mruby-1.3.0
- Files:
-
- 1 added
- 27 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
EcnlProtoTool/trunk/mruby-1.3.0/include/mrbconf.h
r321 r331 8 8 #define MRUBYCONF_H 9 9 10 #include <limits.h> 11 #include <stdint.h> 12 13 /* architecture selection: */ 14 /* specify -DMRB_32BIT or -DMRB_64BIT to override */ 15 #if !defined(MRB_32BIT) && !defined(MRB_64BIT) 16 #if UINT64_MAX == SIZE_MAX 17 #define MRB_64BIT 18 #else 19 #define MRB_32BIT 20 #endif 21 #endif 22 23 #if defined(MRB_32BIT) && defined(MRB_64BIT) 24 #error Cannot build for 32 and 64 bit architecture at the same time 25 #endif 26 10 27 /* configuration options: */ 11 28 /* add -DMRB_USE_FLOAT to use float instead of double for floating point numbers */ 12 29 //#define MRB_USE_FLOAT 13 #define MRB_USE_FLOAT14 30 15 31 /* add -DMRB_INT16 to use 16bit integer for mrb_int; conflict with MRB_INT64 */ … … 33 49 /* argv max size in mrb_funcall */ 34 50 //#define MRB_FUNCALL_ARGC_MAX 16 35 #define MRB_FUNCALL_ARGC_MAX 836 51 37 52 /* number of object per heap page */ 38 53 //#define MRB_HEAP_PAGE_SIZE 1024 39 #define MRB_HEAP_PAGE_SIZE 6440 54 41 55 /* use segmented list for IV table */ 42 56 //#define MRB_USE_IV_SEGLIST 43 #define MRB_USE_IV_SEGLIST44 57 45 58 /* initial size for IV khash; ignored when MRB_USE_IV_SEGLIST is set */ … … 58 71 /* default size of khash table bucket */ 59 72 //#define KHASH_DEFAULT_SIZE 32 60 #define KHASH_DEFAULT_SIZE 861 73 62 74 /* allocated memory address alignment */ … … 65 77 /* page size of memory pool */ 66 78 //#define POOL_PAGE_SIZE 16000 67 #define POOL_PAGE_SIZE 409668 79 69 80 /* initial minimum size for string buffer */ 70 81 //#define MRB_STR_BUF_MIN_SIZE 128 71 #define MRB_STR_BUF_MIN_SIZE 2072 82 73 83 /* arena size */ … … 76 86 /* fixed size GC arena */ 77 87 //#define MRB_GC_FIXED_ARENA 78 #define MRB_GC_FIXED_ARENA79 88 80 89 /* state atexit stack size */ -
EcnlProtoTool/trunk/mruby-1.3.0/include/mruby.h
r321 r331 2 2 ** mruby - An embeddable Ruby implementation 3 3 ** 4 ** Copyright (c) mruby developers 2010-201 54 ** Copyright (c) mruby developers 2010-2017 5 5 ** 6 6 ** Permission is hereby granted, free of charge, to any person obtaining … … 29 29 #define MRUBY_H 30 30 31 #ifdef __cplusplus 32 #define __STDC_LIMIT_MACROS 33 #define __STDC_CONSTANT_MACROS 34 #define __STDC_FORMAT_MACROS 35 #endif 36 31 37 #include <stdint.h> 32 38 #include <stddef.h> 33 39 #include <limits.h> 34 40 41 #ifdef __cplusplus 42 #ifndef SIZE_MAX 43 #ifdef __SIZE_MAX__ 44 #define SIZE_MAX __SIZE_MAX__ 45 #else 46 #define SIZE_MAX std::numeric_limits<size_t>::max() 47 #endif 48 #endif 49 #endif 50 51 #ifdef MRB_DEBUG 52 #include <assert.h> 53 #define mrb_assert(p) assert(p) 54 #define mrb_assert_int_fit(t1,n,t2,max) assert((n)>=0 && ((sizeof(n)<=sizeof(t2))||(n<=(t1)(max)))) 55 #else 56 #define mrb_assert(p) ((void)0) 57 #define mrb_assert_int_fit(t1,n,t2,max) ((void)0) 58 #endif 59 60 #if __STDC_VERSION__ >= 201112L 61 #define mrb_static_assert(exp, str) _Static_assert(exp, str) 62 #else 63 #define mrb_static_assert(exp, str) mrb_assert(exp) 64 #endif 65 35 66 #include "mrbconf.h" 67 68 #ifdef MRB_USE_FLOAT 69 #define MRB_FLOAT_EPSILON FLT_EPSILON 70 #else 71 #define MRB_FLOAT_EPSILON DBL_EPSILON 72 #endif 73 36 74 #include "mruby/common.h" 37 #include "mruby/value.h"38 #include "mruby/gc.h"39 #include "mruby/version.h"75 #include <mruby/value.h> 76 #include <mruby/gc.h> 77 #include <mruby/version.h> 40 78 41 79 /** … … 76 114 int nregs; 77 115 int ridx; 78 int e idx;116 int epos; 79 117 struct REnv *env; 80 118 mrb_code *pc; /* return address */ … … 88 126 MRB_FIBER_CREATED = 0, 89 127 MRB_FIBER_RUNNING, 90 MRB_FIBER_RESUM ING,128 MRB_FIBER_RESUMED, 91 129 MRB_FIBER_SUSPENDED, 92 130 MRB_FIBER_TRANSFERRED, … … 106 144 int rsize; 107 145 struct RProc **ensure; /* ensure handler stack */ 108 int esize ;146 int esize, eidx; 109 147 110 148 enum mrb_fiber_state status; 149 mrb_bool vmexec; 111 150 struct RFiber *fib; 112 151 }; … … 116 155 typedef void (*mrb_atexit_func)(struct mrb_state*); 117 156 157 #define MRB_STATE_NO_REGEXP 1 158 #define MRB_STATE_REGEXP 2 159 118 160 typedef struct mrb_state { 119 161 struct mrb_jmpbuf *jmp; 120 162 163 uint32_t flags; 121 164 mrb_allocf allocf; /* memory allocation function */ 122 165 void *allocf_ud; /* auxiliary data of allocf */ … … 124 167 struct mrb_context *c; 125 168 struct mrb_context *root_c; 169 struct iv_tbl *globals; /* global variable table */ 126 170 127 171 struct RObject *exc; /* exception */ 128 struct iv_tbl *globals; /* global variable table */129 172 130 173 struct RObject *top_self; … … 158 201 #endif 159 202 203 #ifdef MRB_BYTECODE_DECODE_OPTION 204 mrb_code (*bytecode_decoder)(struct mrb_state* mrb, mrb_code code); 205 #endif 206 160 207 struct RClass *eException_class; 161 208 struct RClass *eStandardError_class; 162 209 struct RObject *nomem_err; /* pre-allocated NoMemoryError */ 210 struct RObject *stack_err; /* pre-allocated SysStackError */ 211 #ifdef MRB_GC_FIXED_ARENA 212 struct RObject *arena_err; /* pre-allocated arena overfow error */ 213 #endif 163 214 164 215 void *ud; /* auxiliary data */ … … 182 233 * !!!c 183 234 * void mrb_example_gem_init(mrb_state* mrb) { 184 * 185 * 235 * struct RClass *example_class; 236 * example_class = mrb_define_class(mrb, "Example_Class", mrb->object_class); 186 237 * } 187 238 * 188 239 * void mrb_example_gem_final(mrb_state* mrb) { 189 * 240 * //free(TheAnimals); 190 241 * } 191 242 * … … 200 251 /** 201 252 * Defines a new module. 253 * 202 254 * @param [mrb_state *] mrb_state* The current mruby state. 203 255 * @param [const char *] char* The name of the module. … … 209 261 /** 210 262 * Include a module in another class or module. 211 * Equivalent to: 212 * 213 * module B 214 * include A 215 * end 263 * Equivalent to: 264 * 265 * module B 266 * include A 267 * end 216 268 * @param [mrb_state *] mrb_state* The current mruby state. 217 269 * @param [struct RClass *] RClass* A reference to module or a class. … … 230 282 * @param [struct RClass *] RClass* A reference to module or a class. 231 283 * @param [struct RClass *] RClass* A reference to the module to be prepended. 232 */ 284 */ 233 285 MRB_API void mrb_prepend_module(mrb_state*, struct RClass*, struct RClass*); 234 286 … … 264 316 * 265 317 * Example: 266 * # Ruby style 267 * class Foo 268 * 269 * def Foo.bar 318 * 319 * # Ruby style 320 * class Foo 321 * def Foo.bar 322 * end 270 323 * end 271 * 272 * end 273 * // C style 274 * mrb_value bar_method(mrb_state* mrb, mrb_value self){ 275 * 276 * return mrb_nil_value(); 277 * 278 * } 279 * void mrb_example_gem_init(mrb_state* mrb){ 280 * 281 * struct RClass *foo; 282 * 283 * foo = mrb_define_class(mrb, "Foo", mrb->object_class); 284 * 285 * mrb_define_class_method(mrb, foo, "bar", bar_method, MRB_ARGS_NONE()); 286 * 287 * } 288 * @param [mrb_state *] mrb_state* The MRuby state reference. 324 * // C style 325 * mrb_value bar_method(mrb_state* mrb, mrb_value self){ 326 * return mrb_nil_value(); 327 * } 328 * void mrb_example_gem_init(mrb_state* mrb){ 329 * struct RClass *foo; 330 * foo = mrb_define_class(mrb, "Foo", mrb->object_class); 331 * mrb_define_class_method(mrb, foo, "bar", bar_method, MRB_ARGS_NONE()); 332 * } 333 * @param [mrb_state *] mrb_state* The MRuby state reference. 289 334 * @param [struct RClass *] RClass* The class where the class method will be defined. 290 335 * @param [const char *] char* The name of the class method being defined. … … 299 344 * 300 345 * Example: 301 * # Ruby style 302 * module Foo 303 * 304 * def Foo.bar * end 305 * 306 * end 307 * // C style 308 * mrb_value bar_method(mrb_state* mrb, mrb_value self){ 309 * 310 * return mrb_nil_value(); * 311 * } 312 * void mrb_example_gem_init(mrb_state* mrb){ 313 * 314 * struct RClass *foo; 315 * 316 * foo = mrb_define_module(mrb, "Foo"); 317 * 318 * mrb_define_module_function(mrb, foo, "bar", bar_method, MRB_ARGS_NONE()); 319 * 320 * } 346 * 347 * # Ruby style 348 * module Foo 349 * def Foo.bar 350 * end 351 * end 352 * // C style 353 * mrb_value bar_method(mrb_state* mrb, mrb_value self){ 354 * return mrb_nil_value(); 355 * } 356 * void mrb_example_gem_init(mrb_state* mrb){ 357 * struct RClass *foo; 358 * foo = mrb_define_module(mrb, "Foo"); 359 * mrb_define_module_function(mrb, foo, "bar", bar_method, MRB_ARGS_NONE()); 360 * } 321 361 * @param [mrb_state *] mrb_state* The MRuby state reference. 322 362 * @param [struct RClass *] RClass* The module where the module function will be defined. 323 363 * @param [const char *] char* The name of the module function being defined. 324 * @param [mrb_func_t] mrb_func_t The function pointer to the module function definition. 364 * @param [mrb_func_t] mrb_func_t The function pointer to the module function definition. 325 365 * @param [mrb_aspec] mrb_aspec The method parameters declaration. 326 366 */ … … 331 371 * 332 372 * Example: 333 * # Ruby style 334 * 335 * class ExampleClass 336 * 337 * AGE = 22 338 * 339 * end 340 * 341 * // C style 342 * #include <stdio.h> 343 * #include <mruby.h> 344 * 345 * void 346 * mrb_example_gem_init(mrb_state* mrb){ 347 * 348 * mrb_define_const(mrb, mrb->kernel_module, "AGE", mrb_fixnum_value(22)); 349 * 350 * } 351 * 352 * mrb_value 353 * mrb_example_gem_final(mrb_state* mrb){ 354 * 355 * } 373 * 374 * # Ruby style 375 * class ExampleClass 376 * AGE = 22 377 * end 378 * // C style 379 * #include <stdio.h> 380 * #include <mruby.h> 381 * 382 * void 383 * mrb_example_gem_init(mrb_state* mrb){ 384 * mrb_define_const(mrb, mrb->kernel_module, "AGE", mrb_fixnum_value(22)); 385 * } 386 * 387 * mrb_value 388 * mrb_example_gem_final(mrb_state* mrb){ 389 * } 356 390 * @param [mrb_state *] mrb_state* The MRuby state reference. 357 391 * @param [struct RClass *] RClass* A class or module the constant is defined in. … … 365 399 * 366 400 * Example: 367 * # Ruby style 368 * 369 * class ExampleClassA 370 * 371 * def example_method 372 * "example" 401 * 402 * # Ruby style 403 * 404 * class ExampleClassA 405 * def example_method 406 * "example" 407 * end 373 408 * end 374 * 375 * end 376 * 377 * ExampleClassA.new.example_method # => example 378 * 379 * class ExampleClassB < ExampleClassA 380 * 381 * undef_method :example_method 382 * 383 * end 384 * 385 * ExampleClassB.new.example_method # => undefined method 'example_method' for ExampleClassB (NoMethodError) 386 * 387 * // C style 388 * #include <stdio.h> 389 * #include <mruby.h> 390 * 391 * mrb_value 392 * mrb_example_method(mrb_state *mrb){ 393 * 394 * return mrb_str_new_cstr(mrb, "example"); 395 * 396 * } 397 * 398 * void 399 * mrb_example_gem_init(mrb_state* mrb){ 400 * struct RClass *example_class_a; 401 * struct RClass *example_class_b; 402 * struct RClass *example_class_c; 403 * 404 * example_class_a = mrb_define_class(mrb, "ExampleClassA", mrb->object_class); 405 * 406 * mrb_define_method(mrb, example_class_a, "example_method", mrb_example_method, MRB_ARGS_NONE()); 407 * 408 * example_class_b = mrb_define_class(mrb, "ExampleClassB", example_class_a); 409 * 410 * example_class_c = mrb_define_class(mrb, "ExampleClassC", example_class_b); 411 * 412 * mrb_undef_method(mrb, example_class_c, "example_method"); 413 * 414 * } 415 * 416 * mrb_example_gem_final(mrb_state* mrb){ 417 * 418 * } 419 * 409 * ExampleClassA.new.example_method # => example 410 * 411 * class ExampleClassB < ExampleClassA 412 * undef_method :example_method 413 * end 414 * 415 * ExampleClassB.new.example_method # => undefined method 'example_method' for ExampleClassB (NoMethodError) 416 * 417 * // C style 418 * #include <stdio.h> 419 * #include <mruby.h> 420 * 421 * mrb_value 422 * mrb_example_method(mrb_state *mrb){ 423 * return mrb_str_new_lit(mrb, "example"); 424 * } 425 * 426 * void 427 * mrb_example_gem_init(mrb_state* mrb){ 428 * struct RClass *example_class_a; 429 * struct RClass *example_class_b; 430 * struct RClass *example_class_c; 431 * 432 * example_class_a = mrb_define_class(mrb, "ExampleClassA", mrb->object_class); 433 * mrb_define_method(mrb, example_class_a, "example_method", mrb_example_method, MRB_ARGS_NONE()); 434 * example_class_b = mrb_define_class(mrb, "ExampleClassB", example_class_a); 435 * example_class_c = mrb_define_class(mrb, "ExampleClassC", example_class_b); 436 * mrb_undef_method(mrb, example_class_c, "example_method"); 437 * } 438 * 439 * mrb_example_gem_final(mrb_state* mrb){ 440 * } 420 441 * @param [mrb_state*] mrb_state* The mruby state reference. 421 442 * @param [struct RClass*] RClass* A class the method will be undefined from. … … 426 447 /** 427 448 * Undefine a class method. 428 *429 449 * Example: 430 * # Ruby style 431 * 432 * class ExampleClass 433 * def self.example_method 434 * "example" 435 * end 436 * 437 * end 438 * 439 * ExampleClass.example_method 440 * 441 * // C style 442 * #include <stdio.h> 443 * #include <mruby.h> 444 * 445 * mrb_value 446 * mrb_example_method(mrb_state *mrb){ 447 * 448 * return mrb_str_new_cstr(mrb, "example"); 449 * 450 * } 451 * 452 * void 453 * mrb_example_gem_init(mrb_state* mrb){ 454 * 455 * struct RClass *example_class; 456 * 457 * example_class = mrb_define_class(mrb, "ExampleClass", mrb->object_class); 458 * 459 * mrb_define_class_method(mrb, example_class, "example_method", mrb_example_method, MRB_ARGS_NONE()); 460 * 461 * mrb_undef_class_method(mrb, example_class, "example_method"); 462 * 463 * } 464 * 465 * void 466 * mrb_example_gem_final(mrb_state* mrb){ 467 * 468 * } 450 * 451 * # Ruby style 452 * class ExampleClass 453 * def self.example_method 454 * "example" 455 * end 456 * end 457 * 458 * ExampleClass.example_method 459 * 460 * // C style 461 * #include <stdio.h> 462 * #include <mruby.h> 463 * 464 * mrb_value 465 * mrb_example_method(mrb_state *mrb){ 466 * return mrb_str_new_lit(mrb, "example"); 467 * } 468 * 469 * void 470 * mrb_example_gem_init(mrb_state* mrb){ 471 * struct RClass *example_class; 472 * example_class = mrb_define_class(mrb, "ExampleClass", mrb->object_class); 473 * mrb_define_class_method(mrb, example_class, "example_method", mrb_example_method, MRB_ARGS_NONE()); 474 * mrb_undef_class_method(mrb, example_class, "example_method"); 475 * } 476 * 477 * void 478 * mrb_example_gem_final(mrb_state* mrb){ 479 * } 469 480 * @param [mrb_state*] mrb_state* The mruby state reference. 470 481 * @param [RClass*] RClass* A class the class method will be undefined from. … … 478 489 * Example: 479 490 * 480 * # Ruby style 481 * class ExampleClass 482 * end 483 * 484 * p ExampleClass # => #<ExampleClass:0x9958588> 485 * // C style 486 * #include <stdio.h> 487 * #include <mruby.h> 488 * 489 * void 490 * mrb_example_gem_init(mrb_state* mrb) { 491 * struct RClass *example_class; 492 * mrb_value obj; 493 * 494 * example_class = mrb_define_class(mrb, "ExampleClass", mrb->object_class); # => class ExampleClass; end 495 * obj = mrb_obj_new(mrb, example_class, 0, NULL); # => ExampleClass.new 496 * mrb_p(mrb, obj); // => Kernel#p 497 * } 491 * # Ruby style 492 * class ExampleClass 493 * end 494 * 495 * p ExampleClass # => #<ExampleClass:0x9958588> 496 * // C style 497 * #include <stdio.h> 498 * #include <mruby.h> 499 * 500 * void 501 * mrb_example_gem_init(mrb_state* mrb) { 502 * struct RClass *example_class; 503 * mrb_value obj; 504 * example_class = mrb_define_class(mrb, "ExampleClass", mrb->object_class); # => class ExampleClass; end 505 * obj = mrb_obj_new(mrb, example_class, 0, NULL); # => ExampleClass.new 506 * mrb_p(mrb, obj); // => Kernel#p 507 * } 498 508 * @param [mrb_state*] mrb The current mruby state. 499 509 * @param [RClass*] c Reference to the class of the new object. … … 517 527 * Example: 518 528 * 519 * void520 * mrb_example_gem_init(mrb_state* mrb) {521 * struct RClass *example_class;522 * mrb_value obj;523 * 524 * example_class = mrb_class_new(mrb, mrb->object_class);525 * obj = mrb_obj_new(mrb, example_class, 0, NULL); // => #<#<Class:0x9a945b8>:0x9a94588>526 * mrb_p(mrb, obj); // => Kernel#p527 * }529 * void 530 * mrb_example_gem_init(mrb_state* mrb) { 531 * struct RClass *example_class; 532 * 533 * mrb_value obj; 534 * example_class = mrb_class_new(mrb, mrb->object_class); 535 * obj = mrb_obj_new(mrb, example_class, 0, NULL); // => #<#<Class:0x9a945b8>:0x9a94588> 536 * mrb_p(mrb, obj); // => Kernel#p 537 * } 528 538 * 529 539 * @param [mrb_state*] mrb The current mruby state. … … 537 547 * 538 548 * Example: 539 * void540 * mrb_example_gem_init(mrb_state* mrb) {541 * struct RClass *example_module;542 * 543 * example_module = mrb_module_new(mrb);544 * }549 * void 550 * mrb_example_gem_init(mrb_state* mrb) { 551 * struct RClass *example_module; 552 * 553 * example_module = mrb_module_new(mrb); 554 * } 545 555 * 546 556 * @param [mrb_state*] mrb The current mruby state. … … 553 563 * 554 564 * Example: 555 * void 556 * mrb_example_gem_init(mrb_state* mrb) { 557 * struct RClass *example_class; 558 * mrb_bool cd; 559 * 560 * example_class = mrb_define_class(mrb, "ExampleClass", mrb->object_class); 561 * cd = mrb_class_defined(mrb, "ExampleClass"); 562 * 563 * // If mrb_class_defined returns 1 then puts "True" 564 * // If mrb_class_defined returns 0 then puts "False" 565 * if (cd == 1){ 566 * puts("True"); 565 * void 566 * mrb_example_gem_init(mrb_state* mrb) { 567 * struct RClass *example_class; 568 * mrb_bool cd; 569 * 570 * example_class = mrb_define_class(mrb, "ExampleClass", mrb->object_class); 571 * cd = mrb_class_defined(mrb, "ExampleClass"); 572 * 573 * // If mrb_class_defined returns 1 then puts "True" 574 * // If mrb_class_defined returns 0 then puts "False" 575 * if (cd == 1){ 576 * puts("True"); 577 * } 578 * else { 579 * puts("False"); 580 * } 567 581 * } 568 * else {569 * puts("False");570 * }571 * }572 582 * 573 583 * @param [mrb_state*] mrb The current mruby state. … … 584 594 */ 585 595 MRB_API struct RClass * mrb_class_get(mrb_state *mrb, const char *name); 596 597 /** 598 * Gets a exception class. 599 * @param [mrb_state*] mrb The current mruby state. 600 * @param [const char *] name The name of the class. 601 * @return [struct RClass *] A reference to the class. 602 */ 603 MRB_API struct RClass * mrb_exc_get(mrb_state *mrb, const char *name); 604 605 /** 606 * Returns an mrb_bool. True if inner class was defined, and false if the inner class was not defined. 607 * 608 * Example: 609 * void 610 * mrb_example_gem_init(mrb_state* mrb) { 611 * struct RClass *example_outer, *example_inner; 612 * mrb_bool cd; 613 * 614 * example_outer = mrb_define_module(mrb, "ExampleOuter"); 615 * 616 * example_inner = mrb_define_class_under(mrb, example_outer, "ExampleInner", mrb->object_class); 617 * cd = mrb_class_defined_under(mrb, example_outer, "ExampleInner"); 618 * 619 * // If mrb_class_defined_under returns 1 then puts "True" 620 * // If mrb_class_defined_under returns 0 then puts "False" 621 * if (cd == 1){ 622 * puts("True"); 623 * } 624 * else { 625 * puts("False"); 626 * } 627 * } 628 * 629 * @param [mrb_state*] mrb The current mruby state. 630 * @param [struct RClass *] outer The name of the outer class. 631 * @param [const char *] name A string representing the name of the inner class. 632 * @return [mrb_bool] A boolean value. 633 */ 634 MRB_API mrb_bool mrb_class_defined_under(mrb_state *mrb, struct RClass *outer, const char *name); 586 635 587 636 /** … … 616 665 * 617 666 * Equivalent to: 618 * Object#dup 667 * Object#dup 619 668 * @param [mrb_state*] mrb The current mruby state. 620 669 * @param [mrb_value] obj Object to be duplicate. … … 628 677 * class it returns true, it returns false otherwise. 629 678 * 630 * Example: 631 * # Ruby style 632 * class ExampleClass 633 * def example_method 679 * Example: 680 * # Ruby style 681 * class ExampleClass 682 * def example_method 683 * end 634 684 * end 635 * end 636 * 637 * ExampleClass.new.respond_to?(:example_method) # => true 638 * 639 * // C style 640 * void 641 * mrb_example_gem_init(mrb_state* mrb) { 642 * struct RClass *example_class; 643 * mrb_sym mid; 644 * mrb_bool obj_resp; 645 * 646 * example_class = mrb_define_class(mrb, "ExampleClass", mrb->object_class); 647 * mrb_define_method(mrb, example_class, "example_method", exampleMethod, MRB_ARGS_NONE()); 648 * mid = mrb_intern_str(mrb, mrb_str_new_cstr(mrb, "example_method" )); 649 * obj_resp = mrb_obj_respond_to(mrb, example_class, mid); // => 1(true in Ruby world) 650 * 651 * // If mrb_obj_respond_to returns 1 then puts "True" 652 * // If mrb_obj_respond_to returns 0 then puts "False" 653 * if (obj_resp == 1) { 654 * puts("True"); 685 * 686 * ExampleClass.new.respond_to?(:example_method) # => true 687 * 688 * // C style 689 * void 690 * mrb_example_gem_init(mrb_state* mrb) { 691 * struct RClass *example_class; 692 * mrb_sym mid; 693 * mrb_bool obj_resp; 694 * 695 * example_class = mrb_define_class(mrb, "ExampleClass", mrb->object_class); 696 * mrb_define_method(mrb, example_class, "example_method", exampleMethod, MRB_ARGS_NONE()); 697 * mid = mrb_intern_str(mrb, mrb_str_new_lit(mrb, "example_method" )); 698 * obj_resp = mrb_obj_respond_to(mrb, example_class, mid); // => 1(true in Ruby world) 699 * 700 * // If mrb_obj_respond_to returns 1 then puts "True" 701 * // If mrb_obj_respond_to returns 0 then puts "False" 702 * if (obj_resp == 1) { 703 * puts("True"); 704 * } 705 * else if (obj_resp == 0) { 706 * puts("False"); 707 * } 655 708 * } 656 * else if (obj_resp == 0) {657 * puts("False");658 * }659 * }660 709 * 661 710 * @param [mrb_state*] mrb The current mruby state. … … 795 844 /** 796 845 * Call existing ruby functions. 846 * 847 * #include <stdio.h> 848 * #include <mruby.h> 849 * #include "mruby/compile.h" 850 * 851 * int 852 * main() 853 * { 854 * mrb_int i = 99; 855 * mrb_state *mrb = mrb_open(); 856 * 857 * if (!mrb) { } 858 * FILE *fp = fopen("test.rb","r"); 859 * mrb_value obj = mrb_load_file(mrb,fp); 860 * mrb_funcall(mrb, obj, "method_name", 1, mrb_fixnum_value(i)); 861 * fclose(fp); 862 * mrb_close(mrb); 863 * } 864 * @param [mrb_state*] mrb_state* The current mruby state. 865 * @param [mrb_value] mrb_value A reference to an mruby value. 866 * @param [const char*] const char* The name of the method. 867 * @param [mrb_int] mrb_int The number of arguments the method has. 868 * @param [...] ... Variadic values(not type safe!). 869 * @return [mrb_value] mrb_value mruby function value. 797 870 */ 798 871 MRB_API mrb_value mrb_funcall(mrb_state*, mrb_value, const char*, mrb_int,...); 872 /** 873 * Call existing ruby functions. This is basically the type safe version of mrb_funcall. 874 * 875 * #include <stdio.h> 876 * #include <mruby.h> 877 * #include "mruby/compile.h" 878 * int 879 * main() 880 * { 881 * mrb_int i = 99; 882 * mrb_state *mrb = mrb_open(); 883 * 884 * if (!mrb) { } 885 * mrb_sym m_sym = mrb_intern_lit(mrb, "method_name"); // Symbol for method. 886 * 887 * FILE *fp = fopen("test.rb","r"); 888 * mrb_value obj = mrb_load_file(mrb,fp); 889 * mrb_funcall_argv(mrb, obj, m_sym, 1, &obj); // Calling ruby function from test.rb. 890 * fclose(fp); 891 * mrb_close(mrb); 892 * } 893 * @param [mrb_state*] mrb_state* The current mruby state. 894 * @param [mrb_value] mrb_value A reference to an mruby value. 895 * @param [mrb_sym] mrb_sym The symbol representing the method. 896 * @param [mrb_int] mrb_int The number of arguments the method has. 897 * @param [const mrb_value*] mrb_value* Pointer to the object. 898 * @return [mrb_value] mrb_value mruby function value. 899 * @see mrb_funcall 900 */ 799 901 MRB_API mrb_value mrb_funcall_argv(mrb_state*, mrb_value, mrb_sym, mrb_int, const mrb_value*); 902 /** 903 * Call existing ruby functions with a block. 904 */ 800 905 MRB_API mrb_value mrb_funcall_with_block(mrb_state*, mrb_value, mrb_sym, mrb_int, const mrb_value*, mrb_value); 906 /** 907 * Create a symbol 908 * 909 * # Ruby style: 910 * :pizza # => :pizza 911 * 912 * // C style: 913 * mrb_sym m_sym = mrb_intern_lit(mrb, "pizza"); // => :pizza 914 * @param [mrb_state*] mrb_state* The current mruby state. 915 * @param [const char*] const char* The name of the method. 916 * @return [mrb_sym] mrb_sym A symbol. 917 */ 801 918 MRB_API mrb_sym mrb_intern_cstr(mrb_state*,const char*); 802 919 MRB_API mrb_sym mrb_intern(mrb_state*,const char*,size_t); … … 892 1009 MRB_API mrb_value mrb_top_self(mrb_state *); 893 1010 MRB_API mrb_value mrb_run(mrb_state*, struct RProc*, mrb_value); 894 MRB_API mrb_value mrb_toplevel_run(mrb_state*, struct RProc*); 895 MRB_API mrb_value mrb_context_run(mrb_state*, struct RProc*, mrb_value, unsigned int); 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*); 1014 /* compatibility macros */ 1015 #define mrb_toplevel_run_keep(m,p,k) mrb_top_run((m),(p),mrb_top_self(m),(k)) 1016 #define mrb_toplevel_run(m,p) mrb_toplevel_run_keep((m),(p),0) 1017 #define mrb_context_run(m,p,s,k) mrb_vm_run((m),(p),(s),(k)) 896 1018 897 1019 MRB_API void mrb_p(mrb_state*, mrb_value); … … 965 1087 + exception objects obtained from those macros are local to mrb 966 1088 */ 967 #define E_RUNTIME_ERROR (mrb_class_get(mrb, "RuntimeError")) 968 #define E_TYPE_ERROR (mrb_class_get(mrb, "TypeError")) 969 #define E_ARGUMENT_ERROR (mrb_class_get(mrb, "ArgumentError")) 970 #define E_INDEX_ERROR (mrb_class_get(mrb, "IndexError")) 971 #define E_RANGE_ERROR (mrb_class_get(mrb, "RangeError")) 972 #define E_NAME_ERROR (mrb_class_get(mrb, "NameError")) 973 #define E_NOMETHOD_ERROR (mrb_class_get(mrb, "NoMethodError")) 974 #define E_SCRIPT_ERROR (mrb_class_get(mrb, "ScriptError")) 975 #define E_SYNTAX_ERROR (mrb_class_get(mrb, "SyntaxError")) 976 #define E_LOCALJUMP_ERROR (mrb_class_get(mrb, "LocalJumpError")) 977 #define E_REGEXP_ERROR (mrb_class_get(mrb, "RegexpError")) 978 #define E_SYSSTACK_ERROR (mrb_class_get(mrb, "SystemStackError")) 979 980 #define E_NOTIMP_ERROR (mrb_class_get(mrb, "NotImplementedError")) 981 #define E_FLOATDOMAIN_ERROR (mrb_class_get(mrb, "FloatDomainError")) 982 983 #define E_KEY_ERROR (mrb_class_get(mrb, "KeyError")) 1089 #define E_RUNTIME_ERROR (mrb_exc_get(mrb, "RuntimeError")) 1090 #define E_TYPE_ERROR (mrb_exc_get(mrb, "TypeError")) 1091 #define E_ARGUMENT_ERROR (mrb_exc_get(mrb, "ArgumentError")) 1092 #define E_INDEX_ERROR (mrb_exc_get(mrb, "IndexError")) 1093 #define E_RANGE_ERROR (mrb_exc_get(mrb, "RangeError")) 1094 #define E_NAME_ERROR (mrb_exc_get(mrb, "NameError")) 1095 #define E_NOMETHOD_ERROR (mrb_exc_get(mrb, "NoMethodError")) 1096 #define E_SCRIPT_ERROR (mrb_exc_get(mrb, "ScriptError")) 1097 #define E_SYNTAX_ERROR (mrb_exc_get(mrb, "SyntaxError")) 1098 #define E_LOCALJUMP_ERROR (mrb_exc_get(mrb, "LocalJumpError")) 1099 #define E_REGEXP_ERROR (mrb_exc_get(mrb, "RegexpError")) 1100 1101 #define E_NOTIMP_ERROR (mrb_exc_get(mrb, "NotImplementedError")) 1102 #define E_FLOATDOMAIN_ERROR (mrb_exc_get(mrb, "FloatDomainError")) 1103 1104 #define E_KEY_ERROR (mrb_exc_get(mrb, "KeyError")) 984 1105 985 1106 MRB_API mrb_value mrb_yield(mrb_state *mrb, mrb_value b, mrb_value arg); 986 1107 MRB_API mrb_value mrb_yield_argv(mrb_state *mrb, mrb_value b, mrb_int argc, const mrb_value *argv); 987 1108 MRB_API mrb_value mrb_yield_with_class(mrb_state *mrb, mrb_value b, mrb_int argc, const mrb_value *argv, mrb_value self, struct RClass *c); 1109 1110 /* continue execution to the proc */ 1111 /* this function should always be called as the last function of a method */ 1112 /* e.g. return mrb_yield_cont(mrb, proc, self, argc, argv); */ 1113 mrb_value mrb_yield_cont(mrb_state *mrb, mrb_value b, mrb_value self, mrb_int argc, const mrb_value *argv); 988 1114 989 1115 /* mrb_gc_protect() leaves the object in the arena */ … … 1013 1139 MRB_API mrb_bool mrb_respond_to(mrb_state *mrb, mrb_value obj, mrb_sym mid); 1014 1140 MRB_API mrb_bool mrb_obj_is_instance_of(mrb_state *mrb, mrb_value obj, struct RClass* c); 1141 MRB_API mrb_bool mrb_func_basic_p(mrb_state *mrb, mrb_value obj, mrb_sym mid, mrb_func_t func); 1015 1142 1016 1143 … … 1034 1161 * @mrbgem mruby-fiber 1035 1162 */ 1036 #define E_FIBER_ERROR (mrb_ class_get(mrb, "FiberError"))1163 #define E_FIBER_ERROR (mrb_exc_get(mrb, "FiberError")) 1037 1164 1038 1165 /* memory pool implementation */ … … 1050 1177 MRB_API void mrb_show_copyright(mrb_state *mrb); 1051 1178 1052 #ifdef MRB_DEBUG1053 #include <assert.h>1054 #define mrb_assert(p) assert(p)1055 #define mrb_assert_int_fit(t1,n,t2,max) assert((n)>=0 && ((sizeof(n)<=sizeof(t2))||(n<=(t1)(max))))1056 #else1057 #define mrb_assert(p) ((void)0)1058 #define mrb_assert_int_fit(t1,n,t2,max) ((void)0)1059 #endif1060 1061 #if __STDC_VERSION__ >= 201112L1062 #define mrb_static_assert(exp, str) _Static_assert(exp, str)1063 #else1064 #define mrb_static_assert(exp, str) mrb_assert(exp)1065 #endif1066 1067 1179 MRB_API mrb_value mrb_format(mrb_state *mrb, const char *format, ...); 1068 1180 1181 #if 0 1182 /* memcpy and memset does not work with gdb reverse-next on my box */ 1183 /* use naive memcpy and memset instead */ 1184 #undef memcpy 1185 #undef memset 1186 static inline void* 1187 mrbmemcpy(void *dst, const void *src, size_t n) 1188 { 1189 char *d = dst; 1190 const char *s = src; 1191 while (n--) 1192 *d++ = *s++; 1193 return d; 1194 } 1195 #define memcpy(a,b,c) mrbmemcpy(a,b,c) 1196 1197 static inline void* 1198 mrbmemset(void *s, int c, size_t n) 1199 { 1200 char *t = s; 1201 while (n--) 1202 *t++ = c; 1203 return s; 1204 } 1205 #define memset(a,b,c) mrbmemset(a,b,c) 1206 #endif 1207 1069 1208 MRB_END_DECL 1070 1209 -
EcnlProtoTool/trunk/mruby-1.3.0/include/mruby/array.h
r321 r331 8 8 #define MRUBY_ARRAY_H 9 9 10 #include " mruby/common.h"10 #include "common.h" 11 11 12 12 /* … … 55 55 * 56 56 * @param mrb The mruby state reference. 57 * @return The initialized array 57 * @return The initialized array. 58 58 */ 59 59 MRB_API mrb_value mrb_ary_new(mrb_state *mrb); 60 60 61 /* 62 * Initializes a new array with initial values 63 * 64 * Equivalent to: 65 * 66 * Array[value1, value2, ...] 67 * 68 * @param mrb The mruby state reference. 69 * @param size The numer of values. 70 * @param vals The actual values. 71 * @return The initialized array. 72 */ 61 73 MRB_API mrb_value mrb_ary_new_from_values(mrb_state *mrb, mrb_int size, const mrb_value *vals); 74 75 /* 76 * Initializes a new array with two initial values 77 * 78 * Equivalent to: 79 * 80 * Array[car, cdr] 81 * 82 * @param mrb The mruby state reference. 83 * @param car The first value. 84 * @param cdr The second value. 85 * @return The initialized array. 86 */ 62 87 MRB_API mrb_value mrb_assoc_new(mrb_state *mrb, mrb_value car, mrb_value cdr); 63 MRB_API void mrb_ary_concat(mrb_state*, mrb_value, mrb_value); 64 MRB_API mrb_value mrb_ary_splat(mrb_state*, mrb_value); 88 89 /* 90 * Concatenate two arrays. The target array will be modified 91 * 92 * Equivalent to: 93 * ary.concat(other) 94 * 95 * @param mrb The mruby state reference. 96 * @param self The target array. 97 * @param other The array that will be concatenated to self. 98 */ 99 MRB_API void mrb_ary_concat(mrb_state *mrb, mrb_value self, mrb_value other); 100 101 /* 102 * Create an array from the input. It tries calling to_a on the 103 * value. If value does not respond to that, it creates a new 104 * array with just this value. 105 * 106 * @param mrb The mruby state reference. 107 * @param value The value to change into an array. 108 * @return An array representation of value. 109 */ 110 MRB_API mrb_value mrb_ary_splat(mrb_state *mrb, mrb_value value); 65 111 66 112 /* … … 85 131 * 86 132 * @param mrb The mruby state reference. 87 * @param ary The array from which the value will be pop ed.88 * @return The pop ed value.133 * @param ary The array from which the value will be popped. 134 * @return The popped value. 89 135 */ 90 136 MRB_API mrb_value mrb_ary_pop(mrb_state *mrb, mrb_value ary); … … 118 164 MRB_API void mrb_ary_set(mrb_state *mrb, mrb_value ary, mrb_int n, mrb_value val); 119 165 120 MRB_API void mrb_ary_replace(mrb_state *mrb, mrb_value a, mrb_value b); 166 /* 167 * Replace the array with another array 168 * 169 * Equivalent to: 170 * 171 * ary.replace(other) 172 * 173 * @param mrb The mruby state reference 174 * @param self The target array. 175 * @param other The array to replace it with. 176 */ 177 MRB_API void mrb_ary_replace(mrb_state *mrb, mrb_value self, mrb_value other); 121 178 MRB_API mrb_value mrb_check_array_type(mrb_state *mrb, mrb_value self); 179 180 /* 181 * Unshift an element into an array 182 * 183 * Equivalent to: 184 * 185 * ary.unshift(item) 186 * 187 * @param mrb The mruby state reference. 188 * @param self The target array. 189 * @param item The item to unshift. 190 */ 122 191 MRB_API mrb_value mrb_ary_unshift(mrb_state *mrb, mrb_value self, mrb_value item); 123 192 MRB_API mrb_value mrb_ary_entry(mrb_value ary, mrb_int offset); 193 194 /* 195 * Shifts the first element from the array. 196 * 197 * Equivalent to: 198 * 199 * ary.shift 200 * 201 * @param mrb The mruby state reference. 202 * @param self The array from which the value will be shifted. 203 * @return The shifted value. 204 */ 124 205 MRB_API mrb_value mrb_ary_shift(mrb_state *mrb, mrb_value self); 206 207 /* 208 * Removes all elements from this array 209 * 210 * Equivalent to: 211 * 212 * ary.clear 213 * 214 * @param mrb The mruby state reference. 215 * @param self The target array. 216 * @return self 217 */ 125 218 MRB_API mrb_value mrb_ary_clear(mrb_state *mrb, mrb_value self); 219 220 /* 221 * Join the array elements together in a string 222 * 223 * Equivalent to: 224 * 225 * ary.join(sep="") 226 * 227 * @param mrb The mruby state reference. 228 * @param ary The target array 229 * @param sep The separater, can be NULL 230 */ 126 231 MRB_API mrb_value mrb_ary_join(mrb_state *mrb, mrb_value ary, mrb_value sep); 127 MRB_API mrb_value mrb_ary_resize(mrb_state *mrb, mrb_value ary, mrb_int len); 232 233 /* 234 * Update the capacity of the array 235 * 236 * @param mrb The mruby state reference. 237 * @param ary The target array. 238 * @param new_len The new capacity of the array 239 */ 240 MRB_API mrb_value mrb_ary_resize(mrb_state *mrb, mrb_value ary, mrb_int new_len); 128 241 129 242 static inline mrb_int … … 135 248 } 136 249 250 static inline mrb_value 251 ary_elt(mrb_value ary, mrb_int offset) 252 { 253 if (offset < 0 || RARRAY_LEN(ary) <= offset) { 254 return mrb_nil_value(); 255 } 256 return RARRAY_PTR(ary)[offset]; 257 } 258 137 259 MRB_END_DECL 138 260 -
EcnlProtoTool/trunk/mruby-1.3.0/include/mruby/boxing_nan.h
r321 r331 54 54 55 55 #define mrb_tt(o) ((enum mrb_vtype)(((o).value.ttt & 0xfc000)>>14)-1) 56 #define mrb_type(o) ( (uint32_t)0xfff00000 < (o).value.ttt ? mrb_tt(o) : MRB_TT_FLOAT)56 #define mrb_type(o) (enum mrb_vtype)((uint32_t)0xfff00000 < (o).value.ttt ? mrb_tt(o) : MRB_TT_FLOAT) 57 57 #define mrb_ptr(o) ((void*)((((uintptr_t)0x3fffffffffff)&((uintptr_t)((o).value.p)))<<2)) 58 58 #define mrb_float(o) (o).f … … 61 61 #define mrb_symbol(o) (o).value.sym 62 62 63 #ifdef MRB_64BIT 64 #define BOXNAN_SHIFT_LONG_POINTER(v) (((uintptr_t)(v)>>34)&0x3fff) 65 #else 66 #define BOXNAN_SHIFT_LONG_POINTER(v) 0 67 #endif 68 63 69 #define BOXNAN_SET_VALUE(o, tt, attr, v) do {\ 64 switch (tt) {\ 65 case MRB_TT_FALSE:\ 66 case MRB_TT_TRUE:\ 67 case MRB_TT_UNDEF:\ 68 case MRB_TT_FIXNUM:\ 69 case MRB_TT_SYMBOL: (o).attr = (v); break;\ 70 default: (o).value.i = 0; (o).value.p = (void*)((uintptr_t)(o).value.p | (((uintptr_t)(v))>>2)); break;\ 71 }\ 72 (o).value.ttt = (0xfff00000|(((tt)+1)<<14));\ 70 (o).attr = (v);\ 71 (o).value.ttt = 0xfff00000 | (((tt)+1)<<14);\ 72 } while (0) 73 74 #define BOXNAN_SET_OBJ_VALUE(o, tt, v) do {\ 75 (o).value.p = (void*)((uintptr_t)(v)>>2);\ 76 (o).value.ttt = (0xfff00000|(((tt)+1)<<14)|BOXNAN_SHIFT_LONG_POINTER(v));\ 73 77 } while (0) 74 78 … … 77 81 (r).value.ttt = 0x7ff80000; \ 78 82 (r).value.i = 0; \ 79 } else { \ 83 } \ 84 else { \ 80 85 (r).f = v; \ 81 86 }} while(0) … … 87 92 #define SET_INT_VALUE(r,n) BOXNAN_SET_VALUE(r, MRB_TT_FIXNUM, value.i, (n)) 88 93 #define SET_SYM_VALUE(r,v) BOXNAN_SET_VALUE(r, MRB_TT_SYMBOL, value.sym, (v)) 89 #define SET_OBJ_VALUE(r,v) BOXNAN_SET_ VALUE(r, (((struct RObject*)(v))->tt), value.p, (v))90 #define SET_CPTR_VALUE(mrb,r,v) BOXNAN_SET_ VALUE(r, MRB_TT_CPTR, value.p, v)94 #define SET_OBJ_VALUE(r,v) BOXNAN_SET_OBJ_VALUE(r, (((struct RObject*)(v))->tt), (v)) 95 #define SET_CPTR_VALUE(mrb,r,v) BOXNAN_SET_OBJ_VALUE(r, MRB_TT_CPTR, v) 91 96 #define SET_UNDEF_VALUE(r) BOXNAN_SET_VALUE(r, MRB_TT_UNDEF, value.i, 0) 92 97 -
EcnlProtoTool/trunk/mruby-1.3.0/include/mruby/boxing_word.h
r321 r331 10 10 #if defined(MRB_INT16) 11 11 # error MRB_INT16 is too small for MRB_WORD_BOXING. 12 #endif 13 14 #if defined(MRB_INT64) && !defined(MRB_64BIT) 15 #error MRB_INT64 cannot be used with MRB_WORD_BOXING in 32-bit mode. 12 16 #endif 13 17 … … 63 67 #define mrb_cptr(o) (o).value.vp->p 64 68 #define mrb_float(o) (o).value.fp->f 65 #define mrb_fixnum(o) ( o).value.i69 #define mrb_fixnum(o) ((mrb_int)(o).value.i) 66 70 #define mrb_symbol(o) (o).value.sym 67 71 … … 92 96 #define mrb_nil_p(o) ((o).w == MRB_Qnil) 93 97 94 #define BOXWORD_SET_VALUE(o, ttt, attr, v) do { \98 #define BOXWORD_SET_VALUE(o, ttt, attr, v) do { \ 95 99 switch (ttt) {\ 96 100 case MRB_TT_FALSE: (o).w = (v) ? MRB_Qfalse : MRB_Qnil; break;\ 97 101 case MRB_TT_TRUE: (o).w = MRB_Qtrue; break;\ 98 102 case MRB_TT_UNDEF: (o).w = MRB_Qundef; break;\ 99 case MRB_TT_FIXNUM: (o). value.i_flag = MRB_FIXNUM_FLAG; (o).attr = (v); break;\100 case MRB_TT_SYMBOL: (o). value.sym_flag = MRB_SYMBOL_FLAG; (o).attr = (v); break;\103 case MRB_TT_FIXNUM: (o).w = 0;(o).value.i_flag = MRB_FIXNUM_FLAG; (o).attr = (v); break;\ 104 case MRB_TT_SYMBOL: (o).w = 0;(o).value.sym_flag = MRB_SYMBOL_FLAG; (o).attr = (v); break;\ 101 105 default: (o).w = 0; (o).attr = (v); if ((o).value.bp) (o).value.bp->tt = ttt; break;\ 102 106 }\ -
EcnlProtoTool/trunk/mruby-1.3.0/include/mruby/class.h
r321 r331 8 8 #define MRUBY_CLASS_H 9 9 10 #include " mruby/common.h"10 #include "common.h" 11 11 12 12 /** … … 52 52 } 53 53 54 // TODO: figure out where to put user flags 54 /* TODO: figure out where to put user flags */ 55 #define MRB_FLAG_IS_FROZEN (1 << 18) 55 56 #define MRB_FLAG_IS_PREPENDED (1 << 19) 56 57 #define MRB_FLAG_IS_ORIGIN (1 << 20) -
EcnlProtoTool/trunk/mruby-1.3.0/include/mruby/common.h
r321 r331 1 1 /* 2 ** mruby/common.h - mruby common platform definitions2 **"common.h - mruby common platform definition" 3 3 ** 4 4 ** See Copyright Notice in mruby.h … … 10 10 11 11 #ifdef __cplusplus 12 #ifdef MRB_ENABLE_CXX_ABI 13 #define MRB_BEGIN_DECL 14 #define MRB_END_DECL 15 #else 12 16 # define MRB_BEGIN_DECL extern "C" { 13 17 # define MRB_END_DECL } 18 #endif 14 19 #else 15 20 /** Start declarations in C mode */ -
EcnlProtoTool/trunk/mruby-1.3.0/include/mruby/compile.h
r321 r331 8 8 #define MRUBY_COMPILE_H 9 9 10 #include " mruby/common.h"10 #include "common.h" 11 11 12 12 /** … … 15 15 MRB_BEGIN_DECL 16 16 17 #include "mruby.h"17 #include <mruby.h> 18 18 19 19 struct mrb_jmpbuf; … … 40 40 MRB_API const char *mrbc_filename(mrb_state *mrb, mrbc_context *c, const char *s); 41 41 MRB_API void mrbc_partial_hook(mrb_state *mrb, mrbc_context *c, int (*partial_hook)(struct mrb_parser_state*), void*data); 42 43 MRB_API mrb_value mrb_toplevel_run_keep(mrb_state*, struct RProc*, unsigned int);44 42 45 43 /* AST node structure */ … … 105 103 }; 106 104 107 #define MRB_PARSER_BUF_SIZE 1024 105 #define MRB_PARSER_TOKBUF_MAX 65536 106 #define MRB_PARSER_TOKBUF_SIZE 256 108 107 109 108 /* parser structure */ … … 133 132 134 133 mrb_ast_node *pb; 135 char buf[MRB_PARSER_BUF_SIZE]; 136 int bidx; 134 char *tokbuf; 135 char buf[MRB_PARSER_TOKBUF_SIZE]; 136 int tidx; 137 int tsiz; 137 138 138 139 mrb_ast_node *all_heredocs; /* list of mrb_parser_heredoc_info* */ … … 163 164 MRB_API void mrb_parser_free(struct mrb_parser_state*); 164 165 MRB_API void mrb_parser_parse(struct mrb_parser_state*,mrbc_context*); 166 MRB_API double mrb_float_read(const char*, char**); 165 167 166 168 MRB_API void mrb_parser_set_filename(struct mrb_parser_state*, char const*); … … 174 176 MRB_API struct mrb_parser_state* mrb_parse_nstring(mrb_state*,const char*,int,mrbc_context*); 175 177 MRB_API struct RProc* mrb_generate_code(mrb_state*, struct mrb_parser_state*); 178 MRB_API mrb_value mrb_load_exec(mrb_state *mrb, struct mrb_parser_state *p, mrbc_context *c); 176 179 177 180 /* program load functions */ -
EcnlProtoTool/trunk/mruby-1.3.0/include/mruby/data.h
r321 r331 8 8 #define MRUBY_DATA_H 9 9 10 #include " mruby/common.h"10 #include "common.h" 11 11 12 12 /** -
EcnlProtoTool/trunk/mruby-1.3.0/include/mruby/debug.h
r321 r331 8 8 #define MRUBY_DEBUG_H 9 9 10 #include " mruby/common.h"10 #include "common.h" 11 11 12 12 /** -
EcnlProtoTool/trunk/mruby-1.3.0/include/mruby/dump.h
r321 r331 8 8 #define MRUBY_DUMP_H 9 9 10 #include "mruby.h"11 #include "mruby/irep.h"12 #include " mruby/common.h"10 #include <mruby.h> 11 #include <mruby/irep.h> 12 #include "common.h" 13 13 14 14 /** … … 53 53 #define RITE_BINARY_IDENT "RITE" 54 54 #define RITE_BINARY_IDENT_LIL "ETIR" 55 #define RITE_BINARY_FORMAT_VER "000 3"55 #define RITE_BINARY_FORMAT_VER "0004" 56 56 #define RITE_COMPILER_NAME "MATZ" 57 57 #define RITE_COMPILER_VERSION "0000" -
EcnlProtoTool/trunk/mruby-1.3.0/include/mruby/error.h
r321 r331 8 8 #define MRUBY_ERROR_H 9 9 10 #include " mruby/common.h"10 #include "common.h" 11 11 12 12 /** … … 32 32 /* declaration for fail method */ 33 33 MRB_API mrb_value mrb_f_raise(mrb_state*, mrb_value); 34 35 struct RBreak { 36 MRB_OBJECT_HEADER; 37 struct iv_tbl *iv; 38 struct RProc *proc; 39 mrb_value val; 40 }; 34 41 35 42 /** -
EcnlProtoTool/trunk/mruby-1.3.0/include/mruby/gc.h
r321 r331 8 8 #define MRUBY_GC_H 9 9 10 #include " mruby/common.h"10 #include "common.h" 11 11 12 12 /** … … 18 18 struct mrb_state; 19 19 20 typedef void (mrb_each_object_callback)(struct mrb_state *mrb, struct RBasic *obj, void *data); 20 #define MRB_EACH_OBJ_OK 0 21 #define MRB_EACH_OBJ_BREAK 1 22 typedef int (mrb_each_object_callback)(struct mrb_state *mrb, struct RBasic *obj, void *data); 21 23 void mrb_objspace_each_objects(struct mrb_state *mrb, mrb_each_object_callback *callback, void *data); 22 24 MRB_API void mrb_free_context(struct mrb_state *mrb, struct mrb_context *c); … … 63 65 int interval_ratio; 64 66 int step_ratio; 67 mrb_bool iterating :1; 65 68 mrb_bool disabled :1; 66 69 mrb_bool full :1; -
EcnlProtoTool/trunk/mruby-1.3.0/include/mruby/hash.h
r321 r331 8 8 #define MRUBY_HASH_H 9 9 10 #include "mruby/common.h" 10 #include "common.h" 11 #include <mruby/khash.h> 11 12 12 13 /** … … 24 25 #define mrb_hash_value(p) mrb_obj_value((void*)(p)) 25 26 26 MRB_API mrb_value mrb_hash_new_capa(mrb_state*, int);27 MRB_API mrb_value mrb_hash_new_capa(mrb_state*, mrb_int); 27 28 28 29 /* 29 30 * Initializes a new hash. 31 * 32 * Equivalent to: 33 * 34 * Hash.new 35 * 36 * @param mrb The mruby state reference. 37 * @return The initialized hash. 30 38 */ 31 39 MRB_API mrb_value mrb_hash_new(mrb_state *mrb); … … 33 41 /* 34 42 * Sets a keys and values to hashes. 43 * 44 * Equivalent to: 45 * 46 * hash[key] = val 47 * 48 * @param mrb The mruby state reference. 49 * @param hash The target hash. 50 * @param key The key to set. 51 * @param val The value to set. 52 * @return The value. 35 53 */ 36 54 MRB_API void mrb_hash_set(mrb_state *mrb, mrb_value hash, mrb_value key, mrb_value val); 37 55 38 56 /* 39 * Gets a value from a key. 57 * Gets a value from a key. If the key is not found, the default of the 58 * hash is used. 59 * 60 * Equivalent to: 61 * 62 * hash[key] 63 * 64 * @param mrb The mruby state reference. 65 * @param hash The target hash. 66 * @param key The key to get. 67 * @return The found value. 40 68 */ 41 69 MRB_API mrb_value mrb_hash_get(mrb_state *mrb, mrb_value hash, mrb_value key); 42 70 71 /* 72 * Gets a value from a key. If the key is not found, the default parameter is 73 * used. 74 * 75 * Equivalent to: 76 * 77 * hash.hash_key?(key) ? hash[key] : def 78 * 79 * @param mrb The mruby state reference. 80 * @param hash The target hash. 81 * @param key The key to get. 82 * @param def The default value. 83 * @return The found value. 84 */ 43 85 MRB_API mrb_value mrb_hash_fetch(mrb_state *mrb, mrb_value hash, mrb_value key, mrb_value def); 44 86 45 87 /* 46 88 * Deletes hash key and value pair. 89 * 90 * Equivalent to: 91 * 92 * hash.delete(key) 93 * 94 * @param mrb The mruby state reference. 95 * @param hash The target hash. 96 * @param key The key to delete. 97 * @return The deleted value. 47 98 */ 48 99 MRB_API mrb_value mrb_hash_delete_key(mrb_state *mrb, mrb_value hash, mrb_value key); … … 50 101 /* 51 102 * Gets an array of keys. 103 * 104 * Equivalent to: 105 * 106 * hash.keys 107 * 108 * @param mrb The mruby state reference. 109 * @param hash The target hash. 110 * @return An array with the keys of the hash. 52 111 */ 53 112 MRB_API mrb_value mrb_hash_keys(mrb_state *mrb, mrb_value hash); 54 113 MRB_API mrb_value mrb_check_hash_type(mrb_state *mrb, mrb_value hash); 114 115 /* 116 * Check if the hash is empty 117 * 118 * Equivalent to: 119 * 120 * hash.empty? 121 * 122 * @param mrb The mruby state reference. 123 * @param self The target hash. 124 * @return True if the hash is empty, false otherwise. 125 */ 55 126 MRB_API mrb_value mrb_hash_empty_p(mrb_state *mrb, mrb_value self); 56 127 57 128 /* 129 * Gets an array of values. 130 * 131 * Equivalent to: 132 * 133 * hash.values 134 * 135 * @param mrb The mruby state reference. 136 * @param hash The target hash. 137 * @return An array with the values of the hash. 138 */ 139 MRB_API mrb_value mrb_hash_values(mrb_state *mrb, mrb_value hash); 140 141 /* 58 142 * Clears the hash. 143 * 144 * Equivalent to: 145 * 146 * hash.clear 147 * 148 * @param mrb The mruby state reference. 149 * @param hash The target hash. 150 * @return The hash 59 151 */ 60 152 MRB_API mrb_value mrb_hash_clear(mrb_state *mrb, mrb_value hash); 153 154 /* declaration of struct kh_ht */ 155 /* be careful when you touch the internal */ 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) 61 162 62 163 /* RHASH_TBL allocates st_table if not available. */ … … 67 168 MRB_API struct kh_ht * mrb_hash_tbl(mrb_state *mrb, mrb_value hash); 68 169 69 #define MRB_HASH_PROC_DEFAULT 256 170 #define MRB_HASH_DEFAULT 1 171 #define MRB_HASH_PROC_DEFAULT 2 172 #define MRB_RHASH_DEFAULT_P(h) (RHASH(h)->flags & MRB_HASH_DEFAULT) 70 173 #define MRB_RHASH_PROCDEFAULT_P(h) (RHASH(h)->flags & MRB_HASH_PROC_DEFAULT) 71 174 -
EcnlProtoTool/trunk/mruby-1.3.0/include/mruby/irep.h
r321 r331 8 8 #define MRUBY_IREP_H 9 9 10 #include " mruby/common.h"11 #include "mruby/compile.h"10 #include "common.h" 11 #include <mruby/compile.h> 12 12 13 13 /** … … 40 40 struct mrb_locals *lv; 41 41 /* debug info */ 42 mrb_bool own_filename; 42 43 const char *filename; 43 44 uint16_t *lines; -
EcnlProtoTool/trunk/mruby-1.3.0/include/mruby/khash.h
r321 r331 10 10 #include <string.h> 11 11 12 #include "mruby.h"13 #include " mruby/common.h"12 #include <mruby.h> 13 #include "common.h" 14 14 15 15 /** -
EcnlProtoTool/trunk/mruby-1.3.0/include/mruby/numeric.h
r321 r331 8 8 #define MRUBY_NUMERIC_H 9 9 10 #include " mruby/common.h"10 #include "common.h" 11 11 12 12 /** … … 21 21 #define FIXABLE(f) (POSFIXABLE(f) && NEGFIXABLE(f)) 22 22 23 #ifdef MRB_INT64 24 #define FIXABLE_FLOAT(f) FIXABLE((mrb_int)(f)) 25 #else 26 #define FIXABLE_FLOAT(f) FIXABLE(f) 27 #endif 28 23 29 MRB_API mrb_value mrb_flo_to_fixnum(mrb_state *mrb, mrb_value val); 24 30 MRB_API mrb_value mrb_fixnum_to_str(mrb_state *mrb, mrb_value x, int base); … … 32 38 mrb_value mrb_num_div(mrb_state *mrb, mrb_value x, mrb_value y); 33 39 40 #ifndef __has_builtin 41 #define __has_builtin(x) 0 42 #endif 43 44 #if (defined(__GNUC__) && __GNUC__ >= 5) || \ 45 (__has_builtin(__builtin_add_overflow) && \ 46 __has_builtin(__builtin_sub_overflow) && \ 47 __has_builtin(__builtin_mul_overflow)) 48 # define MRB_HAVE_TYPE_GENERIC_CHECKED_ARITHMETIC_BUILTINS 49 #endif 50 51 /* 52 // Clang 3.8 and 3.9 have problem compiling mruby in 32-bit mode, when MRB_INT64 is set 53 // because of missing __mulodi4 and similar functions in its runtime. We need to use custom 54 // implementation for them. 55 */ 56 #ifdef MRB_HAVE_TYPE_GENERIC_CHECKED_ARITHMETIC_BUILTINS 57 #if defined(__clang__) && (__clang_major__ == 3) && (__clang_minor__ >= 8) && \ 58 defined(MRB_32BIT) && defined(MRB_INT64) 59 #undef MRB_HAVE_TYPE_GENERIC_CHECKED_ARITHMETIC_BUILTINS 60 #endif 61 #endif 62 63 #ifdef MRB_HAVE_TYPE_GENERIC_CHECKED_ARITHMETIC_BUILTINS 64 65 #ifndef MRB_WORD_BOXING 66 # define WBCHK(x) 0 67 #else 68 # define WBCHK(x) !FIXABLE(x) 69 #endif 70 71 static inline mrb_bool 72 mrb_int_add_overflow(mrb_int augend, mrb_int addend, mrb_int *sum) 73 { 74 return __builtin_add_overflow(augend, addend, sum) || WBCHK(*sum); 75 } 76 77 static inline mrb_bool 78 mrb_int_sub_overflow(mrb_int minuend, mrb_int subtrahend, mrb_int *difference) 79 { 80 return __builtin_sub_overflow(minuend, subtrahend, difference) || WBCHK(*difference); 81 } 82 83 static inline mrb_bool 84 mrb_int_mul_overflow(mrb_int multiplier, mrb_int multiplicand, mrb_int *product) 85 { 86 return __builtin_mul_overflow(multiplier, multiplicand, product) || WBCHK(*product); 87 } 88 89 #undef WBCHK 90 91 #else 92 34 93 #define MRB_UINT_MAKE2(n) uint ## n ## _t 35 94 #define MRB_UINT_MAKE(n) MRB_UINT_MAKE2(n) … … 37 96 38 97 #define MRB_INT_OVERFLOW_MASK ((mrb_uint)1 << (MRB_INT_BIT - 1 - MRB_FIXNUM_SHIFT)) 39 40 /* Idea from Potion: https://github.com/perl11/potion (MIT) */41 #if (defined(__clang__) && ((__clang_major__ > 3) || (__clang_major__ == 3 && __clang_minor__ >= 4))) \42 || (defined(__GNUC__) && __GNUC__ >= 5)43 44 static inline mrb_bool45 mrb_int_add_overflow(mrb_int augend, mrb_int addend, mrb_int *sum)46 {47 mrb_bool of;48 49 #ifdef MRB_INT6450 long long val;51 of = __builtin_saddll_overflow(augend, addend, &val) ||52 #else53 int val;54 of = __builtin_sadd_overflow(augend, addend, &val) ||55 #endif56 (val > MRB_INT_MAX) || (val < MRB_INT_MIN);57 58 *sum = (mrb_int) val;59 return of;60 }61 62 static inline mrb_bool63 mrb_int_sub_overflow(mrb_int minuend, mrb_int subtrahend, mrb_int *difference)64 {65 mrb_bool of;66 67 #ifdef MRB_INT6468 long long val;69 of = __builtin_ssubll_overflow(minuend, subtrahend, &val) ||70 #else71 int val;72 of = __builtin_ssub_overflow(minuend, subtrahend, &val) ||73 #endif74 (val > MRB_INT_MAX) || (val < MRB_INT_MIN);75 76 *difference = (mrb_int) val;77 return of;78 }79 #else80 98 81 99 static inline mrb_bool … … 99 117 } 100 118 119 static inline mrb_bool 120 mrb_int_mul_overflow(mrb_int multiplier, mrb_int multiplicand, mrb_int *product) 121 { 122 #if MRB_INT_BIT == 32 123 int64_t n = (int64_t)multiplier * multiplicand; 124 *product = (mrb_int)n; 125 return !FIXABLE(n); 126 #else 127 if (multiplier > 0) { 128 if (multiplicand > 0) { 129 if (multiplier > MRB_INT_MAX / multiplicand) return TRUE; 130 } 131 else { 132 if (multiplicand < MRB_INT_MAX / multiplier) return TRUE; 133 } 134 } 135 else { 136 if (multiplicand > 0) { 137 if (multiplier < MRB_INT_MAX / multiplicand) return TRUE; 138 } 139 else { 140 if (multiplier != 0 && multiplicand < MRB_INT_MAX / multiplier) return TRUE; 141 } 142 } 143 *product = multiplier * multiplicand; 144 return FALSE; 101 145 #endif 146 } 102 147 103 148 #undef MRB_INT_OVERFLOW_MASK … … 106 151 #undef MRB_UINT_MAKE2 107 152 153 #endif 154 108 155 MRB_END_DECL 109 156 -
EcnlProtoTool/trunk/mruby-1.3.0/include/mruby/object.h
r321 r331 23 23 #define mrb_basic_ptr(v) ((struct RBasic*)(mrb_ptr(v))) 24 24 25 #define MRB_FROZEN_P(o) ((o)->flags & MRB_FLAG_IS_FROZEN) 26 #define MRB_SET_FROZEN_FLAG(o) ((o)->flags |= MRB_FLAG_IS_FROZEN) 27 #define MRB_UNSET_FROZEN_FLAG(o) ((o)->flags &= ~MRB_FLAG_IS_FROZEN) 28 25 29 struct RObject { 26 30 MRB_OBJECT_HEADER; -
EcnlProtoTool/trunk/mruby-1.3.0/include/mruby/opcode.h
r321 r331 83 83 OP_JMPNOT,/* A sBx if !R(A) pc+=sBx */ 84 84 OP_ONERR,/* sBx rescue_push(pc+sBx) */ 85 OP_RESCUE,/* A clear(exc); R(A) := exception (ignore when A=0) */ 85 OP_RESCUE,/* A B C if A (if C exc=R(A) else R(A) := exc); 86 if B R(B) := exc.isa?(R(B)); clear(exc) */ 86 87 OP_POPERR,/* A A.times{rescue_pop()} */ 87 88 OP_RAISE,/* A raise(R(A)) */ -
EcnlProtoTool/trunk/mruby-1.3.0/include/mruby/proc.h
r321 r331 8 8 #define MRUBY_PROC_H 9 9 10 #include " mruby/common.h"11 #include "mruby/irep.h"10 #include "common.h" 11 #include <mruby/irep.h> 12 12 13 13 /** … … 19 19 MRB_OBJECT_HEADER; 20 20 mrb_value *stack; 21 mrb_sym mid;22 21 ptrdiff_t cioff; 22 union { 23 mrb_sym mid; 24 struct mrb_context *c; 25 } cxt; 23 26 }; 24 27 … … 27 30 #define MRB_ENV_UNSHARE_STACK(e) ((e)->cioff = -1) 28 31 #define MRB_ENV_STACK_SHARED_P(e) ((e)->cioff >= 0) 32 33 MRB_API void mrb_env_unshare(mrb_state*, struct REnv*); 29 34 30 35 struct RProc { … … 51 56 #define MRB_PROC_STRICT 256 52 57 #define MRB_PROC_STRICT_P(p) (((p)->flags & MRB_PROC_STRICT) != 0) 58 #define MRB_PROC_ORPHAN 512 59 #define MRB_PROC_ORPHAN_P(p) (((p)->flags & MRB_PROC_ORPHAN) != 0) 53 60 54 61 #define mrb_proc_ptr(v) ((struct RProc*)(mrb_ptr(v))) … … 69 76 #define mrb_cfunc_env_get(mrb, idx) mrb_proc_cfunc_env_get(mrb, idx) 70 77 71 #include "mruby/khash.h"78 #include <mruby/khash.h> 72 79 KHASH_DECLARE(mt, mrb_sym, struct RProc*, TRUE) 73 80 -
EcnlProtoTool/trunk/mruby-1.3.0/include/mruby/range.h
r321 r331 8 8 #define MRUBY_RANGE_H 9 9 10 #include " mruby/common.h"10 #include "common.h" 11 11 12 12 /** … … 26 26 }; 27 27 28 #define mrb_range_ptr(v) ((struct RRange*)(mrb_ptr(v))) 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)) 29 30 #define mrb_range_value(p) mrb_obj_value((void*)(p)) 30 31 … … 41 42 MRB_API mrb_value mrb_range_new(mrb_state *mrb, mrb_value start, mrb_value end, mrb_bool exclude); 42 43 43 MRB_API mrb_ bool mrb_range_beg_len(mrb_state *mrb, mrb_value range, mrb_int *begp, mrb_int *lenp, mrb_int len);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); 44 45 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)); 45 46 -
EcnlProtoTool/trunk/mruby-1.3.0/include/mruby/re.h
r321 r331 8 8 #define MRUBY_RE_H 9 9 10 #ifdef __cplusplus 11 extern "C" { 12 #endif 10 MRB_BEGIN_DECL 13 11 14 12 #define REGEXP_CLASS "Regexp" 15 13 16 #ifdef __cplusplus 17 } 18 #endif 14 MRB_END_DECL 19 15 20 16 #endif /* RE_H */ -
EcnlProtoTool/trunk/mruby-1.3.0/include/mruby/string.h
r321 r331 8 8 #define MRUBY_STRING_H 9 9 10 #include " mruby/common.h"10 #include "common.h" 11 11 12 12 /** … … 45 45 if (RSTR_EMBED_P(s)) {\ 46 46 RSTR_SET_EMBED_LEN((s),(n));\ 47 } else {\ 47 }\ 48 else {\ 48 49 s->as.heap.len = (mrb_int)(n);\ 49 50 }\ … … 63 64 #define RSTR_UNSET_NOFREE_FLAG(s) ((s)->flags &= ~MRB_STR_NOFREE) 64 65 65 #define RSTR_FROZEN_P(s) ((s)->flags & MRB_STR_FROZEN)66 #define RSTR_SET_FROZEN_FLAG(s) ((s)->flags |= MRB_STR_FROZEN)67 #define RSTR_UNSET_FROZEN_FLAG(s) ((s)->flags &= ~MRB_STR_FROZEN)68 69 66 /* 70 67 * Returns a pointer from a Ruby string … … 73 70 #define RSTRING(s) mrb_str_ptr(s) 74 71 #define RSTRING_PTR(s) RSTR_PTR(RSTRING(s)) 75 #define RSTRING_EMBED_LEN(s) RSTR_E NBED_LEN(RSTRING(s))72 #define RSTRING_EMBED_LEN(s) RSTR_EMBED_LEN(RSTRING(s)) 76 73 #define RSTRING_LEN(s) RSTR_LEN(RSTRING(s)) 77 74 #define RSTRING_CAPA(s) RSTR_CAPA(RSTRING(s)) 78 75 #define RSTRING_END(s) (RSTRING_PTR(s) + RSTRING_LEN(s)) 79 mrb_int mrb_str_strlen(mrb_state*, struct RString*);76 MRB_API mrb_int mrb_str_strlen(mrb_state*, struct RString*); 80 77 81 78 #define MRB_STR_SHARED 1 82 79 #define MRB_STR_NOFREE 2 83 #define MRB_STR_ FROZEN 484 #define MRB_STR_EMBED 885 #define MRB_STR_EMBED_LEN_MASK 0x 1f086 #define MRB_STR_EMBED_LEN_SHIFT 480 #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 87 84 88 85 void mrb_gc_free_str(mrb_state*, struct RString*); 89 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 94 * int 95 * main(int argc, 96 * char **argv) 97 * { 98 * // Variable declarations. 99 * mrb_value str1; 100 * mrb_value str2; 101 * 102 * mrb_state *mrb = mrb_open(); 103 * if (!mrb) 104 * { 105 * // handle error 106 * } 107 * 108 * // Creates new Ruby strings. 109 * str1 = mrb_str_new_lit(mrb, "abc"); 110 * str2 = mrb_str_new_lit(mrb, "def"); 111 * 112 * // Concatnates str2 to str1. 113 * mrb_str_concat(mrb, str1, str2); 114 * 115 * // Prints new Concatnated Ruby string. 116 * mrb_p(mrb, str1); 117 * 118 * mrb_close(mrb); 119 * return 0; 120 * } 121 * 122 * 123 * Result: 124 * 125 * => "abcdef" 126 * 127 * @param [mrb_state] mrb The current mruby state. 128 * @param [mrb_value] self String to concatenate. 129 * @param [mrb_value] other String to append to self. 130 * @return [mrb_value] Returns a new String appending other to self. 131 */ 90 132 MRB_API void mrb_str_concat(mrb_state*, mrb_value, mrb_value); 91 133 92 134 /* 93 135 * Adds two strings together. 136 * 137 * 138 * Example: 139 * 140 * !!!c 141 * int 142 * main(int argc, 143 * char **argv) 144 * { 145 * // Variable declarations. 146 * mrb_value a; 147 * mrb_value b; 148 * mrb_value c; 149 * 150 * mrb_state *mrb = mrb_open(); 151 * if (!mrb) 152 * { 153 * // handle error 154 * } 155 * 156 * // Creates two Ruby strings from the passed in C strings. 157 * a = mrb_str_new_lit(mrb, "abc"); 158 * b = mrb_str_new_lit(mrb, "def"); 159 * 160 * // Prints both C strings. 161 * mrb_p(mrb, a); 162 * mrb_p(mrb, b); 163 * 164 * // Concatnates both Ruby strings. 165 * c = mrb_str_plus(mrb, a, b); 166 * 167 * // Prints new Concatnated Ruby string. 168 * mrb_p(mrb, c); 169 * 170 * mrb_close(mrb); 171 * return 0; 172 * } 173 * 174 * 175 * Result: 176 * 177 * => "abc" # First string 178 * => "def" # Second string 179 * => "abcdef" # First & Second concatnated. 180 * 181 * @param [mrb_state] mrb The current mruby state. 182 * @param [mrb_value] a First string to concatenate. 183 * @param [mrb_value] b Second string to concatenate. 184 * @return [mrb_value] Returns a new String containing a concatenated to b. 94 185 */ 95 186 MRB_API mrb_value mrb_str_plus(mrb_state*, mrb_value, mrb_value); … … 97 188 /* 98 189 * Converts pointer into a Ruby string. 190 * 191 * @param [mrb_state] mrb The current mruby state. 192 * @param [void*] p The pointer to convert to Ruby string. 193 * @return [mrb_value] Returns a new Ruby String. 99 194 */ 100 195 MRB_API mrb_value mrb_ptr_to_str(mrb_state *, void*); … … 102 197 /* 103 198 * Returns an object as a Ruby string. 199 * 200 * @param [mrb_state] mrb The current mruby state. 201 * @param [mrb_value] obj An object to return as a Ruby string. 202 * @return [mrb_value] An object as a Ruby string. 104 203 */ 105 204 MRB_API mrb_value mrb_obj_as_string(mrb_state *mrb, mrb_value obj); 106 205 107 206 /* 108 * Resizes the string's length. 207 * Resizes the string's length. Returns the amount of characters 208 * in the specified by len. 209 * 210 * Example: 211 * 212 * !!!c 213 * int 214 * main(int argc, 215 * char **argv) 216 * { 217 * // Variable declaration. 218 * mrb_value str; 219 * 220 * mrb_state *mrb = mrb_open(); 221 * if (!mrb) 222 * { 223 * // handle error 224 * } 225 * // Creates a new string. 226 * str = mrb_str_new_lit(mrb, "Hello, world!"); 227 * // Returns 5 characters of 228 * mrb_str_resize(mrb, str, 5); 229 * mrb_p(mrb, str); 230 * 231 * mrb_close(mrb); 232 * return 0; 233 * } 234 * 235 * Result: 236 * 237 * => "Hello" 238 * 239 * @param [mrb_state] mrb The current mruby state. 240 * @param [mrb_value] str The Ruby string to resize. 241 * @param [mrb_value] len The length. 242 * @return [mrb_value] An object as a Ruby string. 109 243 */ 110 244 MRB_API mrb_value mrb_str_resize(mrb_state *mrb, mrb_value str, mrb_int len); … … 112 246 /* 113 247 * Returns a sub string. 248 * 249 * Example: 250 * 251 * !!!c 252 * int 253 * main(int argc, 254 * char const **argv) 255 * { 256 * // Variable declarations. 257 * mrb_value str1; 258 * mrb_value str2; 259 * 260 * mrb_state *mrb = mrb_open(); 261 * if (!mrb) 262 * { 263 * // handle error 264 * } 265 * // Creates new string. 266 * str1 = mrb_str_new_lit(mrb, "Hello, world!"); 267 * // Returns a sub-string within the range of 0..2 268 * str2 = mrb_str_substr(mrb, str1, 0, 2); 269 * 270 * // Prints sub-string. 271 * mrb_p(mrb, str2); 272 * 273 * mrb_close(mrb); 274 * return 0; 275 * } 276 * 277 * Result: 278 * 279 * => "He" 280 * 281 * @param [mrb_state] mrb The current mruby state. 282 * @param [mrb_value] str Ruby string. 283 * @param [mrb_int] beg The beginning point of the sub-string. 284 * @param [mrb_int] len The end point of the sub-string. 285 * @return [mrb_value] An object as a Ruby sub-string. 114 286 */ 115 287 MRB_API mrb_value mrb_str_substr(mrb_state *mrb, mrb_value str, mrb_int beg, mrb_int len); … … 117 289 /* 118 290 * Returns a Ruby string type. 291 * 292 * 293 * @param [mrb_state] mrb The current mruby state. 294 * @param [mrb_value] str Ruby string. 295 * @return [mrb_value] A Ruby string. 119 296 */ 120 297 MRB_API mrb_value mrb_string_type(mrb_state *mrb, mrb_value str); … … 124 301 125 302 MRB_API const char *mrb_string_value_cstr(mrb_state *mrb, mrb_value *ptr); 126 MRB_API const char *mrb_string_value_ptr(mrb_state *mrb, mrb_value ptr); 303 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 */ 312 MRB_API mrb_int mrb_string_value_len(mrb_state *mrb, mrb_value str); 127 313 128 314 /* 129 315 * Duplicates a string object. 316 * 317 * 318 * @param [mrb_state] mrb The current mruby state. 319 * @param [mrb_value] str Ruby string. 320 * @return [mrb_value] Duplicated Ruby string. 130 321 */ 131 322 MRB_API mrb_value mrb_str_dup(mrb_state *mrb, mrb_value str); 132 323 133 324 /* 134 * Returns a symbol from a passed in string. 325 * Returns a symbol from a passed in Ruby string. 326 * 327 * @param [mrb_state] mrb The current mruby state. 328 * @param [mrb_value] self Ruby string. 329 * @return [mrb_value] A symbol. 135 330 */ 136 331 MRB_API mrb_value mrb_str_intern(mrb_state *mrb, mrb_value self); … … 146 341 /* 147 342 * Returns true if the strings match and false if the strings don't match. 343 * 344 * @param [mrb_state] mrb The current mruby state. 345 * @param [mrb_value] str1 Ruby string to compare. 346 * @param [mrb_value] str2 Ruby string to compare. 347 * @return [mrb_value] boolean value. 148 348 */ 149 349 MRB_API mrb_bool mrb_str_equal(mrb_state *mrb, mrb_value str1, mrb_value str2); … … 152 352 * Returns a concated string comprised of a Ruby string and a C string. 153 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. 358 * @return [mrb_value] A Ruby string. 154 359 * @see mrb_str_cat_cstr 155 360 */ … … 159 364 * Returns a concated string comprised of a Ruby string and a C string. 160 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. 369 * @return [mrb_value] A Ruby string. 161 370 * @see mrb_str_cat 162 371 */ … … 176 385 177 386 /* 178 * Returns a C string from a Ruby string. 387 * Returns a newly allocated C string from a Ruby string. 388 * This is an utility function to pass a Ruby string to C library functions. 389 * 390 * - Returned string does not contain any NUL characters (but terminator). 391 * - It raises an ArgumentError exception if Ruby string contains 392 * NUL characters. 393 * - Retured string will be freed automatically on next GC. 394 * - Caller can modify returned string without affecting Ruby string 395 * (e.g. it can be used for mkstemp(3)). 396 * 397 * @param [mrb_state *] mrb The current mruby state. 398 * @param [mrb_value] str Ruby string. Must be an instance of String. 399 * @return [char *] A newly allocated C string. 179 400 */ 180 401 MRB_API char *mrb_str_to_cstr(mrb_state *mrb, mrb_value str); -
EcnlProtoTool/trunk/mruby-1.3.0/include/mruby/throw.h
r321 r331 8 8 #define MRB_THROW_H 9 9 10 #ifdef MRB_ENABLE_CXX_EXCEPTION 10 #if defined(MRB_ENABLE_CXX_ABI) 11 # if !defined(__cplusplus) 12 # error Trying to use C++ exception handling in C code 13 # endif 14 #endif 15 16 #if defined(MRB_ENABLE_CXX_EXCEPTION) && defined(__cplusplus) 11 17 12 18 #define MRB_TRY(buf) do { try { … … 21 27 #include <setjmp.h> 22 28 23 #define MRB_TRY(buf) do { if (setjmp((buf)->impl) == 0) { 29 #if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) 30 #define MRB_SETJMP _setjmp 31 #define MRB_LONGJMP _longjmp 32 #else 33 #define MRB_SETJMP setjmp 34 #define MRB_LONGJMP longjmp 35 #endif 36 37 #define MRB_TRY(buf) do { if (MRB_SETJMP((buf)->impl) == 0) { 24 38 #define MRB_CATCH(buf) } else { 25 39 #define MRB_END_EXC(buf) } } while(0) 26 40 27 #define MRB_THROW(buf) longjmp((buf)->impl, 1);41 #define MRB_THROW(buf) MRB_LONGJMP((buf)->impl, 1); 28 42 #define mrb_jmpbuf_impl jmp_buf 29 43 … … 33 47 mrb_jmpbuf_impl impl; 34 48 35 #if def MRB_ENABLE_CXX_EXCEPTION49 #if defined(MRB_ENABLE_CXX_EXCEPTION) && defined(__cplusplus) 36 50 static mrb_int jmpbuf_id; 37 51 mrb_jmpbuf() : impl(jmpbuf_id++) {} -
EcnlProtoTool/trunk/mruby-1.3.0/include/mruby/value.h
r321 r331 8 8 #define MRUBY_VALUE_H 9 9 10 #include " mruby/common.h"10 #include "common.h" 11 11 12 12 /** … … 21 21 #if defined(MRB_INT16) && defined(MRB_INT64) 22 22 # error "You can't define MRB_INT16 and MRB_INT64 at the same time." 23 #endif 24 25 #if defined _MSC_VER && _MSC_VER < 1800 26 # define PRIo64 "llo" 27 # define PRId64 "lld" 28 # define PRIx64 "llx" 29 # define PRIo16 "ho" 30 # define PRId16 "hd" 31 # define PRIx16 "hx" 32 # define PRIo32 "o" 33 # define PRId32 "d" 34 # define PRIx32 "x" 35 #else 36 # include <inttypes.h> 23 37 #endif 24 38 … … 28 42 # define MRB_INT_MIN (INT64_MIN>>MRB_FIXNUM_SHIFT) 29 43 # define MRB_INT_MAX (INT64_MAX>>MRB_FIXNUM_SHIFT) 44 # define MRB_PRIo PRIo64 45 # define MRB_PRId PRId64 46 # define MRB_PRIx PRIx64 30 47 #elif defined(MRB_INT16) 31 48 typedef int16_t mrb_int; … … 33 50 # define MRB_INT_MIN (INT16_MIN>>MRB_FIXNUM_SHIFT) 34 51 # define MRB_INT_MAX (INT16_MAX>>MRB_FIXNUM_SHIFT) 52 # define MRB_PRIo PRIo16 53 # define MRB_PRId PRId16 54 # define MRB_PRIx PRIx16 35 55 #else 36 56 typedef int32_t mrb_int; … … 38 58 # define MRB_INT_MIN (INT32_MIN>>MRB_FIXNUM_SHIFT) 39 59 # define MRB_INT_MAX (INT32_MAX>>MRB_FIXNUM_SHIFT) 40 #endif 41 60 # define MRB_PRIo PRIo32 61 # define MRB_PRId PRId32 62 # define MRB_PRIx PRIx32 63 #endif 64 65 66 MRB_API double mrb_float_read(const char*, char**); 42 67 #ifdef MRB_USE_FLOAT 43 68 typedef float mrb_float; 44 # define str_to_mrb_float(buf) strtof(buf, NULL)45 69 #else 46 70 typedef double mrb_float; 47 # define str_to_mrb_float(buf) strtod(buf, NULL)48 71 #endif 49 72 … … 63 86 # define isinf(n) (!_finite(n) && !_isnan(n)) 64 87 # define signbit(n) (_copysign(1.0, (n)) < 0.0) 65 # define strtof (float)strtod66 88 static const unsigned int IEEE754_INFINITY_BITS_SINGLE = 0x7F800000; 67 89 # define INFINITY (*(float *)&IEEE754_INFINITY_BITS_SINGLE) … … 94 116 MRB_TT_DATA, /* 21 */ 95 117 MRB_TT_FIBER, /* 22 */ 96 MRB_TT_MAXDEFINE /* 23 */ 118 MRB_TT_ISTRUCT, /* 23 */ 119 MRB_TT_BREAK, /* 24 */ 120 MRB_TT_MAXDEFINE /* 25 */ 97 121 }; 98 122 99 #include "mruby/object.h"123 #include <mruby/object.h> 100 124 101 125 #ifdef MRB_DOCUMENTATION_BLOCK … … 188 212 mrb_value v; 189 213 SET_OBJ_VALUE(v, (struct RBasic*)p); 214 mrb_assert(p == mrb_ptr(v)); 215 mrb_assert(((struct RBasic*)p)->tt == mrb_type(v)); 190 216 return v; 191 217 } … … 242 268 243 269 #ifdef MRB_USE_ETEXT_EDATA 270 #if (defined(__APPLE__) && defined(__MACH__)) 271 #include <mach-o/getsect.h> 272 static inline mrb_bool 273 mrb_ro_data_p(const char *p) 274 { 275 return (const char*)get_etext() < p && p < (const char*)get_edata(); 276 } 277 #else 244 278 extern char _etext[]; 245 279 #ifdef MRB_NO_INIT_ARRAY_START … … 260 294 } 261 295 #endif 296 #endif 262 297 #else 263 298 # define mrb_ro_data_p(p) FALSE -
EcnlProtoTool/trunk/mruby-1.3.0/include/mruby/variable.h
r321 r331 8 8 #define MRUBY_VARIABLE_H 9 9 10 #include " mruby/common.h"10 #include "common.h" 11 11 12 12 /** … … 55 55 MRB_API void mrb_iv_copy(mrb_state *mrb, mrb_value dst, mrb_value src); 56 56 MRB_API mrb_bool mrb_const_defined_at(mrb_state *mrb, mrb_value mod, mrb_sym id); 57 58 /** 59 * Get a global variable. Will return nil if the var does not exist 60 * 61 * Example: 62 * 63 * !!!ruby 64 * # Ruby style 65 * var = $value 66 * 67 * !!!c 68 * // C style 69 * mrb_sym sym = mrb_intern_lit(mrb, "$value"); 70 * mrb_value var = mrb_gv_get(mrb, sym); 71 * 72 * @param mrb The mruby state reference 73 * @param sym The name of the global variable 74 * @return The value of that global variable. May be nil 75 */ 57 76 MRB_API mrb_value mrb_gv_get(mrb_state *mrb, mrb_sym sym); 77 78 /** 79 * Set a global variable 80 * 81 * Example: 82 * 83 * !!!ruby 84 * # Ruby style 85 * $value = "foo" 86 * 87 * !!!c 88 * // C style 89 * mrb_sym sym = mrb_intern_lit(mrb, "$value"); 90 * mrb_gv_set(mrb, sym, mrb_str_new_lit("foo")); 91 * 92 * @param mrb The mruby state reference 93 * @param sym The name of the global variable 94 * @param val The value of the global variable 95 */ 58 96 MRB_API void mrb_gv_set(mrb_state *mrb, mrb_sym sym, mrb_value val); 97 98 /** 99 * Remove a global variable. 100 * 101 * Example: 102 * 103 * !!!ruby 104 * # Ruby style 105 * $value = nil 106 * 107 * !!!c 108 * // C style 109 * mrb_sym sym = mrb_intern_lit(mrb, "$value"); 110 * mrb_gv_remove(mrb, sym); 111 * 112 * @param mrb The mruby state reference 113 * @param sym The name of the global variable 114 * @param val The value of the global variable 115 */ 59 116 MRB_API void mrb_gv_remove(mrb_state *mrb, mrb_sym sym); 117 60 118 MRB_API mrb_value mrb_cv_get(mrb_state *mrb, mrb_value mod, mrb_sym sym); 61 119 MRB_API void mrb_mod_cv_set(mrb_state *mrb, struct RClass * c, mrb_sym sym, mrb_value v); -
EcnlProtoTool/trunk/mruby-1.3.0/include/mruby/version.h
r321 r331 8 8 #define MRUBY_VERSION_H 9 9 10 #include " mruby/common.h"10 #include "common.h" 11 11 12 12 /** … … 43 43 * Minor release version number. 44 44 */ 45 #define MRUBY_RELEASE_MINOR 245 #define MRUBY_RELEASE_MINOR 3 46 46 47 47 /* … … 63 63 * Release year. 64 64 */ 65 #define MRUBY_RELEASE_YEAR 201 565 #define MRUBY_RELEASE_YEAR 2017 66 66 67 67 /* 68 68 * Release month. 69 69 */ 70 #define MRUBY_RELEASE_MONTH 1170 #define MRUBY_RELEASE_MONTH 7 71 71 72 72 /* 73 73 * Release day. 74 74 */ 75 #define MRUBY_RELEASE_DAY 1775 #define MRUBY_RELEASE_DAY 4 76 76 77 77 /*
Note:
See TracChangeset
for help on using the changeset viewer.