mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Merge branch 'master' into attr-perf-fix
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
+2
-2
@@ -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");
|
||||
}
|
||||
|
||||
+2
-2
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user