void tort_gc_mark_range(tort_v referrer, void *b, void *e) { // FIXME #if TORT_GC_SMAL smal_mark_ptr_range(tort_h(referrer), b, e); #endif }
tort_v _tort_m_initializer__mtable(tort_tp tort_v init) { tort_mtable *obj_mt, *cls_mt; /* Create mtable method table. */ obj_mt = tort_mtable_new_0(0); cls_mt = tort_h_mtable(obj_mt); tort_h(cls_mt)->mtable = obj_mt; tort_h(obj_mt)->mtable = obj_mt; tort__mt(mtable) = obj_mt; /* Create object method table. */ // obj_mt = tort_mtable_new_class(0); // cls_mt = tort_h_mtable(obj_mt); // cls_mt->delegate = obj_mt; obj_mt = tort_mtable_new_0(0); tort__mt(object) = obj_mt; /*************************************************/ /* Create core method tables. */ tort__mt(vector_base) = tort_mtable_new_class(tort__mt(object)); tort__mt(pair) = tort_mtable_new_class(tort__mt(object)); tort__mt(vector) = tort_mtable_new_class(tort__mt(vector_base)); tort__mt(map) = tort_mtable_new_class(tort__mt(vector)); _tort_m_mtable__delegateSET(tort_ta tort__mt(mtable), tort__mt(map)); // tort_mtable_set_class_delegate(tort__mt(mtable), tort__mt(map)); // ??? /* Initialize nil object header. */ tort__mt(nil) = tort_mtable_new_class(tort__mt(object)); tort_(nil_header).mtable = tort__mt(nil); tort_(nil_header).applyf = _tort_m_object___cannot_apply; /* Initialize tagged object headers. */ tort__mt(tagged) = tort_mtable_new_class(tort__mt(object)); { int i; for ( i = 0; i < 1 << TORT_TAG_BITS; ++ i ) { tort_(tagged_header[i]).mtable = tort_mtable_new_class(tort__mt(tagged)); tort_(tagged_header[i]).applyf = _tort_m_object___cannot_apply; } } #ifdef tort_tag_fixnum tort__mt(fixnum) = tort_(tagged_header[tort_tag_fixnum]).mtable; #endif #ifdef tort_tag_locative tort__mt(locative) = tort_(tagged_header[tort_tag_locative]).mtable; tort_(tagged_header[tort_tag_locative]).applyf = (void*) _tort_m_locative___applyf; #endif /* Other core. */ tort__mt(word) = tort_mtable_new_class(tort__mt(object)); tort__mt(ptr) = tort_mtable_new_class(tort__mt(word)); tort__mt(u8vector) = tort_mtable_new_class(tort__mt(vector_base)); tort__mt(string) = tort_mtable_new_class(tort__mt(u8vector)); tort__mt(symbol) = tort_mtable_new_class(tort__mt(object)); tort__mt(symbol_encoder) = tort_mtable_new_class(tort__mt(object)); tort__mt(method) = tort_mtable_new_class(tort__mt(object)); tort__mt(slot) = tort_mtable_new_class(tort__mt(object)); tort__mt(slot)->instance_size = sizeof(tort_slot); tort__mt(value) = tort_mtable_new_class(tort__mt(method)); tort__mt(message) = tort_mtable_new_class(tort__mt(object)); tort__mt(message)->instance_size = sizeof(tort_message); tort__mt(caller_info) = tort_mtable_new_class(tort__mt(object)); tort__mt(caller_info)->instance_size = sizeof(tort_caller_info); tort__mt(boolean) = tort_mtable_new_class(tort__mt(object)); tort__mt(initializer) = tort_mtable_new_class(tort__mt(map)); tort__mt(initializer)->instance_size = sizeof(tort_map); /* io */ tort__mt(io) = tort_mtable_new_class(tort__mt(object)); tort__mt(eos) = tort_mtable_new_class(tort__mt(object)); /* dynlib */ tort__mt(dynlib) = tort_mtable_new_class(tort__mt(map)); /* gc */ tort__mt(gc) = tort_mtable_new_class(tort__mt(object)); /* force references for extensions. */ (void) tort__mt(block); return init; }
tort_v tort_runtime_create_ (int *argcp, char ***argvp, char ***envp) { tort_mtable *obj_mt, *cls_mt; tort_v init_backlog[10]; int init_backlog_n = 0; { char *s; if ( (s = getenv("TORT_INIT_DEBUG")) && *s ) _tort_init_debug = atoi(s); } assert(sizeof(tort_header) % sizeof(tort_v) == 0); INIT(malloc); /* Create runtime object. */ #if TORT_MULTIPLICITY _tort = tort_ref(tort_runtime, tort_allocate(0, sizeof(tort_runtime))); #endif tort_(_initialized) = 0; INIT(error); /* Setup environment from main. */ tort_(_argc) = *argcp; tort_(_argv) = *argvp; tort_(_env) = *envp; tort_(stack_bottom) = envp; /* Allocate and initialize mtables */ INIT(mtable); tort_h(_tort)->mtable = tort__mt(runtime); tort_h(_tort)->applyf = _tort_m_object___cannot_apply; #if ! TORT_NIL_IS_ZERO /* Create the nil object. */ tort_nil = tort_allocate(tort__mt(nil), sizeof(tort_object)); #endif /* Create the boolean objects. */ tort_true = tort_allocate(tort__mt(boolean), sizeof(tort_object)); #if ! TORT_FALSE_IS_NIL tort_false = tort_allocate(tort__mt(boolean), sizeof(tort_object)); #endif /* Backpatch object delegate as nil. */ tort_ref(tort_mtable, tort__mt(object))->delegate = tort_nil; /* Initialize the message reference. */ _tort_message = tort_nil; tort_(message) = tort_nil; /* Initialize lookup(). */ INIT(lookup); /*******************************************************/ /* Messaging Boot strap. */ /* Create the symbol table. */ tort_(symbols) = tort_map_new(); obj_mt = tort__mt(mtable); cls_mt = tort_h_mtable(obj_mt); tort__s(lookup) = tort_symbol_new("lookup"); tort_add_method(cls_mt, "lookup", _tort_m_mtable__lookup); tort__s(add_method) = tort_symbol_new("add_method"); tort_add_method(cls_mt, "add_method", _tort_m_mtable__add_method); tort__s(allocate) = tort_symbol_new("allocate"); tort_send(tort__s(add_method), cls_mt, tort__s(allocate), tort_method_new(_tort_M_object__allocate, 0)); /******************************************************/ /* Create the core symbols. */ INIT(symbol); /* Create the mtable map. */ tort_(m_mtable) = tort_map_new(); #define tort_d_mt(X) \ if ( tort__mt(X) ) _tort_m_map__set(tort_ta tort_(m_mtable), tort_symbol_new(#X), tort__mt(X)); #include "tort/d_mt.h" /* Install core methods. */ INIT(method); /* Start initializer. */ tort_(initializer) = tort_send(tort__s(new), tort__mt(initializer)); while ( init_backlog_n > 0 ) tort_send(tort__s(set), tort_(initializer), init_backlog[-- init_backlog_n], tort__s(initialized)); INIT(eq); INIT(cmp); /* Add core slots. */ INIT(slot); /* Create the root table. */ tort_(root) = tort_map_new(); /* Symbol Encoder. */ INIT(symbol_encoder); /* Uncloneable objects. */ tort_add_method(tort__mt(symbol), "clone", _tort_m_object__identity); tort_add_method(tort__mt(nil), "clone", _tort_m_object__identity); tort_add_method(tort__mt(ptr), "clone", _tort_m_object__identity); tort_add_method(tort__mt(tagged), "clone", _tort_m_object__identity); tort_add_method(tort__mt(boolean), "clone", _tort_m_object__identity); /* Initialize system method table. */ tort_h(_tort)->mtable = tort_mtable_new_class(tort__mt(object)); /* Subsystem initialization. */ INIT(gc); /* unknown caller_info */ tort_(unknown_caller_info) = tort_send(tort__s(_allocate), tort__mt(caller_info), tort_i(sizeof(tort_caller_info))); tort_(unknown_caller_info)->file = "<unknown>"; /* Setup the root namespace. */ #define ROOT(N,V) tort_send(tort__s(set), tort_(root), tort_symbol_new(#N), (V)) ROOT(runtime, tort_ref_box(_tort)); ROOT(initializer, tort_(initializer)); ROOT(nil, tort_nil); ROOT(true, tort_true); ROOT(false, tort_false); ROOT(symbols, tort_(symbols)); ROOT(mtable, tort_(m_mtable)); ROOT(unknown_caller_info, tort_(unknown_caller_info)); ROOT(tag_bits, tort_i(TORT_TAG_BITS)); ROOT(word_size, tort_i(sizeof(tort_v))); ROOT(object_header_size, tort_i(sizeof(tort_header))); INIT(io); INIT(printf); INIT(debug); INIT(dynlib); { int i; tort_v m = tort_map_new(); for ( i = 0; i < 1 << TORT_TAG_BITS; ++ i ) { tort_v k = tort_i(i), v = tort_(tagged_header)[i].mtable; if ( ! v ) v = tort_nil; tort_send(tort__s(set), m, k, v); tort_send(tort__s(set), m, v, k); } ROOT(tagged_mtables, m); } { int i; tort_v v = tort_vector_new(0, 0); for ( i = 0; i < tort_(_argc) && tort_(_argv)[i]; ++ i ) { tort_send(tort__s(add), v, tort_string_new_cstr(tort_(_argv)[i])); } ROOT(argv, v); } INIT(gc_ready); tort_(_initialized) = tort_true; // fprintf(stderr, "\ntort: initialized\n"); #undef ROOT #undef INIT return tort_ref_box(_tort); }