Skip to content

Commit

Permalink
Merge pull request #35 from elite-lang/dev
Browse files Browse the repository at this point in the history
修复BasicBlock的bug
  • Loading branch information
xssss1 committed Jan 11, 2016
2 parents f835a0c + efeba3d commit bf9d9f5
Show file tree
Hide file tree
Showing 47 changed files with 2,724 additions and 164 deletions.
19 changes: 5 additions & 14 deletions Builder/src/Builder.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* @Author: sxf
* @Date: 2015-11-08 10:20:02
* @Last Modified by: sxf
Expand Down Expand Up @@ -38,7 +38,7 @@ int Builder::BuildFile(std::string filename) {
string meta_path = this->buildpath + "/meta.bc";
meta_path = PathUtils::native(meta_path); // 本地化
worker->MetaGen(meta_path.c_str());

// 生成obj
call_llc(outfile_path);
call_llc(meta_path);
Expand Down Expand Up @@ -120,15 +120,7 @@ Builder* Builder::Create(Worker* worker) {
}

Builder::Builder(Worker* worker) {
if (worker == 0)
setWorker(Worker::CreateDefault(
PathGetter::getDefaultLexCfg(),
PathGetter::getDefaultParserCfg(),
PathGetter::getElitePackagesPath(),
this
));
else
setWorker(worker);
setWorker(worker);
}

Builder::~Builder() {
Expand Down Expand Up @@ -175,7 +167,7 @@ string Builder::get_file_name(const char* filename) {
}

int Builder::call_llc(std::string filein) {

#if !defined(_WIN32) && (defined(__linux__) || defined(__APPLE__))
string llc = PathGetter::getEliteToolsPath();
llc += "/llvm-3.6/llc";
Expand Down Expand Up @@ -206,8 +198,7 @@ int Builder::call_ld(std::string filein, std::string fileout) {
return system(ld.c_str());
#endif
#if defined(_WIN32)

#endif
return 0;
}

20 changes: 11 additions & 9 deletions Builder/src/Worker.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* @Author: sxf
* @Date: 2015-11-11 16:00:38
* @Last Modified by: sxf
Expand All @@ -21,7 +21,7 @@ void Worker::Init(LexInterface* l, Parser* p, ScriptRunner* s, CodeGen* c) {
// 初始化词法分析器与语法分析器
l->Init(NULL);
p->BuildParser();

}

void Worker::Run(const char* input, const char* output) {
Expand All @@ -43,40 +43,42 @@ void Worker::MetaGen(const char* output) {
}


Worker* Worker::CreateDefault(const char* lex_cfg,
Worker* Worker::CreateDefault(const char* lex_cfg,
const char* parser_cfg, const char* package_path, Builder* b) {
Lex* l = new Lex();
Parser* p = Parser::NewLRParser();
MetaScriptRunner* s = MetaScriptRunner::Create();
RedCodeGen* c = RedCodeGen::Create();

// 配置联系
p->setLex(l);
p->setScriptRunner(s);

// 向脚本引擎中注入更多接口
c->Init(NULL);
s->setCodeGenContext(c->getContext());

// 配置外置插件
s->setUpLoader(package_path);

// 向脚本引擎中注入各对象
// 向脚本引擎中注入各对象
s->setLex(l);
s->setParser(p);
s->setBuilder(b);

// 配置外置插件
s->setUpLoader(package_path);

// 配置词法分析器和语法分析器
l->ReadConfig(lex_cfg);
p->AddBNF(parser_cfg);

printf("Create Default\n");

return Create(l, p, s, c, b);
}

Worker* Worker::Create(LexInterface* l, Parser* p, ScriptRunner* s, CodeGen* c, Builder* b) {
Worker* k = new Worker();
k->builder = b;
k->Init(l, p, s, c);
k->builder = b;
return k;
}

Expand Down
50 changes: 50 additions & 0 deletions EliteTest/bug_list/10/test.elite
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// 八皇后问题

int sum = 0;
int upperlim = 1;

// 试探算法从最右边的列开始。
void test(int row, int ld, int rd)
{
if (row != upperlim)
{
// row,ld,rd进行“或”运算,求得所有可以放置皇后的列,对应位为0,
// 然后再取反后“与”上全1的数,来求得当前所有可以放置皇后的位置,对应列改为1
// 也就是求取当前哪些列可以放置皇后
int pos = upperlim & ~(row | ld | rd);
while (pos != 0) // 0 -- 皇后没有地方可放,回溯
{
// 拷贝pos最右边为1的bit,其余bit置0
// 也就是取得可以放皇后的最右边的列
int p = pos & -pos;

// 将pos最右边为1的bit清零
// 也就是为获取下一次的最右可用列使用做准备,
// 程序将来会回溯到这个位置继续试探
pos -= p;

// row + p,将当前列置1,表示记录这次皇后放置的列。
// (ld + p) << 1,标记当前皇后左边相邻的列不允许下一个皇后放置。
// (ld + p) >> 1,标记当前皇后右边相邻的列不允许下一个皇后放置。
// 此处的移位操作实际上是记录对角线上的限制,只是因为问题都化归
// 到一行网格上来解决,所以表示为列的限制就可以了。显然,随着移位
// 在每次选择列之前进行,原来N×N网格中某个已放置的皇后针对其对角线
// 上产生的限制都被记录下来了
test(row + p, (ld + p) << 1, (rd + p) >> 1);
}
}
else
{
// row的所有位都为1,即找到了一个成功的布局,回溯
sum++;
}
}

int main()
{
int n = 8;
upperlim = (upperlim << n) - 1;
test(0, 0, 0);
printf("共有%ld种排列\\n", sum);
return 0;
}
1 change: 1 addition & 0 deletions EliteTest/bug_list/10/test.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
92
18 changes: 18 additions & 0 deletions EliteTest/bug_list/9/test.elite
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// 质因数分解

int main(){
int n = 90;
printf("%d=", n);
// n>=2才执行下面的循环
for(int i=2; i<=n; i++){
while(n!=i){
if(n%i==0){
printf("%d*",i);
n=n/i;
}else
break;
}
}
printf("%d\n",n);
return 0;
}
1 change: 1 addition & 0 deletions EliteTest/bug_list/9/test.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
90=2*3*3*5
12 changes: 6 additions & 6 deletions EliteTest/bug_list/run_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,24 @@ def __init__(self):
self.compile_error = []
self.run_error = []
self.output_error = []

def walk_dir(self, path):
for line in os.listdir(path):
filepath = os.path.join(path,line)
if os.path.isdir(filepath):
print filepath
ret = self.compile_path(filepath)
if ret != 0:
sys.exit(1)
break
ret = self.run_file(filepath+'/build/test', filepath+'/test.out')
if ret != 0:
sys.exit(1)
break


def compile_path(self, path):
cmd = self.bin_path + ' -i ' + path + '/test.elite -d ' + path + '/build/'
status, output = commands.getstatusoutput(cmd)
if status != 0:
if status != 0:
print '\033[1;31m'
print '编译失败:', path
print output
Expand All @@ -50,7 +50,7 @@ def run_file(self, filepath, output_file):
return status
read_data = ''
with open(output_file, 'rU') as f:
read_data = f.read()
read_data = f.read()
if read_data != output:
print '\033[1;31m'
print '执行结果错误:', filepath
Expand All @@ -76,4 +76,4 @@ def main(self):

if __name__ == '__main__':
tr = TestRunner()
tr.main()
tr.main()
17 changes: 17 additions & 0 deletions EliteTest/full_test/8/test.elite
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// 测试可能有歧义的符号

int main() {
int x = 10;
if (x == 10) {
int x = 20;
if (x == 20)
printf("1");
else
printf("0");
}
if (x == 10)
printf("1");
else
printf("0");
return 0;
}
1 change: 1 addition & 0 deletions EliteTest/full_test/8/test.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
11
2 changes: 2 additions & 0 deletions MetaScriptRunner/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ link_directories(${CMAKE_CURRENT_SOURCE_DIR}/lib)
endif()




# 核心路径配置
include_directories(src include)
file(GLOB_RECURSE source_files ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp)
Expand Down
13 changes: 8 additions & 5 deletions MetaScriptRunner/include/EPackage.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* @Author: sxf
* @Date: 2015-12-24 15:55:11
* @Last Modified by: sxf
Expand Down Expand Up @@ -29,7 +29,7 @@ class EPackage
* @details 构造一个插件包时,当前路径需要被确定校验存在,并含有一个package.json的元数据配置项
* 构造中,会解析package.json的相关数据,但不会加载其他任何内容
* 对于自动加载型的插件包,需要在外层再扫描一次,判断并加载。
*
*
* @param path 当前软件包的路径,应为绝对路径
* @param msr 当前MetaScriptRunner的指针,加载时,可能会加载lua脚本,或者epbc二进制码,该接口负责调用对应功能
*/
Expand Down Expand Up @@ -67,16 +67,19 @@ class EPackage
*/
void Load();


void Run();

/**
* @brief 获取当前包的属性值
*
*
* @param name 属性名
* @return 对应的值
*/
const string& getProp(const string& name);

static string str_null;

private:
map<string, string> props;
string base_path;
Expand All @@ -90,7 +93,7 @@ class EPackage

/**
* @brief 向当前插件包中添加新的属性
*
*
* @param name 属性名
* @param value 属性值
*/
Expand Down
34 changes: 17 additions & 17 deletions MetaScriptRunner/include/MetaScriptRunner.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* @Author: sxf
* @Date: 2015-11-05 21:21:50
* @Last Modified by: sxf
Expand Down Expand Up @@ -59,58 +59,58 @@ class MetaScriptRunner : public ScriptRunner

/**
* @brief 执行一个lua脚本
*
*
* @param filename 脚本的完整或相对路径
* @return 成功为true, 异常为false
*/
bool run_file (string const &filename);

/**
* @brief 加载一个脚本, 但暂不执行 (需要pcall才执行)
*
*
* @param filename 脚本的完整或相对路径
* @return 成功为true, 异常为false
*/
bool load_file (string const &filename);

/**
* @brief 加载一段内存中的lua脚本 (不执行)
*
*
* @param chunk 脚本字符串
* @return 成功为true, 异常为false
*/
bool load_chunk (string const &chunk);

/**
* @brief 运行一段内存中的lua脚本
*
*
* @param chunk 脚本字符串
* @return 成功为true, 异常为false
*/
bool run_chunk (string const &chunk);

void setUpLoader(const string& path);

void setCodeGenContext(CodeGenContext* ctx) { context = ctx; }
void setCodeGenContext(CodeGenContext* ctx) { context = ctx; }
CodeGenContext* getCodeGenContext() { return context; }

void setLex(LexInterface* _lex) { lex = _lex; }
void setLex(LexInterface* _lex) { lex = _lex; }
LexInterface* getLex() { return lex; }
void setParser(Parser* _parser) { parser = _parser; }

void setParser(Parser* _parser) { parser = _parser; }
Parser* getParser() { return parser; }
void setBuilder(Builder* _builder) { builder = _builder; }

void setBuilder(Builder* _builder) { builder = _builder; }
Builder* getBuilder() { return builder; }

protected:
OOLUA::Script* vm;
Node* root;
PackageLoader* loader;
CodeGenContext* context;
LexInterface* lex;
Parser* parser;
Builder* builder;
PackageLoader* loader = NULL;
CodeGenContext* context = NULL;
LexInterface* lex = NULL;
Parser* parser = NULL;
Builder* builder = NULL;

MetaScriptRunner();
~MetaScriptRunner();
Expand Down
Loading

0 comments on commit bf9d9f5

Please sign in to comment.