diff --git a/CMakeLists.txt b/CMakeLists.txt index d9a86293..fb2e0d4a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,7 +20,8 @@ file(GLOB_RECURSE CPP_SOURCES "src/*.cpp") message(${CPP_SOURCES}) -add_library(foo) +add_library(foo + src/compiler/compiler.cppm) target_sources(foo PUBLIC diff --git a/src/compiler/compile_env.cppm b/src/compiler/compile_env.cppm index 5cc77dfa..6dd72ed4 100644 --- a/src/compiler/compile_env.cppm +++ b/src/compiler/compile_env.cppm @@ -4,12 +4,10 @@ module; #include #include -#include "parser.tab.hpp" export module compile_env; import compiler_def; import TVMdef; import Error; -import language; export namespace trc::compiler { // size_t最大值,代表不存在 diff --git a/src/compiler/compiler.cpp b/src/compiler/compiler.cpp deleted file mode 100644 index 18b212bf..00000000 --- a/src/compiler/compiler.cpp +++ /dev/null @@ -1,43 +0,0 @@ -#include "compiler.hpp" -#include -import Error; -import compiler_def; - -namespace trc::compiler { -compiler::compiler() = default; - -int compiler::parse(const compiler_option& option, const std::string& f, TVM_space::TVM_static_data* vm) { - location.initialize(&f); - compile_data = new compiler_public_data(option, vm, location); - scan_begin(f); - yy::parser parse(*this); - parse.set_debug_level(trace_parsing); - int res = parse(); - scan_end(); - delete compile_data; - compile_data = nullptr; - return res; -} - -int compiler::parse(const compiler_option& option, const std::string&filename, FILE* f, TVM_space::TVM_static_data* vm) { - location.initialize(&filename); - compile_data = new compiler_public_data(option, *vm, location); - scan_begin(f); - yy::parser parse(*this); - parse.set_debug_level(trace_parsing); - int res = parse(); - scan_end(); - delete compile_data; - compile_data = nullptr; - return res; -} - -FILE* compiler::open_file(const std::string& file) { - auto f = fopen(file.c_str(), "r"); - if (f == nullptr) { - compile_data->send_error( - error::OpenFileError, language::error::openfileerror, file.c_str()); - } - return f; -} -} diff --git a/src/compiler/compiler.hpp b/src/compiler/compiler.cppm similarity index 65% rename from src/compiler/compiler.hpp rename to src/compiler/compiler.cppm index ecb2b25d..5d89cb43 100644 --- a/src/compiler/compiler.hpp +++ b/src/compiler/compiler.cppm @@ -1,16 +1,14 @@ -#pragma once - +module; #include +export module compiler; +import Error; +import compiler_def; namespace trc::TVM_space { - class TVM_static_data; +class TVM_static_data; } namespace trc::compiler { -class compiler_public_data; - -class compiler_option; - class compiler { public: compiler(); @@ -36,3 +34,18 @@ class compiler { }; } +namespace trc::compiler { +compiler::compiler() = default; + +int compiler::parse(const compiler_option& option, const std::string& f, TVM_space::TVM_static_data* vm) { + +} + +int compiler::parse(const compiler_option& option, const std::string&filename, FILE* f, TVM_space::TVM_static_data* vm) { + +} + +FILE* compiler::open_file(const std::string& file) { + +} +} diff --git a/src/compiler/compiler_def.cppm b/src/compiler/compiler_def.cppm index e3a02192..c45403aa 100644 --- a/src/compiler/compiler_def.cppm +++ b/src/compiler/compiler_def.cppm @@ -5,7 +5,6 @@ #include #include #include -#include "parser.tab.hpp" export module compiler_def; import TVM; import Error; @@ -81,15 +80,14 @@ public: */ class compiler_public_data { public: - compiler_public_data(const compiler_option& option, TVM_space::TVM_static_data& vm, yy::location& location) + compiler_public_data(const compiler_option& option, TVM_space::TVM_static_data& vm) : option(option) , vm(vm) , const_int(vm.const_i) , const_float(vm.const_f) , const_string(vm.const_s) , const_long_int(vm.const_long) - , const_name(name_list) - , loc(location) { + , const_name(name_list) { // 添加true,false,null常量 const_int.add(0); const_int.add(1); @@ -101,7 +99,6 @@ public: std::vector name_list; constant_pool_controller const_string, const_long_int, const_name; - yy::location& loc; /** * @brief 报出错误 @@ -110,7 +107,6 @@ public: void send_error(error::error_type errorn, const P&... argv) { //todo:optimize it std::stringstream ss; - ss << loc; error::send_error_interal(errorn, ss.str(), argv...); } }; diff --git a/src/trc/Trc.cpp b/src/trc/Trc.cpp index c89b0a9a..f0586923 100644 --- a/src/trc/Trc.cpp +++ b/src/trc/Trc.cpp @@ -23,13 +23,12 @@ import help; import run; import style; import tdb; -import tools.token; import tshell; import basic_def; import data; import color; import help; -import Compiler; +import compiler; import ctree_loader; import filesys; import code_loader; @@ -51,8 +50,8 @@ struct { const char* name; argv_func_tools tool_func; } cmd_tool[] = { { "tdb", tools::tools_out::tdb }, - { "help", tools::tools_out::help }, { "run", tools::tools_out::run }, - { "token", tools::tools_out::out_token }, { "dis", tools::tools_out::dis }, + { "help", tools::tools_out::help }, { "run", tools::tools_out::run } + , { "dis", tools::tools_out::dis }, { "build", tools::tools_out::build }, { "style", tools::tools_out::style } };