自作言語nullptrのインタープリターです。
修订版 | 54c9ccaa2b2a4d4ba22188987566ef2404ad0e59 (tree) |
---|---|
时间 | 2015-08-13 00:05:27 |
作者 | VOSystems <diverge.vosystems@gmai...> |
Commiter | VOSystems |
begin to create Load Identifier function
@@ -13,7 +13,7 @@ nullptr interpreter | ||
13 | 13 | using namespace std; |
14 | 14 | using namespace VOSystemsNullptr::Core; |
15 | 15 | |
16 | -inline VOSystemsNullptr::System::ModuleFunction SearchDLL(VOSystemsNullptr::System::Module module, string name); | |
16 | +inline LibraryFunction SearchDLL(Library lib, string name); | |
17 | 17 | |
18 | 18 | bool Module::Connect(std::string name) |
19 | 19 | { |
@@ -43,16 +43,16 @@ bool Module::Run(std::string name, BasicTypes::Int* paramInt, BasicTypes::String | ||
43 | 43 | |
44 | 44 | switch(m_mf.mode){ |
45 | 45 | case System::NotFound: |
46 | - case System::ReturnBool: | |
46 | + case System::BoolType: | |
47 | 47 | default: |
48 | 48 | return false; |
49 | 49 | break; |
50 | - case System::ReturnInt: | |
50 | + case System::IntType: | |
51 | 51 | Core::IntFunc ifunc=(Core::IntFunc)GetProcAddress(m_module,"runRI"); |
52 | 52 | m_int=(*ifunc)(name,paramInt,paramString); |
53 | 53 | |
54 | 54 | break; |
55 | - case System::ReturnString: | |
55 | + case System::StringType: | |
56 | 56 | Core::StrFunc sfunc=(Core::StrFunc)GetProcAddress(m_module,"runRS"); |
57 | 57 | m_str=(*sfunc)(name,paramInt,paramString); |
58 | 58 | break; |
@@ -72,18 +72,18 @@ bool Module::DisConnect(void) | ||
72 | 72 | } |
73 | 73 | } |
74 | 74 | |
75 | -VOSystemsNullptr::System::ModuleFunction Module::DllSearch(std::string name) | |
75 | +LibraryFunction Module::DllSearch(std::string name) | |
76 | 76 | { |
77 | 77 | this->m_modules.size(); |
78 | 78 | vector<thread> th(this->m_modules.size()); |
79 | - vector<future<System::ModuleFunction>> fu(this->m_modules.size()); | |
79 | + vector<future<LibraryFunction>> fu(this->m_modules.size()); | |
80 | 80 | |
81 | 81 | for(size_t C=0; C<this->m_modules.size(); C++){ |
82 | - System::Module mod=m_modules[C]; | |
82 | + Library mod=m_modules[C]; | |
83 | 83 | fu[C]=async([mod,name](string){SearchDLL(mod,name);});//th[C]=thread([mod,name](){SearchDLL(mod,name);}); |
84 | 84 | } |
85 | 85 | |
86 | - vector<System::ModuleFunction> result(this->m_modules.size()); | |
86 | + vector<LibraryFunction> result(this->m_modules.size()); | |
87 | 87 | for(size_t C=0; C<this->m_modules.size(); C++){ |
88 | 88 | result[C]=fu[C].get(); |
89 | 89 | if(!result[C].mode==System::NotFound){ |
@@ -91,19 +91,19 @@ VOSystemsNullptr::System::ModuleFunction Module::DllSearch(std::string name) | ||
91 | 91 | } |
92 | 92 | } |
93 | 93 | |
94 | - VOSystemsNullptr::System::ModuleFunction mf; | |
95 | - mf.mode=VOSystemsNullptr::System::NotFound; | |
94 | + LibraryFunction mf; | |
95 | + mf.mode=System::NotFound; | |
96 | 96 | return mf; |
97 | 97 | } |
98 | 98 | |
99 | -inline VOSystemsNullptr::System::ModuleFunction SearchDLL(VOSystemsNullptr::System::Module module, string name) | |
99 | +inline LibraryFunction SearchDLL(Library lib, string name) | |
100 | 100 | { |
101 | - for(size_t C=0; C<module.size(); C++){ | |
102 | - if(module[C].name==name){ | |
103 | - return module[C]; | |
101 | + for(size_t C=0; C<lib.size(); C++){ | |
102 | + if(lib[C].name==name){ | |
103 | + return lib[C]; | |
104 | 104 | } |
105 | 105 | } |
106 | - VOSystemsNullptr::System::ModuleFunction mf; | |
106 | + LibraryFunction mf; | |
107 | 107 | mf.mode=VOSystemsNullptr::System::NotFound; |
108 | 108 | return mf; |
109 | 109 | } |
\ No newline at end of file |
@@ -11,20 +11,28 @@ namespace VOSystemsNullptr | ||
11 | 11 | { |
12 | 12 | namespace Core |
13 | 13 | { |
14 | + struct LibraryFunction{ | |
15 | + std::string name,dllname; | |
16 | + unsigned char mode; | |
17 | + unsigned char ArguInt,ArguBool,ArguString; | |
18 | + }; | |
19 | + | |
20 | + typedef std::vector<struct LibraryFunction> Library; | |
21 | + | |
14 | 22 | typedef BasicTypes::String (*StrFunc)(std::string, BasicTypes::Int*,BasicTypes::String*); |
15 | 23 | typedef BasicTypes::Int (*IntFunc)(std::string, BasicTypes::Int*,BasicTypes::String*); |
16 | 24 | |
17 | 25 | class Module |
18 | 26 | { |
19 | 27 | private: |
20 | - std::vector<System::Module> m_modules; | |
28 | + std::vector<Library> m_modules; | |
21 | 29 | std::string m_CurrentConnectModuleName; |
22 | 30 | HMODULE m_module; |
23 | - System::ModuleFunction m_mf; | |
31 | + LibraryFunction m_mf; | |
24 | 32 | BasicTypes::Int m_int; |
25 | 33 | BasicTypes::String m_str; |
26 | 34 | |
27 | - VOSystemsNullptr::System::ModuleFunction DllSearch(std::string name); | |
35 | + LibraryFunction DllSearch(std::string name); | |
28 | 36 | public: |
29 | 37 | bool Connect(std::string name); |
30 | 38 | bool Run(std::string name, BasicTypes::Int* paramInt, BasicTypes::String* paramString); |
@@ -122,7 +122,7 @@ void Preprocessor::Trim(void) | ||
122 | 122 | }while(!line.empty()); |
123 | 123 | } |
124 | 124 | |
125 | -void Preprocessor::Load(System::Module& module) | |
125 | +void Preprocessor::LoadLib(Library& module) | |
126 | 126 | { |
127 | 127 | regex func_regex(R"(.+ .+(Int \d+\s*,\s*String \d+\s*,\s*bool \d+\s*);*)"); |
128 | 128 | regex bool_regex(R"(bool .+(Int \d+\s*,\s*String \d+\s*,\s*bool \d+\s*);*)"); |
@@ -136,20 +136,20 @@ void Preprocessor::Load(System::Module& module) | ||
136 | 136 | do{ |
137 | 137 | line=fop(); |
138 | 138 | if(regex_match(line,func_regex)){ |
139 | - System::ModuleFunction mf; | |
139 | + LibraryFunction mf; | |
140 | 140 | mf.dllname=m_modulefiles[C]; |
141 | 141 | string::iterator start; |
142 | 142 | |
143 | 143 | if(regex_match(line,bool_regex)){ |
144 | - mf.mode=System::ReturnBool; | |
144 | + mf.mode=System::BoolType; | |
145 | 145 | start=line.begin()+5; |
146 | 146 | |
147 | - }else if(regex_match(line,bool_regex)){ | |
148 | - mf.mode=System::ReturnInt; | |
147 | + }else if(regex_match(line,int_regex)){ | |
148 | + mf.mode=System::IntType; | |
149 | 149 | start=line.begin()+4; |
150 | 150 | |
151 | - }else if(regex_match(line,bool_regex)){ | |
152 | - mf.mode=System::ReturnString; | |
151 | + }else if(regex_match(line,str_regex)){ | |
152 | + mf.mode=System::StringType; | |
153 | 153 | start=line.begin()+7; |
154 | 154 | |
155 | 155 | }else{ |
@@ -173,4 +173,32 @@ void Preprocessor::Load(System::Module& module) | ||
173 | 173 | } |
174 | 174 | }while(!line.empty()); |
175 | 175 | } |
176 | +} | |
177 | + | |
178 | +void Preprocessor::LoadId(System::IdentifierList& list) | |
179 | +{ | |
180 | + regex | |
181 | + bool_regex(R"(bool[\s\t]+.+)"), | |
182 | + int_regex(R"(Int[\s\t]+.+)"), | |
183 | + str_regex(R"(String[\s\t]+.+)"); | |
184 | + | |
185 | + System::FileOperator fope(m_src,";"); | |
186 | + string line; | |
187 | + System::Identifier id; | |
188 | + | |
189 | + do{ | |
190 | + line=fope(); | |
191 | + | |
192 | + if(regex_match(line,bool_regex)){ | |
193 | + id.type=System::BoolType; | |
194 | + | |
195 | + }else if(regex_match(line,int_regex)){ | |
196 | + id.type=System::IntType; | |
197 | + | |
198 | + }else if(regex_match(line,str_regex)){ | |
199 | + id.type=System::StringType; | |
200 | + | |
201 | + } | |
202 | + | |
203 | + }while(!line.empty()); | |
176 | 204 | } |
\ No newline at end of file |
@@ -17,7 +17,8 @@ namespace VOSystemsNullptr | ||
17 | 17 | Preprocessor(std::string source); |
18 | 18 | void Extract(void); |
19 | 19 | void Trim(void); |
20 | - void Load(System::Module& module); | |
20 | + void LoadLib(Library& module); | |
21 | + void LoadId(System::IdentifierList& list); | |
21 | 22 | }; |
22 | 23 | } |
23 | 24 | } |
\ No newline at end of file |
@@ -82,28 +82,22 @@ namespace VOSystemsNullptr | ||
82 | 82 | } |
83 | 83 | |
84 | 84 | namespace System{ |
85 | + | |
86 | + enum Types{ | |
87 | + NotFound=0, | |
88 | + BoolType=1, | |
89 | + IntType=2, | |
90 | + StringType=4, | |
91 | + }; | |
92 | + | |
85 | 93 | typedef struct _Identifier{ |
86 | 94 | std::string name; |
87 | 95 | std::streamoff pos; |
96 | + unsigned char type; | |
88 | 97 | }Identifier; |
89 | 98 | |
90 | 99 | typedef std::vector<Identifier> IdentifierList; |
91 | 100 | |
92 | - enum ModuleMode{ | |
93 | - NotFound=0, | |
94 | - ReturnBool=1, | |
95 | - ReturnInt=2, | |
96 | - ReturnString=4, | |
97 | - }; | |
98 | - | |
99 | - struct ModuleFunction{ | |
100 | - std::string name,dllname; | |
101 | - unsigned char mode; | |
102 | - unsigned char ArguInt,ArguBool,ArguString; | |
103 | - }; | |
104 | - | |
105 | - typedef std::vector<struct ModuleFunction> Module; | |
106 | - | |
107 | 101 | class FileOperator |
108 | 102 | { |
109 | 103 | private: |