diff options
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | INSTALL | 14 | ||||
| -rw-r--r-- | README.md | 2 | ||||
| -rw-r--r-- | include/mruby.h | 13 | ||||
| -rw-r--r-- | include/mruby/debug.h | 8 | ||||
| -rw-r--r-- | include/mruby/error.h | 2 | ||||
| -rw-r--r-- | include/mruby/string.h | 2 | ||||
| -rw-r--r-- | mrbgems/mruby-random/src/mt19937ar.c | 6 | ||||
| -rw-r--r-- | mrbgems/mruby-random/src/mt19937ar.h | 6 | ||||
| -rw-r--r-- | mrbgems/mruby-struct/src/struct.c | 2 | ||||
| -rw-r--r-- | src/debug.c | 24 | ||||
| -rw-r--r-- | src/dump.c | 7 | ||||
| -rw-r--r-- | src/hash.c | 2 | ||||
| -rw-r--r-- | src/load.c | 10 | ||||
| -rw-r--r-- | src/object.c | 2 | ||||
| -rw-r--r-- | src/parse.y | 6 | ||||
| -rw-r--r-- | tasks/mrbgems_test.rake | 3 |
17 files changed, 67 insertions, 43 deletions
diff --git a/.gitignore b/.gitignore index ae18ca834..75f473258 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ *.d *.o *.orig +*.pdb *.rej *.sav *.swp @@ -28,6 +28,20 @@ send a detailed report to the developers that includes the error log, machine, and OS type. +* Adding existing gems + +Gems from the [list of mruby gems](http://www.mruby.org/libraries/) can be added by adding +their respective GitHub URLs to build_config.rb. For example, to add implementations of the +File and IO Ruby core classes to mruby, insert the following in build_config.rb under the +comment section `Use mrbgems`: + + conf.gem :git => '[email protected]:iij/mruby-io.git', :branch => 'master' + + Afterwards, re-run: + + ruby ./minirake + + * Porting to other platforms @@ -41,7 +41,7 @@ The URL of the mruby home-page is: To subscribe to the mruby mailing list....[T.B.D.] -## How to compile and install +## How to compile and install (mruby and gems) See the INSTALL file. diff --git a/include/mruby.h b/include/mruby.h index 3c8f33b2b..1acedd161 100644 --- a/include/mruby.h +++ b/include/mruby.h @@ -34,6 +34,7 @@ extern "C" { #include <stdint.h> #include <stddef.h> +#include <limits.h> #include "mrbconf.h" #include "mruby/value.h" @@ -231,13 +232,21 @@ struct RClass * mrb_define_module_under(mrb_state *mrb, struct RClass *outer, co int mrb_get_args(mrb_state *mrb, const char *format, ...); +/* `strlen` for character string literals (use with caution or `strlen` instead) + Adjacent string literals are concatenated in C/C++ in translation phase 6. + If `lit` is not one, the compiler will report a syntax error: + MSVC: "error C2143: syntax error : missing ')' before 'string'" + GCC: "error: expected ')' before string constant" +*/ +#define mrb_strlen_lit(lit) (sizeof(lit "") - 1) + mrb_value mrb_funcall(mrb_state*, mrb_value, const char*, int,...); mrb_value mrb_funcall_argv(mrb_state*, mrb_value, mrb_sym, int, mrb_value*); mrb_value mrb_funcall_with_block(mrb_state*, mrb_value, mrb_sym, int, mrb_value*, mrb_value); mrb_sym mrb_intern_cstr(mrb_state*,const char*); mrb_sym mrb_intern(mrb_state*,const char*,size_t); mrb_sym mrb_intern_static(mrb_state*,const char*,size_t); -#define mrb_intern_lit(mrb, lit) mrb_intern_static(mrb, (lit), sizeof(lit) - 1) +#define mrb_intern_lit(mrb, lit) mrb_intern_static(mrb, lit, mrb_strlen_lit(lit)) mrb_sym mrb_intern_str(mrb_state*,mrb_value); mrb_value mrb_check_intern_cstr(mrb_state*,const char*); mrb_value mrb_check_intern(mrb_state*,const char*,size_t); @@ -257,7 +266,7 @@ void mrb_free(mrb_state*, void*); mrb_value mrb_str_new(mrb_state *mrb, const char *p, size_t len); mrb_value mrb_str_new_cstr(mrb_state*, const char*); mrb_value mrb_str_new_static(mrb_state *mrb, const char *p, size_t len); -#define mrb_str_new_lit(mrb, lit) mrb_str_new_static(mrb, (lit), sizeof(lit) - 1) +#define mrb_str_new_lit(mrb, lit) mrb_str_new_static(mrb, (lit), mrb_strlen_lit(lit)) mrb_state* mrb_open(void); mrb_state* mrb_open_allocf(mrb_allocf, void *ud); diff --git a/include/mruby/debug.h b/include/mruby/debug.h index 2e358a4ca..a56321d42 100644 --- a/include/mruby/debug.h +++ b/include/mruby/debug.h @@ -28,10 +28,10 @@ typedef struct mrb_irep_debug_info_file { uint32_t line_entry_count; mrb_debug_line_type line_type; union { - void *line_ptr; - mrb_irep_debug_info_line *line_flat_map; - uint16_t *line_ary; - }; + void *ptr; + mrb_irep_debug_info_line *flat_map; + uint16_t *ary; + } lines; } mrb_irep_debug_info_file; typedef struct mrb_irep_debug_info { diff --git a/include/mruby/error.h b/include/mruby/error.h index 581c9a39c..e357606e4 100644 --- a/include/mruby/error.h +++ b/include/mruby/error.h @@ -13,7 +13,7 @@ extern "C" { void mrb_sys_fail(mrb_state *mrb, const char *mesg); mrb_value mrb_exc_new_str(mrb_state *mrb, struct RClass* c, mrb_value str); -#define mrb_exc_new_str_lit(mrb, c, lit) mrb_exc_new_str(mrb, c, mrb_str_new_lit(mrb, (lit))) +#define mrb_exc_new_str_lit(mrb, c, lit) mrb_exc_new_str(mrb, c, mrb_str_new_lit(mrb, lit)) mrb_value mrb_make_exception(mrb_state *mrb, int argc, mrb_value *argv); mrb_value mrb_format(mrb_state *mrb, const char *format, ...); void mrb_exc_print(mrb_state *mrb, struct RObject *exc); diff --git a/include/mruby/string.h b/include/mruby/string.h index 31e101246..1b4bb1eff 100644 --- a/include/mruby/string.h +++ b/include/mruby/string.h @@ -83,7 +83,7 @@ mrb_bool mrb_str_equal(mrb_state *mrb, mrb_value str1, mrb_value str2); mrb_value mrb_str_dump(mrb_state *mrb, mrb_value str); mrb_value mrb_str_cat(mrb_state *mrb, mrb_value str, const char *ptr, size_t len); mrb_value mrb_str_cat_cstr(mrb_state *mrb, mrb_value str, const char *ptr); -#define mrb_str_cat_lit(mrb, str, lit) mrb_str_cat(mrb, str, (lit), sizeof(lit) - 1) +#define mrb_str_cat_lit(mrb, str, lit) mrb_str_cat(mrb, str, lit, mrb_strlen_lit(lit)) mrb_value mrb_str_append(mrb_state *mrb, mrb_value str, mrb_value str2); int mrb_str_cmp(mrb_state *mrb, mrb_value str1, mrb_value str2); diff --git a/mrbgems/mruby-random/src/mt19937ar.c b/mrbgems/mruby-random/src/mt19937ar.c index 3de935232..a27aee311 100644 --- a/mrbgems/mruby-random/src/mt19937ar.c +++ b/mrbgems/mruby-random/src/mt19937ar.c @@ -63,7 +63,7 @@ unsigned long mrb_random_genrand_int32(mt_state *t) y ^= (y << 15) & 0xefc60000UL; y ^= (y >> 18); - t->gen_int = y; + t->gen.int_ = y; return y; } @@ -71,8 +71,8 @@ unsigned long mrb_random_genrand_int32(mt_state *t) double mrb_random_genrand_real1(mt_state *t) { mrb_random_genrand_int32(t); - t->gen_dbl = t->gen_int*(1.0/4294967295.0); - return t->gen_dbl; + t->gen.double_ = t->gen.int_*(1.0/4294967295.0); + return t->gen.double_; /* divided by 2^32-1 */ } diff --git a/mrbgems/mruby-random/src/mt19937ar.h b/mrbgems/mruby-random/src/mt19937ar.h index 9bf150190..59027c624 100644 --- a/mrbgems/mruby-random/src/mt19937ar.h +++ b/mrbgems/mruby-random/src/mt19937ar.h @@ -10,9 +10,9 @@ typedef struct { unsigned long mt[N]; int mti; union { - unsigned long gen_int; - double gen_dbl; - }; + unsigned long int_; + double double_; + } gen; mrb_int seed; mrb_bool has_seed : 1; diff --git a/mrbgems/mruby-struct/src/struct.c b/mrbgems/mruby-struct/src/struct.c index 02b842e53..646414f0c 100644 --- a/mrbgems/mruby-struct/src/struct.c +++ b/mrbgems/mruby-struct/src/struct.c @@ -381,7 +381,7 @@ mrb_struct_s_def(mrb_state *mrb, mrb_value klass) } st = make_struct(mrb, name, rest, struct_class(mrb)); if (!mrb_nil_p(b)) { - mrb_funcall(mrb, b, "call", 1, &st); + mrb_funcall(mrb, b, "call", 1, st); } return st; diff --git a/src/debug.c b/src/debug.c index cdb0aa9e8..1a3dc275d 100644 --- a/src/debug.c +++ b/src/debug.c @@ -74,11 +74,11 @@ mrb_debug_get_line(mrb_irep *irep, uint32_t pc) switch(f->line_type) { case mrb_debug_line_ary: mrb_assert(f->start_pos <= pc && pc < (f->start_pos + f->line_entry_count)); - return f->line_ary[pc - f->start_pos]; + return f->lines.ary[pc - f->start_pos]; case mrb_debug_line_flat_map: { /* get upper bound */ - mrb_irep_debug_info_line *ret = f->line_flat_map; + mrb_irep_debug_info_line *ret = f->lines.flat_map; uint32_t count = f->line_entry_count; while (count > 0) { int32_t step = count / 2; @@ -92,10 +92,10 @@ mrb_debug_get_line(mrb_irep *irep, uint32_t pc) --ret; /* check line entry pointer range */ - mrb_assert(f->line_flat_map <= ret && ret < (f->line_flat_map + f->line_entry_count)); + mrb_assert(f->lines.flat_map <= ret && ret < (f->lines.flat_map + f->line_entry_count)); /* check pc range */ mrb_assert(ret->start_pos <= pc && - pc < (((ret + 1 - f->line_flat_map) < f->line_entry_count) + pc < (((ret + 1 - f->lines.flat_map) < f->line_entry_count) ? (ret+1)->start_pos : irep->debug_info->pc_count)); return ret->line; @@ -160,31 +160,31 @@ mrb_debug_info_append_file(mrb_state *mrb, mrb_irep *irep, ret->filename = mrb_sym2name_len(mrb, ret->filename_sym, &len); ret->line_type = select_line_type(irep->lines + start_pos, end_pos - start_pos); - ret->line_ptr = NULL; + ret->lines.ptr = NULL; switch(ret->line_type) { case mrb_debug_line_ary: ret->line_entry_count = file_pc_count; - ret->line_ary = (uint16_t*)mrb_malloc(mrb, sizeof(uint16_t) * file_pc_count); + ret->lines.ary = (uint16_t*)mrb_malloc(mrb, sizeof(uint16_t) * file_pc_count); for(i = 0; i < file_pc_count; ++i) { - ret->line_ary[i] = irep->lines[start_pos + i]; + ret->lines.ary[i] = irep->lines[start_pos + i]; } break; case mrb_debug_line_flat_map: { uint16_t prev_line = 0; mrb_irep_debug_info_line m; - ret->line_flat_map = (mrb_irep_debug_info_line*)mrb_malloc(mrb, sizeof(mrb_irep_debug_info_line) * 1); + ret->lines.flat_map = (mrb_irep_debug_info_line*)mrb_malloc(mrb, sizeof(mrb_irep_debug_info_line) * 1); ret->line_entry_count = 0; for(i = 0; i < file_pc_count; ++i) { if(irep->lines[start_pos + i] == prev_line) { continue; } - ret->line_flat_map = (mrb_irep_debug_info_line*)mrb_realloc( - mrb, ret->line_flat_map, + ret->lines.flat_map = (mrb_irep_debug_info_line*)mrb_realloc( + mrb, ret->lines.flat_map, sizeof(mrb_irep_debug_info_line) * (ret->line_entry_count + 1)); m.start_pos = start_pos + i; m.line = irep->lines[start_pos + i]; - ret->line_flat_map[ret->line_entry_count] = m; + ret->lines.flat_map[ret->line_entry_count] = m; /* update */ ++ret->line_entry_count; @@ -207,7 +207,7 @@ mrb_debug_info_free(mrb_state *mrb, mrb_irep_debug_info *d) for(i = 0; i < d->flen; ++i) { mrb_assert(d->files[i]); - mrb_free(mrb, d->files[i]->line_ptr); + mrb_free(mrb, d->files[i]->lines.ptr); mrb_free(mrb, d->files[i]); } mrb_free(mrb, d->files); diff --git a/src/dump.c b/src/dump.c index b9e02fe77..1854f7964 100644 --- a/src/dump.c +++ b/src/dump.c @@ -6,6 +6,7 @@ #include <ctype.h> #include <string.h> +#include <limits.h> #include "mruby/dump.h" #include "mruby/string.h" #include "mruby/irep.h" @@ -578,15 +579,15 @@ write_debug_record_1(mrb_state *mrb, mrb_irep *irep, uint8_t *bin, mrb_sym const case mrb_debug_line_ary: { uint32_t l; for (l = 0; l < file->line_entry_count; ++l) { - cur += uint16_to_bin(file->line_ary[l], cur); + cur += uint16_to_bin(file->lines.ary[l], cur); } } break; case mrb_debug_line_flat_map: { uint32_t line; for (line = 0; line < file->line_entry_count; ++line) { - cur += uint32_to_bin(file->line_flat_map[line].start_pos, cur); - cur += uint16_to_bin(file->line_flat_map[line].line, cur); + cur += uint32_to_bin(file->lines.flat_map[line].start_pos, cur); + cur += uint16_to_bin(file->lines.flat_map[line].line, cur); } } break; diff --git a/src/hash.c b/src/hash.c index 9fbec3fd8..86ad4c63d 100644 --- a/src/hash.c +++ b/src/hash.c @@ -18,7 +18,7 @@ mrb_hash_ht_hash_func(mrb_state *mrb, mrb_value key) khint_t h = (khint_t)mrb_type(key) << 24; mrb_value h2; - h2 = mrb_funcall(mrb, key, "hash", 0, 0); + h2 = mrb_funcall(mrb, key, "hash", 0); h ^= h2.value.i; return h; } diff --git a/src/load.c b/src/load.c index aa39efba4..5762cf2a2 100644 --- a/src/load.c +++ b/src/load.c @@ -324,9 +324,9 @@ read_debug_record(mrb_state *mrb, const uint8_t *start, mrb_irep* irep, size_t * case mrb_debug_line_ary: { uint32_t l; - file->line_ary = (uint16_t *)mrb_malloc(mrb, sizeof(uint16_t) * (size_t)(file->line_entry_count)); + file->lines.ary = (uint16_t *)mrb_malloc(mrb, sizeof(uint16_t) * (size_t)(file->line_entry_count)); for(l = 0; l < file->line_entry_count; ++l) { - file->line_ary[l] = bin_to_uint16(bin); + file->lines.ary[l] = bin_to_uint16(bin); bin += sizeof(uint16_t); } } break; @@ -334,12 +334,12 @@ read_debug_record(mrb_state *mrb, const uint8_t *start, mrb_irep* irep, size_t * case mrb_debug_line_flat_map: { uint32_t l; - file->line_flat_map = (mrb_irep_debug_info_line*)mrb_malloc( + file->lines.flat_map = (mrb_irep_debug_info_line*)mrb_malloc( mrb, sizeof(mrb_irep_debug_info_line) * (size_t)(file->line_entry_count)); for(l = 0; l < file->line_entry_count; ++l) { - file->line_flat_map[l].start_pos = bin_to_uint32(bin); + file->lines.flat_map[l].start_pos = bin_to_uint32(bin); bin += sizeof(uint32_t); - file->line_flat_map[l].line = bin_to_uint16(bin); + file->lines.flat_map[l].line = bin_to_uint16(bin); bin += sizeof(uint16_t); } } break; diff --git a/src/object.c b/src/object.c index a2e18c807..5090e38cf 100644 --- a/src/object.c +++ b/src/object.c @@ -588,7 +588,7 @@ mrb_Float(mrb_state *mrb, mrb_value val) mrb_value mrb_inspect(mrb_state *mrb, mrb_value obj) { - return mrb_obj_as_string(mrb, mrb_funcall(mrb, obj, "inspect", 0, 0)); + return mrb_obj_as_string(mrb, mrb_funcall(mrb, obj, "inspect", 0)); } mrb_bool diff --git a/src/parse.y b/src/parse.y index b82b3e271..c3460555d 100644 --- a/src/parse.y +++ b/src/parse.y @@ -3526,8 +3526,8 @@ static int scan_hex(const int *start, int len, int *retlen) { static const char hexdigit[] = "0123456789abcdef0123456789ABCDEF"; - register const int *s = start; - register int retval = 0; + const int *s = start; + int retval = 0; char *tmp; /* mrb_assert(len <= 2) */ @@ -3932,7 +3932,7 @@ arg_ambiguous(parser_state *p) static int parser_yylex(parser_state *p) { - register int c; + int c; int space_seen = 0; int cmd_state; enum mrb_lex_state_enum last_state; diff --git a/tasks/mrbgems_test.rake b/tasks/mrbgems_test.rake index c66db9bdd..4c27686f2 100644 --- a/tasks/mrbgems_test.rake +++ b/tasks/mrbgems_test.rake @@ -93,8 +93,7 @@ MRuby.each_target do f.puts %Q[ val2 = mrb_ary_shift(mrb2, ary2);] f.puts %Q[ ] f.puts %Q[ while (mrb_test(val2)) {] - f.puts %Q[ char *str = mrb_string_value_cstr(mrb2, &val2);] - f.puts %Q[ mrb_ary_push(mrb, ary1, mrb_str_new_cstr(mrb, str));] + f.puts %Q[ mrb_ary_push(mrb, ary1, mrb_str_new(mrb, RSTRING_PTR(val2), RSTRING_LEN(val2)));] f.puts %Q[ val2 = mrb_ary_shift(mrb2, ary2);] f.puts %Q[ }] f.puts %Q[ }] |
