diff --git a/main.cpp b/main.cpp index f79af204..105796cc 100644 --- a/main.cpp +++ b/main.cpp @@ -1,7 +1,5 @@ #include "nasal.h" -nasal_vm vm; - void help_interact() { std::cout @@ -31,7 +29,7 @@ void help_cmd() void info() { std::cout - <<">> Nasal interpreter ver 6.5 efficient gc test .\n" + <<">> Nasal interpreter ver 6.5.\n" <<">> Thanks to https://github.com/andyross/nasal\n" <<">> Code: https://github.com/ValKmjolnir/Nasal-Interpreter\n" <<">> Code: https://gitee.com/valkmjolnir/Nasal-Interpreter\n" @@ -60,6 +58,7 @@ void execute(std::string& file,std::string& command) nasal_parse parse; nasal_import import; nasal_codegen codegen; + nasal_vm vm; lexer.openfile(file); lexer.scanner(); if(lexer.get_error()) @@ -153,7 +152,7 @@ int main(int argc,const char* argv[]) else if(argc==2 && (!strcmp(argv[1],"-v") || !strcmp(argv[1],"-version"))) { logo(); - std::cout<<"Nasal interpreter ver 6.5 efficient gc test\n"; + std::cout<<"Nasal interpreter ver 6.5\n"; } else if(argc==2 && (!strcmp(argv[1],"-h") || !strcmp(argv[1],"-help"))) help_cmd(); diff --git a/nasal_ast.h b/nasal_ast.h index 90fbbce2..7051346c 100644 --- a/nasal_ast.h +++ b/nasal_ast.h @@ -57,10 +57,12 @@ class nasal_ast nasal_ast(){line=0;type=ast_null;} nasal_ast(int l,int t){line=l;type=t;} nasal_ast(const nasal_ast&); - nasal_ast& operator=(const nasal_ast&); + nasal_ast(nasal_ast&&); + nasal_ast& operator=(const nasal_ast&); + nasal_ast& operator=(nasal_ast&&); void print_ast(int); void clear(); - void add_child(nasal_ast ast){children.push_back(ast);} + void add_child(nasal_ast&& ast){children.push_back(std::move(ast));} void set_line(int l){line=l;} void set_type(int t){type=t;} void set_str(std::string& s){str=s;} @@ -82,6 +84,16 @@ nasal_ast::nasal_ast(const nasal_ast& tmp) return; } +nasal_ast::nasal_ast(nasal_ast&& tmp) +{ + line=tmp.line; + type=tmp.type; + str.swap(tmp.str); + num =tmp.num; + children.swap(tmp.children); + return; +} + nasal_ast& nasal_ast::operator=(const nasal_ast& tmp) { line=tmp.line; @@ -92,6 +104,16 @@ nasal_ast& nasal_ast::operator=(const nasal_ast& tmp) return *this; } +nasal_ast& nasal_ast::operator=(nasal_ast&& tmp) +{ + line=tmp.line; + type=tmp.type; + str.swap(tmp.str); + num=tmp.num; + children.swap(tmp.children); + return *this; +} + void nasal_ast::clear() { line=0; @@ -104,11 +126,10 @@ void nasal_ast::clear() void nasal_ast::print_ast(int depth) { - std::string indentation=""; for(int i=0;i error_token; int in_function; // count when generating function block,used to check return-expression int in_loop; // count when generating loop block,used to check break/continue-expression - void die(int,std::string); + void die(int,std::string&&); void match(int type,const char* err_info=""); bool check_comma(int*); bool check_multi_def(); @@ -140,7 +140,7 @@ void nasal_parse::main_process() <<"check \'(\',\'[\',\'{\',\')\',\']\',\'}\' match or not.\n"; return; } -void nasal_parse::die(int line,std::string info) +void nasal_parse::die(int line,std::string&& info) { ++error; std::cout<<">> [parse] line "<=0;i-=1) + for(var i=26;i>=0;i-=1) { var rand_index=int(i*rand()); (arr[i],arr[rand_index])=(arr[rand_index],arr[i]); @@ -128,9 +115,8 @@ var curve5=func() return; } trans_ttf("just for test"); -trans_ttf("ValKmjolnir"); +trans_ttf(" ValKmjolnir "); curve1(); curve2(); curve3(); -curve4(); -curve5(); \ No newline at end of file +curve4(); \ No newline at end of file diff --git a/test/auto_crash.nas b/test/auto_crash.nas index e13c864b..f5c49d23 100644 --- a/test/auto_crash.nas +++ b/test/auto_crash.nas @@ -1,4 +1,6 @@ # Road check and auto pilot by ValKmjolnir +import("lib.nas"); +import("props.nas"); var dt=0.01; var intergral=0; var derivative=0; diff --git a/test/bf.nas b/test/bf.nas index 69f6157e..14780c56 100644 --- a/test/bf.nas +++ b/test/bf.nas @@ -171,7 +171,7 @@ var bf=func(program) var c=chr(program[i]); if(c=='+' or c=='-') { - append(code,add); + append(code,func_table[add]); append(inum,0); for(;i') { - append(code,mov); + append(code,func_table[mov]); append(inum,0); for(;i