Permalink
Browse files

a new Symbol class, unicode-aware + refactored/cleaned symbol generation

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 19f18d3bcfbc5468d5f79794cd7876efdeaaaab5
Showing with 523 additions and 652 deletions.
  1. +3 −0 encoding.h
  2. +1 −0 id.c
  3. +1 −0 id.h
  4. +1 −1 include/ruby/intern.h
  5. +9 −30 include/ruby/ruby.h
  6. +4 −2 inits.c
  7. +44 −587 parse.y
  8. +1 −1 rakelib/builder/builder.rb
  9. +41 −29 string.c
  10. +362 −0 symbol.c
  11. +54 −0 symbol.h
  12. +2 −2 vm.cpp
View
@@ -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.
@@ -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);
View
1 id.c
@@ -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:");
View
1 id.h
@@ -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;
View
@@ -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);
View
@@ -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);
}
@@ -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 {
@@ -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))
@@ -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);
View
@@ -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);
@@ -63,7 +64,7 @@ void Init_PostVM(void);
void
rb_call_inits()
{
- Init_sym();
+ Init_PreSymbol();
Init_id();
Init_var_tables();
Init_Object();
@@ -73,6 +74,7 @@ rb_call_inits()
Init_Enumerable();
Init_Precision();
Init_String();
+ Init_Symbol();
Init_Exception();
Init_eval();
Init_jump();
Oops, something went wrong.

0 comments on commit 19f18d3

Please sign in to comment.