Skip to content

Commit

Permalink
a new Symbol class, unicode-aware + refactored/cleaned symbol generation
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.macosforge.org/repository/ruby/MacRuby/branches/icu@3617 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information
lrz committed Feb 25, 2010
1 parent ffd9aa0 commit 19f18d3
Show file tree
Hide file tree
Showing 12 changed files with 523 additions and 652 deletions.
3 changes: 3 additions & 0 deletions encoding.h
Expand Up @@ -290,6 +290,8 @@ str_set_valid_encoding(rb_str_t *self, bool status)
STRING_VALID_ENCODING);
}

VALUE str_inspect(rb_str_t *str, bool dump);

// The following functions should always been prefered over anything else,
// especially if this "else" is RSTRING_PTR and RSTRING_LEN.
// They also work on CFStrings.
Expand All @@ -299,6 +301,7 @@ void rb_str_get_uchars(VALUE str, UChar **chars_p, long *chars_len_p,
long rb_str_chars_len(VALUE str);
UChar rb_str_get_uchar(VALUE str, long pos);
void rb_str_append_uchar(VALUE str, UChar c);
unsigned long rb_str_hash_uchars(UChar *chars, long chars_len);

VALUE mr_enc_s_is_compatible(VALUE klass, SEL sel, VALUE str1, VALUE str2);

Expand Down
1 change: 1 addition & 0 deletions id.c
Expand Up @@ -61,6 +61,7 @@ Init_id(void)
selLength = sel_registerName("length");
selSucc = sel_registerName("succ");
selNot = sel_registerName("!");
selNot2 = sel_registerName("!:");
selAlloc = sel_registerName("alloc");
selAllocWithZone = sel_registerName("allocWithZone:");
selCopyWithZone = sel_registerName("copyWithZone:");
Expand Down
1 change: 1 addition & 0 deletions id.h
Expand Up @@ -71,6 +71,7 @@ extern SEL selASET;
extern SEL selLength;
extern SEL selSucc;
extern SEL selNot;
extern SEL selNot2;
extern SEL selAlloc;
extern SEL selAllocWithZone;
extern SEL selCopyWithZone;
Expand Down
2 changes: 1 addition & 1 deletion include/ruby/intern.h
Expand Up @@ -587,7 +587,7 @@ VALUE rb_str_cat2(VALUE, const char*);
VALUE rb_str_append(VALUE, VALUE);
VALUE rb_str_concat(VALUE, VALUE);
VALUE rb_str_plus(VALUE str1, VALUE str2);
int rb_memhash(const void *ptr, long len);
long rb_memhash(const void *ptr, long len);
int rb_str_hash(VALUE);
int rb_str_hash_cmp(VALUE,VALUE);
int rb_str_comparable(VALUE, VALUE);
Expand Down
39 changes: 9 additions & 30 deletions include/ruby/ruby.h
Expand Up @@ -249,7 +249,8 @@ VALUE rb_ull2inum(unsigned LONG_LONG);
#else
// voodoo_float must be a function
// because the parameter must be converted to float
static inline VALUE voodoo_float(float f)
static inline VALUE
voodoo_float(float f)
{
return *(VALUE *)(&f);
}
Expand All @@ -258,15 +259,9 @@ static inline VALUE voodoo_float(float f)
#define FIXFLOAT_P(v) (((VALUE)v & IMMEDIATE_MASK) == FIXFLOAT_FLAG)
#define FIXFLOAT2DBL(v) coerce_ptr_to_double((VALUE)v)

#if WITH_OBJC
# define SYMBOL_P(x) (TYPE(x) == T_SYMBOL)
# define ID2SYM(x) (rb_id2str((ID)x))
# define SYM2ID(x) (RSYMBOL(x)->id)
#else
# define SYMBOL_P(x) (((VALUE)(x)&~(~(VALUE)0<<RUBY_SPECIAL_SHIFT))==SYMBOL_FLAG)
# define ID2SYM(x) (((VALUE)(x)<<RUBY_SPECIAL_SHIFT)|SYMBOL_FLAG)
# define SYM2ID(x) RSHIFT((unsigned long)x,RUBY_SPECIAL_SHIFT)
#endif
#define SYMBOL_P(x) (TYPE(x) == T_SYMBOL)
#define ID2SYM(x) (rb_id2str((ID)x))
#define SYM2ID(x) (rb_sym2id((VALUE)x))

/* special contants - i.e. non-zero and non-fixnum constants */
enum ruby_special_consts {
Expand Down Expand Up @@ -783,7 +778,6 @@ struct RBignum {
#define RFLOAT(obj) (R_CAST(RFloat)(obj))
#if WITH_OBJC
# define RFIXNUM(obj) (R_CAST(RFixnum)(obj))
# define RSYMBOL(obj) (R_CAST(RSymbol)(obj))
#endif
#define RDATA(obj) (R_CAST(RData)(obj))
#define RSTRUCT(obj) (R_CAST(RStruct)(obj))
Expand Down Expand Up @@ -918,33 +912,18 @@ ID rb_intern(const char*);
ID rb_intern2(const char*, long);
ID rb_intern_str(VALUE str);
ID rb_to_id(VALUE);
ID rb_sym2id(VALUE sym);
VALUE rb_id2str(ID);
VALUE rb_name2sym(const char *);
#if WITH_OBJC
# define rb_sym2name(sym) (RSYMBOL(sym)->str)
const char *rb_sym2name(VALUE sym);
VALUE rb_sym2str(VALUE sym);

static inline
const char *rb_id2name(ID val)
{
VALUE s = rb_id2str(val);
return s == 0 ? NULL : rb_sym2name(s);
}
#else
const char *rb_id2name(ID);
#endif

#ifdef __GNUC__
/* __builtin_constant_p and statement expression is available
* since gcc-2.7.2.3 at least. */
#define rb_intern(str) \
(__builtin_constant_p(str) ? \
({ \
static ID rb_intern_id_cache; \
if (!rb_intern_id_cache) \
rb_intern_id_cache = rb_intern(str); \
rb_intern_id_cache; \
}) : \
rb_intern(str))
#endif

const char *rb_class2name(VALUE);
const char *rb_obj_classname(VALUE);
Expand Down
6 changes: 4 additions & 2 deletions inits.c
Expand Up @@ -36,7 +36,8 @@ void Init_Numeric(void);
void Init_Object(void);
void Init_pack(void);
void Init_Precision(void);
void Init_sym(void);
void Init_Symbol(void);
void Init_PreSymbol(void);
void Init_id(void);
void Init_process(void);
void Init_Random(void);
Expand All @@ -63,7 +64,7 @@ void Init_PostVM(void);
void
rb_call_inits()
{
Init_sym();
Init_PreSymbol();
Init_id();
Init_var_tables();
Init_Object();
Expand All @@ -73,6 +74,7 @@ rb_call_inits()
Init_Enumerable();
Init_Precision();
Init_String();
Init_Symbol();
Init_Exception();
Init_eval();
Init_jump();
Expand Down

0 comments on commit 19f18d3

Please sign in to comment.