Class* Method::init(State& S, Environment* env) { Class* mc = env->new_class(S, "Method"); mc->add_method(S, "eval", run_code, -1); mc->add_method(S, "apply", method_apply, -1); mc->add_method(S, "|", method_apply, -1); return mc; }
Class* init_import(State& S) { Class* x = S.env().new_class(S, "Importer"); x->add_method(S, "import", import, 1); x->add_method(S, "load", load, 1); x->add_class_method(S, "current", current, 0); S.env().new_class(S, "ImportError"); return x; }
void Environment::init_ontology(State& S) { check(!top_); String* on = String::internalize(S, "Object"); Class* o = new(S) Class(S, Class::Boot, 0, 0, on); String* cn = String::internalize(S, "Class"); Class* c = new(S) Class(S, Class::Boot, 0, o, cn); String* mn = String::internalize(S, "MetaClass"); Class* m = new(S) Class(S, Class::Boot, 0, 0, mn); Class* mco = new(S) Class(S, Class::Boot, m, c, Class::metaclass_name(S, on)); o->klass_ = mco; Class* mcc = new(S) Class(S, Class::Boot, m, mco, Class::metaclass_name(S, cn)); c->klass_ = mcc; Class* mcm = new(S) Class(S, Class::Boot, m, mco, Class::metaclass_name(S, mn)); m->klass_ = mcm; Class* mod = new(S) Class(S, o, String::internalize(S, "Module")); top_ = new(S) Module(S, mod, String::internalize(S, "lang")); bind(S, on, o); bind(S, cn, c); bind(S, mn, m); bind(S, String::internalize(S, "Module"), mod); Class::init(S, c); Object::init(S, o); Class* trait = Trait::init(S, this); Class* i = Integer::init(S, this); Class* n = new_class(S, "NilClass"); Class* s = new_class(S, "String"); Class* d = new_class(S, "Code"); Class* mc = Method::init(S, this); Class* t = new_class(S, "TrueClass"); t->add_method(S, "to_s", true_to_s, 0); Class* f = new_class(S, "FalseClass"); f->add_method(S, "to_s", false_to_s, 0); Class* tuple = Tuple::init(S, this); Class* dict = new_class(S, "Dictionary"); Class* list = new_class(S, "List"); modules_ = new(S) Dictionary(S); args_ = new(S) List(S); sys_ = new(S) Dictionary(S); sys_->set(S, String::internalize(S, "modules"), modules_); sys_->set(S, String::internalize(S, "args"), args_); Class* exc = new_class(S, "Exception"); Class* rte = new_class(S, "RuntimeError", exc); Class* arg_err = new_class(S, "ArgumentError", rte); new_class(S, "ImportError", rte); Class* nme = new_class(S, "NoMethodError", rte); exc->add_method(S, "message", exc_message, 0); exc->add_method(S, "show", exc_show, 0); Class** tbl = new(S) Class*[OOP::TotalTypes]; tbl[OOP::eNil] = n; tbl[OOP::eClass] = c; tbl[OOP::eInteger] = i; tbl[OOP::eString] = s; tbl[OOP::eCode] = d; tbl[OOP::eUser] = 0; tbl[OOP::eTrue] = t; tbl[OOP::eFalse] = f; tbl[OOP::eUnwind] = new_class(S, "Unwind"); tbl[OOP::eMethod] = mc; tbl[OOP::eTuple] = tuple; tbl[OOP::eDictionary] = dict; tbl[OOP::eList] = list; tbl[OOP::eTrait] = trait; Class::init_base(tbl); Module::init(S, *this); String* io_n = String::internalize(S, "io"); Module* io = new(S) Module(S, mod, io_n); io->add_method(S, "puts", io_puts, 1); io->add_method(S, "print", io_print, 1); bind(S, io_n, io); Class* importer = init_import(S); String::init(S); Dictionary::init(S, dict); List::init(S, list); globals_ = new(S) Closure(14); globals_->set(0, o); globals_->set(1, io); globals_->set(2, c); globals_->set(3, importer); globals_->set(4, dict); globals_->set(5, i); globals_->set(6, sys_); globals_->set(7, trait); globals_->set(8, arg_err); globals_->set(9, nme); globals_->set(10, exc); globals_->set(11, list); Code* enum_code = 0; if(dev_) { FILE* file = fopen("kernel/enumerable.mr", "r"); check(file); Compiler compiler; check(compiler.compile(S, String::internalize(S, "kernel/enumerable.mr"), file)); enum_code = compiler.code(); fclose(file); } else { enum_code = frozen_enumerable(S); } run_top_code(S, enum_code); Trait* enum_ = lookup(S, "Enumerable").as_trait(); tuple->uses_trait(S, enum_); init_builtin_extensions(S); S.set_importer(new(S) User(S, lookup(S, "Importer").as_class())); run_top_code(S, frozen_dir(S)); { #include "kernel/moment.mrc" run_top_code(S, Code::load_raw(S, (unsigned char*)data, data_size)); } globals_->set(12, lookup(S, "Dir")); globals_->set(13, lookup(S, "Moment")); }