diff options
| -rw-r--r-- | include/mruby/boxing_word.h | 4 | ||||
| -rw-r--r-- | include/mruby/string.h | 4 | ||||
| -rw-r--r-- | include/mruby/value.h | 6 | ||||
| -rw-r--r-- | mrbgems/mruby-bin-mruby/bintest/mruby.rb | 11 | ||||
| -rw-r--r-- | mrbgems/mruby-bin-mruby/tools/mruby/mruby.c | 170 | ||||
| -rw-r--r-- | mrbgems/mruby-eval/src/eval.c | 4 | ||||
| -rw-r--r-- | mrbgems/mruby-io/test/mruby_io_test.c | 25 | ||||
| -rw-r--r-- | src/string.c | 2 | ||||
| -rw-r--r-- | src/symbol.c | 16 |
9 files changed, 129 insertions, 113 deletions
diff --git a/include/mruby/boxing_word.h b/include/mruby/boxing_word.h index d763ffaf8..73dffc5ef 100644 --- a/include/mruby/boxing_word.h +++ b/include/mruby/boxing_word.h @@ -43,10 +43,10 @@ enum mrb_special_consts { #define MRB_IMMEDIATE_MASK 0x07 #ifdef MRB_64BIT -#define MRB_SYMBOL_BITSIZE (sizeof(mrb_sym) * CHAR_BIT) +#define MRB_SYMBOL_BIT (sizeof(mrb_sym) * CHAR_BIT) #define MRB_SYMBOL_MAX UINT32_MAX #else -#define MRB_SYMBOL_BITSIZE (sizeof(mrb_sym) * CHAR_BIT - MRB_SYMBOL_SHIFT) +#define MRB_SYMBOL_BIT (sizeof(mrb_sym) * CHAR_BIT - MRB_SYMBOL_SHIFT) #define MRB_SYMBOL_MAX (UINT32_MAX >> MRB_SYMBOL_SHIFT) #endif diff --git a/include/mruby/string.h b/include/mruby/string.h index e5a046073..80b8fbaf8 100644 --- a/include/mruby/string.h +++ b/include/mruby/string.h @@ -115,8 +115,8 @@ MRB_API mrb_int mrb_str_strlen(mrb_state*, struct RString*); #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_EMBED_LEN_BIT 5 +#define MRB_STR_EMBED_LEN_MASK (((1 << MRB_STR_EMBED_LEN_BIT) - 1) << MRB_STR_EMBED_LEN_SHIFT) #define MRB_STR_TYPE_MASK (MRB_STR_POOL - 1) diff --git a/include/mruby/value.h b/include/mruby/value.h index 5a909a5cf..4c1ea098f 100644 --- a/include/mruby/value.h +++ b/include/mruby/value.h @@ -169,9 +169,9 @@ typedef void mrb_value; #include "boxing_no.h" #endif -#if !defined(MRB_SYMBOL_BITSIZE) -#define MRB_SYMBOL_BITSIZE (sizeof(mrb_sym) * CHAR_BIT) -#define MRB_SYMBOL_MAX UINT32_MAX +#if !defined(MRB_SYMBOL_BIT) +#define MRB_SYMBOL_BIT (sizeof(mrb_sym) * CHAR_BIT) +#define MRB_SYMBOL_MAX UINT32_MAX #endif #if INTPTR_MAX < MRB_INT_MAX diff --git a/mrbgems/mruby-bin-mruby/bintest/mruby.rb b/mrbgems/mruby-bin-mruby/bintest/mruby.rb index e032ff79a..df0e991f7 100644 --- a/mrbgems/mruby-bin-mruby/bintest/mruby.rb +++ b/mrbgems/mruby-bin-mruby/bintest/mruby.rb @@ -39,6 +39,11 @@ assert '$0 value' do assert_equal '"-e"', `#{cmd('mruby')} -e #{shellquote('p $0')}`.chomp end +assert 'ARGV value' do + assert_mruby(%{["ab", "cde"]\n}, "", true, %w[-e p(ARGV) ab cde]) + assert_mruby("[]\n", "", true, %w[-e p(ARGV)]) +end + assert('float literal') do script, bin = Tempfile.new('test.rb'), Tempfile.new('test.mrb') File.write script.path, 'p [3.21, 2e308.infinite?, -2e308.infinite?]' @@ -80,10 +85,8 @@ assert('mruby -c option') do end assert('mruby -d option') do - o = `#{cmd('mruby')} -e #{shellquote('p $DEBUG')}` - assert_equal "false\n", o - o = `#{cmd('mruby')} -d -e #{shellquote('p $DEBUG')}` - assert_equal "true\n", o + assert_mruby("false\n", "", true, ["-e", "p $DEBUG"]) + assert_mruby("true\n", "", true, ["-dep $DEBUG"]) end assert('mruby -e option (no code specified)') do diff --git a/mrbgems/mruby-bin-mruby/tools/mruby/mruby.c b/mrbgems/mruby-bin-mruby/tools/mruby/mruby.c index 461e91918..38ebccddc 100644 --- a/mrbgems/mruby-bin-mruby/tools/mruby/mruby.c +++ b/mrbgems/mruby-bin-mruby/tools/mruby/mruby.c @@ -9,18 +9,26 @@ struct _args { FILE *rfp; - char* cmdline; + char *cmdline; mrb_bool fname : 1; mrb_bool mrbfile : 1; mrb_bool check_syntax : 1; mrb_bool verbose : 1; mrb_bool debug : 1; int argc; - char** argv; + char **argv; int libc; char **libv; }; +struct options { + int argc; + char **argv; + char *program; + char *opt; + char short_opt[2]; +}; + static void usage(const char *name) { @@ -44,6 +52,51 @@ usage(const char *name) printf(" %s\n", *p++); } +static void +options_init(struct options *opts, int argc, char **argv) +{ + opts->argc = argc; + opts->argv = argv; + opts->program = *argv; + *opts->short_opt = 0; +} + +static const char * +options_opt(struct options *opts) +{ + if (*opts->short_opt && *++opts->opt) { + short_opt: + opts->short_opt[0] = *opts->opt; + opts->short_opt[1] = 0; + return opts->short_opt; + } + while (++opts->argv, --opts->argc) { + opts->opt = *opts->argv; + if (!opts->opt[0] || opts->opt[0] != '-' || !opts->opt[1]) return NULL; + if (opts->opt[1] == '-') { + opts->opt += 2; + *opts->short_opt = 0; + return opts->opt; + } + else { + ++opts->opt; + goto short_opt; + } + } + return NULL; +} + +static const char * +options_arg(struct options *opts) +{ + if (*opts->short_opt && opts->opt[1]) { + *opts->short_opt = 0; + return opts->opt + 1; + } + --opts->argc, ++opts->argv; + return opts->argc ? *opts->argv : NULL; +} + static char * dup_arg_item(mrb_state *mrb, const char *item) { @@ -56,40 +109,24 @@ dup_arg_item(mrb_state *mrb, const char *item) static int parse_args(mrb_state *mrb, int argc, char **argv, struct _args *args) { - char **origargv = argv; static const struct _args args_zero = { 0 }; + struct options opts[1]; + const char *opt, *item; *args = args_zero; - - for (argc--,argv++; argc > 0; argc--,argv++) { - char *item; - if (argv[0][0] != '-') break; - - if (strlen(*argv) <= 1) { - argc--; argv++; - args->rfp = stdin; - break; - } - - item = argv[0] + 1; - switch (*item++) { - case 'b': + options_init(opts, argc, argv); + while ((opt = options_opt(opts))) { + if (strcmp(opt, "b") == 0) { args->mrbfile = TRUE; - break; - case 'c': + } + else if (strcmp(opt, "c") == 0) { args->check_syntax = TRUE; - break; - case 'd': + } + else if (strcmp(opt, "d") == 0) { args->debug = TRUE; - break; - case 'e': - if (item[0]) { - goto append_cmdline; - } - else if (argc > 1) { - argc--; argv++; - item = argv[0]; -append_cmdline: + } + else if (strcmp(opt, "e") == 0) { + if ((item = options_arg(opts))) { if (!args->cmdline) { args->cmdline = dup_arg_item(mrb, item); } @@ -106,59 +143,60 @@ append_cmdline: } } else { - fprintf(stderr, "%s: No code specified for -e\n", *origargv); + fprintf(stderr, "%s: No code specified for -e\n", opts->program); return EXIT_FAILURE; } - break; - case 'h': - usage(*origargv); + } + else if (strcmp(opt, "h") == 0) { + usage(opts->program); exit(EXIT_SUCCESS); - case 'r': - if (!item[0]) { - if (argc <= 1) { - fprintf(stderr, "%s: No library specified for -r\n", *origargv); - return EXIT_FAILURE; + } + else if (strcmp(opt, "r") == 0) { + if ((item = options_arg(opts))) { + if (args->libc == 0) { + args->libv = (char**)mrb_malloc(mrb, sizeof(char*)); } - argc--; argv++; - item = argv[0]; - } - if (args->libc == 0) { - args->libv = (char**)mrb_malloc(mrb, sizeof(char*)); + else { + args->libv = (char**)mrb_realloc(mrb, args->libv, sizeof(char*) * (args->libc + 1)); + } + args->libv[args->libc++] = dup_arg_item(mrb, item); } else { - args->libv = (char**)mrb_realloc(mrb, args->libv, sizeof(char*) * (args->libc + 1)); + fprintf(stderr, "%s: No library specified for -r\n", opts->program); + return EXIT_FAILURE; } - args->libv[args->libc++] = dup_arg_item(mrb, item); - break; - case 'v': + } + else if (strcmp(opt, "v") == 0) { if (!args->verbose) mrb_show_version(mrb); args->verbose = TRUE; + } + else if (strcmp(opt, "version") == 0) { + mrb_show_version(mrb); + exit(EXIT_SUCCESS); + } + else if (strcmp(opt, "verbose") == 0) { + args->verbose = TRUE; break; - case '-': - if (strcmp((*argv) + 2, "version") == 0) { - mrb_show_version(mrb); - exit(EXIT_SUCCESS); - } - else if (strcmp((*argv) + 2, "verbose") == 0) { - args->verbose = TRUE; - break; - } - else if (strcmp((*argv) + 2, "copyright") == 0) { - mrb_show_copyright(mrb); - exit(EXIT_SUCCESS); - } - default: - fprintf(stderr, "%s: invalid option %s (-h will show valid options)\n", *origargv, *argv); + } + else if (strcmp(opt, "copyright") == 0) { + mrb_show_copyright(mrb); + exit(EXIT_SUCCESS); + } + else { + fprintf(stderr, "%s: invalid option %s%s (-h will show valid options)\n", + opts->program, opt[1] ? "--" : "-", opt); return EXIT_FAILURE; } } - if (args->rfp == NULL && args->cmdline == NULL) { + argc = opts->argc; argv = opts->argv; + if (args->cmdline == NULL) { if (*argv == NULL) args->rfp = stdin; else { - args->rfp = fopen(argv[0], args->mrbfile ? "rb" : "r"); + args->rfp = strcmp(argv[0], "-") == 0 ? + stdin : fopen(argv[0], args->mrbfile ? "rb" : "r"); if (args->rfp == NULL) { - fprintf(stderr, "%s: Cannot open program file: %s\n", *origargv, *argv); + fprintf(stderr, "%s: Cannot open program file: %s\n", opts->program, argv[0]); return EXIT_FAILURE; } args->fname = TRUE; diff --git a/mrbgems/mruby-eval/src/eval.c b/mrbgems/mruby-eval/src/eval.c index c1ddb553a..ca046d88e 100644 --- a/mrbgems/mruby-eval/src/eval.c +++ b/mrbgems/mruby-eval/src/eval.c @@ -110,8 +110,8 @@ patch_irep(mrb_state *mrb, mrb_irep *irep, int bnest, mrb_irep *top) insn = iseq[i]; switch(insn){ case OP_EPUSH: - b = PEEK_S(iseq+i+1); - patch_irep(mrb, irep->reps[b], bnest + 1, top); + a = PEEK_B(iseq+i+1); + patch_irep(mrb, irep->reps[a], bnest + 1, top); break; case OP_LAMBDA: diff --git a/mrbgems/mruby-io/test/mruby_io_test.c b/mrbgems/mruby-io/test/mruby_io_test.c index eb552c41a..f5c55499b 100644 --- a/mrbgems/mruby-io/test/mruby_io_test.c +++ b/mrbgems/mruby-io/test/mruby_io_test.c @@ -177,28 +177,6 @@ mrb_io_test_io_cleanup(mrb_state *mrb, mrb_value self) } static mrb_value -mrb_io_test_file_setup(mrb_state *mrb, mrb_value self) -{ - mrb_value ary = mrb_io_test_io_setup(mrb, self); -#if !defined(_WIN32) && !defined(_WIN64) - if (symlink("/usr/bin", "test-bin") == -1) { - mrb_raise(mrb, E_RUNTIME_ERROR, "can't make a symbolic link"); - } -#endif - - return ary; -} - -static mrb_value -mrb_io_test_file_cleanup(mrb_state *mrb, mrb_value self) -{ - mrb_io_test_io_cleanup(mrb, self); - remove("test-bin"); - - return mrb_nil_value(); -} - -static mrb_value mrb_io_test_mkdtemp(mrb_state *mrb, mrb_value klass) { mrb_value str; @@ -245,9 +223,6 @@ mrb_mruby_io_gem_test(mrb_state* mrb) mrb_define_class_method(mrb, io_test, "io_test_setup", mrb_io_test_io_setup, MRB_ARGS_NONE()); mrb_define_class_method(mrb, io_test, "io_test_cleanup", mrb_io_test_io_cleanup, MRB_ARGS_NONE()); - mrb_define_class_method(mrb, io_test, "file_test_setup", mrb_io_test_file_setup, MRB_ARGS_NONE()); - mrb_define_class_method(mrb, io_test, "file_test_cleanup", mrb_io_test_file_cleanup, MRB_ARGS_NONE()); - mrb_define_class_method(mrb, io_test, "mkdtemp", mrb_io_test_mkdtemp, MRB_ARGS_REQ(1)); mrb_define_class_method(mrb, io_test, "rmdir", mrb_io_test_rmdir, MRB_ARGS_REQ(1)); mrb_define_class_method(mrb, io_test, "win?", mrb_io_win_p, MRB_ARGS_NONE()); diff --git a/src/string.c b/src/string.c index 3399e46a9..dcf338eab 100644 --- a/src/string.c +++ b/src/string.c @@ -2870,7 +2870,7 @@ mrb_init_string(mrb_state *mrb) { struct RClass *s; - mrb_static_assert(RSTRING_EMBED_LEN_MAX < (1 << MRB_STR_EMBED_LEN_BITSIZE), + mrb_static_assert(RSTRING_EMBED_LEN_MAX < (1 << MRB_STR_EMBED_LEN_BIT), "pointer size too big for embedded string"); mrb->string_class = s = mrb_define_class(mrb, "String", mrb->object_class); /* 15.2.10 */ diff --git a/src/symbol.c b/src/symbol.c index a4c453d32..b8d0ea1e7 100644 --- a/src/symbol.c +++ b/src/symbol.c @@ -20,12 +20,12 @@ typedef struct symbol_name { const char *name; } symbol_name; -#define SYMBOL_INLINE_BIT 1 -#define SYMBOL_INLINE_LOWER_BIT 2 -#define SYMBOL_INLINE (1 << (SYMBOL_INLINE_BIT - 1)) -#define SYMBOL_INLINE_LOWER (1 << (SYMBOL_INLINE_LOWER_BIT - 1)) -#define SYMBOL_NORMAL_SHIFT SYMBOL_INLINE_BIT -#define SYMBOL_INLINE_SHIFT SYMBOL_INLINE_LOWER_BIT +#define SYMBOL_INLINE_BIT_POS 1 +#define SYMBOL_INLINE_LOWER_BIT_POS 2 +#define SYMBOL_INLINE (1 << (SYMBOL_INLINE_BIT_POS - 1)) +#define SYMBOL_INLINE_LOWER (1 << (SYMBOL_INLINE_LOWER_BIT_POS - 1)) +#define SYMBOL_NORMAL_SHIFT SYMBOL_INLINE_BIT_POS +#define SYMBOL_INLINE_SHIFT SYMBOL_INLINE_LOWER_BIT_POS #ifdef MRB_ENABLE_ALL_SYMBOLS # define SYMBOL_INLINE_P(sym) FALSE # define SYMBOL_INLINE_LOWER_P(sym) FALSE @@ -50,8 +50,8 @@ static const char pack_table[] = "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRS static mrb_sym sym_inline_pack(const char *name, uint16_t len) { - const int lower_length_max = (MRB_SYMBOL_BITSIZE - 2) / 5; - const int mix_length_max = (MRB_SYMBOL_BITSIZE - 2) / 6; + const int lower_length_max = (MRB_SYMBOL_BIT - 2) / 5; + const int mix_length_max = (MRB_SYMBOL_BIT - 2) / 6; char c; const char *p; |
