@@ -23,6 +23,10 @@ BM::Object *BM::Interpreter::run() {
2323 set (" undefined" , new Undefined);
2424 set (" null" , new Null);
2525
26+ if (!child && !(get (PASS_MODULE_NAME ) && get (PASS_MODULE_NAME )->value ()->type () == STRING && ((String*)get (PASS_MODULE_NAME )->value ())->value () == DEFAULT_IMPORT_NAME )) {
27+ if (!get (DEFAULT_IMPORT_NAME )) import (exports, DEFAULT_IMPORT_NAME , DEFAULT_IMPORT_NAME );
28+ Using (get (DEFAULT_IMPORT_NAME )->value (), new AST::node (" bmlang" , 0 ));
29+ }
2630 while (true ) {
2731 if (!child) ast->parse ();
2832// if (!ast->rValue()) continue;
@@ -724,6 +728,7 @@ void BM::Interpreter::import(Object* exports, const string& name, const string&
724728 script += tmpLine + " \n " ;
725729 }
726730 Interpreter ip (script, name);// import的文件是独立运行的,与import它的脚本连接
731+ ip.set (PASS_MODULE_NAME , new String (name));
727732 auto moduleExports = ip.run ();
728733 if (moduleExports->get (PASS_ERROR )) {
729734 std::cerr << " ImportError: Module script wrong at <" << filename << " >:" << ast->line () << std::endl;
@@ -743,6 +748,7 @@ void BM::Interpreter::import(Object* exports, const string& name, const string&
743748 script += tmpLine + " \n " ;
744749 }
745750 Interpreter ip (script, name);// import的文件是独立运行的,与import它的脚本连接
751+ ip.set (PASS_MODULE_NAME , new String (name));
746752 auto moduleExports = ip.run ();
747753 if (moduleExports->get (PASS_ERROR )) {
748754 std::cerr << " ImportError: Module script wrong at <" << filename << " >:" << ast->line () << std::endl;
@@ -755,13 +761,14 @@ void BM::Interpreter::import(Object* exports, const string& name, const string&
755761 // 为全局模块
756762 if (!finish) {
757763 string path (BMLMPATH + name + (name[nameLen - 1 ] == ' /' ? " init.bm" : " /init.bm" ));
758- file.open (name );
764+ file.open (path );
759765 if (file) {
760766 finish = true ;
761767 while (getline (file, tmpLine)) {
762768 script += tmpLine + " \n " ;
763769 }
764770 Interpreter ip (script, name);// import的文件是独立运行的,不与import它的脚本连接
771+ ip.set (PASS_MODULE_NAME , new String (name));
765772 auto moduleExports = ip.run ();
766773 if (moduleExports->get (PASS_ERROR )) {
767774 std::cerr << " ImportError: Module script wrong at <" << filename << " >:" << ast->line () << std::endl;
0 commit comments