diff options
Diffstat (limited to 'include')
| -rw-r--r-- | include/mruby.h | 270 | ||||
| -rw-r--r-- | include/mruby/array.h | 7 | ||||
| -rw-r--r-- | include/mruby/boxing_nan.h | 11 | ||||
| -rw-r--r-- | include/mruby/boxing_no.h | 21 | ||||
| -rw-r--r-- | include/mruby/boxing_word.h | 138 | ||||
| -rw-r--r-- | include/mruby/class.h | 8 | ||||
| -rw-r--r-- | include/mruby/common.h | 6 | ||||
| -rw-r--r-- | include/mruby/compile.h | 10 | ||||
| -rw-r--r-- | include/mruby/data.h | 4 | ||||
| -rw-r--r-- | include/mruby/debug.h | 4 | ||||
| -rw-r--r-- | include/mruby/dump.h | 4 | ||||
| -rw-r--r-- | include/mruby/error.h | 40 | ||||
| -rw-r--r-- | include/mruby/gc.h | 4 | ||||
| -rw-r--r-- | include/mruby/hash.h | 4 | ||||
| -rw-r--r-- | include/mruby/irep.h | 8 | ||||
| -rw-r--r-- | include/mruby/istruct.h | 4 | ||||
| -rw-r--r-- | include/mruby/khash.h | 4 | ||||
| -rw-r--r-- | include/mruby/numeric.h | 38 | ||||
| -rw-r--r-- | include/mruby/object.h | 16 | ||||
| -rw-r--r-- | include/mruby/opcode.h | 4 | ||||
| -rw-r--r-- | include/mruby/proc.h | 4 | ||||
| -rw-r--r-- | include/mruby/range.h | 6 | ||||
| -rw-r--r-- | include/mruby/re.h | 4 | ||||
| -rw-r--r-- | include/mruby/string.h | 226 | ||||
| -rw-r--r-- | include/mruby/throw.h | 4 | ||||
| -rw-r--r-- | include/mruby/value.h | 59 | ||||
| -rw-r--r-- | include/mruby/variable.h | 7 | ||||
| -rw-r--r-- | include/mruby/version.h | 4 |
28 files changed, 539 insertions, 380 deletions
diff --git a/include/mruby.h b/include/mruby.h index 3ef399716..52c233211 100644 --- a/include/mruby.h +++ b/include/mruby.h @@ -25,6 +25,10 @@ ** [ MIT license: http://www.opensource.org/licenses/mit-license.php ] */ +/** + * @file mruby.h + */ + #ifndef MRUBY_H #define MRUBY_H @@ -97,11 +101,14 @@ MRB_BEGIN_DECL typedef uint8_t mrb_code; /** - * Required arguments signature type. + * \class mrb_aspec + * + * Specifies the number of arguments a function takes + * + * Example: `MRB_ARGS_REQ(2) | MRB_ARGS_OPT(1)` for a method that expects 2..3 arguments */ typedef uint32_t mrb_aspec; - struct mrb_irep; struct mrb_state; @@ -127,8 +134,8 @@ typedef struct { uint16_t ridx; uint16_t epos; struct REnv *env; - mrb_code *pc; /* return address */ - mrb_code *err; /* error position */ + const mrb_code *pc; /* return address */ + const mrb_code *err; /* error position */ int argc; int acc; struct RClass *target_class; @@ -170,7 +177,16 @@ struct mrb_context { # define MRB_METHOD_CACHE_SIZE (1<<7) #endif -typedef mrb_value (*mrb_func_t)(struct mrb_state *mrb, mrb_value); +/** + * Function pointer type for a function callable by mruby. + * + * The arguments to the function are stored on the mrb_state. To get them see mrb_get_args + * + * @param mrb The mruby state + * @param self The self object + * @return [mrb_value] The function's return value + */ +typedef mrb_value (*mrb_func_t)(struct mrb_state *mrb, mrb_value self); #ifdef MRB_METHOD_TABLE_INLINE typedef uintptr_t mrb_method_t; @@ -243,8 +259,8 @@ typedef struct mrb_state { #endif #ifdef MRB_ENABLE_DEBUG_HOOK - void (*code_fetch_hook)(struct mrb_state* mrb, struct mrb_irep *irep, mrb_code *pc, mrb_value *regs); - void (*debug_op_hook)(struct mrb_state* mrb, struct mrb_irep *irep, mrb_code *pc, mrb_value *regs); + void (*code_fetch_hook)(struct mrb_state* mrb, struct mrb_irep *irep, const mrb_code *pc, mrb_value *regs); + void (*debug_op_hook)(struct mrb_state* mrb, struct mrb_irep *irep, const mrb_code *pc, mrb_value *regs); #endif #ifdef MRB_BYTECODE_DECODE_OPTION @@ -285,9 +301,9 @@ typedef struct mrb_state { * //free(TheAnimals); * } * - * @param [mrb_state *] mrb The current mruby state. - * @param [const char *] name The name of the defined class. - * @param [struct RClass *] super The new class parent. + * @param mrb The current mruby state. + * @param name The name of the defined class. + * @param super The new class parent. * @return [struct RClass *] Reference to the newly defined class. * @see mrb_define_class_under */ @@ -296,12 +312,12 @@ MRB_API struct RClass *mrb_define_class(mrb_state *mrb, const char *name, struct /** * Defines a new module. * - * @param [mrb_state *] mrb_state* The current mruby state. - * @param [const char *] char* The name of the module. + * @param mrb The current mruby state. + * @param name The name of the module. * @return [struct RClass *] Reference to the newly defined module. */ -MRB_API struct RClass *mrb_define_module(mrb_state *, const char*); -MRB_API mrb_value mrb_singleton_class(mrb_state*, mrb_value); +MRB_API struct RClass *mrb_define_module(mrb_state *mrb, const char *name); +MRB_API mrb_value mrb_singleton_class(mrb_state *mrb, mrb_value val); /** * Include a module in another class or module. @@ -310,11 +326,11 @@ MRB_API mrb_value mrb_singleton_class(mrb_state*, mrb_value); * module B * include A * end - * @param [mrb_state *] mrb_state* The current mruby state. - * @param [struct RClass *] RClass* A reference to module or a class. - * @param [struct RClass *] RClass* A reference to the module to be included. + * @param mrb The current mruby state. + * @param cla A reference to module or a class. + * @param included A reference to the module to be included. */ -MRB_API void mrb_include_module(mrb_state*, struct RClass*, struct RClass*); +MRB_API void mrb_include_module(mrb_state *mrb, struct RClass *cla, struct RClass *included); /** * Prepends a module in another class or module. @@ -323,11 +339,11 @@ MRB_API void mrb_include_module(mrb_state*, struct RClass*, struct RClass*); * module B * prepend A * end - * @param [mrb_state *] mrb_state* The current mruby state. - * @param [struct RClass *] RClass* A reference to module or a class. - * @param [struct RClass *] RClass* A reference to the module to be prepended. + * @param mrb The current mruby state. + * @param cla A reference to module or a class. + * @param prepended A reference to the module to be prepended. */ -MRB_API void mrb_prepend_module(mrb_state*, struct RClass*, struct RClass*); +MRB_API void mrb_prepend_module(mrb_state *mrb, struct RClass *cla, struct RClass *prepended); /** * Defines a global function in ruby. @@ -336,7 +352,6 @@ MRB_API void mrb_prepend_module(mrb_state*, struct RClass*, struct RClass*); * * Example: * - * !!!c * mrb_value example_method(mrb_state* mrb, mrb_value self) * { * puts("Executing example command!"); @@ -348,11 +363,11 @@ MRB_API void mrb_prepend_module(mrb_state*, struct RClass*, struct RClass*); * mrb_define_method(mrb, mrb->kernel_module, "example_method", example_method, MRB_ARGS_NONE()); * } * - * @param [mrb_state *] mrb The MRuby state reference. - * @param [struct RClass *] cla The class pointer where the method will be defined. - * @param [const char *] name The name of the method being defined. - * @param [mrb_func_t] func The function pointer to the method definition. - * @param [mrb_aspec] aspec The method parameters declaration. + * @param mrb The MRuby state reference. + * @param cla The class pointer where the method will be defined. + * @param name The name of the method being defined. + * @param func The function pointer to the method definition. + * @param aspec The method parameters declaration. */ MRB_API void mrb_define_method(mrb_state *mrb, struct RClass *cla, const char *name, mrb_func_t func, mrb_aspec aspec); @@ -375,14 +390,20 @@ MRB_API void mrb_define_method(mrb_state *mrb, struct RClass *cla, const char *n * foo = mrb_define_class(mrb, "Foo", mrb->object_class); * mrb_define_class_method(mrb, foo, "bar", bar_method, MRB_ARGS_NONE()); * } - * @param [mrb_state *] mrb_state* The MRuby state reference. - * @param [struct RClass *] RClass* The class where the class method will be defined. - * @param [const char *] char* The name of the class method being defined. - * @param [mrb_func_t] mrb_func_t The function pointer to the class method definition. - * @param [mrb_aspec] mrb_aspec The method parameters declaration. + * @param mrb The MRuby state reference. + * @param cla The class where the class method will be defined. + * @param name The name of the class method being defined. + * @param fun The function pointer to the class method definition. + * @param aspec The method parameters declaration. + */ +MRB_API void mrb_define_class_method(mrb_state *mrb, struct RClass *cla, const char *name, mrb_func_t fun, mrb_aspec aspec); + +/** + * Defines a singleton method + * + * @see mrb_define_class_method */ -MRB_API void mrb_define_class_method(mrb_state *, struct RClass *, const char *, mrb_func_t, mrb_aspec); -MRB_API void mrb_define_singleton_method(mrb_state*, struct RObject*, const char*, mrb_func_t, mrb_aspec); +MRB_API void mrb_define_singleton_method(mrb_state *mrb, struct RObject *cla, const char *name, mrb_func_t fun, mrb_aspec aspec); /** * Defines a module function. @@ -403,13 +424,13 @@ MRB_API void mrb_define_singleton_method(mrb_state*, struct RObject*, const char * foo = mrb_define_module(mrb, "Foo"); * mrb_define_module_function(mrb, foo, "bar", bar_method, MRB_ARGS_NONE()); * } - * @param [mrb_state *] mrb_state* The MRuby state reference. - * @param [struct RClass *] RClass* The module where the module function will be defined. - * @param [const char *] char* The name of the module function being defined. - * @param [mrb_func_t] mrb_func_t The function pointer to the module function definition. - * @param [mrb_aspec] mrb_aspec The method parameters declaration. + * @param mrb The MRuby state reference. + * @param cla The module where the module function will be defined. + * @param name The name of the module function being defined. + * @param fun The function pointer to the module function definition. + * @param aspec The method parameters declaration. */ -MRB_API void mrb_define_module_function(mrb_state*, struct RClass*, const char*, mrb_func_t, mrb_aspec); +MRB_API void mrb_define_module_function(mrb_state *mrb, struct RClass *cla, const char *name, mrb_func_t fun, mrb_aspec aspec); /** * Defines a constant. @@ -432,12 +453,12 @@ MRB_API void mrb_define_module_function(mrb_state*, struct RClass*, const char*, * mrb_value * mrb_example_gem_final(mrb_state* mrb){ * } - * @param [mrb_state *] mrb_state* The MRuby state reference. - * @param [struct RClass *] RClass* A class or module the constant is defined in. - * @param [const char *] name The name of the constant being defined. - * @param [mrb_value] mrb_value The value for the constant. + * @param mrb The MRuby state reference. + * @param cla A class or module the constant is defined in. + * @param name The name of the constant being defined. + * @param val The value for the constant. */ -MRB_API void mrb_define_const(mrb_state*, struct RClass*, const char *name, mrb_value); +MRB_API void mrb_define_const(mrb_state* mrb, struct RClass* cla, const char *name, mrb_value val); /** * Undefines a method. @@ -483,11 +504,11 @@ MRB_API void mrb_define_const(mrb_state*, struct RClass*, const char *name, mrb_ * * mrb_example_gem_final(mrb_state* mrb){ * } - * @param [mrb_state*] mrb_state* The mruby state reference. - * @param [struct RClass*] RClass* A class the method will be undefined from. - * @param [const char*] const char* The name of the method to be undefined. + * @param mrb The mruby state reference. + * @param cla The class the method will be undefined from. + * @param name The name of the method to be undefined. */ -MRB_API void mrb_undef_method(mrb_state*, struct RClass*, const char*); +MRB_API void mrb_undef_method(mrb_state *mrb, struct RClass *cla, const char *name); MRB_API void mrb_undef_method_id(mrb_state*, struct RClass*, mrb_sym); /** @@ -523,11 +544,11 @@ MRB_API void mrb_undef_method_id(mrb_state*, struct RClass*, mrb_sym); * void * mrb_example_gem_final(mrb_state* mrb){ * } - * @param [mrb_state*] mrb_state* The mruby state reference. - * @param [RClass*] RClass* A class the class method will be undefined from. - * @param [const char*] const char* The name of the class method to be undefined. + * @param mrb The mruby state reference. + * @param cls A class the class method will be undefined from. + * @param name The name of the class method to be undefined. */ -MRB_API void mrb_undef_class_method(mrb_state*, struct RClass*, const char*); +MRB_API void mrb_undef_class_method(mrb_state *mrb, struct RClass *cls, const char *name); /** * Initialize a new object instance of c class. @@ -551,10 +572,10 @@ MRB_API void mrb_undef_class_method(mrb_state*, struct RClass*, const char*); * obj = mrb_obj_new(mrb, example_class, 0, NULL); # => ExampleClass.new * mrb_p(mrb, obj); // => Kernel#p * } - * @param [mrb_state*] mrb The current mruby state. - * @param [RClass*] c Reference to the class of the new object. - * @param [mrb_int] argc Number of arguments in argv - * @param [const mrb_value *] argv Array of mrb_value to initialize the object + * @param mrb The current mruby state. + * @param c Reference to the class of the new object. + * @param argc Number of arguments in argv + * @param argv Array of mrb_value to initialize the object * @return [mrb_value] The newly initialized object */ MRB_API mrb_value mrb_obj_new(mrb_state *mrb, struct RClass *c, mrb_int argc, const mrb_value *argv); @@ -580,8 +601,8 @@ MRB_INLINE mrb_value mrb_class_new_instance(mrb_state *mrb, mrb_int argc, const * mrb_p(mrb, obj); // => Kernel#p * } * - * @param [mrb_state*] mrb The current mruby state. - * @param [struct RClass *] super The super class or parent. + * @param mrb The current mruby state. + * @param super The super class or parent. * @return [struct RClass *] Reference to the new class. */ MRB_API struct RClass * mrb_class_new(mrb_state *mrb, struct RClass *super); @@ -597,7 +618,7 @@ MRB_API struct RClass * mrb_class_new(mrb_state *mrb, struct RClass *super); * example_module = mrb_module_new(mrb); * } * - * @param [mrb_state*] mrb The current mruby state. + * @param mrb The current mruby state. * @return [struct RClass *] Reference to the new module. */ MRB_API struct RClass * mrb_module_new(mrb_state *mrb); @@ -624,24 +645,24 @@ MRB_API struct RClass * mrb_module_new(mrb_state *mrb); * } * } * - * @param [mrb_state*] mrb The current mruby state. - * @param [const char *] name A string representing the name of the class. + * @param mrb The current mruby state. + * @param name A string representing the name of the class. * @return [mrb_bool] A boolean value. */ MRB_API mrb_bool mrb_class_defined(mrb_state *mrb, const char *name); /** * Gets a class. - * @param [mrb_state*] mrb The current mruby state. - * @param [const char *] name The name of the class. + * @param mrb The current mruby state. + * @param name The name of the class. * @return [struct RClass *] A reference to the class. */ MRB_API struct RClass * mrb_class_get(mrb_state *mrb, const char *name); /** * Gets a exception class. - * @param [mrb_state*] mrb The current mruby state. - * @param [const char *] name The name of the class. + * @param mrb The current mruby state. + * @param name The name of the class. * @return [struct RClass *] A reference to the class. */ MRB_API struct RClass * mrb_exc_get(mrb_state *mrb, const char *name); @@ -670,35 +691,35 @@ MRB_API struct RClass * mrb_exc_get(mrb_state *mrb, const char *name); * } * } * - * @param [mrb_state*] mrb The current mruby state. - * @param [struct RClass *] outer The name of the outer class. - * @param [const char *] name A string representing the name of the inner class. + * @param mrb The current mruby state. + * @param outer The name of the outer class. + * @param name A string representing the name of the inner class. * @return [mrb_bool] A boolean value. */ MRB_API mrb_bool mrb_class_defined_under(mrb_state *mrb, struct RClass *outer, const char *name); /** * Gets a child class. - * @param [mrb_state*] mrb The current mruby state. - * @param [struct RClass *] outer The name of the parent class. - * @param [const char *] name The name of the class. + * @param mrb The current mruby state. + * @param outer The name of the parent class. + * @param name The name of the class. * @return [struct RClass *] A reference to the class. */ MRB_API struct RClass * mrb_class_get_under(mrb_state *mrb, struct RClass *outer, const char *name); /** * Gets a module. - * @param [mrb_state*] mrb The current mruby state. - * @param [const char *] name The name of the module. + * @param mrb The current mruby state. + * @param name The name of the module. * @return [struct RClass *] A reference to the module. */ MRB_API struct RClass * mrb_module_get(mrb_state *mrb, const char *name); /** * Gets a module defined under another module. - * @param [mrb_state*] mrb The current mruby state. - * @param [struct RClass *] outer The name of the outer module. - * @param [const char *] name The name of the module. + * @param mrb The current mruby state. + * @param outer The name of the outer module. + * @param name The name of the module. * @return [struct RClass *] A reference to the module. */ MRB_API struct RClass * mrb_module_get_under(mrb_state *mrb, struct RClass *outer, const char *name); @@ -712,8 +733,8 @@ MRB_API mrb_value mrb_notimplement_m(mrb_state*, mrb_value); * * Equivalent to: * Object#dup - * @param [mrb_state*] mrb The current mruby state. - * @param [mrb_value] obj Object to be duplicate. + * @param mrb The current mruby state. + * @param obj Object to be duplicate. * @return [mrb_value] The newly duplicated object. */ MRB_API mrb_value mrb_obj_dup(mrb_state *mrb, mrb_value obj); @@ -753,9 +774,9 @@ MRB_API mrb_value mrb_obj_dup(mrb_state *mrb, mrb_value obj); * } * } * - * @param [mrb_state*] mrb The current mruby state. - * @param [struct RClass *] c A reference to a class. - * @param [mrb_sym] mid A symbol referencing a method id. + * @param mrb The current mruby state. + * @param c A reference to a class. + * @param mid A symbol referencing a method id. * @return [mrb_bool] A boolean value. */ MRB_API mrb_bool mrb_obj_respond_to(mrb_state *mrb, struct RClass* c, mrb_sym mid); @@ -763,10 +784,10 @@ MRB_API mrb_bool mrb_obj_respond_to(mrb_state *mrb, struct RClass* c, mrb_sym mi /** * Defines a new class under a given module * - * @param [mrb_state*] mrb The current mruby state. - * @param [struct RClass *] outer Reference to the module under which the new class will be defined - * @param [const char *] name The name of the defined class - * @param [struct RClass *] super The new class parent + * @param mrb The current mruby state. + * @param outer Reference to the module under which the new class will be defined + * @param name The name of the defined class + * @param super The new class parent * @return [struct RClass *] Reference to the newly defined class * @see mrb_define_class */ @@ -836,16 +857,18 @@ MRB_API struct RClass * mrb_define_module_under(mrb_state *mrb, struct RClass *o * | `S` | {String} | {mrb_value} | when `!` follows, the value may be `nil` | * | `A` | {Array} | {mrb_value} | when `!` follows, the value may be `nil` | * | `H` | {Hash} | {mrb_value} | when `!` follows, the value may be `nil` | - * | `s` | {String} | char *, {mrb_int} | Receive two arguments; `s!` gives (`NULL`,`0`) for `nil` | + * | `s` | {String} | char *, {mrb_int} | Receive two arguments; `s!` gives (`NULL`,`0`) for `nil` | * | `z` | {String} | char * | `NULL` terminated string; `z!` gives `NULL` for `nil` | * | `a` | {Array} | {mrb_value} *, {mrb_int} | Receive two arguments; `a!` gives (`NULL`,`0`) for `nil` | - * | `f` | {Float} | {mrb_float} | | - * | `i` | {Integer} | {mrb_int} | | + * | `f` | {Fixnum}/{Float} | {mrb_float} | | + * | `i` | {Fixnum}/{Float} | {mrb_int} | | * | `b` | boolean | {mrb_bool} | | - * | `n` | {Symbol} | {mrb_sym} | | + * | `n` | {String}/{Symbol} | {mrb_sym} | | + * | `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` | + * | `I` | inline struct | void * | | * | `&` | block | {mrb_value} | &! raises exception if no block given. | - * | `*` | rest arguments | {mrb_value} *, {mrb_int} | Receive the rest of arguments as an array; *! avoid copy of the stack. | - * | | | optional | | After this spec following specs would be optional. | + * | `*` | rest arguments | {mrb_value} *, {mrb_int} | Receive the rest of arguments as an array; `*!` avoid copy of the stack. | + * | <code>\|</code> | optional | | After this spec following specs would be optional. | * | `?` | optional given | {mrb_bool} | `TRUE` if preceding argument is given. Used to check optional argument is given. | * * @see mrb_get_args @@ -856,7 +879,7 @@ typedef const char *mrb_args_format; * Retrieve arguments from mrb_state. * * @param mrb The current MRuby state. - * @param format [mrb_args_format] is a list of format specifiers + * @param format is a list of format specifiers * @param ... The passing variadic arguments must be a pointer of retrieving type. * @return the number of arguments retrieved. * @see mrb_args_format @@ -889,6 +912,8 @@ MRB_API mrb_value* mrb_get_argv(mrb_state *mrb); /** * Call existing ruby functions. * + * Example: + * * #include <stdio.h> * #include <mruby.h> * #include "mruby/compile.h" @@ -905,15 +930,16 @@ MRB_API mrb_value* mrb_get_argv(mrb_state *mrb); * mrb_funcall(mrb, obj, "method_name", 1, mrb_fixnum_value(i)); * fclose(fp); * mrb_close(mrb); - * } - * @param [mrb_state*] mrb_state* The current mruby state. - * @param [mrb_value] mrb_value A reference to an mruby value. - * @param [const char*] const char* The name of the method. - * @param [mrb_int] mrb_int The number of arguments the method has. - * @param [...] ... Variadic values(not type safe!). - * @return [mrb_value] mrb_value mruby function value. + * } + * + * @param mrb The current mruby state. + * @param val A reference to an mruby value. + * @param name The name of the method. + * @param argc The number of arguments the method has. + * @param ... Variadic values(not type safe!). + * @return [mrb_value] mruby function value. */ -MRB_API mrb_value mrb_funcall(mrb_state*, mrb_value, const char*, mrb_int,...); +MRB_API mrb_value mrb_funcall(mrb_state *mrb, mrb_value val, const char *name, mrb_int argc, ...); /** * Call existing ruby functions. This is basically the type safe version of mrb_funcall. * @@ -935,15 +961,15 @@ MRB_API mrb_value mrb_funcall(mrb_state*, mrb_value, const char*, mrb_int,...); * fclose(fp); * mrb_close(mrb); * } - * @param [mrb_state*] mrb_state* The current mruby state. - * @param [mrb_value] mrb_value A reference to an mruby value. - * @param [mrb_sym] mrb_sym The symbol representing the method. - * @param [mrb_int] mrb_int The number of arguments the method has. - * @param [const mrb_value*] mrb_value* Pointer to the object. + * @param mrb The current mruby state. + * @param val A reference to an mruby value. + * @param name_sym The symbol representing the method. + * @param argc The number of arguments the method has. + * @param obj Pointer to the object. * @return [mrb_value] mrb_value mruby function value. * @see mrb_funcall */ -MRB_API mrb_value mrb_funcall_argv(mrb_state*, mrb_value, mrb_sym, mrb_int, const mrb_value*); +MRB_API mrb_value mrb_funcall_argv(mrb_state *mrb, mrb_value val, mrb_sym name_sym, mrb_int argc, const mrb_value* obj); /** * Call existing ruby functions with a block. */ @@ -951,16 +977,19 @@ MRB_API mrb_value mrb_funcall_with_block(mrb_state*, mrb_value, mrb_sym, mrb_int /** * Create a symbol * + * Example: + * * # Ruby style: * :pizza # => :pizza * * // C style: * mrb_sym m_sym = mrb_intern_lit(mrb, "pizza"); // => :pizza - * @param [mrb_state*] mrb_state* The current mruby state. - * @param [const char*] const char* The name of the method. + * + * @param mrb The current mruby state. + * @param str The string to be symbolized * @return [mrb_sym] mrb_sym A symbol. */ -MRB_API mrb_sym mrb_intern_cstr(mrb_state*,const char*); +MRB_API mrb_sym mrb_intern_cstr(mrb_state *mrb, const char* str); MRB_API mrb_sym mrb_intern(mrb_state*,const char*,size_t); MRB_API mrb_sym mrb_intern_static(mrb_state*,const char*,size_t); #define mrb_intern_lit(mrb, lit) mrb_intern_static(mrb, lit, mrb_strlen_lit(lit)) @@ -1055,7 +1084,7 @@ MRB_API mrb_value mrb_top_self(mrb_state *); MRB_API mrb_value mrb_run(mrb_state*, struct RProc*, mrb_value); MRB_API mrb_value mrb_top_run(mrb_state*, struct RProc*, mrb_value, unsigned int); MRB_API mrb_value mrb_vm_run(mrb_state*, struct RProc*, mrb_value, unsigned int); -MRB_API mrb_value mrb_vm_exec(mrb_state*, struct RProc*, mrb_code*); +MRB_API mrb_value mrb_vm_exec(mrb_state*, struct RProc*, const mrb_code*); /* compatibility macros */ #define mrb_toplevel_run_keep(m,p,k) mrb_top_run((m),(p),mrb_top_self(m),(k)) #define mrb_toplevel_run(m,p) mrb_toplevel_run_keep((m),(p),0) @@ -1184,6 +1213,7 @@ MRB_API void mrb_gc_unregister(mrb_state *mrb, mrb_value obj); MRB_API mrb_value mrb_to_int(mrb_state *mrb, mrb_value val); #define mrb_int(mrb, val) mrb_fixnum(mrb_to_int(mrb, val)) +/* string type checking (contrary to the name, it doesn't convert) */ MRB_API mrb_value mrb_to_str(mrb_state *mrb, mrb_value val); MRB_API void mrb_check_type(mrb_state *mrb, mrb_value x, enum mrb_vtype t); @@ -1210,31 +1240,31 @@ MRB_API mrb_bool mrb_obj_is_instance_of(mrb_state *mrb, mrb_value obj, struct RC MRB_API mrb_bool mrb_func_basic_p(mrb_state *mrb, mrb_value obj, mrb_sym mid, mrb_func_t func); -/* +/** * Resume a Fiber * - * @mrbgem mruby-fiber + * Implemented in mruby-fiber */ MRB_API mrb_value mrb_fiber_resume(mrb_state *mrb, mrb_value fib, mrb_int argc, const mrb_value *argv); -/* +/** * Yield a Fiber * - * @mrbgem mruby-fiber + * Implemented in mruby-fiber */ MRB_API mrb_value mrb_fiber_yield(mrb_state *mrb, mrb_int argc, const mrb_value *argv); -/* +/** * Check if a Fiber is alive * - * @mrbgem mruby-fiber + * Implemented in mruby-fiber */ MRB_API mrb_value mrb_fiber_alive_p(mrb_state *mrb, mrb_value fib); -/* +/** * FiberError reference * - * @mrbgem mruby-fiber + * Implemented in mruby-fiber */ #define E_FIBER_ERROR (mrb_exc_get(mrb, "FiberError")) MRB_API void mrb_stack_extend(mrb_state*, mrb_int); diff --git a/include/mruby/array.h b/include/mruby/array.h index 0c0a002f5..9664214d6 100644 --- a/include/mruby/array.h +++ b/include/mruby/array.h @@ -1,5 +1,5 @@ -/* -** mruby/array.h - Array class +/** +** @file mruby/array.h - Array class ** ** See Copyright Notice in mruby.h */ @@ -33,6 +33,7 @@ struct RArray { } aux; mrb_value *ptr; } heap; + void *ary[3]; } as; }; @@ -45,7 +46,7 @@ struct RArray { #define ARY_UNSET_EMBED_FLAG(a) ((a)->flags &= ~(MRB_ARY_EMBED_MASK)) #define ARY_EMBED_LEN(a) ((mrb_int)(((a)->flags & MRB_ARY_EMBED_MASK) - 1)) #define ARY_SET_EMBED_LEN(a,len) ((a)->flags = ((a)->flags&~MRB_ARY_EMBED_MASK) | ((uint32_t)(len) + 1)) -#define ARY_EMBED_PTR(a) ((mrb_value*)&(a)->as) +#define ARY_EMBED_PTR(a) ((mrb_value*)(&(a)->as.ary)) #define ARY_LEN(a) (ARY_EMBED_P(a)?ARY_EMBED_LEN(a):(a)->as.heap.len) #define ARY_PTR(a) (ARY_EMBED_P(a)?ARY_EMBED_PTR(a):(a)->as.heap.ptr) diff --git a/include/mruby/boxing_nan.h b/include/mruby/boxing_nan.h index ff6f6082d..af598e34e 100644 --- a/include/mruby/boxing_nan.h +++ b/include/mruby/boxing_nan.h @@ -1,5 +1,5 @@ -/* -** mruby/boxing_nan.h - nan boxing mrb_value definition +/** +** @file mruby/boxing_nan.h - nan boxing mrb_value definition ** ** See Copyright Notice in mruby.h */ @@ -20,13 +20,6 @@ #endif #define MRB_FIXNUM_SHIFT 0 -#define MRB_TT_HAS_BASIC MRB_TT_OBJECT - -#ifdef MRB_ENDIAN_BIG -#define MRB_ENDIAN_LOHI(a,b) a b -#else -#define MRB_ENDIAN_LOHI(a,b) b a -#endif /* value representation by nan-boxing: * float : FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF diff --git a/include/mruby/boxing_no.h b/include/mruby/boxing_no.h index 86ce64555..19372b587 100644 --- a/include/mruby/boxing_no.h +++ b/include/mruby/boxing_no.h @@ -1,5 +1,5 @@ -/* -** mruby/boxing_no.h - unboxed mrb_value definition +/** +** @file mruby/boxing_no.h - unboxed mrb_value definition ** ** See Copyright Notice in mruby.h */ @@ -8,17 +8,18 @@ #define MRUBY_BOXING_NO_H #define MRB_FIXNUM_SHIFT 0 -#define MRB_TT_HAS_BASIC MRB_TT_OBJECT -typedef struct mrb_value { - union { +union mrb_value_union { #ifndef MRB_WITHOUT_FLOAT - mrb_float f; + mrb_float f; #endif - void *p; - mrb_int i; - mrb_sym sym; - } value; + void *p; + mrb_int i; + mrb_sym sym; +}; + +typedef struct mrb_value { + union mrb_value_union value; enum mrb_vtype tt; } mrb_value; diff --git a/include/mruby/boxing_word.h b/include/mruby/boxing_word.h index 2fb84052a..1a0c59ddb 100644 --- a/include/mruby/boxing_word.h +++ b/include/mruby/boxing_word.h @@ -1,5 +1,5 @@ -/* -** mruby/boxing_word.h - word boxing mrb_value definition +/** +** @file mruby/boxing_word.h - word boxing mrb_value definition ** ** See Copyright Notice in mruby.h */ @@ -27,43 +27,59 @@ struct RCptr { void *p; }; -#define MRB_FIXNUM_SHIFT 1 -#ifdef MRB_WITHOUT_FLOAT -#define MRB_TT_HAS_BASIC MRB_TT_CPTR -#else -#define MRB_TT_HAS_BASIC MRB_TT_FLOAT -#endif - enum mrb_special_consts { - MRB_Qnil = 0, - MRB_Qfalse = 2, - MRB_Qtrue = 4, - MRB_Qundef = 6, + MRB_Qnil = 0, + MRB_Qfalse = 4, + MRB_Qtrue = 12, + MRB_Qundef = 20, }; -#define MRB_FIXNUM_FLAG 0x01 -#define MRB_SYMBOL_FLAG 0x0e -#define MRB_SPECIAL_SHIFT 8 +#define MRB_FIXNUM_SHIFT 1 +#define MRB_SYMBOL_SHIFT 2 +#define MRB_FIXNUM_FLAG (1 << (MRB_FIXNUM_SHIFT - 1)) +#define MRB_SYMBOL_FLAG (1 << (MRB_SYMBOL_SHIFT - 1)) +#define MRB_FIXNUM_MASK ((1 << MRB_FIXNUM_SHIFT) - 1) +#define MRB_SYMBOL_MASK ((1 << MRB_SYMBOL_SHIFT) - 1) +#define MRB_IMMEDIATE_MASK 0x07 -#if defined(MRB_64BIT) +#ifdef MRB_64BIT #define MRB_SYMBOL_BITSIZE (sizeof(mrb_sym) * CHAR_BIT) #define MRB_SYMBOL_MAX UINT32_MAX #else -#define MRB_SYMBOL_BITSIZE (sizeof(mrb_sym) * CHAR_BIT - MRB_SPECIAL_SHIFT) -#define MRB_SYMBOL_MAX (UINT32_MAX >> MRB_SPECIAL_SHIFT) +#define MRB_SYMBOL_BITSIZE (sizeof(mrb_sym) * CHAR_BIT - MRB_SYMBOL_SHIFT) +#define MRB_SYMBOL_MAX (UINT32_MAX >> MRB_SYMBOL_SHIFT) #endif +#define BOXWORD_SHIFT_VALUE(o,n,t) \ + ((((t)(o).w)) >> MRB_##n##_SHIFT) +#define BOXWORD_SET_SHIFT_VALUE(o,n,v) \ + ((o).w = (((unsigned long)(v)) << MRB_##n##_SHIFT) | MRB_##n##_FLAG) +#define BOXWORD_SHIFT_VALUE_P(o,n) \ + (((o).w & MRB_##n##_MASK) == MRB_##n##_FLAG) + +/* + * mrb_value representation: + * + * nil : ...0000 0000 (all bits are zero) + * false : ...0000 0100 + * true : ...0000 1100 + * undef : ...0001 0100 + * fixnum: ...IIII III1 + * symbol: ...SSSS SS10 (high-order 32-bit are symbol value in 64-bit mode) + * object: ...PPPP P000 + */ typedef union mrb_value { union { void *p; +#ifdef MRB_64BIT + /* use struct to avoid bit shift. */ struct { - unsigned int i_flag : MRB_FIXNUM_SHIFT; - mrb_int i : (MRB_INT_BIT - MRB_FIXNUM_SHIFT); - }; - struct { - unsigned int sym_flag : MRB_SPECIAL_SHIFT; - mrb_sym sym : MRB_SYMBOL_BITSIZE; + MRB_ENDIAN_LOHI( + mrb_sym sym; + ,uint32_t sym_flag; + ) }; +#endif struct RBasic *bp; #ifndef MRB_WITHOUT_FLOAT struct RFloat *fp; @@ -88,8 +104,42 @@ MRB_API mrb_value mrb_word_boxing_float_pool(struct mrb_state*, mrb_float); #ifndef MRB_WITHOUT_FLOAT #define mrb_float(o) (o).value.fp->f #endif -#define mrb_fixnum(o) ((mrb_int)(o).value.i) +#define mrb_fixnum(o) BOXWORD_SHIFT_VALUE(o, FIXNUM, mrb_int) +#ifdef MRB_64BIT #define mrb_symbol(o) (o).value.sym +#else +#define mrb_symbol(o) BOXWORD_SHIFT_VALUE(o, SYMBOL, mrb_sym) +#endif +#define mrb_bool(o) (((o).w & ~(unsigned long)MRB_Qfalse) != 0) + +#define mrb_immediate_p(o) ((o).w & MRB_IMMEDIATE_MASK || (o).w == MRB_Qnil) +#define mrb_fixnum_p(o) BOXWORD_SHIFT_VALUE_P(o, FIXNUM) +#ifdef MRB_64BIT +#define mrb_symbol_p(o) ((o).value.sym_flag == MRB_SYMBOL_FLAG) +#else +#define mrb_symbol_p(o) BOXWORD_SHIFT_VALUE_P(o, SYMBOL) +#endif +#define mrb_undef_p(o) ((o).w == MRB_Qundef) +#define mrb_nil_p(o) ((o).w == MRB_Qnil) +#define mrb_false_p(o) ((o).w == MRB_Qfalse) +#define mrb_true_p(o) ((o).w == MRB_Qtrue) + +#ifndef MRB_WITHOUT_FLOAT +#define SET_FLOAT_VALUE(mrb,r,v) ((r) = mrb_word_boxing_float_value(mrb, v)) +#endif +#define SET_CPTR_VALUE(mrb,r,v) ((r) = mrb_word_boxing_cptr_value(mrb, v)) +#define SET_UNDEF_VALUE(r) ((r).w = MRB_Qundef) +#define SET_NIL_VALUE(r) ((r).w = MRB_Qnil) +#define SET_FALSE_VALUE(r) ((r).w = MRB_Qfalse) +#define SET_TRUE_VALUE(r) ((r).w = MRB_Qtrue) +#define SET_BOOL_VALUE(r,b) ((b) ? SET_TRUE_VALUE(r) : SET_FALSE_VALUE(r)) +#define SET_INT_VALUE(r,n) BOXWORD_SET_SHIFT_VALUE(r, FIXNUM, n) +#ifdef MRB_64BIT +#define SET_SYM_VALUE(r,v) ((r).value.sym = v, (r).value.sym_flag = MRB_SYMBOL_FLAG) +#else +#define SET_SYM_VALUE(r,n) BOXWORD_SET_SHIFT_VALUE(r, SYMBOL, n) +#endif +#define SET_OBJ_VALUE(r,v) ((r).value.p = v) MRB_INLINE enum mrb_vtype mrb_type(mrb_value o) @@ -103,45 +153,13 @@ mrb_type(mrb_value o) case MRB_Qundef: return MRB_TT_UNDEF; } - if (o.value.i_flag == MRB_FIXNUM_FLAG) { + if (mrb_fixnum_p(o)) { return MRB_TT_FIXNUM; } - if (o.value.sym_flag == MRB_SYMBOL_FLAG) { + if (mrb_symbol_p(o)) { return MRB_TT_SYMBOL; } return o.value.bp->tt; } -#define mrb_bool(o) ((o).w != MRB_Qnil && (o).w != MRB_Qfalse) -#define mrb_fixnum_p(o) ((o).value.i_flag == MRB_FIXNUM_FLAG) -#define mrb_undef_p(o) ((o).w == MRB_Qundef) -#define mrb_nil_p(o) ((o).w == MRB_Qnil) -#define mrb_false_p(o) ((o).w == MRB_Qfalse) -#define mrb_true_p(o) ((o).w == MRB_Qtrue) - -#ifndef MRB_WITHOUT_FLOAT -#define SET_FLOAT_VALUE(mrb,r,v) ((r) = mrb_word_boxing_float_value(mrb, v)) -#endif -#define SET_CPTR_VALUE(mrb,r,v) ((r) = mrb_word_boxing_cptr_value(mrb, v)) -#define SET_UNDEF_VALUE(r) ((r).w = MRB_Qundef) -#define SET_NIL_VALUE(r) ((r).w = MRB_Qnil) -#define SET_FALSE_VALUE(r) ((r).w = MRB_Qfalse) -#define SET_TRUE_VALUE(r) ((r).w = MRB_Qtrue) -#define SET_BOOL_VALUE(r,b) ((b) ? SET_TRUE_VALUE(r) : SET_FALSE_VALUE(r)) -#define SET_INT_VALUE(r,n) do { \ - (r).w = 0; \ - (r).value.i_flag = MRB_FIXNUM_FLAG; \ - (r).value.i = (n); \ -} while (0) -#define SET_SYM_VALUE(r,v) do { \ - (r).w = 0; \ - (r).value.sym_flag = MRB_SYMBOL_FLAG; \ - (r).value.sym = (v); \ -} while (0) -#define SET_OBJ_VALUE(r,v) do { \ - (r).w = 0; \ - (r).value.p = (v); \ - if ((r).value.bp) (r).value.bp->tt = ((struct RObject*)(v))->tt; \ -} while (0) - #endif /* MRUBY_BOXING_WORD_H */ diff --git a/include/mruby/class.h b/include/mruby/class.h index c79a487b5..7c925f3b3 100644 --- a/include/mruby/class.h +++ b/include/mruby/class.h @@ -1,5 +1,5 @@ -/* -** mruby/class.h - Class class +/** +** @file mruby/class.h - Class class ** ** See Copyright Notice in mruby.h */ @@ -75,8 +75,8 @@ mrb_class(mrb_state *mrb, mrb_value v) MRB_API struct RClass* mrb_define_class_id(mrb_state*, mrb_sym, struct RClass*); MRB_API struct RClass* mrb_define_module_id(mrb_state*, mrb_sym); -MRB_API struct RClass *mrb_vm_define_class(mrb_state*, mrb_value, mrb_value, mrb_sym); -MRB_API struct RClass *mrb_vm_define_module(mrb_state*, mrb_value, mrb_sym); +struct RClass *mrb_vm_define_class(mrb_state*, mrb_value, mrb_value, mrb_sym); +struct RClass *mrb_vm_define_module(mrb_state*, mrb_value, mrb_sym); MRB_API void mrb_define_method_raw(mrb_state*, struct RClass*, mrb_sym, mrb_method_t); MRB_API void mrb_define_method_id(mrb_state *mrb, struct RClass *c, mrb_sym mid, mrb_func_t func, mrb_aspec aspec); MRB_API void mrb_alias_method(mrb_state*, struct RClass *c, mrb_sym a, mrb_sym b); diff --git a/include/mruby/common.h b/include/mruby/common.h index dc9e3acc5..5be9a40c6 100644 --- a/include/mruby/common.h +++ b/include/mruby/common.h @@ -1,5 +1,5 @@ -/* -**"common.h - mruby common platform definition" +/** +** @file common.h - mruby common platform definition" ** ** See Copyright Notice in mruby.h */ @@ -62,6 +62,7 @@ MRB_BEGIN_DECL #define MRB_INLINE static inline /** Declare a public MRuby API function. */ +#ifndef MRB_API #if defined(MRB_BUILD_AS_DLL) #if defined(MRB_CORE) || defined(MRB_LIB) # define MRB_API __declspec(dllexport) @@ -71,6 +72,7 @@ MRB_BEGIN_DECL #else # define MRB_API extern #endif +#endif MRB_END_DECL diff --git a/include/mruby/compile.h b/include/mruby/compile.h index 8f8f2ebd7..ac9a9892a 100644 --- a/include/mruby/compile.h +++ b/include/mruby/compile.h @@ -1,5 +1,5 @@ -/* -** mruby/compile.h - mruby parser +/** +** @file mruby/compile.h - mruby parser ** ** See Copyright Notice in mruby.h */ @@ -24,7 +24,7 @@ typedef struct mrbc_context { mrb_sym *syms; int slen; char *filename; - short lineno; + uint16_t lineno; int (*partial_hook)(struct mrb_parser_state*); void *partial_data; struct RClass *target_class; @@ -67,7 +67,7 @@ enum mrb_lex_state_enum { /* saved error message */ struct mrb_parser_message { - int lineno; + uint16_t lineno; int column; char* message; }; @@ -119,7 +119,7 @@ struct mrb_parser_state { #endif mrbc_context *cxt; mrb_sym filename_sym; - int lineno; + uint16_t lineno; int column; enum mrb_lex_state_enum lstate; diff --git a/include/mruby/data.h b/include/mruby/data.h index 54466dcd6..35ec2c25b 100644 --- a/include/mruby/data.h +++ b/include/mruby/data.h @@ -1,5 +1,5 @@ -/* -** mruby/data.h - Data class +/** +** @file mruby/data.h - Data class ** ** See Copyright Notice in mruby.h */ diff --git a/include/mruby/debug.h b/include/mruby/debug.h index e08c47cfc..f28dd645a 100644 --- a/include/mruby/debug.h +++ b/include/mruby/debug.h @@ -1,5 +1,5 @@ -/* -** mruby/debug.h - mruby debug info +/** +** @file mruby/debug.h - mruby debug info ** ** See Copyright Notice in mruby.h */ diff --git a/include/mruby/dump.h b/include/mruby/dump.h index 65ed8af9d..46c3b63ce 100644 --- a/include/mruby/dump.h +++ b/include/mruby/dump.h @@ -1,5 +1,5 @@ -/* -** mruby/dump.h - mruby binary dumper (mrbc binary format) +/** +** @file mruby/dump.h - mruby binary dumper (mrbc binary format) ** ** See Copyright Notice in mruby.h */ diff --git a/include/mruby/error.h b/include/mruby/error.h index 237c701ad..20090d197 100644 --- a/include/mruby/error.h +++ b/include/mruby/error.h @@ -1,5 +1,5 @@ -/* -** mruby/error.h - Exception class +/** +** @file mruby/error.h - Exception class ** ** See Copyright Notice in mruby.h */ @@ -32,23 +32,51 @@ MRB_API mrb_noreturn void mrb_no_method_error(mrb_state *mrb, mrb_sym id, mrb_va /* declaration for `fail` method */ MRB_API mrb_value mrb_f_raise(mrb_state*, mrb_value); +#if defined(MRB_64BIT) || defined(MRB_USE_FLOAT) || defined(MRB_NAN_BOXING) || defined(MRB_WORD_BOXING) struct RBreak { MRB_OBJECT_HEADER; struct RProc *proc; mrb_value val; }; +#define mrb_break_value_get(brk) ((brk)->val) +#define mrb_break_value_set(brk, v) ((brk)->val = v) +#else +struct RBreak { + MRB_OBJECT_HEADER; + struct RProc *proc; + union mrb_value_union value; +}; +#define RBREAK_VALUE_TT_MASK ((1 << 8) - 1) +static inline mrb_value +mrb_break_value_get(struct RBreak *brk) +{ + mrb_value val; + val.value = brk->value; + val.tt = brk->flags & RBREAK_VALUE_TT_MASK; + return val; +} +static inline void +mrb_break_value_set(struct RBreak *brk, mrb_value val) +{ + brk->value = val.value; + brk->flags &= ~RBREAK_VALUE_TT_MASK; + brk->flags |= val.tt; +} +#endif /* MRB_64BIT || MRB_USE_FLOAT || MRB_NAN_BOXING || MRB_WORD_BOXING */ +#define mrb_break_proc_get(brk) ((brk)->proc) +#define mrb_break_proc_set(brk, p) ((brk)->proc = p) /** * Protect * - * @mrbgem mruby-error + * Implemented in the mruby-error mrbgem */ MRB_API mrb_value mrb_protect(mrb_state *mrb, mrb_func_t body, mrb_value data, mrb_bool *state); /** * Ensure * - * @mrbgem mruby-error + * Implemented in the mruby-error mrbgem */ MRB_API mrb_value mrb_ensure(mrb_state *mrb, mrb_func_t body, mrb_value b_data, mrb_func_t ensure, mrb_value e_data); @@ -56,7 +84,7 @@ MRB_API mrb_value mrb_ensure(mrb_state *mrb, mrb_func_t body, mrb_value b_data, /** * Rescue * - * @mrbgem mruby-error + * Implemented in the mruby-error mrbgem */ MRB_API mrb_value mrb_rescue(mrb_state *mrb, mrb_func_t body, mrb_value b_data, mrb_func_t rescue, mrb_value r_data); @@ -64,7 +92,7 @@ MRB_API mrb_value mrb_rescue(mrb_state *mrb, mrb_func_t body, mrb_value b_data, /** * Rescue exception * - * @mrbgem mruby-error + * Implemented in the mruby-error mrbgem */ MRB_API mrb_value mrb_rescue_exceptions(mrb_state *mrb, mrb_func_t body, mrb_value b_data, mrb_func_t rescue, mrb_value r_data, diff --git a/include/mruby/gc.h b/include/mruby/gc.h index 2a3ff4182..4d9fb60eb 100644 --- a/include/mruby/gc.h +++ b/include/mruby/gc.h @@ -1,5 +1,5 @@ -/* -** mruby/gc.h - garbage collector for mruby +/** +** @file mruby/gc.h - garbage collector for mruby ** ** See Copyright Notice in mruby.h */ diff --git a/include/mruby/hash.h b/include/mruby/hash.h index 7e2ed5596..734a8c3b5 100644 --- a/include/mruby/hash.h +++ b/include/mruby/hash.h @@ -1,5 +1,5 @@ -/* -** mruby/hash.h - Hash class +/** +** @file mruby/hash.h - Hash class ** ** See Copyright Notice in mruby.h */ diff --git a/include/mruby/irep.h b/include/mruby/irep.h index d42fd0fb8..4393129c7 100644 --- a/include/mruby/irep.h +++ b/include/mruby/irep.h @@ -1,5 +1,5 @@ -/* -** mruby/irep.h - mrb_irep structure +/** +** @file mruby/irep.h - mrb_irep structure ** ** See Copyright Notice in mruby.h */ @@ -32,7 +32,7 @@ typedef struct mrb_irep { uint16_t nregs; /* Number of register variables */ uint8_t flags; - mrb_code *iseq; + const mrb_code *iseq; mrb_value *pool; mrb_sym *syms; struct mrb_irep **reps; @@ -80,7 +80,7 @@ struct mrb_insn_data { uint8_t c; }; -struct mrb_insn_data mrb_decode_insn(mrb_code *pc); +struct mrb_insn_data mrb_decode_insn(const mrb_code *pc); MRB_END_DECL diff --git a/include/mruby/istruct.h b/include/mruby/istruct.h index 23c9bfa36..45b1fadae 100644 --- a/include/mruby/istruct.h +++ b/include/mruby/istruct.h @@ -1,5 +1,5 @@ -/* -** mruby/istruct.h - Inline structures +/** +** @file mruby/istruct.h - Inline structures ** ** See Copyright Notice in mruby.h */ diff --git a/include/mruby/khash.h b/include/mruby/khash.h index 9c40c6b80..c00357061 100644 --- a/include/mruby/khash.h +++ b/include/mruby/khash.h @@ -1,5 +1,5 @@ -/* -** mruby/khash.c - Hash for mruby +/** +** @file mruby/khash.h - Hash for mruby ** ** See Copyright Notice in mruby.h */ diff --git a/include/mruby/numeric.h b/include/mruby/numeric.h index 34707e441..a176d96cd 100644 --- a/include/mruby/numeric.h +++ b/include/mruby/numeric.h @@ -1,5 +1,5 @@ -/* -** mruby/numeric.h - Numeric, Integer, Float, Fixnum class +/** +** @file mruby/numeric.h - Numeric, Integer, Float, Fixnum class ** ** See Copyright Notice in mruby.h */ @@ -23,8 +23,12 @@ MRB_BEGIN_DECL #define NEGFIXABLE(f) TYPED_NEGFIXABLE(f,mrb_int) #define FIXABLE(f) TYPED_FIXABLE(f,mrb_int) #ifndef MRB_WITHOUT_FLOAT +#ifdef MRB_INT64 +#define FIXABLE_FLOAT(f) ((f)>=-9223372036854775808.0 && (f)<9223372036854775808.0) +#else #define FIXABLE_FLOAT(f) TYPED_FIXABLE(f,mrb_float) #endif +#endif #ifndef MRB_WITHOUT_FLOAT MRB_API mrb_value mrb_flo_to_fixnum(mrb_state *mrb, mrb_value val); @@ -156,6 +160,36 @@ mrb_int_mul_overflow(mrb_int multiplier, mrb_int multiplicand, mrb_int *product) #endif +#ifndef MRB_WITHOUT_FLOAT +# include <stdint.h> +# include <float.h> + +# define MRB_FLT_RADIX FLT_RADIX + +# ifdef MRB_USE_FLOAT +# define MRB_FLT_MANT_DIG FLT_MANT_DIG +# define MRB_FLT_EPSILON FLT_EPSILON +# define MRB_FLT_DIG FLT_DIG +# define MRB_FLT_MIN_EXP FLT_MIN_EXP +# define MRB_FLT_MIN FLT_MIN +# define MRB_FLT_MIN_10_EXP FLT_MIN_10_EXP +# define MRB_FLT_MAX_EXP FLT_MAX_EXP +# define MRB_FLT_MAX FLT_MAX +# define MRB_FLT_MAX_10_EXP FLT_MAX_10_EXP + +# else /* not MRB_USE_FLOAT */ +# define MRB_FLT_MANT_DIG DBL_MANT_DIG +# define MRB_FLT_EPSILON DBL_EPSILON +# define MRB_FLT_DIG DBL_DIG +# define MRB_FLT_MIN_EXP DBL_MIN_EXP +# define MRB_FLT_MIN DBL_MIN +# define MRB_FLT_MIN_10_EXP DBL_MIN_10_EXP +# define MRB_FLT_MAX_EXP DBL_MAX_EXP +# define MRB_FLT_MAX DBL_MAX +# define MRB_FLT_MAX_10_EXP DBL_MAX_10_EXP +# endif /* MRB_USE_FLOAT */ +#endif /* MRB_WITHOUT_FLOAT */ + MRB_END_DECL #endif /* MRUBY_NUMERIC_H */ diff --git a/include/mruby/object.h b/include/mruby/object.h index 373e3bec7..53511a1bb 100644 --- a/include/mruby/object.h +++ b/include/mruby/object.h @@ -1,5 +1,5 @@ -/* -** mruby/object.h - mruby object definition +/** +** @file mruby/object.h - mruby object definition ** ** See Copyright Notice in mruby.h */ @@ -8,15 +8,14 @@ #define MRUBY_OBJECT_H #define MRB_OBJECT_HEADER \ - enum mrb_vtype tt:8;\ - uint32_t color:3;\ - uint32_t flags:21;\ - struct RClass *c;\ - struct RBasic *gcnext + struct RClass *c; \ + struct RBasic *gcnext; \ + enum mrb_vtype tt:8; \ + uint32_t color:3; \ + uint32_t flags:21 #define MRB_FLAG_TEST(obj, flag) ((obj)->flags & (flag)) - struct RBasic { MRB_OBJECT_HEADER; }; @@ -33,7 +32,6 @@ struct RObject { }; #define mrb_obj_ptr(v) ((struct RObject*)(mrb_ptr(v))) -#define mrb_immediate_p(x) (mrb_type(x) < MRB_TT_HAS_BASIC) #define mrb_special_const_p(x) mrb_immediate_p(x) struct RFiber { diff --git a/include/mruby/opcode.h b/include/mruby/opcode.h index d513ca472..95e6736a4 100644 --- a/include/mruby/opcode.h +++ b/include/mruby/opcode.h @@ -1,5 +1,5 @@ -/* -** mruby/opcode.h - RiteVM operation codes +/** +** @file mruby/opcode.h - RiteVM operation codes ** ** See Copyright Notice in mruby.h */ diff --git a/include/mruby/proc.h b/include/mruby/proc.h index a8b16db1d..d6459f8bf 100644 --- a/include/mruby/proc.h +++ b/include/mruby/proc.h @@ -1,5 +1,5 @@ -/* -** mruby/proc.h - Proc class +/** +** @file mruby/proc.h - Proc class ** ** See Copyright Notice in mruby.h */ diff --git a/include/mruby/range.h b/include/mruby/range.h index ee6eb8d1d..fea700c24 100644 --- a/include/mruby/range.h +++ b/include/mruby/range.h @@ -1,5 +1,5 @@ -/* -** mruby/range.h - Range class +/** +** @file mruby/range.h - Range class ** ** See Copyright Notice in mruby.h */ @@ -14,7 +14,7 @@ */ MRB_BEGIN_DECL -#if defined(MRB_NAN_BOXING) || defined(MRB_WORD_BOXING) +#if defined(MRB_NAN_BOXING) && defined(MRB_64BIT) || defined(MRB_WORD_BOXING) # define MRB_RANGE_EMBED #endif diff --git a/include/mruby/re.h b/include/mruby/re.h index 1d09d06c9..2d48019cf 100644 --- a/include/mruby/re.h +++ b/include/mruby/re.h @@ -1,5 +1,5 @@ -/* -** mruby/re.h - Regexp class +/** +** @file mruby/re.h - Regexp class ** ** See Copyright Notice in mruby.h */ diff --git a/include/mruby/string.h b/include/mruby/string.h index 22445f654..fd078b9f3 100644 --- a/include/mruby/string.h +++ b/include/mruby/string.h @@ -1,5 +1,5 @@ -/* -** mruby/string.h - String class +/** +** @file mruby/string.h - String class ** ** See Copyright Notice in mruby.h */ @@ -16,7 +16,8 @@ MRB_BEGIN_DECL extern const char mrb_digitmap[]; -#define RSTRING_EMBED_LEN_MAX ((mrb_int)(sizeof(void*) * 3 - 1)) +#define RSTRING_EMBED_LEN_MAX \ + ((mrb_int)(sizeof(void*) * 3 + sizeof(void*) - 32 / CHAR_BIT - 1)) struct RString { MRB_OBJECT_HEADER; @@ -30,9 +31,15 @@ struct RString { } aux; char *ptr; } heap; - char ary[RSTRING_EMBED_LEN_MAX + 1]; } as; }; +struct RStringEmbed { + MRB_OBJECT_HEADER; + char ary[]; +}; + +#define RSTR_SET_TYPE_FLAG(s, type) (RSTR_UNSET_TYPE_FLAG(s), (s)->flags |= MRB_STR_##type) +#define RSTR_UNSET_TYPE_FLAG(s) ((s)->flags &= ~(MRB_STR_TYPE_MASK|MRB_STR_EMBED_LEN_MASK)) #define RSTR_EMBED_P(s) ((s)->flags & MRB_STR_EMBED) #define RSTR_SET_EMBED_FLAG(s) ((s)->flags |= MRB_STR_EMBED) @@ -50,9 +57,12 @@ struct RString { (s)->as.heap.len = (mrb_int)(n);\ }\ } while (0) +#define RSTR_EMBED_PTR(s) (((struct RStringEmbed*)(s))->ary) #define RSTR_EMBED_LEN(s)\ (mrb_int)(((s)->flags & MRB_STR_EMBED_LEN_MASK) >> MRB_STR_EMBED_LEN_SHIFT) -#define RSTR_PTR(s) ((RSTR_EMBED_P(s)) ? (s)->as.ary : (s)->as.heap.ptr) +#define RSTR_EMBEDDABLE_P(len) ((len) <= RSTRING_EMBED_LEN_MAX) + +#define RSTR_PTR(s) ((RSTR_EMBED_P(s)) ? RSTR_EMBED_PTR(s) : (s)->as.heap.ptr) #define RSTR_LEN(s) ((RSTR_EMBED_P(s)) ? RSTR_EMBED_LEN(s) : (s)->as.heap.len) #define RSTR_CAPA(s) (RSTR_EMBED_P(s) ? RSTRING_EMBED_LEN_MAX : (s)->as.heap.aux.capa) @@ -68,10 +78,24 @@ struct RString { #define RSTR_SET_NOFREE_FLAG(s) ((s)->flags |= MRB_STR_NOFREE) #define RSTR_UNSET_NOFREE_FLAG(s) ((s)->flags &= ~MRB_STR_NOFREE) +#ifdef MRB_UTF8_STRING +# define RSTR_ASCII_P(s) ((s)->flags & MRB_STR_ASCII) +# define RSTR_SET_ASCII_FLAG(s) ((s)->flags |= MRB_STR_ASCII) +# define RSTR_UNSET_ASCII_FLAG(s) ((s)->flags &= ~MRB_STR_ASCII) +# define RSTR_WRITE_ASCII_FLAG(s, v) (RSTR_UNSET_ASCII_FLAG(s), (s)->flags |= v) +# define RSTR_COPY_ASCII_FLAG(dst, src) RSTR_WRITE_ASCII_FLAG(dst, RSTR_ASCII_P(src)) +#else +# define RSTR_ASCII_P(s) (void)0 +# define RSTR_SET_ASCII_FLAG(s) (void)0 +# define RSTR_UNSET_ASCII_FLAG(s) (void)0 +# define RSTR_WRITE_ASCII_FLAG(s, v) (void)0 +# define RSTR_COPY_ASCII_FLAG(dst, src) (void)0 +#endif + #define RSTR_POOL_P(s) ((s)->flags & MRB_STR_POOL) #define RSTR_SET_POOL_FLAG(s) ((s)->flags |= MRB_STR_POOL) -/* +/** * Returns a pointer from a Ruby string */ #define mrb_str_ptr(s) ((struct RString*)(mrb_ptr(s))) @@ -82,32 +106,38 @@ struct RString { #define RSTRING_CAPA(s) RSTR_CAPA(RSTRING(s)) #define RSTRING_END(s) (RSTRING_PTR(s) + RSTRING_LEN(s)) MRB_API mrb_int mrb_str_strlen(mrb_state*, struct RString*); +#define RSTRING_CSTR(mrb,s) mrb_string_cstr(mrb, s) #define MRB_STR_SHARED 1 #define MRB_STR_FSHARED 2 #define MRB_STR_NOFREE 4 -#define MRB_STR_POOL 8 -#define MRB_STR_NO_UTF 16 -#define MRB_STR_EMBED 32 -#define MRB_STR_EMBED_LEN_MASK 0x7c0 +#define MRB_STR_EMBED 8 /* type flags up to here */ +#define MRB_STR_POOL 16 /* status flags from here */ +#define MRB_STR_ASCII 32 #define MRB_STR_EMBED_LEN_SHIFT 6 +#define MRB_STR_EMBED_LEN_BITSIZE 5 +#define MRB_STR_EMBED_LEN_MASK (((1 << MRB_STR_EMBED_LEN_BITSIZE) - 1) << MRB_STR_EMBED_LEN_SHIFT) +#define MRB_STR_TYPE_MASK (MRB_STR_POOL - 1) + void mrb_gc_free_str(mrb_state*, struct RString*); -MRB_API void mrb_str_modify(mrb_state*, struct RString*); -/* +MRB_API void mrb_str_modify(mrb_state *mrb, struct RString *s); +/* mrb_str_modify() with keeping ASCII flag if set */ +MRB_API void mrb_str_modify_keep_ascii(mrb_state *mrb, struct RString *s); + +/** * Finds the index of a substring in a string */ MRB_API mrb_int mrb_str_index(mrb_state*, mrb_value, const char*, mrb_int, mrb_int); #define mrb_str_index_lit(mrb, str, lit, off) mrb_str_index(mrb, str, lit, mrb_strlen_lit(lit), off); -/* +/** * Appends self to other. Returns self as a concatenated string. * * - * Example: + * Example: * - * !!!c * int * main(int argc, * char **argv) @@ -129,32 +159,30 @@ MRB_API mrb_int mrb_str_index(mrb_state*, mrb_value, const char*, mrb_int, mrb_i * // Concatenates str2 to str1. * mrb_str_concat(mrb, str1, str2); * - * // Prints new Concatenated Ruby string. - * mrb_p(mrb, str1); - * - * mrb_close(mrb); - * return 0; - * } + * // Prints new Concatenated Ruby string. + * mrb_p(mrb, str1); * + * mrb_close(mrb); + * return 0; + * } * - * Result: + * Result: * * => "abcdef" * - * @param [mrb_state] mrb The current mruby state. - * @param [mrb_value] self String to concatenate. - * @param [mrb_value] other String to append to self. + * @param mrb The current mruby state. + * @param self String to concatenate. + * @param other String to append to self. * @return [mrb_value] Returns a new String appending other to self. */ -MRB_API void mrb_str_concat(mrb_state*, mrb_value, mrb_value); +MRB_API void mrb_str_concat(mrb_state *mrb, mrb_value self, mrb_value other); -/* +/** * Adds two strings together. * * - * Example: + * Example: * - * !!!c * int * main(int argc, * char **argv) @@ -181,52 +209,51 @@ MRB_API void mrb_str_concat(mrb_state*, mrb_value, mrb_value); * // Concatenates both Ruby strings. * c = mrb_str_plus(mrb, a, b); * - * // Prints new Concatenated Ruby string. - * mrb_p(mrb, c); + * // Prints new Concatenated Ruby string. + * mrb_p(mrb, c); * - * mrb_close(mrb); - * return 0; - * } + * mrb_close(mrb); + * return 0; + * } * * - * Result: + * Result: * * => "abc" # First string * => "def" # Second string * => "abcdef" # First & Second concatenated. * - * @param [mrb_state] mrb The current mruby state. - * @param [mrb_value] a First string to concatenate. - * @param [mrb_value] b Second string to concatenate. + * @param mrb The current mruby state. + * @param a First string to concatenate. + * @param b Second string to concatenate. * @return [mrb_value] Returns a new String containing a concatenated to b. */ -MRB_API mrb_value mrb_str_plus(mrb_state*, mrb_value, mrb_value); +MRB_API mrb_value mrb_str_plus(mrb_state *mrb, mrb_value a, mrb_value b); -/* +/** * Converts pointer into a Ruby string. * - * @param [mrb_state] mrb The current mruby state. - * @param [void*] p The pointer to convert to Ruby string. + * @param mrb The current mruby state. + * @param p The pointer to convert to Ruby string. * @return [mrb_value] Returns a new Ruby String. */ -MRB_API mrb_value mrb_ptr_to_str(mrb_state *, void*); +MRB_API mrb_value mrb_ptr_to_str(mrb_state *mrb, void *p); -/* +/** * Returns an object as a Ruby string. * - * @param [mrb_state] mrb The current mruby state. - * @param [mrb_value] obj An object to return as a Ruby string. + * @param mrb The current mruby state. + * @param obj An object to return as a Ruby string. * @return [mrb_value] An object as a Ruby string. */ MRB_API mrb_value mrb_obj_as_string(mrb_state *mrb, mrb_value obj); -/* +/** * Resizes the string's length. Returns the amount of characters * in the specified by len. * * Example: * - * !!!c * int * main(int argc, * char **argv) @@ -251,21 +278,20 @@ MRB_API mrb_value mrb_obj_as_string(mrb_state *mrb, mrb_value obj); * * Result: * - * => "Hello" + * => "Hello" * - * @param [mrb_state] mrb The current mruby state. - * @param [mrb_value] str The Ruby string to resize. - * @param [mrb_value] len The length. + * @param mrb The current mruby state. + * @param str The Ruby string to resize. + * @param len The length. * @return [mrb_value] An object as a Ruby string. */ MRB_API mrb_value mrb_str_resize(mrb_state *mrb, mrb_value str, mrb_int len); -/* +/** * Returns a sub string. * - * Example: + * Example: * - * !!!c * int * main(int argc, * char const **argv) @@ -291,24 +317,24 @@ MRB_API mrb_value mrb_str_resize(mrb_state *mrb, mrb_value str, mrb_int len); * return 0; * } * - * Result: + * Result: * * => "He" * - * @param [mrb_state] mrb The current mruby state. - * @param [mrb_value] str Ruby string. - * @param [mrb_int] beg The beginning point of the sub-string. - * @param [mrb_int] len The end point of the sub-string. + * @param mrb The current mruby state. + * @param str Ruby string. + * @param beg The beginning point of the sub-string. + * @param len The end point of the sub-string. * @return [mrb_value] An object as a Ruby sub-string. */ MRB_API mrb_value mrb_str_substr(mrb_state *mrb, mrb_value str, mrb_int beg, mrb_int len); -/* +/** * Returns a Ruby string type. * * - * @param [mrb_state] mrb The current mruby state. - * @param [mrb_value] str Ruby string. + * @param mrb The current mruby state. + * @param str Ruby string. * @return [mrb_value] A Ruby string. */ MRB_API mrb_value mrb_ensure_string_type(mrb_state *mrb, mrb_value str); @@ -320,33 +346,30 @@ MRB_API mrb_value mrb_string_type(mrb_state *mrb, mrb_value str); MRB_API mrb_value mrb_str_new_capa(mrb_state *mrb, size_t capa); MRB_API mrb_value mrb_str_buf_new(mrb_state *mrb, size_t capa); -MRB_API const char *mrb_string_value_cstr(mrb_state *mrb, mrb_value *ptr); +/* NULL terminated C string from mrb_value */ +MRB_API const char *mrb_string_cstr(mrb_state *mrb, mrb_value str); +/* NULL terminated C string from mrb_value; `str` will be updated */ +MRB_API const char *mrb_string_value_cstr(mrb_state *mrb, mrb_value *str); +/* obslete: use RSTRING_PTR() */ MRB_API const char *mrb_string_value_ptr(mrb_state *mrb, mrb_value str); -/* - * Returns the length of the Ruby string. - * - * - * @param [mrb_state] mrb The current mruby state. - * @param [mrb_value] str Ruby string. - * @return [mrb_int] The length of the passed in Ruby string. - */ +/* obslete: use RSTRING_LEN() */ MRB_API mrb_int mrb_string_value_len(mrb_state *mrb, mrb_value str); -/* +/** * Duplicates a string object. * * - * @param [mrb_state] mrb The current mruby state. - * @param [mrb_value] str Ruby string. + * @param mrb The current mruby state. + * @param str Ruby string. * @return [mrb_value] Duplicated Ruby string. */ MRB_API mrb_value mrb_str_dup(mrb_state *mrb, mrb_value str); -/* +/** * Returns a symbol from a passed in Ruby string. * - * @param [mrb_state] mrb The current mruby state. - * @param [mrb_value] self Ruby string. + * @param mrb The current mruby state. + * @param self Ruby string. * @return [mrb_value] A symbol. */ MRB_API mrb_value mrb_str_intern(mrb_state *mrb, mrb_value self); @@ -356,40 +379,40 @@ MRB_API mrb_value mrb_cstr_to_inum(mrb_state *mrb, const char *s, mrb_int base, MRB_API double mrb_str_to_dbl(mrb_state *mrb, mrb_value str, mrb_bool badcheck); MRB_API double mrb_cstr_to_dbl(mrb_state *mrb, const char *s, mrb_bool badcheck); -/* +/** * Returns a converted string type. * For type checking, non converting `mrb_to_str` is recommended. */ MRB_API mrb_value mrb_str_to_str(mrb_state *mrb, mrb_value str); -/* +/** * Returns true if the strings match and false if the strings don't match. * - * @param [mrb_state] mrb The current mruby state. - * @param [mrb_value] str1 Ruby string to compare. - * @param [mrb_value] str2 Ruby string to compare. + * @param mrb The current mruby state. + * @param str1 Ruby string to compare. + * @param str2 Ruby string to compare. * @return [mrb_value] boolean value. */ MRB_API mrb_bool mrb_str_equal(mrb_state *mrb, mrb_value str1, mrb_value str2); -/* - * Returns a concated string comprised of a Ruby string and a C string. +/** + * Returns a concatenated string comprised of a Ruby string and a C string. * - * @param [mrb_state] mrb The current mruby state. - * @param [mrb_value] str Ruby string. - * @param [const char *] ptr A C string. - * @param [size_t] len length of C string. + * @param mrb The current mruby state. + * @param str Ruby string. + * @param ptr A C string. + * @param len length of C string. * @return [mrb_value] A Ruby string. * @see mrb_str_cat_cstr */ MRB_API mrb_value mrb_str_cat(mrb_state *mrb, mrb_value str, const char *ptr, size_t len); -/* - * Returns a concated string comprised of a Ruby string and a C string. +/** + * Returns a concatenated string comprised of a Ruby string and a C string. * - * @param [mrb_state] mrb The current mruby state. - * @param [mrb_value] str Ruby string. - * @param [const char *] ptr A C string. + * @param mrb The current mruby state. + * @param str Ruby string. + * @param ptr A C string. * @return [mrb_value] A Ruby string. * @see mrb_str_cat */ @@ -397,17 +420,17 @@ MRB_API mrb_value mrb_str_cat_cstr(mrb_state *mrb, mrb_value str, const char *pt MRB_API mrb_value mrb_str_cat_str(mrb_state *mrb, mrb_value str, mrb_value str2); #define mrb_str_cat_lit(mrb, str, lit) mrb_str_cat(mrb, str, lit, mrb_strlen_lit(lit)) -/* +/** * Adds str2 to the end of str1. */ MRB_API mrb_value mrb_str_append(mrb_state *mrb, mrb_value str, mrb_value str2); -/* +/** * 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. */ MRB_API int mrb_str_cmp(mrb_state *mrb, mrb_value str1, mrb_value str2); -/* +/** * Returns a newly allocated C string from a Ruby string. * This is an utility function to pass a Ruby string to C library functions. * @@ -418,8 +441,8 @@ MRB_API int mrb_str_cmp(mrb_state *mrb, mrb_value str1, mrb_value str2); * - Caller can modify returned string without affecting Ruby string * (e.g. it can be used for mkstemp(3)). * - * @param [mrb_state *] mrb The current mruby state. - * @param [mrb_value] str Ruby string. Must be an instance of String. + * @param mrb The current mruby state. + * @param str Ruby string. Must be an instance of String. * @return [char *] A newly allocated C string. */ MRB_API char *mrb_str_to_cstr(mrb_state *mrb, mrb_value str); @@ -428,7 +451,7 @@ mrb_value mrb_str_pool(mrb_state *mrb, mrb_value str); uint32_t mrb_str_hash(mrb_state *mrb, mrb_value str); mrb_value mrb_str_dump(mrb_state *mrb, mrb_value str); -/* +/** * Returns a printable version of str, surrounded by quote marks, with special characters escaped. */ mrb_value mrb_str_inspect(mrb_state *mrb, mrb_value str); @@ -438,6 +461,9 @@ mrb_value mrb_str_inspect(mrb_state *mrb, mrb_value str); #define mrb_str_buf_cat(mrb, str, ptr, len) mrb_str_cat(mrb, str, ptr, len) #define mrb_str_buf_append(mrb, str, str2) mrb_str_cat_str(mrb, str, str2) +mrb_bool mrb_str_beg_len(mrb_int str_len, mrb_int *begp, mrb_int *lenp); +mrb_value mrb_str_byte_subseq(mrb_state *mrb, mrb_value str, mrb_int beg, mrb_int len); + #ifdef MRB_UTF8_STRING mrb_int mrb_utf8_len(const char *str, mrb_int byte_len); #endif diff --git a/include/mruby/throw.h b/include/mruby/throw.h index 4a1fd8d60..1f1298d7d 100644 --- a/include/mruby/throw.h +++ b/include/mruby/throw.h @@ -1,5 +1,5 @@ -/* -** mruby/throw.h - mruby exception throwing handler +/** +** @file mruby/throw.h - mruby exception throwing handler ** ** See Copyright Notice in mruby.h */ diff --git a/include/mruby/value.h b/include/mruby/value.h index be3dd397f..52ce93d58 100644 --- a/include/mruby/value.h +++ b/include/mruby/value.h @@ -1,5 +1,5 @@ -/* -** mruby/value.h - mruby value definitions +/** +** @file mruby/value.h - mruby value definitions ** ** See Copyright Notice in mruby.h */ @@ -9,12 +9,28 @@ #include "common.h" -/** +/* * MRuby Value definition functions and macros. */ MRB_BEGIN_DECL +/** + * mruby Symbol. + * @class mrb_sym + * + * You can create an mrb_sym by simply using mrb_str_intern() or mrb_intern_cstr() + */ typedef uint32_t mrb_sym; + +/** + * mruby Boolean. + * @class mrb_bool + * + * + * Used internally to represent boolean. Can be TRUE or FALSE. + * Not to be confused with Ruby's boolean classes, which can be + * obtained using mrb_false_value() and mrb_true_value() + */ typedef uint8_t mrb_bool; struct mrb_state; @@ -62,6 +78,11 @@ struct mrb_state; # define MRB_PRIx PRIx32 #endif +#ifdef MRB_ENDIAN_BIG +# define MRB_ENDIAN_LOHI(a,b) a b +#else +# define MRB_ENDIAN_LOHI(a,b) b a +#endif #ifndef MRB_WITHOUT_FLOAT MRB_API double mrb_float_read(const char*, char**); @@ -92,13 +113,13 @@ static const unsigned int IEEE754_INFINITY_BITS_SINGLE = 0x7F800000; enum mrb_vtype { MRB_TT_FALSE = 0, /* 0 */ - MRB_TT_FREE, /* 1 */ - MRB_TT_TRUE, /* 2 */ + MRB_TT_TRUE, /* 1 */ + MRB_TT_FLOAT, /* 2 */ MRB_TT_FIXNUM, /* 3 */ MRB_TT_SYMBOL, /* 4 */ MRB_TT_UNDEF, /* 5 */ - MRB_TT_FLOAT, /* 6 */ - MRB_TT_CPTR, /* 7 */ + MRB_TT_CPTR, /* 6 */ + MRB_TT_FREE, /* 7 */ MRB_TT_OBJECT, /* 8 */ MRB_TT_CLASS, /* 9 */ MRB_TT_MODULE, /* 10 */ @@ -145,9 +166,17 @@ typedef void mrb_value; #include "boxing_no.h" #endif +#define MRB_TT_HAS_BASIC MRB_TT_FREE + +#ifndef mrb_immediate_p +#define mrb_immediate_p(o) (mrb_type(o) < MRB_TT_HAS_BASIC) +#endif #ifndef mrb_fixnum_p #define mrb_fixnum_p(o) (mrb_type(o) == MRB_TT_FIXNUM) #endif +#ifndef mrb_symbol_p +#define mrb_symbol_p(o) (mrb_type(o) == MRB_TT_SYMBOL) +#endif #ifndef mrb_undef_p #define mrb_undef_p(o) (mrb_type(o) == MRB_TT_UNDEF) #endif @@ -170,7 +199,6 @@ typedef void mrb_value; #ifndef MRB_WITHOUT_FLOAT #define mrb_float_p(o) (mrb_type(o) == MRB_TT_FLOAT) #endif -#define mrb_symbol_p(o) (mrb_type(o) == MRB_TT_SYMBOL) #define mrb_array_p(o) (mrb_type(o) == MRB_TT_ARRAY) #define mrb_string_p(o) (mrb_type(o) == MRB_TT_STRING) #define mrb_hash_p(o) (mrb_type(o) == MRB_TT_HASH) @@ -178,8 +206,10 @@ typedef void mrb_value; #define mrb_exception_p(o) (mrb_type(o) == MRB_TT_EXCEPTION) #define mrb_test(o) mrb_bool(o) -/* +/** * Returns a float in Ruby. + * + * Takes a float and boxes it into an mrb_value */ #ifndef MRB_WITHOUT_FLOAT MRB_INLINE mrb_value mrb_float_value(struct mrb_state *mrb, mrb_float f) @@ -200,8 +230,10 @@ mrb_cptr_value(struct mrb_state *mrb, void *p) return v; } -/* +/** * Returns a fixnum in Ruby. + * + * Takes an integer and boxes it into an mrb_value */ MRB_INLINE mrb_value mrb_fixnum_value(mrb_int i) { @@ -228,8 +260,7 @@ mrb_obj_value(void *p) return v; } - -/* +/** * Get a nil mrb_value object. * * @return @@ -242,7 +273,7 @@ MRB_INLINE mrb_value mrb_nil_value(void) return v; } -/* +/** * Returns false in Ruby. */ MRB_INLINE mrb_value mrb_false_value(void) @@ -252,7 +283,7 @@ MRB_INLINE mrb_value mrb_false_value(void) return v; } -/* +/** * Returns true in Ruby. */ MRB_INLINE mrb_value mrb_true_value(void) diff --git a/include/mruby/variable.h b/include/mruby/variable.h index ff01e5cc8..6e918cf57 100644 --- a/include/mruby/variable.h +++ b/include/mruby/variable.h @@ -1,5 +1,5 @@ -/* -** mruby/variable.h - mruby variables +/** +** @file mruby/variable.h - mruby variables ** ** See Copyright Notice in mruby.h */ @@ -97,18 +97,15 @@ MRB_API void mrb_gv_set(mrb_state *mrb, mrb_sym sym, mrb_value val); * * Example: * - * !!!ruby * # Ruby style * $value = nil * - * !!!c * // C style * mrb_sym sym = mrb_intern_lit(mrb, "$value"); * mrb_gv_remove(mrb, sym); * * @param mrb The mruby state reference * @param sym The name of the global variable - * @param val The value of the global variable */ MRB_API void mrb_gv_remove(mrb_state *mrb, mrb_sym sym); diff --git a/include/mruby/version.h b/include/mruby/version.h index 206078df0..3140ea481 100644 --- a/include/mruby/version.h +++ b/include/mruby/version.h @@ -1,5 +1,5 @@ -/* -** mruby/version.h - mruby version definition +/** +** @file mruby/version.h - mruby version definition ** ** See Copyright Notice in mruby.h */ |
