mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Merge branch 'master' of git://github.com/mruby/mruby into XCode
This commit is contained in:
+2
-2
@@ -22,10 +22,10 @@ typedef intptr_t mrb_sym;
|
||||
#define readint(p,base) strtol((p),NULL,(base))
|
||||
|
||||
#undef INCLUDE_ENCODING /* not use encoding classes (ascii only) */
|
||||
#define INCLUDE_ENCODING /* use UTF-8 encoding classes */
|
||||
//#define INCLUDE_ENCODING /* use UTF-8 encoding classes */
|
||||
|
||||
#undef INCLUDE_REGEXP /* not use regular expression classes */
|
||||
#define INCLUDE_REGEXP /* use regular expression classes */
|
||||
//#define INCLUDE_REGEXP /* use regular expression classes */
|
||||
|
||||
#ifdef INCLUDE_REGEXP
|
||||
# define INCLUDE_ENCODING /* Regexp depends Encoding */
|
||||
|
||||
+7
-88
@@ -341,8 +341,9 @@ void *mrb_realloc(mrb_state*, void*, size_t);
|
||||
struct RBasic *mrb_obj_alloc(mrb_state*, enum mrb_vtype, struct RClass*);
|
||||
void *mrb_free(mrb_state*, void*);
|
||||
|
||||
mrb_value mrb_str_new(mrb_state *mrb, const char *p, size_t len); /* mrb_str_new */
|
||||
mrb_value mrb_str_new(mrb_state *mrb, const char *p, int len); /* mrb_str_new */
|
||||
mrb_value mrb_str_new_cstr(mrb_state*, const char*);
|
||||
mrb_value mrb_str_new2(mrb_state *mrb, const char *p);
|
||||
|
||||
mrb_state* mrb_open(void);
|
||||
mrb_state* mrb_open_allocf(mrb_allocf);
|
||||
@@ -415,9 +416,6 @@ mrb_value mrb_check_funcall(mrb_state *mrb, mrb_value recv, mrb_sym mid, int arg
|
||||
#define ISXDIGIT(c) (ISASCII(c) && isxdigit((int)(unsigned char)(c)))
|
||||
#endif
|
||||
|
||||
extern mrb_value mrb_rs;
|
||||
extern mrb_value mrb_default_rs;
|
||||
|
||||
int mrb_block_given_p(void);
|
||||
void mrb_raise(mrb_state *mrb, struct RClass *c, const char *fmt, ...);
|
||||
void rb_raise(struct RClass *c, const char *fmt, ...);
|
||||
@@ -447,16 +445,6 @@ void mrb_bug(const char *fmt, ...);
|
||||
|
||||
#define SYM2ID(x) ((x).value.sym)
|
||||
|
||||
#define CONST_ID_CACHE(mrb, result, str) \
|
||||
{ \
|
||||
static mrb_sym mrb_intern_id_cache;\
|
||||
if (!mrb_intern_id_cache) \
|
||||
mrb_intern_id_cache = mrb_intern(mrb, str); \
|
||||
result mrb_intern_id_cache; \
|
||||
}
|
||||
#define CONST_ID(mrb, var, str) \
|
||||
do CONST_ID_CACHE(mrb, var =, str) while (0)
|
||||
|
||||
#define NUM2CHR_internal(x) (((mrb_type(x) == MRB_TT_STRING)&&(RSTRING_LEN(x)>=1))?\
|
||||
RSTRING_PTR(x)[0]:(char)(mrb_fixnum_number(x)&0xff))
|
||||
#ifdef __GNUC__
|
||||
@@ -471,24 +459,6 @@ NUM2CHR(mrb_value x)
|
||||
*/
|
||||
#define NUM2CHR(x) NUM2CHR_internal(x)
|
||||
#endif
|
||||
mrb_value mrb_io_gets(mrb_state *mrb, mrb_value);
|
||||
mrb_value mrb_io_getbyte(mrb_state *mrb, mrb_value);
|
||||
mrb_value mrb_io_ungetc(mrb_state *, mrb_value, mrb_value);
|
||||
mrb_value mrb_io_ungetbyte(mrb_state *mrb, mrb_value, mrb_value);
|
||||
mrb_value mrb_io_close(mrb_state *mrb, mrb_value);
|
||||
mrb_value mrb_io_flush(mrb_state *mrb, mrb_value);
|
||||
mrb_value mrb_io_eof(mrb_value);
|
||||
mrb_value mrb_io_binmode(mrb_state *mrb, mrb_value);
|
||||
mrb_value mrb_io_ascii8bit_binmode(mrb_value);
|
||||
mrb_value mrb_io_addstr(mrb_state *mrb, mrb_value, mrb_value);
|
||||
mrb_value mrb_io_printf(mrb_state *mrb, int, mrb_value*, mrb_value);
|
||||
mrb_value mrb_io_print(mrb_state *mrb, int, mrb_value*, mrb_value);
|
||||
mrb_value mrb_io_puts(mrb_state *mrb, /*int argc, mrb_value *argv,*/ mrb_value);
|
||||
mrb_value mrb_io_fdopen(int, int, const char*);
|
||||
mrb_value mrb_io_get_io(mrb_state *mrb, mrb_value);
|
||||
mrb_value mrb_file_open(mrb_state *mrb, const char*, const char*);
|
||||
mrb_value mrb_file_open_str(mrb_value, const char*);
|
||||
mrb_value mrb_gets(mrb_state *mrb);
|
||||
|
||||
mrb_value mrb_yield(mrb_state *mrb, mrb_value v, mrb_value blk);
|
||||
mrb_value mrb_yield_argv(mrb_state *mrb, mrb_value b, int argc, mrb_value *argv);
|
||||
@@ -505,61 +475,11 @@ mrb_value mrb_exec_recursive(mrb_state *mrb, mrb_value(*)(mrb_state *, mrb_value
|
||||
#define xfree free
|
||||
#endif
|
||||
|
||||
void mrb_gc(void);
|
||||
#define thread_debug if(0)printf
|
||||
|
||||
#define RUBY_VM 1 /* YARV */
|
||||
#define HAVE_NATIVETHREAD
|
||||
int ruby_native_thread_p(void);
|
||||
|
||||
#define RUBY_EVENT_NONE 0x0000
|
||||
#define RUBY_EVENT_LINE 0x0001
|
||||
#define RUBY_EVENT_CLASS 0x0002
|
||||
#define RUBY_EVENT_END 0x0004
|
||||
#define RUBY_EVENT_CALL 0x0008
|
||||
#define RUBY_EVENT_RETURN 0x0010
|
||||
#define RUBY_EVENT_C_CALL 0x0020
|
||||
#define RUBY_EVENT_C_RETURN 0x0040
|
||||
#define RUBY_EVENT_RAISE 0x0080
|
||||
#define RUBY_EVENT_ALL 0xffff
|
||||
#define RUBY_EVENT_VM 0x10000
|
||||
#define RUBY_EVENT_SWITCH 0x20000
|
||||
#define RUBY_EVENT_COVERAGE 0x40000
|
||||
|
||||
typedef unsigned int mrb_event_flag_t;
|
||||
typedef void (*mrb_event_hook_func_t)(mrb_state *mrb, mrb_event_flag_t, mrb_value data, mrb_value, mrb_sym, mrb_value klass);
|
||||
|
||||
typedef struct mrb_event_hook_struct {
|
||||
mrb_event_flag_t flag;
|
||||
mrb_event_hook_func_t func;
|
||||
mrb_value data;
|
||||
struct mrb_event_hook_struct *next;
|
||||
} mrb_event_hook_t;
|
||||
|
||||
#define RB_EVENT_HOOKS_HAVE_CALLBACK_DATA 1
|
||||
void mrb_add_event_hook(mrb_state *mrb, mrb_event_hook_func_t func, mrb_event_flag_t events,
|
||||
mrb_value data);
|
||||
int mrb_remove_event_hook(mrb_event_hook_func_t func);
|
||||
void mrb_garbage_collect(mrb_state *mrb);
|
||||
void mrb_gc_protect(mrb_state *mrb, mrb_value obj);
|
||||
mrb_value mrb_to_int(mrb_state *mrb, mrb_value val);
|
||||
void mrb_check_type(mrb_state *mrb, mrb_value x, enum mrb_vtype t);
|
||||
|
||||
//#define RUBY_SETJMP(env) ${setjmp_prefix}setjmp(env${setjmp_sigmask+,0})
|
||||
//#define RUBY_LONGJMP(env,val) ${setjmp_prefix}longjmp(env,val)
|
||||
//#define RUBY_JMP_BUF ${setjmp_sigmask+${setjmp_prefix}}jmp_buf
|
||||
#define RUBY_SETJMP(env) __builtin_setjmp(env)
|
||||
#define RUBY_LONGJMP(env,val) __builtin_longjmp(env,1)//(env,val)
|
||||
//#define RUBY_JMP_BUF ${setjmp_sigmask+${setjmp_prefix}}jmp_buf
|
||||
#define select(n, r, w, e, t) select_large_fdset(n, r, w, e, t)
|
||||
|
||||
//int RUBY_SETJMP(mrb_jmpbuf_t env); /* add kusuda */
|
||||
#define ruby_setjmp(env) RUBY_SETJMP(env)
|
||||
#define ruby_longjmp(env,val) RUBY_LONGJMP(env,val)
|
||||
|
||||
#define KHASH 0
|
||||
#define STHASH 1
|
||||
#define BASICHASH 2
|
||||
#define HASH_CLASS_METHOD BASICHASH
|
||||
|
||||
typedef enum call_type {
|
||||
CALL_PUBLIC,
|
||||
CALL_FCALL,
|
||||
@@ -571,8 +491,6 @@ typedef enum call_type {
|
||||
void mrb_cmperr(mrb_state *mrb, mrb_value x, mrb_value y);
|
||||
int mrb_cmpint(mrb_state *mrb, mrb_value val, mrb_value a, mrb_value b);
|
||||
|
||||
#define REALLOC_N(mrb,var,type,n) (var)=(type*)mrb_realloc(mrb, (char*)(var), sizeof(type)*(n))
|
||||
|
||||
#ifndef ANYARGS
|
||||
# ifdef __cplusplus
|
||||
# define ANYARGS ...
|
||||
@@ -585,10 +503,11 @@ const char *mrb_class_name(mrb_state *mrb, struct RClass* klass);
|
||||
void mrb_define_global_const(mrb_state *mrb, const char *name, mrb_value val);
|
||||
|
||||
mrb_value mrb_block_proc(void);
|
||||
int mrb_sourceline(void);
|
||||
void ruby_default_signal(int sig);
|
||||
mrb_value mrb_attr_get(mrb_state *mrb, mrb_value obj, mrb_sym id);
|
||||
|
||||
int mrb_respond_to(mrb_state *mrb, mrb_value obj, mrb_sym mid);
|
||||
int mrb_obj_is_instance_of(mrb_state *mrb, mrb_value obj, struct RClass* c);
|
||||
|
||||
/* memory pool implementation */
|
||||
typedef struct mrb_pool mrb_pool;
|
||||
struct mrb_pool* mrb_pool_open(mrb_state*);
|
||||
|
||||
@@ -32,7 +32,7 @@ void mrb_ary_concat(mrb_state*, mrb_value, mrb_value);
|
||||
mrb_value mrb_ary_splat(mrb_state*, mrb_value);
|
||||
void mrb_ary_push(mrb_state*, mrb_value, mrb_value);
|
||||
mrb_value mrb_ary_pop(mrb_state *mrb, mrb_value ary);
|
||||
mrb_value mrb_ary_new_from_values(mrb_state *mrb, mrb_value *vals, size_t size);
|
||||
mrb_value mrb_ary_new_from_values(mrb_state *mrb, size_t size, mrb_value *vals);
|
||||
mrb_value mrb_ary_aget(mrb_state *mrb, mrb_value self);
|
||||
mrb_value mrb_ary_ref(mrb_state *mrb, mrb_value ary, mrb_int n);
|
||||
void mrb_ary_set(mrb_state *mrb, mrb_value ary, mrb_int n, mrb_value val);
|
||||
|
||||
@@ -74,8 +74,6 @@ struct RClass *mrb_class_outer_module(mrb_state*, struct RClass *);
|
||||
struct RProc *mrb_method_search_vm(mrb_state*, struct RClass**, mrb_sym);
|
||||
struct RProc *mrb_method_search(mrb_state*, struct RClass*, mrb_sym);
|
||||
|
||||
int mrb_respond_to(mrb_state *mrb, mrb_value obj, mrb_sym mid);
|
||||
int mrb_obj_is_instance_of(mrb_state *mrb, mrb_value obj, struct RClass* c);
|
||||
struct RClass* mrb_class_real(struct RClass* cl);
|
||||
|
||||
void mrb_obj_call_init(mrb_state *mrb, mrb_value obj, int argc, mrb_value *argv);
|
||||
|
||||
+5
-52
@@ -21,8 +21,6 @@ extern "C" {
|
||||
|
||||
#define IS_EVSTR(p,e) ((p) < (e) && (*(p) == '$' || *(p) == '@' || *(p) == '{'))
|
||||
|
||||
#define mrb_str_new4 mrb_str_new_frozen
|
||||
|
||||
#define STR_BUF_MIN_SIZE 128
|
||||
|
||||
extern const char mrb_digitmap[];
|
||||
@@ -37,27 +35,11 @@ struct RString {
|
||||
char *buf;
|
||||
};
|
||||
|
||||
extern struct SCOPE {
|
||||
struct RBasic super;
|
||||
mrb_sym *local_tbl;
|
||||
mrb_value *local_vars;
|
||||
int flags;
|
||||
} *ruby_scope;
|
||||
|
||||
struct RVarmap {
|
||||
struct RBasic super;
|
||||
mrb_sym id;
|
||||
mrb_value val;
|
||||
struct RVarmap *next;
|
||||
};
|
||||
extern struct RVarmap *ruby_dyna_vars;
|
||||
|
||||
#define mrb_str_ptr(s) ((struct RString*)((s).value.p))
|
||||
#define RSTRING(s) ((struct RString*)((s).value.p))
|
||||
#define RSTRING_PTR(s) (RSTRING(s)->buf)
|
||||
#define RSTRING_LEN(s) (RSTRING(s)->len)
|
||||
#define RSTRING_CAPA(s) (RSTRING(s)->aux.capa)
|
||||
#define RSTRING_SHARED(s) (RSTRING(s)->aux.shared)
|
||||
#define RSTRING_END(s) (RSTRING(s)->buf + RSTRING(s)->len)
|
||||
|
||||
#define MRB_STR_SHARED 256
|
||||
@@ -73,64 +55,35 @@ void mrb_str_concat(mrb_state*, mrb_value, mrb_value);
|
||||
mrb_value mrb_obj_to_str(mrb_state*, mrb_value);
|
||||
mrb_value mrb_str_plus(mrb_state*, mrb_value, mrb_value);
|
||||
mrb_value mrb_obj_as_string(mrb_state *mrb, mrb_value obj);
|
||||
mrb_value mrb_str_resize(mrb_state *mrb, mrb_value str, size_t len); /* mrb_str_resize */
|
||||
mrb_value mrb_str_resize(mrb_state *mrb, mrb_value str, int len); /* mrb_str_resize */
|
||||
mrb_value mrb_string_value(mrb_state *mrb, mrb_value *ptr); /* StringValue */
|
||||
mrb_value mrb_str_substr(mrb_state *mrb, mrb_value str, mrb_int beg, int len);
|
||||
mrb_value mrb_check_string_type(mrb_state *mrb, mrb_value str);
|
||||
mrb_value mrb_str_buf_new(mrb_state *mrb, size_t capa);
|
||||
mrb_value mrb_str_buf_cat(mrb_state *mrb, mrb_value str, const char *ptr, size_t len);
|
||||
mrb_value str_buf_cat(mrb_state *mrb, mrb_value str, const char *ptr, size_t len);
|
||||
mrb_value mrb_str_buf_new(mrb_state *mrb, int capa);
|
||||
mrb_value mrb_str_buf_cat(mrb_state *mrb, mrb_value str, const char *ptr, int len);
|
||||
|
||||
char *mrb_string_value_cstr(mrb_state *mrb, mrb_value *ptr);
|
||||
char *mrb_string_value_ptr(mrb_state *mrb, mrb_value ptr);
|
||||
mrb_value mrb_str_subseq(mrb_state *mrb, mrb_value str, long beg, long len);
|
||||
size_t mrb_str_sublen(mrb_state *mrb, mrb_value str, long pos);
|
||||
mrb_value mrb_str_size(mrb_state *mrb, mrb_value self);
|
||||
long mrb_str_offset(mrb_state *mrb, mrb_value str, long pos);
|
||||
mrb_value mrb_str_new2(mrb_state *mrb, const char *p);
|
||||
int mrb_str_sublen(mrb_state *mrb, mrb_value str, int pos);
|
||||
int mrb_str_offset(mrb_state *mrb, mrb_value str, int pos);
|
||||
mrb_value mrb_str_dup(mrb_state *mrb, mrb_value str); /* mrb_str_dup */
|
||||
mrb_value mrb_str_new_frozen(mrb_state *mrb, mrb_value orig);
|
||||
mrb_value mrb_lastline_get(mrb_state *mrb);
|
||||
mrb_value mrb_usascii_str_new(mrb_state *mrb, const char *ptr, long len);
|
||||
void mrb_lastline_set(mrb_value val);
|
||||
mrb_value mrb_str_buf_cat_ascii(mrb_state *mrb, mrb_value str, const char *ptr);
|
||||
void mrb_str_modify(mrb_state *mrb, mrb_value str);
|
||||
void mrb_str_set_len(mrb_state *mrb, mrb_value str, long len);
|
||||
mrb_value mrb_str_intern(mrb_state *mrb, mrb_value self);
|
||||
void mrb_str_shared_replace(mrb_state *mrb, mrb_value str, mrb_value str2);
|
||||
mrb_value mrb_str_cat2(mrb_state *mrb, mrb_value str, const char *ptr);
|
||||
mrb_value mrb_str_catf(mrb_state *mrb, mrb_value str, const char *format, ...);
|
||||
mrb_value mrb_str_to_inum(mrb_state *mrb, mrb_value str, int base, int badcheck);
|
||||
double mrb_str_to_dbl(mrb_state *mrb, mrb_value str, int badcheck);
|
||||
mrb_value mrb_str_to_str(mrb_state *mrb, mrb_value str);
|
||||
mrb_value mrb_locale_str_new(mrb_state *mrb, const char *ptr, long len);
|
||||
mrb_value mrb_filesystem_str_new_cstr(mrb_state *mrb, const char *ptr);
|
||||
mrb_int mrb_str_hash(mrb_state *mrb, mrb_value str);
|
||||
int mrb_str_hash_cmp(mrb_state *mrb, mrb_value str1, mrb_value str2);
|
||||
mrb_value str_new3(mrb_state *mrb, struct RClass* klass, mrb_value str);
|
||||
mrb_value mrb_str_buf_append(mrb_state *mrb, mrb_value str, mrb_value str2);
|
||||
void mrb_str_setter(mrb_state *mrb, mrb_value val, mrb_sym id, mrb_value *var);
|
||||
int mrb_str_is_ascii_only_p(mrb_state *mrb, mrb_value str);
|
||||
mrb_value mrb_str_inspect(mrb_state *mrb, mrb_value str);
|
||||
int mrb_str_equal(mrb_state *mrb, mrb_value str1, mrb_value str2);
|
||||
mrb_value str_new4(mrb_state *mrb, mrb_value str);
|
||||
mrb_value * mrb_svar(mrb_int cnt);
|
||||
mrb_value mrb_str_drop_bytes(mrb_state *mrb, mrb_value str, long len);
|
||||
mrb_value mrb_str_dump(mrb_state *mrb, mrb_value str);
|
||||
mrb_value mrb_str_cat(mrb_state *mrb, mrb_value str, const char *ptr, long len);
|
||||
mrb_value mrb_str_append(mrb_state *mrb, mrb_value str, mrb_value str2);
|
||||
size_t mrb_str_capacity(mrb_value str);
|
||||
|
||||
#ifdef INCLUDE_ENCODING
|
||||
int sym_printable(mrb_state *mrb, const char *s, const char *send, mrb_encoding *enc);
|
||||
mrb_value mrb_str_conv_enc(mrb_state *mrb, mrb_value str, mrb_encoding *from, mrb_encoding *to);
|
||||
mrb_value mrb_str_conv_enc_opts(mrb_state *mrb, mrb_value str, mrb_encoding *from, mrb_encoding *to, int ecflags, mrb_value ecopts);
|
||||
mrb_value mrb_enc_str_new(mrb_state *mrb, const char *ptr, long len, mrb_encoding *enc);
|
||||
#else
|
||||
int mrb_symname_p(const char *name);
|
||||
#endif
|
||||
|
||||
mrb_value mrb_tainted_str_new(mrb_state *mrb, const char *ptr, long len);
|
||||
int mrb_str_cmp(mrb_state *mrb, mrb_value str1, mrb_value str2);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
|
||||
+5
-4
@@ -28,13 +28,14 @@ module Kernel
|
||||
# Alias for +send+.
|
||||
#
|
||||
# ISO 15.3.1.3.4
|
||||
def __send__(symbol, *args, &block)
|
||||
#def __send__(symbol, *args, &block)
|
||||
### *** TODO *** ###
|
||||
end
|
||||
#end
|
||||
|
||||
# 15.3.1.3.18
|
||||
def instance_eval(string=nil, &block)
|
||||
### *** TODO *** ###
|
||||
raise "Not implemented yet"
|
||||
end
|
||||
|
||||
##
|
||||
@@ -62,9 +63,9 @@ module Kernel
|
||||
# block.
|
||||
#
|
||||
# ISO 15.3.1.3.44
|
||||
def send(symbol, *args, &block)
|
||||
#def send(symbol, *args, &block)
|
||||
### *** TODO *** ###
|
||||
end
|
||||
#end
|
||||
|
||||
##
|
||||
# Print arguments
|
||||
|
||||
+45
-62
@@ -10,9 +10,6 @@
|
||||
#include "mruby/string.h"
|
||||
#include "mruby/class.h"
|
||||
|
||||
mrb_value mrb_exec_recursive_paired(mrb_state *mrb, mrb_value (*func) (mrb_state *, mrb_value, mrb_value, int),
|
||||
mrb_value obj, mrb_value paired_obj, void* arg);
|
||||
|
||||
//#define ARY_DEFAULT_LEN 16
|
||||
#define ARY_DEFAULT_LEN 4
|
||||
#define ARY_SHRINK_RATIO 5 /* must be larger than 2 */
|
||||
@@ -30,8 +27,8 @@ ary_elt(mrb_value ary, long offset)
|
||||
return RARRAY_PTR(ary)[offset];
|
||||
}
|
||||
|
||||
mrb_value
|
||||
mrb_ary_new_capa(mrb_state *mrb, size_t capa)
|
||||
static struct RArray*
|
||||
ary_new_capa(mrb_state *mrb, size_t capa)
|
||||
{
|
||||
struct RArray *a;
|
||||
size_t blen;
|
||||
@@ -55,6 +52,13 @@ mrb_ary_new_capa(mrb_state *mrb, size_t capa)
|
||||
a->capa = capa;
|
||||
a->len = 0;
|
||||
|
||||
return a;
|
||||
}
|
||||
|
||||
mrb_value
|
||||
mrb_ary_new_capa(mrb_state *mrb, size_t capa)
|
||||
{
|
||||
struct RArray *a = ary_new_capa(mrb, capa);
|
||||
return mrb_obj_value(a);
|
||||
}
|
||||
|
||||
@@ -65,7 +69,7 @@ mrb_ary_new(mrb_state *mrb)
|
||||
}
|
||||
|
||||
mrb_value
|
||||
mrb_ary_new_from_values(mrb_state *mrb, mrb_value *vals, size_t size)
|
||||
mrb_ary_new_from_values(mrb_state *mrb, size_t size, mrb_value *vals)
|
||||
{
|
||||
mrb_value ary;
|
||||
struct RArray *a;
|
||||
@@ -84,7 +88,7 @@ mrb_assoc_new(mrb_state *mrb, mrb_value car, mrb_value cdr)
|
||||
mrb_value arv[2];
|
||||
arv[0] = car;
|
||||
arv[1] = cdr;
|
||||
return mrb_ary_new_from_values(mrb, arv, 2);
|
||||
return mrb_ary_new_from_values(mrb, 2, arv);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -156,7 +160,7 @@ mrb_ary_s_create(mrb_state *mrb, mrb_value self)
|
||||
int len;
|
||||
|
||||
mrb_get_args(mrb, "*", &vals, &len);
|
||||
return mrb_ary_new_from_values(mrb, vals, (size_t)len);
|
||||
return mrb_ary_new_from_values(mrb, (size_t)len, vals);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -200,25 +204,6 @@ mrb_ary_plus(mrb_state *mrb, mrb_value self)
|
||||
return ary;
|
||||
}
|
||||
|
||||
static mrb_value
|
||||
recursive_cmp(mrb_state *mrb, mrb_value ary1, mrb_value ary2, int recur)
|
||||
{
|
||||
long i, len;
|
||||
|
||||
if (recur) return mrb_undef_value(); /* Subtle! */
|
||||
len = RARRAY_LEN(ary1);
|
||||
if (len > RARRAY_LEN(ary2)) {
|
||||
len = RARRAY_LEN(ary2);
|
||||
}
|
||||
|
||||
for (i=0; i<len; i++) {
|
||||
mrb_value r = mrb_funcall(mrb, ary_elt(ary1, i), "<=>", 1, ary_elt(ary2, i));
|
||||
if (mrb_type(r) != MRB_TT_FIXNUM || mrb_fixnum(r) != 0) return r;
|
||||
}
|
||||
|
||||
return mrb_undef_value();
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* ary <=> other_ary -> -1, 0, +1 or nil
|
||||
@@ -242,15 +227,23 @@ mrb_ary_cmp(mrb_state *mrb, mrb_value ary1)
|
||||
{
|
||||
mrb_value ary2;
|
||||
struct RArray *a1, *a2;
|
||||
mrb_value r;
|
||||
long len;
|
||||
mrb_value r = mrb_nil_value();
|
||||
long i, len;
|
||||
|
||||
mrb_get_args(mrb, "o", &ary2);
|
||||
if (mrb_type(ary2) != MRB_TT_ARRAY) return mrb_nil_value();
|
||||
a1 = RARRAY(ary1); a2 = RARRAY(ary2);
|
||||
if (a1->len == a2->len && a1->buf == a2->buf) return mrb_fixnum_value(0);
|
||||
r = mrb_exec_recursive_paired(mrb, recursive_cmp, ary1, ary2, &ary2);
|
||||
if (mrb_type(r) != MRB_TT_UNDEF) return r;
|
||||
else {
|
||||
len = RARRAY_LEN(ary1);
|
||||
if (len > RARRAY_LEN(ary2)) {
|
||||
len = RARRAY_LEN(ary2);
|
||||
}
|
||||
for (i=0; i<len; i++) {
|
||||
r = mrb_funcall(mrb, ary_elt(ary1, i), "<=>", 1, ary_elt(ary2, i));
|
||||
if (mrb_type(r) != MRB_TT_FIXNUM || mrb_fixnum(r) != 0) return r;
|
||||
}
|
||||
}
|
||||
len = a1->len - a2->len;
|
||||
return mrb_fixnum_value((len == 0)? 0: (len > 0)? 1: -1);
|
||||
}
|
||||
@@ -569,7 +562,7 @@ mrb_ary_aget(mrb_state *mrb, mrb_value self)
|
||||
if ((len = mrb_fixnum(argv[0])) < 0) return mrb_nil_value();
|
||||
if (a->len == (size_t)index) return mrb_ary_new(mrb);
|
||||
if ((size_t)len > a->len - index) len = a->len - index;
|
||||
return mrb_ary_new_from_values(mrb, a->buf + index, len);
|
||||
return mrb_ary_new_from_values(mrb, len, a->buf + index);
|
||||
|
||||
default:
|
||||
mrb_raise(mrb, E_ARGUMENT_ERROR, "wrong number of arguments");
|
||||
@@ -654,7 +647,7 @@ mrb_ary_first(mrb_state *mrb, mrb_value self)
|
||||
/* len == 1 */
|
||||
size = mrb_fixnum(*vals);
|
||||
if (size > a->len) size = a->len;
|
||||
return mrb_ary_new_from_values(mrb, a->buf, size);
|
||||
return mrb_ary_new_from_values(mrb, size, a->buf);
|
||||
}
|
||||
|
||||
mrb_value
|
||||
@@ -676,7 +669,7 @@ mrb_ary_last(mrb_state *mrb, mrb_value self)
|
||||
/* len == 1 */
|
||||
size = mrb_fixnum(*vals);
|
||||
if (size > a->len) size = a->len;
|
||||
return mrb_ary_new_from_values(mrb, a->buf + a->len - size, size);
|
||||
return mrb_ary_new_from_values(mrb, size, a->buf + a->len - size);
|
||||
}
|
||||
|
||||
mrb_value
|
||||
@@ -716,7 +709,7 @@ mrb_ary_splat(mrb_state *mrb, mrb_value v)
|
||||
return v;
|
||||
}
|
||||
else {
|
||||
return mrb_ary_new_from_values(mrb, &v, 1);
|
||||
return mrb_ary_new_from_values(mrb, 1, &v);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -923,19 +916,6 @@ mrb_ary_join_m(mrb_state *mrb, mrb_value ary)
|
||||
return mrb_ary_join(mrb, ary, sep);
|
||||
}
|
||||
|
||||
static mrb_value
|
||||
recursive_equal(mrb_state *mrb, mrb_value ary1, mrb_value ary2, int recur)
|
||||
{
|
||||
long i;
|
||||
|
||||
if (recur) return mrb_true_value(); /* Subtle! */
|
||||
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_true_value();
|
||||
}
|
||||
|
||||
/* 15.2.12.5.33 (x) */
|
||||
/*
|
||||
* call-seq:
|
||||
@@ -970,20 +950,15 @@ mrb_ary_equal(mrb_state *mrb, mrb_value ary1)
|
||||
}
|
||||
}
|
||||
if (RARRAY_LEN(ary1) != RARRAY_LEN(ary2)) return mrb_false_value();
|
||||
return mrb_exec_recursive_paired(mrb, recursive_equal, ary1, ary2, &ary2);
|
||||
}
|
||||
else {
|
||||
long i;
|
||||
|
||||
static mrb_value
|
||||
recursive_eql(mrb_state *mrb, mrb_value ary1, mrb_value ary2, int recur)
|
||||
{
|
||||
long i;
|
||||
|
||||
if (recur) return mrb_true_value(); /* Subtle! */
|
||||
for (i=0; i<RARRAY_LEN(ary1); i++) {
|
||||
if (!mrb_eql(mrb, ary_elt(ary1, i), ary_elt(ary2, i)))
|
||||
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_true_value();
|
||||
}
|
||||
return mrb_true_value();
|
||||
}
|
||||
|
||||
/* 15.2.12.5.34 (x) */
|
||||
@@ -1001,10 +976,18 @@ mrb_ary_eql(mrb_state *mrb, mrb_value ary1)
|
||||
mrb_value ary2;
|
||||
|
||||
mrb_get_args(mrb, "o", &ary2);
|
||||
if (mrb_obj_equal(mrb, ary1,ary2)) return mrb_true_value();
|
||||
if (mrb_obj_equal(mrb, ary1, ary2)) return mrb_true_value();
|
||||
if (mrb_type(ary2) != MRB_TT_ARRAY) return mrb_false_value();
|
||||
if (RARRAY_LEN(ary1) != RARRAY_LEN(ary2)) return mrb_false_value();
|
||||
return mrb_exec_recursive_paired(mrb, recursive_eql, ary1, ary2, &ary2);
|
||||
else {
|
||||
long i;
|
||||
|
||||
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_true_value();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
-96
@@ -1,96 +0,0 @@
|
||||
/**********************************************************************
|
||||
ascii.c - Oniguruma (regular expression library)
|
||||
**********************************************************************/
|
||||
/*-
|
||||
* Copyright (c) 2002-2006 K.Kosako <sndgk393 AT ybb DOT ne DOT jp>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "mruby.h"
|
||||
#ifdef INCLUDE_ENCODING
|
||||
#include "regenc.h"
|
||||
|
||||
OnigEncodingDefine(ascii, ASCII) = {
|
||||
onigenc_single_byte_mbc_enc_len,
|
||||
"ASCII-8BIT",/* name */
|
||||
1, /* max byte length */
|
||||
1, /* min byte length */
|
||||
onigenc_is_mbc_newline_0x0a,
|
||||
onigenc_single_byte_mbc_to_code,
|
||||
onigenc_single_byte_code_to_mbclen,
|
||||
onigenc_single_byte_code_to_mbc,
|
||||
onigenc_ascii_mbc_case_fold,
|
||||
onigenc_ascii_apply_all_case_fold,
|
||||
onigenc_ascii_get_case_fold_codes_by_str,
|
||||
onigenc_minimum_property_name_to_ctype,
|
||||
onigenc_ascii_is_code_ctype,
|
||||
onigenc_not_support_get_ctype_code_range,
|
||||
onigenc_single_byte_left_adjust_char_head,
|
||||
onigenc_always_true_is_allowed_reverse_match
|
||||
};
|
||||
ENC_ALIAS("BINARY", "ASCII-8BIT")
|
||||
ENC_REPLICATE("IBM437", "ASCII-8BIT")
|
||||
ENC_ALIAS("CP437", "IBM437")
|
||||
ENC_REPLICATE("IBM737", "ASCII-8BIT")
|
||||
ENC_ALIAS("CP737", "IBM737")
|
||||
ENC_REPLICATE("IBM775", "ASCII-8BIT")
|
||||
ENC_ALIAS("CP775", "IBM775")
|
||||
ENC_REPLICATE("CP850", "ASCII-8BIT")
|
||||
ENC_ALIAS("IBM850", "CP850")
|
||||
ENC_REPLICATE("IBM852", "ASCII-8BIT")
|
||||
ENC_REPLICATE("CP852", "IBM852")
|
||||
ENC_REPLICATE("IBM855", "ASCII-8BIT")
|
||||
ENC_REPLICATE("CP855", "IBM855")
|
||||
ENC_REPLICATE("IBM857", "ASCII-8BIT")
|
||||
ENC_ALIAS("CP857", "IBM857")
|
||||
ENC_REPLICATE("IBM860", "ASCII-8BIT")
|
||||
ENC_ALIAS("CP860", "IBM860")
|
||||
ENC_REPLICATE("IBM861", "ASCII-8BIT")
|
||||
ENC_ALIAS("CP861", "IBM861")
|
||||
ENC_REPLICATE("IBM862", "ASCII-8BIT")
|
||||
ENC_ALIAS("CP862", "IBM862")
|
||||
ENC_REPLICATE("IBM863", "ASCII-8BIT")
|
||||
ENC_ALIAS("CP863", "IBM863")
|
||||
ENC_REPLICATE("IBM864", "ASCII-8BIT")
|
||||
ENC_ALIAS("CP864", "IBM864")
|
||||
ENC_REPLICATE("IBM865", "ASCII-8BIT")
|
||||
ENC_ALIAS("CP865", "IBM865")
|
||||
ENC_REPLICATE("IBM866", "ASCII-8BIT")
|
||||
ENC_ALIAS("CP866", "IBM866")
|
||||
ENC_REPLICATE("IBM869", "ASCII-8BIT")
|
||||
ENC_ALIAS("CP869", "IBM869")
|
||||
ENC_REPLICATE("Windows-1258", "ASCII-8BIT")
|
||||
ENC_ALIAS("CP1258", "Windows-1258")
|
||||
ENC_REPLICATE("GB1988", "ASCII-8BIT")
|
||||
ENC_REPLICATE("macCentEuro", "ASCII-8BIT")
|
||||
ENC_REPLICATE("macCroatian", "ASCII-8BIT")
|
||||
ENC_REPLICATE("macCyrillic", "ASCII-8BIT")
|
||||
ENC_REPLICATE("macGreek", "ASCII-8BIT")
|
||||
ENC_REPLICATE("macIceland", "ASCII-8BIT")
|
||||
ENC_REPLICATE("macRoman", "ASCII-8BIT")
|
||||
ENC_REPLICATE("macRomania", "ASCII-8BIT")
|
||||
ENC_REPLICATE("macThai", "ASCII-8BIT")
|
||||
ENC_REPLICATE("macTurkish", "ASCII-8BIT")
|
||||
ENC_REPLICATE("macUkraine", "ASCII-8BIT")
|
||||
#endif //INCLUDE_ENCODING
|
||||
+46
-7
@@ -17,12 +17,6 @@
|
||||
|
||||
#include "mruby/khash.h"
|
||||
|
||||
#ifdef INCLUDE_REGEXP
|
||||
#define mrb_usascii_str_new2 mrb_usascii_str_new_cstr
|
||||
#else
|
||||
#define mrb_usascii_str_new2 mrb_str_new_cstr
|
||||
#endif
|
||||
|
||||
KHASH_MAP_INIT_INT(mt, struct RProc*);
|
||||
KHASH_MAP_INIT_INT(iv, mrb_value);
|
||||
|
||||
@@ -1052,7 +1046,7 @@ mrb_mod_to_s(mrb_state *mrb, mrb_value klass)
|
||||
{
|
||||
//if (FL_TEST(klass, FL_SINGLETON)) {
|
||||
if (mrb_type(klass) == MRB_TT_SCLASS) {
|
||||
mrb_value s = mrb_usascii_str_new2(mrb, "#<");
|
||||
mrb_value s = mrb_str_new_cstr(mrb, "#<");
|
||||
mrb_value v = mrb_iv_get(mrb, klass, mrb_intern(mrb, "__attached__"));
|
||||
|
||||
mrb_str_cat2(mrb, s, "Class:");
|
||||
@@ -1140,6 +1134,48 @@ mrb_mod_undef(mrb_state *mrb, mrb_value mod)
|
||||
return mrb_nil_value();
|
||||
}
|
||||
|
||||
static mrb_sym
|
||||
mrb_sym_value(mrb_state *mrb, mrb_value val)
|
||||
{
|
||||
if(val.tt == MRB_TT_STRING) {
|
||||
return mrb_intern(mrb, RSTRING_PTR(val));
|
||||
}
|
||||
else if(val.tt != MRB_TT_SYMBOL) {
|
||||
mrb_value obj = mrb_funcall(mrb, val, "inspect", 0);
|
||||
mrb_raise(mrb, E_TYPE_ERROR, "%s is not a symbol",
|
||||
mrb_string_value_ptr(mrb, obj));
|
||||
}
|
||||
return mrb_symbol(val);
|
||||
}
|
||||
|
||||
mrb_value
|
||||
mrb_mod_const_defined(mrb_state *mrb, mrb_value mod)
|
||||
{
|
||||
mrb_value sym;
|
||||
mrb_get_args(mrb, "o", &sym);
|
||||
if(mrb_const_defined(mrb, mod, mrb_sym_value(mrb, sym))) {
|
||||
return mrb_true_value();
|
||||
}
|
||||
return mrb_false_value();
|
||||
}
|
||||
|
||||
mrb_value
|
||||
mrb_mod_const_get(mrb_state *mrb, mrb_value mod)
|
||||
{
|
||||
mrb_value sym;
|
||||
mrb_get_args(mrb, "o", &sym);
|
||||
return mrb_const_get(mrb, mod, mrb_sym_value(mrb, sym));
|
||||
}
|
||||
|
||||
mrb_value
|
||||
mrb_mod_const_set(mrb_state *mrb, mrb_value mod)
|
||||
{
|
||||
mrb_value sym, value;
|
||||
mrb_get_args(mrb, "oo", &sym, &value);
|
||||
mrb_const_set(mrb, mod, mrb_sym_value(mrb, sym), value);
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
static mrb_value
|
||||
mrb_mod_eqq(mrb_state *mrb, mrb_value mod)
|
||||
@@ -1197,6 +1233,9 @@ mrb_init_class(mrb_state *mrb)
|
||||
mrb_define_method(mrb, mod, "to_s", mrb_mod_to_s, ARGS_NONE());
|
||||
mrb_define_method(mrb, mod, "alias_method", mrb_mod_alias, ARGS_ANY());
|
||||
mrb_define_method(mrb, mod, "undef_method", mrb_mod_undef, ARGS_ANY());
|
||||
mrb_define_method(mrb, mod, "const_defined?", mrb_mod_const_defined, ARGS_REQ(1));
|
||||
mrb_define_method(mrb, mod, "const_get", mrb_mod_const_get, ARGS_REQ(1));
|
||||
mrb_define_method(mrb, mod, "const_set", mrb_mod_const_set, ARGS_REQ(2));
|
||||
|
||||
mrb_define_method(mrb, mod, "===", mrb_mod_eqq, ARGS_REQ(1));
|
||||
}
|
||||
|
||||
+20
-5
@@ -1225,15 +1225,30 @@ codegen(codegen_scope *s, node *tree, int val)
|
||||
break;
|
||||
|
||||
case NODE_OP_ASGN:
|
||||
codegen(s, tree->car, VAL);
|
||||
codegen(s, tree->cdr->cdr->car, VAL);
|
||||
genop(s, MKOP_A(OP_LOADNIL, cursp()));
|
||||
pop(); pop();
|
||||
{
|
||||
mrb_sym sym = (mrb_sym)tree->cdr->car;
|
||||
const char *name = mrb_sym2name(s->mrb, sym);
|
||||
int idx = new_msym(s, sym);
|
||||
int idx;
|
||||
|
||||
codegen(s, tree->car, VAL);
|
||||
if ((name[0] == '|' && strlen(name) == 2 && name[1] == '|') ||
|
||||
(name[0] == '&' && strlen(name) == 2 && name[1] == '&')) {
|
||||
int pos;
|
||||
|
||||
pop();
|
||||
pos = new_label(s);
|
||||
genop(s, MKOP_AsBx(name[0] == '|' ? OP_JMPIF : OP_JMPNOT, cursp(), 0));
|
||||
codegen(s, tree->cdr->cdr->car, VAL);
|
||||
pop();
|
||||
gen_assignment(s, tree->car, cursp(), val);
|
||||
dispatch(s, pos);
|
||||
break;
|
||||
}
|
||||
codegen(s, tree->cdr->cdr->car, VAL);
|
||||
genop(s, MKOP_A(OP_LOADNIL, cursp()));
|
||||
pop(); pop();
|
||||
|
||||
idx = new_msym(s, sym);
|
||||
if (name[0] == '+' && strlen(name) == 1) {
|
||||
genop(s, MKOP_ABC(OP_ADD, cursp(), idx, 1));
|
||||
}
|
||||
|
||||
-1685
File diff suppressed because it is too large
Load Diff
+1
-8
@@ -174,11 +174,7 @@ int mrb_enc_codelen(mrb_state *mrb, int code, mrb_encoding *enc);
|
||||
#endif //INCLUDE_ENCODING
|
||||
|
||||
/* code,ptr,encoding -> write buf */
|
||||
#ifdef INCLUDE_ENCODING
|
||||
#define mrb_enc_mbcput(c,buf,enc) ONIGENC_CODE_TO_MBC(enc,c,(UChar*)(buf))
|
||||
#else
|
||||
#define mrb_enc_mbcput(c,buf,enc) *(buf) = (char)(c)
|
||||
#endif //INCLUDE_ENCODING
|
||||
#define mrb_enc_mbcput(c,buf,enc) ((*(buf) = (char)(c)),1)
|
||||
|
||||
/* start, ptr, end, encoding -> prev_char */
|
||||
#define mrb_enc_prev_char(s,p,e,enc) (char *)onigenc_get_prev_char_head(enc,(UChar*)(s),(UChar*)(p),(UChar*)(e))
|
||||
@@ -232,9 +228,6 @@ mrb_value mrb_enc_default_internal(mrb_state *mrb);
|
||||
void mrb_enc_set_default_external(mrb_state *mrb, mrb_value encoding);
|
||||
void mrb_enc_set_default_internal(mrb_state *mrb, mrb_value encoding);
|
||||
mrb_value mrb_locale_charmap(mrb_state *mrb, mrb_value klass);
|
||||
#ifdef INCLUDE_ENCODING
|
||||
int mrb_memsearch(mrb_state *mrb, const void*,int,const void*,int,mrb_encoding*);
|
||||
#endif //INCLUDE_ENCODING
|
||||
mrb_value mrb_usascii_str_new_cstr(mrb_state *mrb, const char *ptr);
|
||||
int mrb_str_buf_cat_escaped_char(mrb_state *mrb, mrb_value result, unsigned int c, int unicode_p);
|
||||
|
||||
|
||||
@@ -242,6 +242,24 @@ mrb_init_heap(mrb_state *mrb)
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
gc_protect(mrb_state *mrb, struct RBasic *p)
|
||||
{
|
||||
if (mrb->arena_idx > MRB_ARENA_SIZE) {
|
||||
/* arena overflow error */
|
||||
mrb->arena_idx = MRB_ARENA_SIZE - 4; /* force room in arena */
|
||||
mrb_raise(mrb, mrb->eRuntimeError_class, "arena overflow error");
|
||||
}
|
||||
mrb->arena[mrb->arena_idx++] = p;
|
||||
}
|
||||
|
||||
void
|
||||
mrb_gc_protect(mrb_state *mrb, mrb_value obj)
|
||||
{
|
||||
if (SPECIAL_CONST_P(obj)) return;
|
||||
gc_protect(mrb, RBASIC(obj));
|
||||
}
|
||||
|
||||
struct RBasic*
|
||||
mrb_obj_alloc(mrb_state *mrb, enum mrb_vtype ttype, struct RClass *cls)
|
||||
{
|
||||
@@ -264,12 +282,7 @@ mrb_obj_alloc(mrb_state *mrb, enum mrb_vtype ttype, struct RClass *cls)
|
||||
}
|
||||
|
||||
mrb->live++;
|
||||
if (mrb->arena_idx > MRB_ARENA_SIZE) {
|
||||
/* arena overflow error */
|
||||
mrb->arena_idx = MRB_ARENA_SIZE - 2; /* force room in arena */
|
||||
mrb_raise(mrb, mrb->eRuntimeError_class, "arena overflow error");
|
||||
}
|
||||
mrb->arena[mrb->arena_idx++] = p;
|
||||
gc_protect(mrb, p);
|
||||
memset(p, 0, sizeof(RVALUE));
|
||||
p->tt = ttype;
|
||||
p->c = cls;
|
||||
@@ -362,9 +375,8 @@ gc_mark_children(mrb_state *mrb, struct RBasic *obj)
|
||||
{
|
||||
struct RString *s = (struct RString*)obj;
|
||||
|
||||
while (s->flags & MRB_STR_SHARED) {
|
||||
s = s->aux.shared;
|
||||
if (!s) break;
|
||||
if (s->flags & MRB_STR_SHARED) {
|
||||
mrb_gc_mark(mrb, (struct RBasic*)s->aux.shared);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
+37
-78
@@ -11,34 +11,28 @@
|
||||
#include "mruby/array.h"
|
||||
#include "mruby/string.h"
|
||||
#include "mruby/variable.h"
|
||||
#include "st.h"
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
static khint_t
|
||||
static inline khint_t
|
||||
mrb_hash_ht_hash_func(mrb_state *mrb, mrb_value key)
|
||||
{
|
||||
char type = mrb_type(key);
|
||||
mrb_value s1 = mrb_str_new(mrb, &type, 1);
|
||||
mrb_value s2 = mrb_inspect(mrb, key);
|
||||
s1 = mrb_str_cat(mrb, s1, RSTRING_PTR(s2), RSTRING_LEN(s2));
|
||||
return kh_str_hash_func(mrb, RSTRING_PTR(s1));
|
||||
khint_t h = mrb_type(key) << 24;
|
||||
mrb_value h2;
|
||||
|
||||
h2 = mrb_funcall(mrb, key, "hash", 0, 0);
|
||||
h ^= h2.value.i;
|
||||
return h;
|
||||
}
|
||||
|
||||
static khint_t
|
||||
static inline khint_t
|
||||
mrb_hash_ht_hash_equal(mrb_state *mrb, mrb_value a, mrb_value b)
|
||||
{
|
||||
return mrb_equal(mrb, a, b);
|
||||
return mrb_eql(mrb, a, b);
|
||||
}
|
||||
|
||||
KHASH_INIT(ht, mrb_value, mrb_value, 1, mrb_hash_ht_hash_func, mrb_hash_ht_hash_equal);
|
||||
|
||||
mrb_value mrb_exec_recursive_paired(mrb_state *mrb, mrb_value (*func) (mrb_state *, mrb_value, mrb_value, int),
|
||||
mrb_value obj, mrb_value paired_obj, void* arg);
|
||||
|
||||
#ifndef FALSE
|
||||
#define FALSE 0
|
||||
#endif
|
||||
@@ -61,12 +55,11 @@ mrb_hash_ht_key(mrb_state *mrb, mrb_value key)
|
||||
#define KEY(key) mrb_hash_ht_key(mrb, key)
|
||||
|
||||
void
|
||||
mrb_gc_mark_ht(mrb_state *mrb, struct RHash *c)
|
||||
mrb_gc_mark_ht(mrb_state *mrb, struct RHash *hash)
|
||||
{
|
||||
khiter_t k;
|
||||
khash_t(ht) *h = ((struct RHash*)c)->ht;
|
||||
khash_t(ht) *h = hash->ht;
|
||||
|
||||
if (!h) return;
|
||||
for (k = kh_begin(h); k != kh_end(h); k++)
|
||||
if (kh_exist(h, k)) {
|
||||
mrb_gc_mark_value(mrb, kh_key(h, k));
|
||||
@@ -75,23 +68,15 @@ mrb_gc_mark_ht(mrb_state *mrb, struct RHash *c)
|
||||
}
|
||||
|
||||
size_t
|
||||
mrb_gc_mark_ht_size(mrb_state *mrb, struct RHash *c)
|
||||
mrb_gc_mark_ht_size(mrb_state *mrb, struct RHash *hash)
|
||||
{
|
||||
size_t ht_size = 0;
|
||||
khash_t(ht) *h = c->ht;
|
||||
|
||||
/* ((struct RHash*)c)->ht */
|
||||
if (h) ht_size += kh_size(h)*2;
|
||||
|
||||
return ht_size;
|
||||
return kh_size(hash->ht)*2;
|
||||
}
|
||||
|
||||
void
|
||||
mrb_gc_free_ht(mrb_state *mrb, struct RHash *c)
|
||||
mrb_gc_free_ht(mrb_state *mrb, struct RHash *hash)
|
||||
{
|
||||
khash_t(ht) *h = c->ht;
|
||||
|
||||
kh_destroy(ht, h);
|
||||
kh_destroy(ht, hash->ht);
|
||||
}
|
||||
|
||||
|
||||
@@ -119,11 +104,9 @@ mrb_hash_get(mrb_state *mrb, mrb_value hash, mrb_value key) /* mrb_hash_aref */
|
||||
khash_t(ht) *h = RHASH_TBL(hash);
|
||||
khiter_t k;
|
||||
|
||||
if (h) {
|
||||
k = kh_get(ht, h, key);
|
||||
if (k != kh_end(h))
|
||||
return kh_value(h, k);
|
||||
}
|
||||
k = kh_get(ht, h, key);
|
||||
if (k != kh_end(h))
|
||||
return kh_value(h, k);
|
||||
|
||||
/* not found */
|
||||
if (MRB_RHASH_PROCDEFAULT_P(hash)) {
|
||||
@@ -175,21 +158,6 @@ mrb_hash_freeze(mrb_value hash)
|
||||
return (hash);
|
||||
}
|
||||
|
||||
mrb_value
|
||||
mrb_hash(mrb_state *mrb, mrb_value obj)
|
||||
{
|
||||
mrb_value hval = mrb_funcall(mrb, obj, "Hash", 0);
|
||||
retry:
|
||||
switch (mrb_type(hval)) {
|
||||
case MRB_TT_FIXNUM:
|
||||
return hval;
|
||||
|
||||
default:
|
||||
hval = mrb_to_int(mrb, hval);
|
||||
goto retry;
|
||||
}
|
||||
}
|
||||
|
||||
mrb_value
|
||||
mrb_hash_dup(mrb_state *mrb, mrb_value hash)
|
||||
{
|
||||
@@ -675,7 +643,7 @@ mrb_hash_values_at(mrb_state *mrb, int argc, mrb_value *argv, mrb_value hash)
|
||||
long i;
|
||||
|
||||
for (i=0; i<argc; i++) {
|
||||
mrb_ary_push(mrb, result, KEY(mrb_hash_get(mrb, hash, argv[i])));
|
||||
mrb_ary_push(mrb, result, mrb_hash_get(mrb, hash, argv[i]));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -1135,28 +1103,6 @@ mrb_hash_has_value(mrb_state *mrb, mrb_value hash)
|
||||
return mrb_hash_has_valueWithvalue(mrb, hash, val);
|
||||
}
|
||||
|
||||
static mrb_value
|
||||
recursive_eql(mrb_state *mrb, mrb_value hash, mrb_value dt, int recur)
|
||||
{
|
||||
khash_t(ht) *h1 = RHASH_TBL(hash);
|
||||
khash_t(ht) *h2 = RHASH_TBL(dt);
|
||||
khiter_t k1, k2;
|
||||
mrb_value key1;
|
||||
|
||||
for (k1 = kh_begin(h1); k1 != kh_end(h1); k1++) {
|
||||
if (!kh_exist(h1, k1)) continue;
|
||||
key1 = kh_key(h1,k1);
|
||||
k2 = kh_get(ht, h2, key1);
|
||||
if ( k2 != kh_end(h2)) {
|
||||
if (mrb_equal(mrb, kh_value(h1,k1), kh_value(h2,k2))) {
|
||||
continue; /* next key */
|
||||
}
|
||||
}
|
||||
return mrb_false_value();
|
||||
}
|
||||
return mrb_true_value();
|
||||
}
|
||||
|
||||
static mrb_value
|
||||
hash_equal(mrb_state *mrb, mrb_value hash1, mrb_value hash2, int eql)
|
||||
{
|
||||
@@ -1171,9 +1117,25 @@ hash_equal(mrb_state *mrb, mrb_value hash1, mrb_value hash2, int eql)
|
||||
return mrb_fixnum_value(mrb_equal(mrb, hash2, hash1));
|
||||
}
|
||||
if (RHASH_SIZE(hash1) != RHASH_SIZE(hash2)) return mrb_false_value();
|
||||
if (!RHASH(hash1)->ht || !RHASH(hash2)->ht) return mrb_true_value();
|
||||
else {
|
||||
khash_t(ht) *h1 = RHASH_TBL(hash1);
|
||||
khash_t(ht) *h2 = RHASH_TBL(hash2);
|
||||
khiter_t k1, k2;
|
||||
mrb_value key;
|
||||
|
||||
return mrb_exec_recursive_paired(mrb, recursive_eql, hash1, hash2, (void*)0);
|
||||
for (k1 = kh_begin(h1); k1 != kh_end(h1); k1++) {
|
||||
if (!kh_exist(h1, k1)) continue;
|
||||
key = kh_key(h1,k1);
|
||||
k2 = kh_get(ht, h2, key);
|
||||
if (k2 != kh_end(h2)) {
|
||||
if (mrb_equal(mrb, kh_value(h1,k1), kh_value(h2,k2))) {
|
||||
continue; /* next key */
|
||||
}
|
||||
}
|
||||
return mrb_false_value();
|
||||
}
|
||||
}
|
||||
return mrb_true_value();
|
||||
}
|
||||
|
||||
/* 15.2.13.4.1 */
|
||||
@@ -1319,9 +1281,6 @@ mrb_hash_rassoc(mrb_state *mrb, mrb_value hash)
|
||||
mrb_value key, value, has_key;
|
||||
|
||||
mrb_get_args(mrb, "o", &key);
|
||||
if (mrb_nil_p(key))
|
||||
mrb_raise(mrb, E_ARGUMENT_ERROR, "wrong number of arguments");
|
||||
|
||||
has_key = mrb_hash_has_keyWithKey(mrb, hash, key);
|
||||
if (mrb_test(has_key)) {
|
||||
value = mrb_hash_get(mrb, hash, key);
|
||||
|
||||
@@ -20,7 +20,6 @@ void mrb_init_proc(mrb_state*);
|
||||
void mrb_init_range(mrb_state*);
|
||||
void mrb_init_string(mrb_state*);
|
||||
void mrb_init_regexp(mrb_state*);
|
||||
void mrb_init_encoding(mrb_state*);
|
||||
void mrb_init_exception(mrb_state*);
|
||||
void mrb_init_time(mrb_state*);
|
||||
void mrb_init_io(mrb_state*);
|
||||
@@ -54,7 +53,6 @@ mrb_init_core(mrb_state *mrb)
|
||||
mrb_init_gc(mrb);
|
||||
#ifdef INCLUDE_REGEXP
|
||||
mrb_init_regexp(mrb);
|
||||
mrb_init_encoding(mrb);
|
||||
#endif
|
||||
mrb_init_exception(mrb);
|
||||
mrb_init_print(mrb);
|
||||
|
||||
+4
-4
@@ -274,11 +274,11 @@ mrb_f_send(int argc, mrb_value *argv, mrb_value recv)
|
||||
static mrb_value
|
||||
mrb_f_send_m(mrb_state *mrb, mrb_value self)
|
||||
{
|
||||
mrb_value *argv;
|
||||
mrb_value name, block, *argv;
|
||||
int argc;
|
||||
|
||||
mrb_get_args(mrb, "*", &argv, &argc);
|
||||
return mrb_f_send(argc, argv, self);
|
||||
|
||||
mrb_get_args(mrb, "&o*", &block, &name, &argv, &argc);
|
||||
return mrb_funcall_with_block(mrb,self, mrb_string_value_ptr(mrb, name), argc, argv, block);
|
||||
}
|
||||
|
||||
/* 15.3.1.2.1 */
|
||||
|
||||
@@ -336,7 +336,6 @@ read_rite_irep_record(mrb_state *mrb, unsigned char *src, mrb_irep *irep, uint32
|
||||
uint16_t crc, tt, pdl, snl, offset, bufsize=MRB_DUMP_DEFAULT_STR_LEN;
|
||||
mrb_int fix_num;
|
||||
mrb_float f;
|
||||
mrb_value str;
|
||||
int ai = mrb_gc_arena_save(mrb);
|
||||
|
||||
recordStart = src;
|
||||
|
||||
+6
-13
@@ -11,13 +11,6 @@
|
||||
#include "mruby/class.h"
|
||||
#include "mruby/numeric.h"
|
||||
|
||||
#ifdef INCLUDE_REGEXP
|
||||
#define mrb_usascii_str_new2 mrb_usascii_str_new_cstr
|
||||
#else
|
||||
#define mrb_usascii_str_new2 mrb_str_new_cstr
|
||||
#define mrb_usascii_str_new mrb_str_new
|
||||
#endif
|
||||
|
||||
#ifndef FALSE
|
||||
#define FALSE 0
|
||||
#endif
|
||||
@@ -106,7 +99,7 @@ mrb_true(mrb_state *mrb, mrb_value obj)
|
||||
static mrb_value
|
||||
nil_to_s(mrb_state *mrb, mrb_value obj)
|
||||
{
|
||||
return mrb_usascii_str_new(mrb, 0, 0);
|
||||
return mrb_str_new(mrb, 0, 0);
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
@@ -166,7 +159,7 @@ true_xor(mrb_state *mrb, mrb_value obj)
|
||||
static mrb_value
|
||||
true_to_s(mrb_state *mrb, mrb_value obj)
|
||||
{
|
||||
return mrb_usascii_str_new2(mrb, "true");
|
||||
return mrb_str_new_cstr(mrb, "true");
|
||||
}
|
||||
|
||||
/* 15.2.5.3.4 */
|
||||
@@ -279,7 +272,7 @@ false_or(mrb_state *mrb, mrb_value obj)
|
||||
static mrb_value
|
||||
false_to_s(mrb_state *mrb, mrb_value obj)
|
||||
{
|
||||
return mrb_usascii_str_new2(mrb, "false");
|
||||
return mrb_str_new_cstr(mrb, "false");
|
||||
}
|
||||
|
||||
void
|
||||
@@ -626,12 +619,12 @@ mrb_Float(mrb_state *mrb, mrb_value val)
|
||||
mrb_value
|
||||
mrb_inspect(mrb_state *mrb, mrb_value obj)
|
||||
{
|
||||
return mrb_obj_as_string(mrb, mrb_funcall(mrb, obj, "inspect", 0, 0));
|
||||
return mrb_obj_as_string(mrb, mrb_funcall(mrb, obj, "inspect", 0, 0));
|
||||
}
|
||||
|
||||
int
|
||||
mrb_eql(mrb_state *mrb, mrb_value obj1, mrb_value obj2)
|
||||
{
|
||||
return RTEST(mrb_funcall(mrb, obj1, "eql?", 1, obj2));
|
||||
if (mrb_obj_eq(mrb, obj1, obj2)) return TRUE;
|
||||
return RTEST(mrb_funcall(mrb, obj1, "eql?", 1, obj2));
|
||||
}
|
||||
|
||||
|
||||
+5
-29
@@ -520,7 +520,6 @@ mrb_str_format(mrb_state *mrb, int argc, const mrb_value *argv, mrb_value fmt)
|
||||
++argc;
|
||||
--argv;
|
||||
mrb_string_value(mrb, &fmt);
|
||||
fmt = mrb_str_new4(mrb, fmt);
|
||||
p = RSTRING_PTR(fmt);
|
||||
end = p + RSTRING_LEN(fmt);
|
||||
blen = 0;
|
||||
@@ -668,44 +667,37 @@ retry:
|
||||
mrb_value tmp;
|
||||
unsigned int c;
|
||||
int n;
|
||||
#ifdef INCLUDE_ENCODING
|
||||
mrb_encoding *enc = mrb_enc_get(mrb, fmt);
|
||||
#endif //INCLUDE_ENCODING
|
||||
|
||||
tmp = mrb_check_string_type(mrb, val);
|
||||
if (!mrb_nil_p(tmp)) {
|
||||
if (RSTRING_LEN(tmp) != 1 ) {
|
||||
mrb_raise(mrb, E_ARGUMENT_ERROR, "%%c requires a character");
|
||||
}
|
||||
#ifdef INCLUDE_ENCODING
|
||||
c = mrb_enc_codepoint_len(mrb, RSTRING_PTR(tmp), RSTRING_END(tmp), &n, enc);
|
||||
#else
|
||||
c = RSTRING_PTR(tmp)[0];
|
||||
n = 1;
|
||||
#endif //INCLUDE_ENCODING
|
||||
}
|
||||
else {
|
||||
c = mrb_fixnum(val);
|
||||
n = mrb_enc_codelen(mrb, c, enc);
|
||||
n = 1;
|
||||
}
|
||||
if (n <= 0) {
|
||||
mrb_raise(mrb, E_ARGUMENT_ERROR, "invalid character");
|
||||
}
|
||||
if (!(flags & FWIDTH)) {
|
||||
CHECK(n);
|
||||
mrb_enc_mbcput(c, &buf[blen], enc);
|
||||
buf[blen] = c;
|
||||
blen += n;
|
||||
}
|
||||
else if ((flags & FMINUS)) {
|
||||
CHECK(n);
|
||||
mrb_enc_mbcput(c, &buf[blen], enc);
|
||||
buf[blen] = c;
|
||||
blen += n;
|
||||
FILL(' ', width-1);
|
||||
}
|
||||
else {
|
||||
FILL(' ', width-1);
|
||||
CHECK(n);
|
||||
mrb_enc_mbcput(c, &buf[blen], enc);
|
||||
buf[blen] = c;
|
||||
blen += n;
|
||||
}
|
||||
}
|
||||
@@ -717,25 +709,18 @@ format_s:
|
||||
{
|
||||
mrb_value arg = GETARG();
|
||||
long len, slen;
|
||||
#ifdef INCLUDE_ENCODING
|
||||
mrb_encoding *enc = mrb_enc_get(mrb, fmt);
|
||||
#endif //INCLUDE_ENCODING
|
||||
|
||||
if (*p == 'p') arg = mrb_inspect(mrb, arg);
|
||||
str = mrb_obj_as_string(mrb, arg);
|
||||
len = RSTRING_LEN(str);
|
||||
mrb_str_set_len(mrb, result, blen);
|
||||
RSTRING_LEN(result) = blen;
|
||||
if (flags&(FPREC|FWIDTH)) {
|
||||
slen = RSTRING_LEN(str);
|
||||
if (slen < 0) {
|
||||
mrb_raise(mrb, E_ARGUMENT_ERROR, "invalid mbstring sequence");
|
||||
}
|
||||
if ((flags&FPREC) && (prec < slen)) {
|
||||
#ifdef INCLUDE_ENCODING
|
||||
char *p = mrb_enc_nth(mrb, RSTRING_PTR(str), RSTRING_END(str),prec, enc);
|
||||
#else
|
||||
char *p = RSTRING_PTR(str) + prec;
|
||||
#endif //INCLUDE_ENCODING
|
||||
slen = prec;
|
||||
len = p - RSTRING_PTR(str);
|
||||
}
|
||||
@@ -757,12 +742,10 @@ format_s:
|
||||
buf[blen++] = ' ';
|
||||
}
|
||||
}
|
||||
mrb_enc_associate(mrb, result, enc);
|
||||
break;
|
||||
}
|
||||
}
|
||||
PUSH(RSTRING_PTR(str), len);
|
||||
mrb_enc_associate(mrb, result, enc);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -915,15 +898,8 @@ bin_retry:
|
||||
if (*p == 'X') {
|
||||
char *pp = s;
|
||||
int c;
|
||||
#ifdef INCLUDE_ENCODING
|
||||
mrb_encoding *enc = mrb_enc_get(mrb, fmt);
|
||||
#endif //INCLUDE_ENCODING
|
||||
while ((c = (int)(unsigned char)*pp) != 0) {
|
||||
#ifdef INCLUDE_ENCODING
|
||||
*pp = mrb_enc_toupper(c, enc);
|
||||
#else
|
||||
*pp = toupper(c);
|
||||
#endif //INCLUDE_ENCODING
|
||||
pp++;
|
||||
}
|
||||
}
|
||||
|
||||
+287
-2271
File diff suppressed because it is too large
Load Diff
+1
-1
@@ -379,7 +379,7 @@ mrb_struct_s_def(mrb_state *mrb, mrb_value klass)
|
||||
pargv = &argv[0];
|
||||
argcnt++;
|
||||
}
|
||||
rest = mrb_ary_new_from_values(mrb, pargv, argcnt);
|
||||
rest = mrb_ary_new_from_values(mrb, argcnt, pargv);
|
||||
}
|
||||
st = make_struct(mrb, name, rest, struct_class(mrb));
|
||||
if (!mrb_nil_p(b)) {
|
||||
|
||||
+106
-42
@@ -149,13 +149,7 @@ mrb_sym_to_s(mrb_state *mrb, mrb_value sym)
|
||||
{
|
||||
mrb_sym id = SYM2ID(sym);
|
||||
|
||||
#ifdef INCLUDE_REGEXP
|
||||
//return str_new3(mrb_cString, mrb_id2str(id));
|
||||
return str_new3(mrb, mrb_obj_class(mrb, sym), mrb_str_new_cstr(mrb, mrb_sym2name(mrb, id)));
|
||||
#else
|
||||
return mrb_str_new_cstr(mrb, mrb_sym2name(mrb, id)); //mrb_str_new2(mrb_id2name(SYM2ID(sym)));
|
||||
#endif
|
||||
|
||||
return mrb_str_new_cstr(mrb, mrb_sym2name(mrb, id));
|
||||
}
|
||||
|
||||
/* 15.2.11.3.4 */
|
||||
@@ -185,42 +179,113 @@ sym_to_sym(mrb_state *mrb, mrb_value sym)
|
||||
* :fred.inspect #=> ":fred"
|
||||
*/
|
||||
|
||||
#if __STDC__
|
||||
# define SIGN_EXTEND_CHAR(c) ((signed char)(c))
|
||||
#else /* not __STDC__ */
|
||||
/* As in Harbison and Steele. */
|
||||
# define SIGN_EXTEND_CHAR(c) ((((unsigned char)(c)) ^ 128) - 128)
|
||||
#endif
|
||||
#define is_identchar(c) (SIGN_EXTEND_CHAR(c)!=-1&&(ISALNUM(c) || (c) == '_'))
|
||||
|
||||
static int
|
||||
is_special_global_name(m)
|
||||
const char *m;
|
||||
{
|
||||
switch (*m) {
|
||||
case '~': case '*': case '$': case '?': case '!': case '@':
|
||||
case '/': case '\\': case ';': case ',': case '.': case '=':
|
||||
case ':': case '<': case '>': case '\"':
|
||||
case '&': case '`': case '\'': case '+':
|
||||
case '0':
|
||||
++m;
|
||||
break;
|
||||
case '-':
|
||||
++m;
|
||||
if (is_identchar(*m)) m += 1;
|
||||
break;
|
||||
default:
|
||||
if (!ISDIGIT(*m)) return 0;
|
||||
do ++m; while (ISDIGIT(*m));
|
||||
}
|
||||
return !*m;
|
||||
}
|
||||
|
||||
static int
|
||||
symname_p(const char *name)
|
||||
{
|
||||
const char *m = name;
|
||||
int localid = FALSE;
|
||||
|
||||
if (!m) return FALSE;
|
||||
switch (*m) {
|
||||
case '\0':
|
||||
return FALSE;
|
||||
|
||||
case '$':
|
||||
if (is_special_global_name(++m)) return TRUE;
|
||||
goto id;
|
||||
|
||||
case '@':
|
||||
if (*++m == '@') ++m;
|
||||
goto id;
|
||||
|
||||
case '<':
|
||||
switch (*++m) {
|
||||
case '<': ++m; break;
|
||||
case '=': if (*++m == '>') ++m; break;
|
||||
default: break;
|
||||
}
|
||||
break;
|
||||
|
||||
case '>':
|
||||
switch (*++m) {
|
||||
case '>': case '=': ++m; break;
|
||||
}
|
||||
break;
|
||||
|
||||
case '=':
|
||||
switch (*++m) {
|
||||
case '~': ++m; break;
|
||||
case '=': if (*++m == '=') ++m; break;
|
||||
default: return FALSE;
|
||||
}
|
||||
break;
|
||||
|
||||
case '*':
|
||||
if (*++m == '*') ++m;
|
||||
break;
|
||||
|
||||
case '+': case '-':
|
||||
if (*++m == '@') ++m;
|
||||
break;
|
||||
|
||||
case '|': case '^': case '&': case '/': case '%': case '~': case '`':
|
||||
++m;
|
||||
break;
|
||||
|
||||
case '[':
|
||||
if (*++m != ']') return FALSE;
|
||||
if (*++m == '=') ++m;
|
||||
break;
|
||||
|
||||
default:
|
||||
localid = !ISUPPER(*m);
|
||||
id:
|
||||
if (*m != '_' && !ISALPHA(*m)) return FALSE;
|
||||
while (is_identchar(*m)) m += 1;
|
||||
if (localid) {
|
||||
switch (*m) {
|
||||
case '!': case '?': case '=': ++m;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
return *m ? FALSE : TRUE;
|
||||
}
|
||||
|
||||
static mrb_value
|
||||
sym_inspect(mrb_state *mrb, mrb_value sym)
|
||||
{
|
||||
#ifdef INCLUDE_ENCODING
|
||||
#define STR_ENC_GET(mrb, str) mrb_enc_from_index(mrb, ENCODING_GET(mrb, str))
|
||||
mrb_value str;
|
||||
mrb_sym id = SYM2ID(sym);
|
||||
mrb_encoding *enc;
|
||||
const char *ptr;
|
||||
long len;
|
||||
char *dest;
|
||||
mrb_encoding *resenc = mrb_default_internal_encoding(mrb);
|
||||
|
||||
if (resenc == NULL) resenc = mrb_default_external_encoding(mrb);
|
||||
sym = mrb_str_new_cstr(mrb, mrb_sym2name(mrb, id));//mrb_id2str(id);
|
||||
enc = STR_ENC_GET(mrb, sym);
|
||||
ptr = RSTRING_PTR(sym);
|
||||
len = RSTRING_LEN(sym);
|
||||
if ((resenc != enc && !mrb_str_is_ascii_only_p(mrb, sym)) || len != (long)strlen(ptr) ||
|
||||
!mrb_enc_symname_p(ptr, enc) || !sym_printable(mrb, ptr, ptr + len, enc)) {
|
||||
str = mrb_str_inspect(mrb, sym);
|
||||
len = RSTRING_LEN(str);
|
||||
mrb_str_resize(mrb, str, len + 1);
|
||||
dest = RSTRING_PTR(str);
|
||||
memmove(dest + 1, dest, len);
|
||||
dest[0] = ':';
|
||||
}
|
||||
else {
|
||||
char *dest;
|
||||
str = mrb_enc_str_new(mrb, 0, len + 1, enc);
|
||||
dest = RSTRING_PTR(str);
|
||||
dest[0] = ':';
|
||||
memcpy(dest + 1, ptr, len);
|
||||
}
|
||||
return str;
|
||||
#else
|
||||
mrb_value str;
|
||||
const char *name;
|
||||
mrb_sym id = SYM2ID(sym);
|
||||
@@ -229,12 +294,11 @@ sym_inspect(mrb_state *mrb, mrb_value sym)
|
||||
str = mrb_str_new(mrb, 0, strlen(name)+1);
|
||||
RSTRING(str)->buf[0] = ':';
|
||||
strcpy(RSTRING(str)->buf+1, name);
|
||||
if (!mrb_symname_p(name)) {
|
||||
if (!symname_p(name)) {
|
||||
str = mrb_str_dump(mrb, str);
|
||||
strncpy(RSTRING(str)->buf, ":\"", 2);
|
||||
}
|
||||
return str;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
-4386
File diff suppressed because it is too large
Load Diff
@@ -1,109 +0,0 @@
|
||||
/**********************************************************************
|
||||
|
||||
transcode_data.h -
|
||||
|
||||
$Author: duerst $
|
||||
created at: Mon 10 Dec 2007 14:01:47 JST 2007
|
||||
|
||||
Copyright (C) 2007 Martin Duerst
|
||||
|
||||
**********************************************************************/
|
||||
|
||||
//#include "ruby/ruby.h"
|
||||
|
||||
#ifndef RUBY_TRANSCODE_DATA_H
|
||||
#define RUBY_TRANSCODE_DATA_H 1
|
||||
|
||||
#define WORDINDEX_SHIFT_BITS 2
|
||||
#define WORDINDEX2INFO(widx) ((widx) << WORDINDEX_SHIFT_BITS)
|
||||
#define INFO2WORDINDEX(info) ((info) >> WORDINDEX_SHIFT_BITS)
|
||||
#define BYTE_LOOKUP_BASE(bl) ((bl)[0])
|
||||
#define BYTE_LOOKUP_INFO(bl) ((bl)[1])
|
||||
|
||||
#define PType (unsigned int)
|
||||
|
||||
#define NOMAP (PType 0x01) /* direct map */
|
||||
#define ONEbt (0x02) /* one byte payload */
|
||||
#define TWObt (0x03) /* two bytes payload */
|
||||
#define THREEbt (0x05) /* three bytes payload */
|
||||
#define FOURbt (0x06) /* four bytes payload, UTF-8 only, macros start at getBT0 */
|
||||
#define INVALID (PType 0x07) /* invalid byte sequence */
|
||||
#define UNDEF (PType 0x09) /* legal but undefined */
|
||||
#define ZERObt (PType 0x0A) /* zero bytes of payload, i.e. remove */
|
||||
#define FUNii (PType 0x0B) /* function from info to info */
|
||||
#define FUNsi (PType 0x0D) /* function from start to info */
|
||||
#define FUNio (PType 0x0E) /* function from info to output */
|
||||
#define FUNso (PType 0x0F) /* function from start to output */
|
||||
#define STR1 (PType 0x11) /* string 4 <= len <= 259 bytes: 1byte length + content */
|
||||
#define GB4bt (PType 0x12) /* GB18030 four bytes payload */
|
||||
#define FUNsio (PType 0x13) /* function from start and info to output */
|
||||
|
||||
#define STR1_LENGTH(byte_addr) (unsigned int)(*(byte_addr) + 4)
|
||||
#define STR1_BYTEINDEX(w) ((w) >> 6)
|
||||
#define makeSTR1(bi) (((bi) << 6) | STR1)
|
||||
#define makeSTR1LEN(len) ((len)-4)
|
||||
|
||||
#define o1(b1) (PType((((unsigned char)(b1))<<8)|ONEbt))
|
||||
#define o2(b1,b2) (PType((((unsigned char)(b1))<<8)|(((unsigned char)(b2))<<16)|TWObt))
|
||||
#define o3(b1,b2,b3) (PType(((((unsigned char)(b1))<<8)|(((unsigned char)(b2))<<16)|(((unsigned int)(unsigned char)(b3))<<24)|THREEbt)&0xffffffffU))
|
||||
#define o4(b0,b1,b2,b3) (PType(((((unsigned char)(b1))<<8)|(((unsigned char)(b2))<<16)|(((unsigned char)(b3))<<24)|((((unsigned char)(b0))&0x07)<<5)|FOURbt)&0xffffffffU))
|
||||
#define g4(b0,b1,b2,b3) (PType(((((unsigned char)(b0))<<8)|(((unsigned char)(b2))<<16)|((((unsigned char)(b1))&0x0f)<<24)|((((unsigned int)(unsigned char)(b3))&0x0f)<<28)|GB4bt)&0xffffffffU))
|
||||
#define funsio(diff) (PType((((unsigned int)(diff))<<8)|FUNsio))
|
||||
|
||||
#define getBT1(a) ((unsigned char)((a)>> 8))
|
||||
#define getBT2(a) ((unsigned char)((a)>>16))
|
||||
#define getBT3(a) ((unsigned char)((a)>>24))
|
||||
#define getBT0(a) (((unsigned char)((a)>> 5)&0x07)|0xF0) /* for UTF-8 only!!! */
|
||||
|
||||
#define getGB4bt0(a) ((unsigned char)((a)>> 8))
|
||||
#define getGB4bt1(a) ((((unsigned char)((a)>>24))&0x0F)|0x30)
|
||||
#define getGB4bt2(a) ((unsigned char)((a)>>16))
|
||||
#define getGB4bt3(a) ((((unsigned char)((a)>>28))&0x0F)|0x30)
|
||||
|
||||
#define o2FUNii(b1,b2) (PType((((unsigned char)(b1))<<8)|(((unsigned char)(b2))<<16)|FUNii))
|
||||
|
||||
/* do we need these??? maybe not, can be done with simple tables */
|
||||
#define ONETRAIL /* legal but undefined if one more trailing UTF-8 */
|
||||
#define TWOTRAIL /* legal but undefined if two more trailing UTF-8 */
|
||||
#define THREETRAIL /* legal but undefined if three more trailing UTF-8 */
|
||||
|
||||
typedef enum {
|
||||
asciicompat_converter, /* ASCII-compatible -> ASCII-compatible */
|
||||
asciicompat_decoder, /* ASCII-incompatible -> ASCII-compatible */
|
||||
asciicompat_encoder /* ASCII-compatible -> ASCII-incompatible */
|
||||
/* ASCII-incompatible -> ASCII-incompatible is intentionally omitted. */
|
||||
} mrb_transcoder_asciicompat_type_t;
|
||||
|
||||
typedef struct mrb_transcoder mrb_transcoder;
|
||||
|
||||
/* static structure, one per supported encoding pair */
|
||||
struct mrb_transcoder {
|
||||
const char *src_encoding;
|
||||
const char *dst_encoding;
|
||||
unsigned int conv_tree_start;
|
||||
const unsigned char *byte_array;
|
||||
unsigned int byte_array_length;
|
||||
const unsigned int *word_array;
|
||||
unsigned int word_array_length;
|
||||
int word_size;
|
||||
int input_unit_length;
|
||||
int max_input;
|
||||
int max_output;
|
||||
mrb_transcoder_asciicompat_type_t asciicompat_type;
|
||||
size_t state_size;
|
||||
int (*state_init_func)(void*); /* ret==0:success ret!=0:failure(errno) */
|
||||
int (*state_fini_func)(void*); /* ret==0:success ret!=0:failure(errno) */
|
||||
mrb_value (*func_ii)(void*, mrb_value); /* info -> info */
|
||||
mrb_value (*func_si)(void*, const unsigned char*, size_t); /* start -> info */
|
||||
ssize_t (*func_io)(void*, mrb_value, const unsigned char*, size_t); /* info -> output */
|
||||
ssize_t (*func_so)(void*, const unsigned char*, size_t, unsigned char*, size_t); /* start -> output */
|
||||
ssize_t (*finish_func)(void*, unsigned char*, size_t); /* -> output */
|
||||
ssize_t (*resetsize_func)(void*); /* -> len */
|
||||
ssize_t (*resetstate_func)(void*, unsigned char*, size_t); /* -> output */
|
||||
ssize_t (*func_sio)(void*, const unsigned char*, size_t, mrb_value, unsigned char*, size_t); /* start -> output */
|
||||
};
|
||||
|
||||
void mrb_declare_transcoder(mrb_state *mrb, const char *enc1, const char *enc2, const char *lib);
|
||||
void mrb_register_transcoder(mrb_state *mrb, const mrb_transcoder *);
|
||||
|
||||
#endif /* RUBY_TRANSCODE_DATA_H */
|
||||
-2607
File diff suppressed because it is too large
Load Diff
@@ -1,34 +0,0 @@
|
||||
#include "mruby.h"
|
||||
#ifdef INCLUDE_ENCODING
|
||||
#include "regenc.h"
|
||||
|
||||
static int
|
||||
us_ascii_mbc_enc_len(const UChar* p, const UChar* e, OnigEncoding enc)
|
||||
{
|
||||
if (*p & 0x80)
|
||||
return ONIGENC_CONSTRUCT_MBCLEN_INVALID();
|
||||
return ONIGENC_CONSTRUCT_MBCLEN_CHARFOUND(1);
|
||||
}
|
||||
|
||||
OnigEncodingDefine(us_ascii, US_ASCII) = {
|
||||
us_ascii_mbc_enc_len,
|
||||
"US-ASCII",/* name */
|
||||
1, /* max byte length */
|
||||
1, /* min byte length */
|
||||
onigenc_is_mbc_newline_0x0a,
|
||||
onigenc_single_byte_mbc_to_code,
|
||||
onigenc_single_byte_code_to_mbclen,
|
||||
onigenc_single_byte_code_to_mbc,
|
||||
onigenc_ascii_mbc_case_fold,
|
||||
onigenc_ascii_apply_all_case_fold,
|
||||
onigenc_ascii_get_case_fold_codes_by_str,
|
||||
onigenc_minimum_property_name_to_ctype,
|
||||
onigenc_ascii_is_code_ctype,
|
||||
onigenc_not_support_get_ctype_code_range,
|
||||
onigenc_single_byte_left_adjust_char_head,
|
||||
onigenc_always_true_is_allowed_reverse_match
|
||||
};
|
||||
ENC_ALIAS("ASCII", "US-ASCII")
|
||||
ENC_ALIAS("ANSI_X3.4-1968", "US-ASCII")
|
||||
ENC_ALIAS("646", "US-ASCII")
|
||||
#endif //INCLUDE_ENCODING
|
||||
-460
@@ -1,460 +0,0 @@
|
||||
/**********************************************************************
|
||||
utf_8.c - Oniguruma (regular expression library)
|
||||
**********************************************************************/
|
||||
/*-
|
||||
* Copyright (c) 2002-2007 K.Kosako <sndgk393 AT ybb DOT ne DOT jp>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "mruby.h"
|
||||
#ifdef INCLUDE_ENCODING
|
||||
#include "regenc.h"
|
||||
|
||||
#define USE_INVALID_CODE_SCHEME
|
||||
|
||||
#ifdef USE_INVALID_CODE_SCHEME
|
||||
/* virtual codepoint values for invalid encoding byte 0xfe and 0xff */
|
||||
#define INVALID_CODE_FE 0xfffffffe
|
||||
#define INVALID_CODE_FF 0xffffffff
|
||||
#define VALID_CODE_LIMIT 0x7fffffff
|
||||
#endif
|
||||
|
||||
#define utf8_islead(c) ((UChar )((c) & 0xc0) != 0x80)
|
||||
|
||||
static const int EncLen_UTF8[] = {
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
||||
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
||||
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
|
||||
4, 4, 4, 4, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
FAILURE = -2,
|
||||
ACCEPT,
|
||||
S0, S1, S2, S3,
|
||||
S4, S5, S6, S7
|
||||
} state_t;
|
||||
#define A ACCEPT
|
||||
#define F FAILURE
|
||||
static const signed char trans[][0x100] = {
|
||||
{ /* S0 0 1 2 3 4 5 6 7 8 9 a b c d e f */
|
||||
/* 0 */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
|
||||
/* 1 */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
|
||||
/* 2 */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
|
||||
/* 3 */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
|
||||
/* 4 */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
|
||||
/* 5 */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
|
||||
/* 6 */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
|
||||
/* 7 */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
|
||||
/* 8 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 9 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* a */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* b */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* c */ F, F, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
/* d */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
/* e */ 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 3, 3,
|
||||
/* f */ 5, 6, 6, 6, 7, F, F, F, F, F, F, F, F, F, F, F
|
||||
},
|
||||
{ /* S1 0 1 2 3 4 5 6 7 8 9 a b c d e f */
|
||||
/* 0 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 1 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 2 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 3 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 4 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 5 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 6 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 7 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 8 */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
|
||||
/* 9 */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
|
||||
/* a */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
|
||||
/* b */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
|
||||
/* c */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* d */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* e */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* f */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F
|
||||
},
|
||||
{ /* S2 0 1 2 3 4 5 6 7 8 9 a b c d e f */
|
||||
/* 0 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 1 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 2 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 3 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 4 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 5 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 6 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 7 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 8 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 9 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* a */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
/* b */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
/* c */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* d */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* e */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* f */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F
|
||||
},
|
||||
{ /* S3 0 1 2 3 4 5 6 7 8 9 a b c d e f */
|
||||
/* 0 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 1 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 2 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 3 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 4 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 5 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 6 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 7 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 8 */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
/* 9 */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
/* a */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
/* b */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
/* c */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* d */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* e */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* f */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F
|
||||
},
|
||||
{ /* S4 0 1 2 3 4 5 6 7 8 9 a b c d e f */
|
||||
/* 0 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 1 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 2 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 3 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 4 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 5 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 6 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 7 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 8 */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
/* 9 */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
/* a */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* b */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* c */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* d */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* e */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* f */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F
|
||||
},
|
||||
{ /* S5 0 1 2 3 4 5 6 7 8 9 a b c d e f */
|
||||
/* 0 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 1 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 2 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 3 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 4 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 5 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 6 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 7 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 8 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 9 */ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
|
||||
/* a */ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
|
||||
/* b */ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
|
||||
/* c */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* d */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* e */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* f */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F
|
||||
},
|
||||
{ /* S6 0 1 2 3 4 5 6 7 8 9 a b c d e f */
|
||||
/* 0 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 1 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 2 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 3 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 4 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 5 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 6 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 7 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 8 */ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
|
||||
/* 9 */ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
|
||||
/* a */ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
|
||||
/* b */ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
|
||||
/* c */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* d */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* e */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* f */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F
|
||||
},
|
||||
{ /* S7 0 1 2 3 4 5 6 7 8 9 a b c d e f */
|
||||
/* 0 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 1 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 2 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 3 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 4 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 5 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 6 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 7 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* 8 */ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
|
||||
/* 9 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* a */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* b */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* c */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* d */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* e */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
||||
/* f */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F
|
||||
},
|
||||
};
|
||||
#undef A
|
||||
#undef F
|
||||
|
||||
static int
|
||||
mbc_enc_len(const UChar* p, const UChar* e, OnigEncoding enc ARG_UNUSED)
|
||||
{
|
||||
int firstbyte = *p++;
|
||||
state_t s;
|
||||
s = trans[0][firstbyte];
|
||||
if (s < 0) return s == ACCEPT ? ONIGENC_CONSTRUCT_MBCLEN_CHARFOUND(1) :
|
||||
ONIGENC_CONSTRUCT_MBCLEN_INVALID();
|
||||
|
||||
if (p == e) return ONIGENC_CONSTRUCT_MBCLEN_NEEDMORE(EncLen_UTF8[firstbyte]-1);
|
||||
s = trans[s][*p++];
|
||||
if (s < 0) return s == ACCEPT ? ONIGENC_CONSTRUCT_MBCLEN_CHARFOUND(2) :
|
||||
ONIGENC_CONSTRUCT_MBCLEN_INVALID();
|
||||
|
||||
if (p == e) return ONIGENC_CONSTRUCT_MBCLEN_NEEDMORE(EncLen_UTF8[firstbyte]-2);
|
||||
s = trans[s][*p++];
|
||||
if (s < 0) return s == ACCEPT ? ONIGENC_CONSTRUCT_MBCLEN_CHARFOUND(3) :
|
||||
ONIGENC_CONSTRUCT_MBCLEN_INVALID();
|
||||
|
||||
if (p == e) return ONIGENC_CONSTRUCT_MBCLEN_NEEDMORE(EncLen_UTF8[firstbyte]-3);
|
||||
s = trans[s][*p++];
|
||||
return s == ACCEPT ? ONIGENC_CONSTRUCT_MBCLEN_CHARFOUND(4) :
|
||||
ONIGENC_CONSTRUCT_MBCLEN_INVALID();
|
||||
}
|
||||
|
||||
static int
|
||||
is_mbc_newline(const UChar* p, const UChar* end, OnigEncoding enc)
|
||||
{
|
||||
if (p < end) {
|
||||
if (*p == 0x0a) return 1;
|
||||
|
||||
#ifdef USE_UNICODE_ALL_LINE_TERMINATORS
|
||||
#ifndef USE_CRNL_AS_LINE_TERMINATOR
|
||||
if (*p == 0x0d) return 1;
|
||||
#endif
|
||||
if (p + 1 < end) {
|
||||
if (*(p+1) == 0x85 && *p == 0xc2) /* U+0085 */
|
||||
return 1;
|
||||
if (p + 2 < end) {
|
||||
if ((*(p+2) == 0xa8 || *(p+2) == 0xa9)
|
||||
&& *(p+1) == 0x80 && *p == 0xe2) /* U+2028, U+2029 */
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static OnigCodePoint
|
||||
mbc_to_code(const UChar* p, const UChar* end, OnigEncoding enc)
|
||||
{
|
||||
int c, len;
|
||||
OnigCodePoint n;
|
||||
|
||||
len = enclen(enc, p, end);
|
||||
c = *p++;
|
||||
if (len > 1) {
|
||||
len--;
|
||||
n = c & ((1 << (6 - len)) - 1);
|
||||
while (len--) {
|
||||
c = *p++;
|
||||
n = (n << 6) | (c & ((1 << 6) - 1));
|
||||
}
|
||||
return n;
|
||||
}
|
||||
else {
|
||||
#ifdef USE_INVALID_CODE_SCHEME
|
||||
if (c > 0xfd) {
|
||||
return ((c == 0xfe) ? INVALID_CODE_FE : INVALID_CODE_FF);
|
||||
}
|
||||
#endif
|
||||
return (OnigCodePoint )c;
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
code_to_mbclen(OnigCodePoint code, OnigEncoding enc ARG_UNUSED)
|
||||
{
|
||||
if ((code & 0xffffff80) == 0) return 1;
|
||||
else if ((code & 0xfffff800) == 0) return 2;
|
||||
else if ((code & 0xffff0000) == 0) return 3;
|
||||
else if ((code & 0xffe00000) == 0) return 4;
|
||||
else if ((code & 0xfc000000) == 0) return 5;
|
||||
else if ((code & 0x80000000) == 0) return 6;
|
||||
#ifdef USE_INVALID_CODE_SCHEME
|
||||
else if (code == INVALID_CODE_FE) return 1;
|
||||
else if (code == INVALID_CODE_FF) return 1;
|
||||
#endif
|
||||
else
|
||||
return ONIGERR_TOO_BIG_WIDE_CHAR_VALUE;
|
||||
}
|
||||
|
||||
static int
|
||||
code_to_mbc(OnigCodePoint code, UChar *buf, OnigEncoding enc ARG_UNUSED)
|
||||
{
|
||||
#define UTF8_TRAILS(code, shift) (UChar )((((code) >> (shift)) & 0x3f) | 0x80)
|
||||
#define UTF8_TRAIL0(code) (UChar )(((code) & 0x3f) | 0x80)
|
||||
|
||||
if ((code & 0xffffff80) == 0) {
|
||||
*buf = (UChar )code;
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
UChar *p = buf;
|
||||
|
||||
if ((code & 0xfffff800) == 0) {
|
||||
*p++ = (UChar )(((code>>6)& 0x1f) | 0xc0);
|
||||
}
|
||||
else if ((code & 0xffff0000) == 0) {
|
||||
*p++ = (UChar )(((code>>12) & 0x0f) | 0xe0);
|
||||
*p++ = UTF8_TRAILS(code, 6);
|
||||
}
|
||||
else if ((code & 0xffe00000) == 0) {
|
||||
*p++ = (UChar )(((code>>18) & 0x07) | 0xf0);
|
||||
*p++ = UTF8_TRAILS(code, 12);
|
||||
*p++ = UTF8_TRAILS(code, 6);
|
||||
}
|
||||
else if ((code & 0xfc000000) == 0) {
|
||||
*p++ = (UChar )(((code>>24) & 0x03) | 0xf8);
|
||||
*p++ = UTF8_TRAILS(code, 18);
|
||||
*p++ = UTF8_TRAILS(code, 12);
|
||||
*p++ = UTF8_TRAILS(code, 6);
|
||||
}
|
||||
else if ((code & 0x80000000) == 0) {
|
||||
*p++ = (UChar )(((code>>30) & 0x01) | 0xfc);
|
||||
*p++ = UTF8_TRAILS(code, 24);
|
||||
*p++ = UTF8_TRAILS(code, 18);
|
||||
*p++ = UTF8_TRAILS(code, 12);
|
||||
*p++ = UTF8_TRAILS(code, 6);
|
||||
}
|
||||
#ifdef USE_INVALID_CODE_SCHEME
|
||||
else if (code == INVALID_CODE_FE) {
|
||||
*p = 0xfe;
|
||||
return 1;
|
||||
}
|
||||
else if (code == INVALID_CODE_FF) {
|
||||
*p = 0xff;
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
else {
|
||||
return ONIGERR_TOO_BIG_WIDE_CHAR_VALUE;
|
||||
}
|
||||
|
||||
*p++ = UTF8_TRAIL0(code);
|
||||
return (int)(p - buf);
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
mbc_case_fold(OnigCaseFoldType flag, const UChar** pp,
|
||||
const UChar* end, UChar* fold, OnigEncoding enc)
|
||||
{
|
||||
const UChar* p = *pp;
|
||||
|
||||
if (ONIGENC_IS_MBC_ASCII(p)) {
|
||||
#ifdef USE_UNICODE_CASE_FOLD_TURKISH_AZERI
|
||||
if ((flag & ONIGENC_CASE_FOLD_TURKISH_AZERI) != 0) {
|
||||
if (*p == 0x49) {
|
||||
*fold++ = 0xc4;
|
||||
*fold = 0xb1;
|
||||
(*pp)++;
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
*fold = ONIGENC_ASCII_CODE_TO_LOWER_CASE(*p);
|
||||
(*pp)++;
|
||||
return 1; /* return byte length of converted char to lower */
|
||||
}
|
||||
else {
|
||||
return onigenc_unicode_mbc_case_fold(enc, flag, pp, end, fold);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
get_ctype_code_range(OnigCtype ctype, OnigCodePoint *sb_out,
|
||||
const OnigCodePoint* ranges[], OnigEncoding enc ARG_UNUSED)
|
||||
{
|
||||
*sb_out = 0x80;
|
||||
return onigenc_unicode_ctype_code_range(ctype, ranges);
|
||||
}
|
||||
|
||||
|
||||
static UChar*
|
||||
left_adjust_char_head(const UChar* start, const UChar* s, const UChar* end, OnigEncoding enc ARG_UNUSED)
|
||||
{
|
||||
const UChar *p;
|
||||
|
||||
if (s <= start) return (UChar* )s;
|
||||
p = s;
|
||||
|
||||
while (!utf8_islead(*p) && p > start) p--;
|
||||
return (UChar* )p;
|
||||
}
|
||||
|
||||
static int
|
||||
get_case_fold_codes_by_str(OnigCaseFoldType flag,
|
||||
const OnigUChar* p, const OnigUChar* end, OnigCaseFoldCodeItem items[],
|
||||
OnigEncoding enc)
|
||||
{
|
||||
return onigenc_unicode_get_case_fold_codes_by_str(enc, flag, p, end, items);
|
||||
}
|
||||
|
||||
OnigEncodingDefine(utf_8, UTF_8) = {
|
||||
mbc_enc_len,
|
||||
"UTF-8", /* name */
|
||||
6, /* max byte length */
|
||||
1, /* min byte length */
|
||||
is_mbc_newline,
|
||||
mbc_to_code,
|
||||
code_to_mbclen,
|
||||
code_to_mbc,
|
||||
mbc_case_fold,
|
||||
onigenc_unicode_apply_all_case_fold,
|
||||
get_case_fold_codes_by_str,
|
||||
onigenc_unicode_property_name_to_ctype,
|
||||
onigenc_unicode_is_code_ctype,
|
||||
get_ctype_code_range,
|
||||
left_adjust_char_head,
|
||||
onigenc_always_true_is_allowed_reverse_match
|
||||
};
|
||||
ENC_ALIAS("CP65001", "UTF-8")
|
||||
|
||||
/*
|
||||
* Name: UTF8-MAC
|
||||
* Link: http://developer.apple.com/documentation/MacOSX/Conceptual/BPFileSystem/BPFileSystem.html
|
||||
* Link: http://developer.apple.com/qa/qa2001/qa1235.html
|
||||
* Link: http://developer.apple.com/jp/qa/qa2001/qa1235.html
|
||||
* Link: http://www.gnu.org/software/emacs/NEWS.23.2
|
||||
*/
|
||||
ENC_REPLICATE("UTF8-MAC", "UTF-8")
|
||||
ENC_ALIAS("UTF-8-MAC", "UTF8-MAC")
|
||||
ENC_ALIAS("UTF-8-HFS", "UTF8-MAC") /* Emacs 23.2 */
|
||||
|
||||
#endif //INCLUDE_ENCODING
|
||||
+1
-1
@@ -85,7 +85,7 @@ assert('String#chomp', '15.2.10.5.9') do
|
||||
d == "abc\n" and e == 'abc' and f == "abc\n"
|
||||
end
|
||||
|
||||
assert('String#chomp', '15.2.10.5.10') do
|
||||
assert('String#chomp!', '15.2.10.5.10') do
|
||||
a = 'abc'
|
||||
b = ''
|
||||
c = "abc\n"
|
||||
|
||||
Reference in New Issue
Block a user