Commit fd9cc993 authored by Ryan Scott's avatar Ryan Scott

Merge branch 'master' into attr-perf-fix

parents 43c0f43f bc843ed9
...@@ -11,10 +11,11 @@ ...@@ -11,10 +11,11 @@
extern "C" { extern "C" {
#endif #endif
/* Program data array struct */
typedef struct mrb_irep { typedef struct mrb_irep {
uint32_t idx; uint32_t idx;
uint16_t nlocals; uint16_t nlocals; /* Number of local variables */
uint16_t nregs; uint16_t nregs; /* Number of register variables */
uint8_t flags; uint8_t flags;
mrb_code *iseq; mrb_code *iseq;
......
...@@ -15,11 +15,19 @@ ...@@ -15,11 +15,19 @@
#include <mruby/data.h> #include <mruby/data.h>
#include <mruby/compile.h> #include <mruby/compile.h>
#ifdef ENABLE_READLINE #ifdef ENABLE_READLINE
#include <limits.h>
#include <readline/readline.h> #include <readline/readline.h>
#include <readline/history.h> #include <readline/history.h>
#endif #endif
#include <mruby/string.h> #include <mruby/string.h>
#ifdef ENABLE_READLINE
static const char *history_file_name = ".mirb_history";
char history_path[PATH_MAX];
#endif
static void static void
p(mrb_state *mrb, mrb_value obj, int prompt) p(mrb_state *mrb, mrb_value obj, int prompt)
{ {
...@@ -245,6 +253,7 @@ main(int argc, char **argv) ...@@ -245,6 +253,7 @@ main(int argc, char **argv)
int n; int n;
int code_block_open = FALSE; int code_block_open = FALSE;
int ai; int ai;
char *home = NULL;
/* new interpreter instance */ /* new interpreter instance */
mrb = mrb_open(); mrb = mrb_open();
...@@ -268,6 +277,21 @@ main(int argc, char **argv) ...@@ -268,6 +277,21 @@ main(int argc, char **argv)
if (args.verbose) cxt->dump_result = 1; if (args.verbose) cxt->dump_result = 1;
ai = mrb_gc_arena_save(mrb); ai = mrb_gc_arena_save(mrb);
#ifdef ENABLE_READLINE
using_history();
home = getenv("HOME");
#ifdef _WIN32
if (!home)
home = getenv("USERPROFILE");
#endif
strcpy(history_path, home);
strcat(history_path, "/");
strcat(history_path, history_file_name);
read_history(history_path);
#endif
while (TRUE) { while (TRUE) {
#ifndef ENABLE_READLINE #ifndef ENABLE_READLINE
print_cmdline(code_block_open); print_cmdline(code_block_open);
...@@ -361,5 +385,9 @@ main(int argc, char **argv) ...@@ -361,5 +385,9 @@ main(int argc, char **argv)
mrbc_context_free(mrb, cxt); mrbc_context_free(mrb, cxt);
mrb_close(mrb); mrb_close(mrb);
#ifdef ENABLE_READLINE
write_history(history_path);
#endif
return 0; return 0;
} }
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
#define ARY_DEFAULT_LEN 4 #define ARY_DEFAULT_LEN 4
#define ARY_SHRINK_RATIO 5 /* must be larger than 2 */ #define ARY_SHRINK_RATIO 5 /* must be larger than 2 */
#define ARY_C_MAX_SIZE (SIZE_MAX / sizeof(mrb_value)) #define ARY_C_MAX_SIZE (SIZE_MAX / sizeof(mrb_value))
#define ARY_MAX_SIZE ((ARY_C_MAX_SIZE < (size_t)MRB_INT_MAX) ? (mrb_int)ARY_C_MAX_SIZE : MRB_INT_MAX) #define ARY_MAX_SIZE ((ARY_C_MAX_SIZE < (size_t)MRB_INT_MAX) ? (mrb_int)ARY_C_MAX_SIZE : MRB_INT_MAX-1)
static inline mrb_value static inline mrb_value
ary_elt(mrb_value ary, mrb_int offset) ary_elt(mrb_value ary, mrb_int offset)
...@@ -40,7 +40,7 @@ ary_new_capa(mrb_state *mrb, mrb_int capa) ...@@ -40,7 +40,7 @@ ary_new_capa(mrb_state *mrb, mrb_int capa)
if (capa > ARY_MAX_SIZE) { if (capa > ARY_MAX_SIZE) {
mrb_raise(mrb, E_ARGUMENT_ERROR, "array size too big"); mrb_raise(mrb, E_ARGUMENT_ERROR, "array size too big");
} }
blen = capa * sizeof(mrb_value) ; blen = capa * sizeof(mrb_value);
if (blen < capa) { if (blen < capa) {
mrb_raise(mrb, E_ARGUMENT_ERROR, "array size too big"); mrb_raise(mrb, E_ARGUMENT_ERROR, "array size too big");
} }
......
...@@ -399,12 +399,12 @@ end ...@@ -399,12 +399,12 @@ end
assert('String#to_i', '15.2.10.5.38') do assert('String#to_i', '15.2.10.5.38') do
a = ''.to_i a = ''.to_i
b = '123456789'.to_i b = '32143'.to_i
c = 'a'.to_i(16) c = 'a'.to_i(16)
d = '100'.to_i(2) d = '100'.to_i(2)
assert_equal a, 0 assert_equal a, 0
assert_equal b, 123456789 assert_equal b, 32143
assert_equal c, 10 assert_equal c, 10
assert_equal d, 4 assert_equal d, 4
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment