summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRyan Scott <[email protected]>2013-07-21 18:18:35 +1000
committerRyan Scott <[email protected]>2013-07-21 18:18:35 +1000
commitfd9cc9938cb5998c2388431c396afe238462c9e2 (patch)
tree0bf823a60f3922b3c92c94e2f79c0bbb31084e06
parent43c0f43f1355c1d421b36f5ede7bb5c3aa6b6dd8 (diff)
parentbc843ed9272d9733cafea7df130134264d15d6d9 (diff)
downloadmruby-fd9cc9938cb5998c2388431c396afe238462c9e2.tar.gz
mruby-fd9cc9938cb5998c2388431c396afe238462c9e2.zip
Merge branch 'master' into attr-perf-fix
-rw-r--r--include/mruby/irep.h5
-rw-r--r--mrbgems/mruby-bin-mirb/tools/mirb/mirb.c28
-rw-r--r--src/array.c4
-rw-r--r--test/t/string.rb4
4 files changed, 35 insertions, 6 deletions
diff --git a/include/mruby/irep.h b/include/mruby/irep.h
index 856b12099..498b58ca3 100644
--- a/include/mruby/irep.h
+++ b/include/mruby/irep.h
@@ -11,10 +11,11 @@
extern "C" {
#endif
+/* Program data array struct */
typedef struct mrb_irep {
uint32_t idx;
- uint16_t nlocals;
- uint16_t nregs;
+ uint16_t nlocals; /* Number of local variables */
+ uint16_t nregs; /* Number of register variables */
uint8_t flags;
mrb_code *iseq;
diff --git a/mrbgems/mruby-bin-mirb/tools/mirb/mirb.c b/mrbgems/mruby-bin-mirb/tools/mirb/mirb.c
index eb7194f30..3111eea8f 100644
--- a/mrbgems/mruby-bin-mirb/tools/mirb/mirb.c
+++ b/mrbgems/mruby-bin-mirb/tools/mirb/mirb.c
@@ -15,11 +15,19 @@
#include <mruby/data.h>
#include <mruby/compile.h>
#ifdef ENABLE_READLINE
+#include <limits.h>
#include <readline/readline.h>
#include <readline/history.h>
#endif
#include <mruby/string.h>
+
+#ifdef ENABLE_READLINE
+static const char *history_file_name = ".mirb_history";
+char history_path[PATH_MAX];
+#endif
+
+
static void
p(mrb_state *mrb, mrb_value obj, int prompt)
{
@@ -245,6 +253,7 @@ main(int argc, char **argv)
int n;
int code_block_open = FALSE;
int ai;
+ char *home = NULL;
/* new interpreter instance */
mrb = mrb_open();
@@ -268,6 +277,21 @@ main(int argc, char **argv)
if (args.verbose) cxt->dump_result = 1;
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) {
#ifndef ENABLE_READLINE
print_cmdline(code_block_open);
@@ -361,5 +385,9 @@ main(int argc, char **argv)
mrbc_context_free(mrb, cxt);
mrb_close(mrb);
+#ifdef ENABLE_READLINE
+ write_history(history_path);
+#endif
+
return 0;
}
diff --git a/src/array.c b/src/array.c
index ed087515a..b5bbdf0fa 100644
--- a/src/array.c
+++ b/src/array.c
@@ -19,7 +19,7 @@
#define ARY_DEFAULT_LEN 4
#define ARY_SHRINK_RATIO 5 /* must be larger than 2 */
#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
ary_elt(mrb_value ary, mrb_int offset)
@@ -40,7 +40,7 @@ ary_new_capa(mrb_state *mrb, mrb_int capa)
if (capa > ARY_MAX_SIZE) {
mrb_raise(mrb, E_ARGUMENT_ERROR, "array size too big");
}
- blen = capa * sizeof(mrb_value) ;
+ blen = capa * sizeof(mrb_value);
if (blen < capa) {
mrb_raise(mrb, E_ARGUMENT_ERROR, "array size too big");
}
diff --git a/test/t/string.rb b/test/t/string.rb
index ddae92d4a..c208835b4 100644
--- a/test/t/string.rb
+++ b/test/t/string.rb
@@ -399,12 +399,12 @@ end
assert('String#to_i', '15.2.10.5.38') do
a = ''.to_i
- b = '123456789'.to_i
+ b = '32143'.to_i
c = 'a'.to_i(16)
d = '100'.to_i(2)
assert_equal a, 0
- assert_equal b, 123456789
+ assert_equal b, 32143
assert_equal c, 10
assert_equal d, 4
end