Skip to content

Commit fabf65c

Browse files
committed
Merge pull request #26 from elite-lang/dev
v0.7.4
2 parents 5d6edfc + 2857d3c commit fabf65c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+680
-66
lines changed

.gitmodules

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@
99
[submodule "RedApple"]
1010
path = RedApple
1111
url = https://github.com/elite-lang/RedApple.git
12+
13+
[submodule "tools"]
14+
path = tools
15+
url = https://github.com/elite-lang/tools.git

Builder/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@ SET (EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
1313
include_directories(../Lex/include
1414
../LR_Scanner/include
1515
../RedApple/includes
16-
../MetaScriptRunner/include)
16+
../MetaScriptRunner/include
17+
)
1718
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/lib)
1819
endif()
1920

2021

2122
# 核心路径配置
22-
include_directories(src include)
23+
include_directories(src include ../tools)
2324
file(GLOB_RECURSE source_files ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp)
2425
if(USE_DYNAMIC)
2526
add_library(builder SHARED ${source_files}) # 使用动态库

Builder/include/Builder.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @Author: sxf
33
* @Date: 2015-11-08 09:06:35
44
* @Last Modified by: sxf
5-
* @Last Modified time: 2015-12-21 19:30:12
5+
* @Last Modified time: 2015-12-25 14:34:16
66
*/
77

88

@@ -59,7 +59,6 @@ class Builder
5959

6060
Worker* worker = 0;
6161
std::string buildpath;
62-
static std::string fileReader(const char* path);
6362
static std::string make_default_name(const char* filename);
6463
static std::string get_file_name(const char* filename);
6564

Builder/include/PathGetter.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @Author: sxf
33
* @Date: 2015-11-08 11:08:05
44
* @Last Modified by: sxf
5-
* @Last Modified time: 2015-12-22 08:22:19
5+
* @Last Modified time: 2015-12-25 10:24:59
66
*/
77

88
#ifndef PATH_GETTER_H
@@ -23,6 +23,7 @@ class PathGetter
2323
static const char* getEliteLibPath();
2424
static const char* getEliteCfgPath();
2525
static const char* getEliteToolsPath();
26+
static const char* getElitePackagesPath();
2627
static const char* getDefaultLexCfg();
2728
static const char* getDefaultParserCfg();
2829
static const char* getNowPath();

Builder/include/Worker.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @Author: sxf
33
* @Date: 2015-11-11 13:52:11
44
* @Last Modified by: sxf
5-
* @Last Modified time: 2015-12-22 11:18:14
5+
* @Last Modified time: 2015-12-25 10:12:56
66
*/
77
#ifndef WORKER_H
88
#define WORKER_H
@@ -23,7 +23,7 @@ class Worker
2323
void Run(const char* input, const char* output);
2424
void MetaGen(const char* output);
2525

26-
static Worker* CreateDefault(const char* lex_cfg, const char* parser_cfg);
26+
static Worker* CreateDefault(const char* lex_cfg, const char* parser_cfg, const char* package_path);
2727
static Worker* Create(LexInterface* l, Parser* p, ScriptRunner* s, CodeGen* c);
2828

2929
LexInterface* getLex() { return lex; }

Builder/src/Builder.cpp

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @Author: sxf
33
* @Date: 2015-11-08 10:20:02
44
* @Last Modified by: sxf
5-
* @Last Modified time: 2015-12-22 11:19:18
5+
* @Last Modified time: 2015-12-25 14:34:46
66
*/
77

88
#include "Builder.h"
@@ -30,7 +30,7 @@ int Builder::BuildFile(std::string filename) {
3030
string outfile_path = this->buildpath + "/" + program + ".bc";
3131
outfile_path = PathUtils::native(outfile_path); // 本地化
3232

33-
string data = fileReader(filename.c_str());
33+
string data = FileUtils::fileReader(filename.c_str());
3434
printf("输入文件: %s \n输出文件: %s\n", filename.c_str(), outfile_path.c_str());
3535
worker->Run(data.c_str(), outfile_path.c_str());
3636

@@ -115,7 +115,10 @@ Builder* Builder::Create(Worker* worker) {
115115
Builder::Builder(Worker* worker) {
116116
if (worker == 0)
117117
setWorker(Worker::CreateDefault(
118-
PathGetter::getDefaultLexCfg(), PathGetter::getDefaultParserCfg()));
118+
PathGetter::getDefaultLexCfg(),
119+
PathGetter::getDefaultParserCfg(),
120+
PathGetter::getElitePackagesPath()
121+
));
119122
else
120123
setWorker(worker);
121124
}
@@ -128,18 +131,7 @@ void Builder::Close() {
128131
delete this;
129132
}
130133

131-
std::string Builder::fileReader(const char* path) {
132-
std::ifstream t(path, std::ios::binary);
133-
std::string str;
134134

135-
t.seekg(0, std::ios::end);
136-
str.reserve(t.tellg());
137-
t.seekg(0, std::ios::beg);
138-
139-
str.assign((std::istreambuf_iterator<char>(t)),
140-
std::istreambuf_iterator<char>());
141-
return str;
142-
}
143135
string Builder::make_default_name(const char* filename) {
144136
const char* ans = strrchr(filename, '/');
145137
const char* file;

Builder/src/PathGetter.cpp

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
* @Author: sxf
33
* @Date: 2015-11-08 11:16:04
44
* @Last Modified by: sxf
5-
* @Last Modified time: 2015-12-20 12:02:27
5+
* @Last Modified time: 2015-12-25 11:16:36
66
*/
77

88
#include <stdlib.h>
99
#include "PathGetter.h"
1010
#include "FileUtils.h"
1111
#include "PathUtils.h"
12-
12+
#include "elite_tools.h"
1313

1414
class PathGetter_Private {
1515
public:
@@ -21,6 +21,7 @@ class PathGetter_Private {
2121
string elite_parser_path;
2222
string elite_now_path;
2323
string elite_tools_path;
24+
string elite_packages_path;
2425
};
2526

2627

@@ -53,6 +54,11 @@ const char* PathGetter::getEliteToolsPath() {
5354
return getInstance()->elite_tools_path.c_str();
5455
}
5556

57+
const char* PathGetter::getElitePackagesPath() {
58+
return getInstance()->elite_packages_path.c_str();
59+
}
60+
61+
5662
PathGetter_Private* PathGetter::getInstance() {
5763
if (instance == NULL) {
5864
instance = new PathGetter_Private();
@@ -75,11 +81,14 @@ void PathGetter_Private::setPath() {
7581
elite_lib_path = elite_home;
7682
elite_cfg_path = elite_home;
7783
elite_tools_path = elite_home;
84+
elite_packages_path = elite_home;
7885
elite_lib_path.append("/libs");
7986
elite_cfg_path.append("/conf");
87+
elite_packages_path.append("/packages");
8088
// 本地化
8189
elite_lib_path = PathUtils::native(elite_lib_path);
8290
elite_cfg_path = PathUtils::native(elite_cfg_path);
91+
elite_packages_path = PathUtils::native(elite_packages_path);
8392

8493
if (!FileUtils::test_dir(elite_lib_path)) {
8594
printf("%s 目录找不到\n", elite_lib_path.c_str());
@@ -89,16 +98,12 @@ void PathGetter_Private::setPath() {
8998
printf("%s 目录找不到\n", elite_cfg_path.c_str());
9099
exit(1);
91100
}
101+
if (!FileUtils::test_dir(elite_packages_path)) {
102+
printf("%s 目录找不到\n", elite_packages_path.c_str());
103+
exit(1);
104+
}
92105

93-
#if defined(_WIN32)
94-
elite_tools_path.append("/tools/windows_x64");
95-
#endif
96-
#if defined(__linux__)
97-
elite_tools_path.append("/tools/linux_x64");
98-
#endif
99-
#if defined(__APPLE__) && defined(__MACH__)
100-
elite_tools_path.append("/tools/darwin_x64");
101-
#endif
106+
elite_tools_path.append(ELITE_TOOLS_PATH);
102107
// 本地化
103108
elite_tools_path = PathUtils::native(elite_tools_path);
104109

Builder/src/Worker.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @Author: sxf
33
* @Date: 2015-11-11 16:00:38
44
* @Last Modified by: sxf
5-
* @Last Modified time: 2015-12-22 11:18:24
5+
* @Last Modified time: 2015-12-25 10:26:37
66
*/
77

88

@@ -43,11 +43,12 @@ void Worker::MetaGen(const char* output) {
4343
}
4444

4545

46-
Worker* Worker::CreateDefault(const char* lex_cfg, const char* parser_cfg) {
46+
Worker* Worker::CreateDefault(const char* lex_cfg,
47+
const char* parser_cfg, const char* package_path) {
4748
Lex* l = new Lex();
4849
Parser* p = Parser::NewLRParser();
49-
ScriptRunner* s = MetaScriptRunner::Create();
50-
CodeGen* c = RedCodeGen::Create();
50+
MetaScriptRunner* s = MetaScriptRunner::Create();
51+
RedCodeGen* c = RedCodeGen::Create();
5152

5253
// 配置联系
5354
p->setLex(l);
@@ -57,6 +58,9 @@ Worker* Worker::CreateDefault(const char* lex_cfg, const char* parser_cfg) {
5758
l->ReadConfig(lex_cfg);
5859
p->AddBNF(parser_cfg);
5960

61+
// 配置外置插件
62+
s->setUpLoader(package_path);
63+
6064
return Create(l, p, s, c);
6165
}
6266

EliteTest/bug_list/7/test.elite

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// 这是一道经典的汉诺塔
2+
3+
void work(int k, int src, int obj) {
4+
if (k==1) {
5+
print(src, obj);
6+
return;
7+
}
8+
work(k-1, src, 3-obj-src);
9+
print(src, obj);
10+
work(k-1, 3-obj-src, obj);
11+
}
12+
13+
int main() {
14+
work(3, 0, 2);
15+
return 0;
16+
}
17+
18+
char[] select(int k) {
19+
if (k == 0) return "A";
20+
if (k == 1) return "B";
21+
if (k == 2) return "C";
22+
}
23+
24+
void print(int src, int obj) {
25+
printf("%s => %s", select(src), select(obj));
26+
}
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ void print(int k) {
33
printf("hello-%d\n",k);
44
}
55

6-
void main() {
6+
int main() {
77
FunctionCall("print", 5);
8-
}
8+
return 0;
9+
}

0 commit comments

Comments
 (0)