mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Merge remote-tracking branch 'upstream/master'
This commit is contained in:
@@ -11,3 +11,6 @@ Original Authors "mruby developers" are:
|
||||
Masaki Muranaka
|
||||
Internet Initiative Japan Inc.
|
||||
Tadashi FUKUZAWA
|
||||
MATSUMOTO Ryosuke
|
||||
Yasuhiro Matsumoto
|
||||
Koji Yoshioka
|
||||
|
||||
@@ -15,9 +15,9 @@ MRuby::CrossBuild.new("Arduino Due") do |conf|
|
||||
|
||||
conf.cc do |cc|
|
||||
cc.command = "#{BIN_PATH}/arm-none-eabi-gcc"
|
||||
cc.include_paths << ["#{SAM_PATH}/system/libsam -I#{SAM_PATH}/system/CMSIS/CMSIS/Include/",
|
||||
cc.include_paths << ["#{SAM_PATH}/system/libsam", "#{SAM_PATH}/system/CMSIS/CMSIS/Include/",
|
||||
"#{SAM_PATH}/system/CMSIS/Device/ATMEL/",
|
||||
"#{SAM_PATH}/cores/arduino -I#{TARGET_PATH}"]
|
||||
"#{SAM_PATH}/cores/arduino", "#{SAM_PATH}/libraries","#{TARGET_PATH}"]
|
||||
cc.flags = %w(-g -Os -w -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500
|
||||
-Dprintf=iprintf -mcpu=cortex-m3 -DF_CPU=84000000L -DARDUINO=152 -D__SAM3X8E__ -mthumb -DUSB_PID=0x003e -DUSB_VID=0x2341 -DUSBCON)
|
||||
cc.compile_options = "%{flags} -o %{outfile} -c %{infile}"
|
||||
|
||||
+16
-13
@@ -73,15 +73,15 @@ enum mrb_fiber_state {
|
||||
struct mrb_context {
|
||||
struct mrb_context *prev;
|
||||
|
||||
mrb_value *stack;
|
||||
mrb_value *stack; /* stack of virtual machine */
|
||||
mrb_value *stbase, *stend;
|
||||
|
||||
mrb_callinfo *ci;
|
||||
mrb_callinfo *cibase, *ciend;
|
||||
|
||||
mrb_code **rescue;
|
||||
mrb_code **rescue; /* exception handler stack */
|
||||
int rsize;
|
||||
struct RProc **ensure;
|
||||
struct RProc **ensure; /* ensure handler stack */
|
||||
int esize;
|
||||
|
||||
uint8_t status;
|
||||
@@ -97,19 +97,19 @@ enum gc_state {
|
||||
typedef struct mrb_state {
|
||||
void *jmp;
|
||||
|
||||
mrb_allocf allocf;
|
||||
mrb_allocf allocf; /* memory allocation function */
|
||||
|
||||
struct mrb_context *c;
|
||||
struct mrb_context *root_c;
|
||||
|
||||
struct RObject *exc;
|
||||
struct iv_tbl *globals;
|
||||
struct mrb_irep **irep;
|
||||
struct RObject *exc; /* exception */
|
||||
struct iv_tbl *globals; /* global variable table */
|
||||
struct mrb_irep **irep; /* program data array */
|
||||
size_t irep_len, irep_capa;
|
||||
|
||||
mrb_sym init_sym;
|
||||
struct RObject *top_self;
|
||||
struct RClass *object_class;
|
||||
struct RClass *object_class; /* Object class */
|
||||
struct RClass *class_class;
|
||||
struct RClass *module_class;
|
||||
struct RClass *proc_class;
|
||||
@@ -125,11 +125,11 @@ typedef struct mrb_state {
|
||||
struct RClass *symbol_class;
|
||||
struct RClass *kernel_module;
|
||||
|
||||
struct heap_page *heaps;
|
||||
struct heap_page *heaps; /* heaps for GC */
|
||||
struct heap_page *sweeps;
|
||||
struct heap_page *free_heaps;
|
||||
size_t live; /* count of live objects */
|
||||
struct RBasic *arena[MRB_ARENA_SIZE];
|
||||
struct RBasic *arena[MRB_ARENA_SIZE]; /* GC protection array */
|
||||
int arena_idx;
|
||||
|
||||
enum gc_state gc_state; /* state of gc */
|
||||
@@ -178,6 +178,7 @@ struct RClass * mrb_class_new(mrb_state *mrb, struct RClass *super);
|
||||
struct RClass * mrb_module_new(mrb_state *mrb);
|
||||
int mrb_class_defined(mrb_state *mrb, const char *name);
|
||||
struct RClass * mrb_class_get(mrb_state *mrb, const char *name);
|
||||
struct RClass * mrb_class_get_under(mrb_state *mrb, struct RClass *outer, const char *name);
|
||||
|
||||
mrb_value mrb_obj_dup(mrb_state *mrb, mrb_value obj);
|
||||
mrb_value mrb_check_to_integer(mrb_state *mrb, mrb_value val, const char *method);
|
||||
@@ -239,9 +240,11 @@ mrb_sym mrb_intern(mrb_state *mrb,const char *cstr)
|
||||
return mrb_intern_cstr(mrb, cstr);
|
||||
}
|
||||
|
||||
void *mrb_malloc(mrb_state*, size_t);
|
||||
void *mrb_calloc(mrb_state*, size_t, size_t);
|
||||
void *mrb_realloc(mrb_state*, void*, size_t);
|
||||
void *mrb_malloc(mrb_state*, size_t); /* raise RuntimeError if no mem */
|
||||
void *mrb_calloc(mrb_state*, size_t, size_t); /* ditto */
|
||||
void *mrb_realloc(mrb_state*, void*, size_t); /* ditto */
|
||||
void *mrb_realloc_simple(mrb_state*, void*, size_t); /* return NULL if no memory available */
|
||||
void *mrb_malloc_simple(mrb_state*, size_t); /* return NULL if no memory available */
|
||||
struct RBasic *mrb_obj_alloc(mrb_state*, enum mrb_vtype, struct RClass*);
|
||||
void mrb_free(mrb_state*, void*);
|
||||
|
||||
|
||||
+22
-16
@@ -51,23 +51,29 @@
|
||||
typedef short mrb_sym;
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# define _ALLOW_KEYWORD_MACROS
|
||||
# include <float.h>
|
||||
# define inline __inline
|
||||
# ifndef __cplusplus
|
||||
# define inline __inline
|
||||
# endif
|
||||
# define snprintf _snprintf
|
||||
# define isnan _isnan
|
||||
# define isinf(n) (!_finite(n) && !_isnan(n))
|
||||
# define strtoll _strtoi64
|
||||
# define PRId32 "I32d"
|
||||
# define PRIi32 "I32i"
|
||||
# define PRIo32 "I32o"
|
||||
# define PRIx32 "I32x"
|
||||
# define PRIX32 "I32X"
|
||||
# define PRId64 "I64d"
|
||||
# define PRIi64 "I64i"
|
||||
# define PRIo64 "I64o"
|
||||
# define PRIx64 "I64x"
|
||||
# define PRIX64 "I64X"
|
||||
# if _MSC_VER < 1800
|
||||
# include <float.h>
|
||||
# define isnan _isnan
|
||||
# define isinf(n) (!_finite(n) && !_isnan(n))
|
||||
# define strtoll _strtoi64
|
||||
# define strtof (float)strtod
|
||||
# define PRId32 "I32d"
|
||||
# define PRIi32 "I32i"
|
||||
# define PRIo32 "I32o"
|
||||
# define PRIx32 "I32x"
|
||||
# define PRIX32 "I32X"
|
||||
# define PRId64 "I64d"
|
||||
# define PRIi64 "I64i"
|
||||
# define PRIo64 "I64o"
|
||||
# define PRIx64 "I64x"
|
||||
# define PRIX64 "I64X"
|
||||
# else
|
||||
# include <inttypes.h>
|
||||
# endif
|
||||
#else
|
||||
# include <inttypes.h>
|
||||
#endif
|
||||
|
||||
@@ -317,6 +317,8 @@ class RakeApp
|
||||
"Require MODULE before executing rakefile."],
|
||||
['--tasks', '-T', GetoptLong::NO_ARGUMENT,
|
||||
"Display the tasks and dependencies, then exit."],
|
||||
['--pull_gems','-p', GetoptLong::NO_ARGUMENT,
|
||||
"Pull all git mrbgems."],
|
||||
['--trace', '-t', GetoptLong::NO_ARGUMENT,
|
||||
"Turn on invoke/execute tracing."],
|
||||
['--usage', '-h', GetoptLong::NO_ARGUMENT,
|
||||
@@ -401,6 +403,8 @@ class RakeApp
|
||||
require value
|
||||
when '--tasks'
|
||||
$show_tasks = true
|
||||
when '--pull_gems'
|
||||
$pull_gems = true
|
||||
when '--trace'
|
||||
$trace = true
|
||||
when '--usage'
|
||||
@@ -419,6 +423,7 @@ class RakeApp
|
||||
# Read and handle the command line options.
|
||||
def handle_options
|
||||
$verbose = false
|
||||
$pull_gems = false
|
||||
opts = GetoptLong.new(*command_line_options)
|
||||
opts.each { |opt, value| do_option(opt, value) }
|
||||
end
|
||||
|
||||
@@ -41,6 +41,9 @@ MRuby::GemBox.new do |conf|
|
||||
# Use Random class
|
||||
conf.gem :core => "mruby-random"
|
||||
|
||||
# Use extensional Object class
|
||||
conf.gem :core => "mruby-object-ext"
|
||||
|
||||
# Use ObjectSpace class
|
||||
conf.gem :core => "mruby-objectspace"
|
||||
|
||||
|
||||
@@ -12,8 +12,8 @@
|
||||
#define domain_error(msg) \
|
||||
mrb_raise(mrb, E_RANGE_ERROR, "Numerical argument is out of domain - " #msg)
|
||||
|
||||
/* math functions not provided under Microsoft Visual C++ */
|
||||
#ifdef _MSC_VER
|
||||
/* math functions not provided by Microsoft Visual C++ 2012 or older */
|
||||
#if defined _MSC_VER && _MSC_VER < 1800
|
||||
|
||||
#define MATH_TOLERANCE 1E-12
|
||||
|
||||
@@ -87,6 +87,12 @@ erfc(double x)
|
||||
return one_sqrtpi*exp(-x*x)*q2;
|
||||
}
|
||||
|
||||
double
|
||||
log2(double x)
|
||||
{
|
||||
return log10(x)/log10(2.0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
@@ -358,18 +364,6 @@ math_atanh(mrb_state *mrb, mrb_value obj)
|
||||
# define log10(x) ((x) < 0.0 ? nan("") : log10(x))
|
||||
#endif
|
||||
|
||||
#ifndef log2
|
||||
#ifndef HAVE_LOG2
|
||||
double
|
||||
log2(double x)
|
||||
{
|
||||
return log10(x)/log10(2.0);
|
||||
}
|
||||
#else
|
||||
extern double log2(double);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* Math.exp(x) -> float
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
MRuby::Gem::Specification.new('mruby-object-ext') do |spec|
|
||||
spec.license = 'MIT'
|
||||
spec.authors = 'mruby developers'
|
||||
end
|
||||
@@ -0,0 +1,108 @@
|
||||
#include "mruby.h"
|
||||
#include "mruby/array.h"
|
||||
#include "mruby/class.h"
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* nil.to_a -> []
|
||||
*
|
||||
* Always returns an empty array.
|
||||
*/
|
||||
|
||||
static mrb_value
|
||||
nil_to_a(mrb_state *mrb, mrb_value obj)
|
||||
{
|
||||
return mrb_ary_new(mrb);
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* nil.to_f -> 0.0
|
||||
*
|
||||
* Always returns zero.
|
||||
*/
|
||||
|
||||
static mrb_value
|
||||
nil_to_f(mrb_state *mrb, mrb_value obj)
|
||||
{
|
||||
return mrb_float_value(mrb, 0.0);
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* nil.to_i -> 0
|
||||
*
|
||||
* Always returns zero.
|
||||
*/
|
||||
|
||||
static mrb_value
|
||||
nil_to_i(mrb_state *mrb, mrb_value obj)
|
||||
{
|
||||
return mrb_fixnum_value(0);
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* obj.instance_exec(arg...) {|var...| block } -> obj
|
||||
*
|
||||
* Executes the given block within the context of the receiver
|
||||
* (_obj_). In order to set the context, the variable +self+ is set
|
||||
* to _obj_ while the code is executing, giving the code access to
|
||||
* _obj_'s instance variables. Arguments are passed as block parameters.
|
||||
*
|
||||
* class KlassWithSecret
|
||||
* def initialize
|
||||
* @secret = 99
|
||||
* end
|
||||
* end
|
||||
* k = KlassWithSecret.new
|
||||
* k.instance_exec(5) {|x| @secret+x } #=> 104
|
||||
*/
|
||||
|
||||
mrb_value
|
||||
mrb_yield_internal(mrb_state *mrb, mrb_value b, int argc, mrb_value *argv, mrb_value self, struct RClass *c);
|
||||
|
||||
static mrb_value
|
||||
mrb_obj_instance_exec(mrb_state *mrb, mrb_value self)
|
||||
{
|
||||
mrb_value *argv;
|
||||
int argc;
|
||||
mrb_value blk;
|
||||
struct RClass *c;
|
||||
|
||||
mrb_get_args(mrb, "*&", &argv, &argc, &blk);
|
||||
|
||||
if (mrb_nil_p(blk)) {
|
||||
mrb_raise(mrb, E_ARGUMENT_ERROR, "no block given");
|
||||
}
|
||||
|
||||
switch (mrb_type(self)) {
|
||||
case MRB_TT_SYMBOL:
|
||||
case MRB_TT_FIXNUM:
|
||||
case MRB_TT_FLOAT:
|
||||
c = 0;
|
||||
break;
|
||||
default:
|
||||
c = mrb_class_ptr(mrb_singleton_class(mrb, self));
|
||||
break;
|
||||
}
|
||||
|
||||
return mrb_yield_internal(mrb, blk, argc, argv, self, c);
|
||||
}
|
||||
|
||||
void
|
||||
mrb_mruby_object_ext_gem_init(mrb_state* mrb)
|
||||
{
|
||||
struct RClass * n = mrb->nil_class;
|
||||
|
||||
mrb_define_method(mrb, n, "to_a", nil_to_a, MRB_ARGS_NONE());
|
||||
mrb_define_method(mrb, n, "to_f", nil_to_f, MRB_ARGS_NONE());
|
||||
mrb_define_method(mrb, n, "to_i", nil_to_i, MRB_ARGS_NONE());
|
||||
|
||||
mrb_define_method(mrb, mrb->object_class, "instance_exec", mrb_obj_instance_exec, MRB_ARGS_ANY() | MRB_ARGS_BLOCK());
|
||||
}
|
||||
|
||||
void
|
||||
mrb_mruby_object_ext_gem_final(mrb_state* mrb)
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
assert('NilClass#to_a') do
|
||||
assert_equal nil.to_a, []
|
||||
end
|
||||
|
||||
assert('NilClass#to_f') do
|
||||
assert_equal nil.to_f, 0.0
|
||||
end
|
||||
|
||||
assert('NilClass#to_i') do
|
||||
assert_equal nil.to_i, 0
|
||||
end
|
||||
@@ -0,0 +1,9 @@
|
||||
assert('Object#instance_exec') do
|
||||
class KlassWithSecret
|
||||
def initialize
|
||||
@secret = 99
|
||||
end
|
||||
end
|
||||
k = KlassWithSecret.new
|
||||
assert_equal k.instance_exec(5) {|x| @secret+x }, 104
|
||||
end
|
||||
@@ -15,10 +15,6 @@
|
||||
#include <math.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#include <float.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_IEEEFP_H
|
||||
#include <ieeefp.h>
|
||||
#endif
|
||||
|
||||
@@ -185,8 +185,7 @@ static mrb_value
|
||||
mrb_struct_set(mrb_state *mrb, mrb_value obj, mrb_value val)
|
||||
{
|
||||
const char *name;
|
||||
int i;
|
||||
size_t len;
|
||||
size_t i, len;
|
||||
mrb_sym mid;
|
||||
mrb_value members, slot, *ptr, *ptr_members;
|
||||
|
||||
|
||||
+19
-44
@@ -1056,39 +1056,26 @@ static mrb_value
|
||||
mrb_ary_equal(mrb_state *mrb, mrb_value ary1)
|
||||
{
|
||||
mrb_value ary2;
|
||||
mrb_bool equal_p;
|
||||
mrb_int i;
|
||||
|
||||
mrb_get_args(mrb, "o", &ary2);
|
||||
if (mrb_obj_equal(mrb, ary1, ary2)) {
|
||||
equal_p = 1;
|
||||
}
|
||||
else if (mrb_special_const_p(ary2)) {
|
||||
equal_p = 0;
|
||||
}
|
||||
else if (!mrb_array_p(ary2)) {
|
||||
if (mrb_obj_equal(mrb, ary1, ary2)) return mrb_true_value();
|
||||
if (mrb_special_const_p(ary2)) return mrb_false_value();
|
||||
if (!mrb_array_p(ary2)) {
|
||||
if (!mrb_respond_to(mrb, ary2, mrb_intern2(mrb, "to_ary", 6))) {
|
||||
equal_p = 0;
|
||||
return mrb_false_value();
|
||||
}
|
||||
else {
|
||||
equal_p = mrb_equal(mrb, ary2, ary1);
|
||||
return mrb_bool_value(mrb_equal(mrb, ary2, ary1));
|
||||
}
|
||||
}
|
||||
else if (RARRAY_LEN(ary1) != RARRAY_LEN(ary2)) {
|
||||
equal_p = 0;
|
||||
}
|
||||
else {
|
||||
mrb_int i;
|
||||
|
||||
equal_p = 1;
|
||||
for (i=0; i<RARRAY_LEN(ary1); i++) {
|
||||
if (!mrb_equal(mrb, ary_elt(ary1, i), ary_elt(ary2, i))) {
|
||||
equal_p = 0;
|
||||
break;
|
||||
}
|
||||
if (RARRAY_LEN(ary1) != RARRAY_LEN(ary2)) return mrb_false_value();
|
||||
for (i=0; i<RARRAY_LEN(ary1); i++) {
|
||||
if (!mrb_equal(mrb, ary_elt(ary1, i), ary_elt(ary2, i))) {
|
||||
return mrb_false_value();
|
||||
}
|
||||
}
|
||||
|
||||
return mrb_bool_value(equal_p);
|
||||
return mrb_true_value();
|
||||
}
|
||||
|
||||
/* 15.2.12.5.34 (x) */
|
||||
@@ -1104,30 +1091,18 @@ static mrb_value
|
||||
mrb_ary_eql(mrb_state *mrb, mrb_value ary1)
|
||||
{
|
||||
mrb_value ary2;
|
||||
mrb_bool eql_p;
|
||||
mrb_int i;
|
||||
|
||||
mrb_get_args(mrb, "o", &ary2);
|
||||
if (mrb_obj_equal(mrb, ary1, ary2)) {
|
||||
eql_p = 1;
|
||||
}
|
||||
else if (!mrb_array_p(ary2)) {
|
||||
eql_p = 0;
|
||||
}
|
||||
else if (RARRAY_LEN(ary1) != RARRAY_LEN(ary2)) {
|
||||
eql_p = 0;
|
||||
}
|
||||
else {
|
||||
mrb_int i;
|
||||
eql_p = 1;
|
||||
for (i=0; i<RARRAY_LEN(ary1); i++) {
|
||||
if (!mrb_eql(mrb, ary_elt(ary1, i), ary_elt(ary2, i))) {
|
||||
eql_p = 0;
|
||||
break;
|
||||
}
|
||||
if (mrb_obj_equal(mrb, ary1, ary2)) return mrb_true_value();
|
||||
if (!mrb_array_p(ary2)) return mrb_false_value();
|
||||
if (RARRAY_LEN(ary1) != RARRAY_LEN(ary2)) return mrb_false_value();
|
||||
for (i=0; i<RARRAY_LEN(ary1); i++) {
|
||||
if (!mrb_eql(mrb, ary_elt(ary1, i), ary_elt(ary2, i))) {
|
||||
return mrb_false_value();
|
||||
}
|
||||
}
|
||||
|
||||
return mrb_bool_value(eql_p);
|
||||
return mrb_true_value();
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
+25
-19
@@ -159,9 +159,7 @@ mrb_define_class_id(mrb_state *mrb, mrb_sym name, struct RClass *super)
|
||||
struct RClass*
|
||||
mrb_define_class(mrb_state *mrb, const char *name, struct RClass *super)
|
||||
{
|
||||
struct RClass *c;
|
||||
c = mrb_define_class_id(mrb, mrb_intern(mrb, name), super);
|
||||
return c;
|
||||
return mrb_define_class_id(mrb, mrb_intern(mrb, name), super);
|
||||
}
|
||||
|
||||
struct RClass*
|
||||
@@ -227,7 +225,13 @@ class_from_sym(mrb_state *mrb, struct RClass *klass, mrb_sym id)
|
||||
struct RClass *
|
||||
mrb_class_get(mrb_state *mrb, const char *name)
|
||||
{
|
||||
return class_from_sym(mrb, mrb->object_class, mrb_intern(mrb, name));
|
||||
return mrb_class_get_under(mrb, mrb->object_class, name);
|
||||
}
|
||||
|
||||
struct RClass *
|
||||
mrb_class_get_under(mrb_state *mrb, struct RClass *outer, const char *name)
|
||||
{
|
||||
return class_from_sym(mrb, outer, mrb_intern(mrb, name));
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -371,20 +375,22 @@ to_hash(mrb_state *mrb, mrb_value val)
|
||||
|
||||
format specifiers:
|
||||
|
||||
o: Object [mrb_value]
|
||||
S: String [mrb_value]
|
||||
A: Array [mrb_value]
|
||||
H: Hash [mrb_value]
|
||||
s: String [char*,int]
|
||||
z: String [char*]
|
||||
a: Array [mrb_value*,mrb_int]
|
||||
f: Float [mrb_float]
|
||||
i: Integer [mrb_int]
|
||||
b: Boolean [mrb_bool]
|
||||
n: Symbol [mrb_sym]
|
||||
&: Block [mrb_value]
|
||||
*: rest argument [mrb_value*,int]
|
||||
|: optional
|
||||
string mruby type C type note
|
||||
----------------------------------------------------------------------------------------------
|
||||
o: Object [mrb_value]
|
||||
S: String [mrb_value]
|
||||
A: Array [mrb_value]
|
||||
H: Hash [mrb_value]
|
||||
s: String [char*,int] Receive two arguments.
|
||||
z: String [char*] NUL terminated string.
|
||||
a: Array [mrb_value*,mrb_int] Receive two arguments.
|
||||
f: Float [mrb_float]
|
||||
i: Integer [mrb_int]
|
||||
b: Boolean [mrb_bool]
|
||||
n: Symbol [mrb_sym]
|
||||
&: Block [mrb_value]
|
||||
*: rest argument [mrb_value*,int] Receive the rest of the arguments as an array.
|
||||
|: optional Next argument of '|' and later are optional.
|
||||
*/
|
||||
int
|
||||
mrb_get_args(mrb_state *mrb, const char *format, ...)
|
||||
@@ -487,7 +493,7 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
|
||||
if (i < argc) {
|
||||
ss = to_str(mrb, *sp++);
|
||||
s = mrb_str_ptr(ss);
|
||||
if (strlen(s->ptr) != s->len) {
|
||||
if (strlen(s->ptr) < s->len) {
|
||||
mrb_raise(mrb, E_ARGUMENT_ERROR, "String contains NUL");
|
||||
}
|
||||
*ps = s->ptr;
|
||||
|
||||
+6
-6
@@ -59,7 +59,7 @@ typedef struct scope {
|
||||
int icapa;
|
||||
|
||||
mrb_irep *irep;
|
||||
int pcapa;
|
||||
size_t pcapa;
|
||||
int scapa;
|
||||
|
||||
int nlocals;
|
||||
@@ -426,8 +426,7 @@ push_(codegen_scope *s)
|
||||
static inline int
|
||||
new_lit(codegen_scope *s, mrb_value val)
|
||||
{
|
||||
int i;
|
||||
|
||||
size_t i;
|
||||
|
||||
switch (mrb_type(val)) {
|
||||
case MRB_TT_STRING:
|
||||
@@ -462,7 +461,7 @@ new_lit(codegen_scope *s, mrb_value val)
|
||||
static inline int
|
||||
new_msym(codegen_scope *s, mrb_sym sym)
|
||||
{
|
||||
int i, len;
|
||||
size_t i, len;
|
||||
|
||||
len = s->irep->slen;
|
||||
if (len > 256) len = 256;
|
||||
@@ -481,7 +480,7 @@ new_msym(codegen_scope *s, mrb_sym sym)
|
||||
static inline int
|
||||
new_sym(codegen_scope *s, mrb_sym sym)
|
||||
{
|
||||
int i;
|
||||
size_t i;
|
||||
|
||||
for (i=0; i<s->irep->slen; i++) {
|
||||
if (s->irep->syms[i] == sym) return i;
|
||||
@@ -2506,7 +2505,8 @@ codedump(mrb_state *mrb, int n)
|
||||
{
|
||||
#ifdef ENABLE_STDIO
|
||||
mrb_irep *irep = mrb->irep[n];
|
||||
int i, ai;
|
||||
uint32_t i;
|
||||
int ai;
|
||||
mrb_code c;
|
||||
|
||||
if (!irep) return;
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
#include <limits.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
#include <stddef.h>
|
||||
|
||||
// Calculate CRC (CRC-16-CCITT)
|
||||
//
|
||||
|
||||
+4
-5
@@ -334,8 +334,7 @@ static int
|
||||
write_lineno_record(mrb_state *mrb, mrb_irep *irep, uint8_t* bin)
|
||||
{
|
||||
uint8_t *cur = bin;
|
||||
size_t filename_len = 0;
|
||||
int iseq_no;
|
||||
size_t filename_len = 0, iseq_no;
|
||||
|
||||
cur += sizeof(uint32_t); /* record size */
|
||||
|
||||
@@ -365,13 +364,13 @@ write_lineno_record(mrb_state *mrb, mrb_irep *irep, uint8_t* bin)
|
||||
}
|
||||
|
||||
static int
|
||||
mrb_write_section_lineno(mrb_state *mrb, int start_index, uint8_t *bin)
|
||||
mrb_write_section_lineno(mrb_state *mrb, size_t start_index, uint8_t *bin)
|
||||
{
|
||||
int irep_no;
|
||||
size_t irep_no;
|
||||
uint32_t section_size = 0, rlen = 0; /* size of irep record */
|
||||
uint8_t *cur = bin;
|
||||
|
||||
if (mrb == NULL || start_index < 0 || start_index >= mrb->irep_len || bin == NULL) {
|
||||
if (mrb == NULL || start_index >= mrb->irep_len || bin == NULL) {
|
||||
return MRB_DUMP_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
|
||||
@@ -148,29 +148,39 @@ gettimeofday_time(void)
|
||||
|
||||
#define GC_STEP_SIZE 1024
|
||||
|
||||
|
||||
void*
|
||||
mrb_realloc(mrb_state *mrb, void *p, size_t len)
|
||||
mrb_realloc_simple(mrb_state *mrb, void *p, size_t len)
|
||||
{
|
||||
void *p2;
|
||||
|
||||
p2 = (mrb->allocf)(mrb, p, len, mrb->ud);
|
||||
|
||||
if (!p2 && len > 0 && mrb->heaps) {
|
||||
mrb_garbage_collect(mrb);
|
||||
p2 = (mrb->allocf)(mrb, p, len, mrb->ud);
|
||||
}
|
||||
|
||||
return p2;
|
||||
}
|
||||
|
||||
|
||||
void*
|
||||
mrb_realloc(mrb_state *mrb, void *p, size_t len)
|
||||
{
|
||||
void *p2;
|
||||
|
||||
p2 = mrb_realloc_simple(mrb, p, len);
|
||||
if (!p2 && len) {
|
||||
if (mrb->out_of_memory) {
|
||||
/* mrb_panic(mrb); */
|
||||
}
|
||||
else {
|
||||
mrb->out_of_memory = 1;
|
||||
mrb->out_of_memory = TRUE;
|
||||
mrb_raise(mrb, E_RUNTIME_ERROR, "Out of memory");
|
||||
}
|
||||
}
|
||||
else {
|
||||
mrb->out_of_memory = 0;
|
||||
mrb->out_of_memory = FALSE;
|
||||
}
|
||||
|
||||
return p2;
|
||||
@@ -182,6 +192,12 @@ mrb_malloc(mrb_state *mrb, size_t len)
|
||||
return mrb_realloc(mrb, 0, len);
|
||||
}
|
||||
|
||||
void*
|
||||
mrb_malloc_simple(mrb_state *mrb, size_t len)
|
||||
{
|
||||
return mrb_realloc_simple(mrb, 0, len);
|
||||
}
|
||||
|
||||
void*
|
||||
mrb_calloc(mrb_state *mrb, size_t nelem, size_t len)
|
||||
{
|
||||
@@ -614,8 +630,7 @@ obj_free(mrb_state *mrb, struct RBasic *obj)
|
||||
static void
|
||||
root_scan_phase(mrb_state *mrb)
|
||||
{
|
||||
int j;
|
||||
size_t i, e;
|
||||
size_t i, e, j;
|
||||
|
||||
if (!is_minor_gc(mrb)) {
|
||||
mrb->gray_list = 0;
|
||||
|
||||
+8
-16
@@ -145,7 +145,9 @@ mrb_hash_set(mrb_state *mrb, mrb_value hash, mrb_value key, mrb_value val) /* mr
|
||||
k = kh_get(ht, h, key);
|
||||
if (k == kh_end(h)) {
|
||||
/* expand */
|
||||
int ai = mrb_gc_arena_save(mrb);
|
||||
k = kh_put(ht, h, KEY(key));
|
||||
mrb_gc_arena_restore(mrb, ai);
|
||||
}
|
||||
|
||||
kh_value(h, k) = val;
|
||||
@@ -169,7 +171,9 @@ mrb_hash_dup(mrb_state *mrb, mrb_value hash)
|
||||
|
||||
for (k = kh_begin(h); k != kh_end(h); k++) {
|
||||
if (kh_exist(h,k)) {
|
||||
int ai = mrb_gc_arena_save(mrb);
|
||||
ret_k = kh_put(ht, ret_h, KEY(kh_key(h,k)));
|
||||
mrb_gc_arena_restore(mrb, ai);
|
||||
kh_val(ret_h, ret_k) = kh_val(h,k);
|
||||
}
|
||||
}
|
||||
@@ -772,16 +776,9 @@ mrb_value
|
||||
mrb_hash_empty_p(mrb_state *mrb, mrb_value self)
|
||||
{
|
||||
khash_t(ht) *h = RHASH_TBL(self);
|
||||
mrb_bool empty_p;
|
||||
|
||||
if (h) {
|
||||
empty_p = (kh_size(h) == 0);
|
||||
}
|
||||
else {
|
||||
empty_p = 1;
|
||||
}
|
||||
|
||||
return mrb_bool_value(empty_p);
|
||||
if (h) return mrb_bool_value(kh_size(h) == 0);
|
||||
return mrb_true_value();
|
||||
}
|
||||
|
||||
static mrb_value
|
||||
@@ -921,17 +918,12 @@ mrb_hash_has_keyWithKey(mrb_state *mrb, mrb_value hash, mrb_value key)
|
||||
{
|
||||
khash_t(ht) *h = RHASH_TBL(hash);
|
||||
khiter_t k;
|
||||
mrb_bool result;
|
||||
|
||||
if (h) {
|
||||
k = kh_get(ht, h, key);
|
||||
result = (k != kh_end(h));
|
||||
return mrb_bool_value(k != kh_end(h));
|
||||
}
|
||||
else {
|
||||
result = 0;
|
||||
}
|
||||
|
||||
return mrb_bool_value(result);
|
||||
return mrb_false_value();
|
||||
}
|
||||
|
||||
/* 15.2.13.4.13 */
|
||||
|
||||
+7
-9
@@ -187,7 +187,6 @@ read_rite_section_irep(mrb_state *mrb, const uint8_t *bin)
|
||||
{
|
||||
int result;
|
||||
size_t sirep;
|
||||
size_t i;
|
||||
uint32_t len;
|
||||
uint16_t nirep;
|
||||
uint16_t n;
|
||||
@@ -200,14 +199,14 @@ read_rite_section_irep(mrb_state *mrb, const uint8_t *bin)
|
||||
nirep = bin_to_uint16(header->nirep);
|
||||
|
||||
//Read Binary Data Section
|
||||
for (n = 0, i = sirep; n < nirep; n++, i++) {
|
||||
for (n = 0; n < nirep; n++) {
|
||||
result = read_rite_irep_record(mrb, bin, &len);
|
||||
if (result != MRB_DUMP_OK)
|
||||
goto error_exit;
|
||||
bin += len;
|
||||
}
|
||||
|
||||
result = sirep + bin_to_uint16(header->sirep);
|
||||
result = nirep;
|
||||
error_exit:
|
||||
if (result < MRB_DUMP_OK) {
|
||||
irep_free(sirep, mrb);
|
||||
@@ -368,7 +367,7 @@ mrb_read_irep(mrb_state *mrb, const uint8_t *bin)
|
||||
bin += bin_to_uint32(section_header->section_size);
|
||||
} while (memcmp(section_header->section_identify, RITE_BINARY_EOF, sizeof(section_header->section_identify)) != 0);
|
||||
|
||||
return total_nirep;
|
||||
return sirep;
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -464,7 +463,6 @@ read_rite_section_irep_file(mrb_state *mrb, FILE *fp)
|
||||
{
|
||||
int32_t result;
|
||||
size_t sirep;
|
||||
size_t i;
|
||||
uint16_t nirep;
|
||||
uint16_t n;
|
||||
uint32_t len, buf_size;
|
||||
@@ -488,7 +486,7 @@ read_rite_section_irep_file(mrb_state *mrb, FILE *fp)
|
||||
}
|
||||
|
||||
//Read Binary Data Section
|
||||
for (n = 0, i = sirep; n < nirep; n++, i++) {
|
||||
for (n = 0; n < nirep; n++) {
|
||||
void *ptr;
|
||||
|
||||
if (fread(buf, record_header_size, 1, fp) == 0) {
|
||||
@@ -516,7 +514,7 @@ read_rite_section_irep_file(mrb_state *mrb, FILE *fp)
|
||||
goto error_exit;
|
||||
}
|
||||
|
||||
result = sirep + bin_to_uint16(header.sirep);
|
||||
result = nirep;
|
||||
error_exit:
|
||||
if (buf) {
|
||||
mrb_free(mrb, buf);
|
||||
@@ -567,7 +565,7 @@ mrb_read_irep_file(mrb_state *mrb, FILE* fp)
|
||||
fpos = ftell(fp);
|
||||
/* You don't need use SIZE_ERROR as block_size is enough small. */
|
||||
for (i = 0; i < block_fallback_count; i++,block_size >>= 1){
|
||||
buf = mrb_malloc(mrb, block_size);
|
||||
buf = mrb_malloc_simple(mrb, block_size);
|
||||
if (buf) break;
|
||||
}
|
||||
if (!buf) {
|
||||
@@ -614,7 +612,7 @@ mrb_read_irep_file(mrb_state *mrb, FILE* fp)
|
||||
fseek(fp, fpos + section_size, SEEK_SET);
|
||||
} while (memcmp(section_header.section_identify, RITE_BINARY_EOF, sizeof(section_header.section_identify)) != 0);
|
||||
|
||||
return total_nirep;
|
||||
return sirep;
|
||||
}
|
||||
|
||||
mrb_value
|
||||
|
||||
+2
-1
@@ -5,6 +5,7 @@
|
||||
*/
|
||||
|
||||
#include "mruby.h"
|
||||
#include "mruby/array.h"
|
||||
#include "mruby/class.h"
|
||||
#include "mruby/numeric.h"
|
||||
#include "mruby/string.h"
|
||||
@@ -16,7 +17,7 @@ mrb_obj_eq(mrb_state *mrb, mrb_value v1, mrb_value v2)
|
||||
if (mrb_type(v1) != mrb_type(v2)) return FALSE;
|
||||
switch (mrb_type(v1)) {
|
||||
case MRB_TT_TRUE:
|
||||
return 1;
|
||||
return TRUE;
|
||||
|
||||
case MRB_TT_FALSE:
|
||||
case MRB_TT_FIXNUM:
|
||||
|
||||
+8
-6
@@ -3293,7 +3293,7 @@ peek_n(parser_state *p, int c, int n)
|
||||
list = push(list, (node*)(intptr_t)c0);
|
||||
} while(n--);
|
||||
if (p->pb) {
|
||||
p->pb = push(p->pb, (node*)list);
|
||||
p->pb = append(p->pb, (node*)list);
|
||||
}
|
||||
else {
|
||||
p->pb = list;
|
||||
@@ -3620,12 +3620,14 @@ parse_string(parser_state *p)
|
||||
tokadd(p, '\n');
|
||||
}
|
||||
else {
|
||||
pushback(p, c);
|
||||
|
||||
if(type & STR_FUNC_REGEXP)
|
||||
if (type & STR_FUNC_REGEXP) {
|
||||
tokadd(p, '\\');
|
||||
|
||||
tokadd(p, read_escape(p));
|
||||
if (c != -1)
|
||||
tokadd(p, c);
|
||||
} else {
|
||||
pushback(p, c);
|
||||
tokadd(p, read_escape(p));
|
||||
}
|
||||
if (hinf)
|
||||
hinf->line_head = FALSE;
|
||||
}
|
||||
|
||||
+25
-44
@@ -152,30 +152,22 @@ mrb_range_eq(mrb_state *mrb, mrb_value range)
|
||||
struct RRange *rr;
|
||||
struct RRange *ro;
|
||||
mrb_value obj;
|
||||
mrb_bool eq_p;
|
||||
|
||||
mrb_get_args(mrb, "o", &obj);
|
||||
|
||||
if (mrb_obj_equal(mrb, range, obj)) {
|
||||
eq_p = 1;
|
||||
}
|
||||
else if (!mrb_obj_is_instance_of(mrb, obj, mrb_obj_class(mrb, range))) { /* same class? */
|
||||
eq_p = 0;
|
||||
}
|
||||
else {
|
||||
rr = mrb_range_ptr(range);
|
||||
ro = mrb_range_ptr(obj);
|
||||
if (!mrb_obj_equal(mrb, rr->edges->beg, ro->edges->beg) ||
|
||||
!mrb_obj_equal(mrb, rr->edges->end, ro->edges->end) ||
|
||||
rr->excl != ro->excl) {
|
||||
eq_p = 0;
|
||||
}
|
||||
else {
|
||||
eq_p = 1;
|
||||
}
|
||||
if (mrb_obj_equal(mrb, range, obj)) return mrb_true_value();
|
||||
if (!mrb_obj_is_instance_of(mrb, obj, mrb_obj_class(mrb, range))) { /* same class? */
|
||||
return mrb_false_value();
|
||||
}
|
||||
|
||||
return mrb_bool_value(eq_p);
|
||||
rr = mrb_range_ptr(range);
|
||||
ro = mrb_range_ptr(obj);
|
||||
if (!mrb_bool(mrb_funcall(mrb, rr->edges->beg, "==", 1, ro->edges->beg)) ||
|
||||
!mrb_bool(mrb_funcall(mrb, rr->edges->end, "==", 1, ro->edges->end)) ||
|
||||
rr->excl != ro->excl) {
|
||||
return mrb_false_value();
|
||||
}
|
||||
return mrb_true_value();
|
||||
}
|
||||
|
||||
static int
|
||||
@@ -385,34 +377,23 @@ range_eql(mrb_state *mrb, mrb_value range)
|
||||
{
|
||||
mrb_value obj;
|
||||
struct RRange *r, *o;
|
||||
mrb_bool eql_p;
|
||||
|
||||
mrb_get_args(mrb, "o", &obj);
|
||||
if (mrb_obj_equal(mrb, range, obj)) {
|
||||
eql_p = 1;
|
||||
}
|
||||
else if (!mrb_obj_is_kind_of(mrb, obj, RANGE_CLASS)) {
|
||||
eql_p = 0;
|
||||
}
|
||||
else {
|
||||
r = mrb_range_ptr(range);
|
||||
if (mrb_type(obj) != MRB_TT_RANGE) {
|
||||
eql_p = 0;
|
||||
}
|
||||
else {
|
||||
o = mrb_range_ptr(obj);
|
||||
if (!mrb_eql(mrb, r->edges->beg, o->edges->beg) ||
|
||||
!mrb_eql(mrb, r->edges->end, o->edges->end) ||
|
||||
(r->excl != o->excl)) {
|
||||
eql_p = 0;
|
||||
}
|
||||
else {
|
||||
eql_p = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return mrb_bool_value(eql_p);
|
||||
if (mrb_obj_equal(mrb, range, obj)) return mrb_true_value();
|
||||
if (!mrb_obj_is_kind_of(mrb, obj, RANGE_CLASS)) {
|
||||
return mrb_false_value();
|
||||
}
|
||||
if (mrb_type(obj) != MRB_TT_RANGE) return mrb_false_value();
|
||||
|
||||
r = mrb_range_ptr(range);
|
||||
o = mrb_range_ptr(obj);
|
||||
if (!mrb_eql(mrb, r->edges->beg, o->edges->beg) ||
|
||||
!mrb_eql(mrb, r->edges->end, o->edges->end) ||
|
||||
(r->excl != o->excl)) {
|
||||
return mrb_false_value();
|
||||
}
|
||||
return mrb_true_value();
|
||||
}
|
||||
|
||||
/* 15.2.14.4.15(x) */
|
||||
|
||||
@@ -220,19 +220,28 @@ module MRuby
|
||||
|
||||
class Command::Git < Command
|
||||
attr_accessor :flags
|
||||
attr_accessor :clone_options
|
||||
attr_accessor :clone_options, :pull_options
|
||||
|
||||
def initialize(build)
|
||||
super
|
||||
@command = 'git'
|
||||
@flags = []
|
||||
@clone_options = "clone %{flags} %{url} %{dir}"
|
||||
@pull_options = "pull"
|
||||
end
|
||||
|
||||
def run_clone(dir, url, _flags = [])
|
||||
_pp "GIT", url, dir.relative_path
|
||||
_run clone_options, { :flags => [flags, _flags].flatten.join(' '), :url => url, :dir => filename(dir) }
|
||||
end
|
||||
|
||||
def run_pull(dir, url)
|
||||
root = Dir.pwd
|
||||
Dir.chdir dir
|
||||
_pp "GIT PULL", url, dir.relative_path
|
||||
_run pull_options
|
||||
Dir.chdir root
|
||||
end
|
||||
end
|
||||
|
||||
class Command::Mrbc < Command
|
||||
|
||||
@@ -40,13 +40,19 @@ module MRuby
|
||||
elsif params[:git]
|
||||
url = params[:git]
|
||||
gemdir = "build/mrbgems/#{url.match(/([-\w]+)(\.[-\w]+|)$/).to_a[1]}"
|
||||
return gemdir if File.exists?(gemdir)
|
||||
|
||||
options = [params[:options]] || []
|
||||
options << "--branch \"#{params[:branch]}\"" if params[:branch]
|
||||
|
||||
FileUtils.mkdir_p "build/mrbgems"
|
||||
git.run_clone gemdir, url, options
|
||||
if File.exists?(gemdir)
|
||||
if $pull_gems
|
||||
git.run_pull gemdir, url
|
||||
else
|
||||
gemdir
|
||||
end
|
||||
else
|
||||
options = [params[:options]] || []
|
||||
options << "--branch \"#{params[:branch]}\"" if params[:branch]
|
||||
FileUtils.mkdir_p "build/mrbgems"
|
||||
git.run_clone gemdir, url, options
|
||||
end
|
||||
else
|
||||
fail "unknown gem option #{params}"
|
||||
end
|
||||
|
||||
@@ -27,4 +27,3 @@ end
|
||||
assert('NilClass#to_s', '15.2.4.3.5') do
|
||||
assert_equal nil.to_s, ''
|
||||
end
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ end
|
||||
assert('Range#==', '15.2.14.4.1') do
|
||||
assert_true (1..10) == (1..10)
|
||||
assert_false (1..10) == (1..100)
|
||||
assert_true (1..10) == Range.new(1.0, 10.0)
|
||||
end
|
||||
|
||||
assert('Range#===', '15.2.14.4.2') do
|
||||
@@ -72,3 +73,10 @@ assert('Range#member?', '15.2.14.4.11') do
|
||||
assert_true a.member?(5)
|
||||
assert_false a.member?(20)
|
||||
end
|
||||
|
||||
assert('Range#eql?', '15.2.14.4.14') do
|
||||
assert_true (1..10).eql? (1..10)
|
||||
assert_false (1..10).eql? (1..100)
|
||||
assert_false (1..10).eql? (Range.new(1.0, 10.0))
|
||||
assert_false (1..10).eql? "1..10"
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user