Permalink
Browse files

more work

git-svn-id: http://svn.macosforge.org/repository/ruby/MacRuby/branches/icu@3565 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information...
1 parent dc4596a commit ae4da82af175341de376be13196cadac6dcefa7d @lrz lrz committed Feb 17, 2010
Showing with 58 additions and 31 deletions.
  1. +16 −10 encoding.c
  2. +5 −3 eval.c
  3. +8 −9 parse.y
  4. +2 −2 rakelib/builder/options.rb
  5. +2 −2 re.c
  6. +17 −5 string.c
  7. +8 −0 vm.cpp
View
@@ -216,16 +216,12 @@ add_encoding(
default:
abort();
}
-
- // create constants
- define_encoding_constant(public_name, encoding);
- for (unsigned int i = 0; i < aliases_count; ++i) {
- define_encoding_constant(aliases[i], encoding);
- }
}
-static void
-create_encodings(void)
+// This Init function is called very early. Do not use any runtime method
+// because things may not be initialized properly yet.
+void
+Init_PreEncoding(void)
{
add_encoding(ENCODING_BINARY, ENCODING_TYPE_SPECIAL, "ASCII-8BIT", 1, true, true, "BINARY", NULL);
add_encoding(ENCODING_ASCII, ENCODING_TYPE_UCNV, "US-ASCII", 1, true, true, "ASCII", "ANSI_X3.4-1968", "646", NULL);
@@ -251,7 +247,10 @@ mr_enc_s_is_compatible(VALUE klass, SEL sel, VALUE str1, VALUE str2);
void
Init_Encoding(void)
{
- rb_cEncoding = rb_define_class("Encoding", rb_cObject);
+ // rb_cEncoding is defined earlier in Init_PreVM().
+ rb_set_class_path(rb_cEncoding, rb_cObject, "Encoding");
+ rb_const_set(rb_cObject, rb_intern("Encoding"), rb_cEncoding);
+
rb_undef_alloc_func(rb_cEncoding);
rb_objc_define_method(rb_cEncoding, "to_s", mr_enc_name, 0);
@@ -283,7 +282,14 @@ Init_Encoding(void)
//rb_define_singleton_method(rb_cEncoding, "default_internal=", set_default_internal, 1);
//rb_define_singleton_method(rb_cEncoding, "locale_charmap", rb_locale_charmap, 0);
- create_encodings();
+ // Create constants.
+ for (unsigned int i = 0; i < ENCODINGS_COUNT; i++) {
+ rb_encoding_t *enc = rb_encodings[i];
+ define_encoding_constant(enc->public_name, enc);
+ for (unsigned int j = 0; j < enc->aliases_count; j++) {
+ define_encoding_constant(enc->aliases[j], enc);
+ }
+ }
}
// MRI C-API compatibility.
View
8 eval.c
@@ -39,6 +39,7 @@ void Init_ext(void);
void Init_PreGC(void);
void Init_PreVM(void);
void Init_PreGCD(void);
+void Init_PreEncoding(void);
bool ruby_dlog_enabled = false;
FILE *ruby_dlog_file = NULL;
@@ -72,9 +73,10 @@ ruby_init(void)
}
}
- Init_PreGC();
- Init_PreVM();
- Init_PreGCD();
+ Init_PreGC(); // requires nothing
+ Init_PreVM(); // requires nothing
+ Init_PreGCD(); // requires nothing
+ Init_PreEncoding(); // requires rb_cEncoding, GC
rb_call_inits();
ruby_prog_init();
View
17 parse.y
@@ -9341,7 +9341,6 @@ Init_sym(void)
global_symbols.id_str = CFDictionaryCreateMutable(NULL,
0, NULL, NULL);
GC_ROOT(&global_symbols.id_str);
- rb_cSymbol = rb_objc_create_class("Symbol", (VALUE)objc_getClass("NSString"));
#else
global_symbols.sym_id = st_init_table_with_size(&symhash, 1000);
global_symbols.id_str = st_init_numtable_with_size(1000);
@@ -9518,16 +9517,16 @@ rb_enc_symname2_p(const char *name, int len, rb_encoding *enc)
static inline VALUE
rsymbol_new(const char *name, const int len, ID id)
{
- VALUE sym;
+ assert(rb_cSymbol != 0);
- sym = (VALUE)orig_malloc(sizeof(struct RSymbol));
- RSYMBOL(sym)->str = orig_malloc(len + 1);
- RSYMBOL(sym)->klass = rb_cSymbol;
- strcpy(RSYMBOL(sym)->str, name);
- RSYMBOL(sym)->len = len;
- RSYMBOL(sym)->id = id;
+ struct RSymbol *sym = (struct RSymbol *)orig_malloc(sizeof(struct RSymbol));
+ sym->klass = rb_cSymbol;
+ sym->str = orig_malloc(len + 1);
+ strcpy(sym->str, name);
+ sym->len = len;
+ sym->id = id;
- return sym;
+ return (VALUE)sym;
}
#endif
@@ -99,8 +99,8 @@ def self.option(name, default)
ARCHFLAGS = ARCHS.map { |a| '-arch ' + a }.join(' ')
LLVM_MODULES = "core jit nativecodegen bitwriter"
-CC = '/usr/bin/gcc'
-CXX = '/usr/bin/g++'
+CC = '/usr/bin/gcc-4.2'
+CXX = '/usr/bin/g++-4.2'
CFLAGS = "-I. -I./include -I./onig -I/usr/include/libxml2 #{ARCHFLAGS} -fno-common -pipe -O3 -g -Wall -fexceptions"
CFLAGS << " -I./unicode" # TODO use /usr/local/include/unicode on FNI installs...
CFLAGS << " -Wno-parentheses -Wno-deprecated-declarations -Werror" if NO_WARN_BUILD
View
4 re.c
@@ -2452,7 +2452,7 @@ rb_reg_preprocess(const char *p, const char *end, rb_encoding *enc,
buf = rb_str_buf_new(0);
*fixed_enc = 0;
- if (rb_enc_asciicompat(enc))
+ if (true) //rb_enc_asciicompat(enc))
*fixed_enc = 0;
else {
*fixed_enc = enc;
@@ -3329,7 +3329,7 @@ rb_reg_s_union(VALUE self, VALUE args0)
v = rb_check_regexp_type(e);
if (!NIL_P(v)) {
rb_encoding *enc = rb_enc_get(v);
- if (!rb_enc_asciicompat(enc)) {
+ if (false) {//!rb_enc_asciicompat(enc)) {
if (!has_ascii_incompat)
has_ascii_incompat = enc;
else if (has_ascii_incompat != enc)
View
@@ -211,6 +211,8 @@ str_replace_with_bytes(rb_str_t *self, const char *bytes, long len,
rb_encoding_t *enc)
{
assert(len >= 0);
+ assert(enc != NULL);
+
self->flags = 0;
self->encoding = enc;
self->capacity_in_bytes = self->length_in_bytes = len;
@@ -1328,10 +1330,12 @@ Init_String(void)
rb_cNSMutableString = (VALUE)objc_getClass("NSMutableString");
assert(rb_cNSMutableString != 0);
- rb_cRubyString = rb_define_class("String", rb_cNSMutableString);
+ // rb_cRubyString is defined earlier in Init_PreVM().
+ rb_set_class_path(rb_cRubyString, rb_cObject, "String");
+ rb_const_set(rb_cObject, rb_intern("String"), rb_cRubyString);
+
rb_objc_define_method(*(VALUE *)rb_cRubyString, "alloc",
mr_str_s_alloc, 0);
-
rb_objc_define_method(rb_cRubyString, "initialize", mr_str_initialize, -1);
rb_objc_define_method(rb_cRubyString, "initialize_copy", mr_str_replace, 1);
rb_objc_define_method(rb_cRubyString, "replace", mr_str_replace, 1);
@@ -1372,6 +1376,10 @@ Init_String(void)
rb_fs = Qnil;
rb_define_variable("$;", &rb_fs);
rb_define_variable("$-F", &rb_fs);
+
+ // rb_cSymbol is defined earlier in Init_PreVM().
+ rb_set_class_path(rb_cSymbol, rb_cObject, "Symbol");
+ rb_const_set(rb_cObject, rb_intern("Symbol"), rb_cSymbol);
}
bool
@@ -1422,7 +1430,8 @@ VALUE
bstr_new_with_data(const uint8_t *bytes, long len)
{
rb_str_t *str = str_alloc(rb_cRubyString);
- str_replace_with_bytes(str, (char *)bytes, len, ENCODING_BINARY);
+ str_replace_with_bytes(str, (char *)bytes, len,
+ rb_encodings[ENCODING_BINARY]);
return (VALUE)str;
}
@@ -1469,7 +1478,7 @@ rb_enc_str_new(const char *cstr, long len, rb_encoding_t *enc)
VALUE
rb_str_new(const char *cstr, long len)
{
- return rb_enc_str_new(cstr, len, ENCODING_BINARY);
+ return rb_enc_str_new(cstr, len, rb_encodings[ENCODING_BINARY]);
}
VALUE
@@ -1662,7 +1671,7 @@ rb_enc_str_buf_cat(VALUE str, const char *cstr, long len, rb_encoding_t *enc)
VALUE
rb_str_buf_cat(VALUE str, const char *cstr, long len)
{
- return rb_enc_str_buf_cat(str, cstr, len, ENCODING_BINARY);
+ return rb_enc_str_buf_cat(str, cstr, len, rb_encodings[ENCODING_BINARY]);
}
VALUE
@@ -1751,6 +1760,9 @@ rb_str_dup(VALUE str)
if (IS_RSTR(str)) {
return (VALUE)str_dup(str);
}
+ if (TYPE(str) == T_SYMBOL) {
+ return rb_str_new2(RSYMBOL(str)->str);
+ }
abort(); // TODO
}
View
8 vm.cpp
@@ -4922,6 +4922,14 @@ Init_PreVM(void)
assert(m != NULL);
old_resolveInstanceMethod_imp = method_getImplementation(m);
method_setImplementation(m, (IMP)resolveInstanceMethod_imp);
+
+ // Early define some classes.
+ rb_cSymbol = rb_objc_create_class("Symbol",
+ (VALUE)objc_getClass("NSString"));
+ rb_cEncoding = rb_objc_create_class("Encoding",
+ (VALUE)objc_getClass("NSObject"));
+ rb_cRubyString = rb_objc_create_class("String",
+ (VALUE)objc_getClass("NSMutableString"));
}
static VALUE

0 comments on commit ae4da82

Please sign in to comment.