diff --git a/README.md b/README.md index 30e0694..ea7d6e7 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,7 @@ __Contact us if having great ideas to share!__ ![star](https://img.shields.io/github/stars/ValKmjolnir/Nasal-Interpreter?style=flat-square&logo=github) ![fork](https://img.shields.io/github/forks/ValKmjolnir/Nasal-Interpreter?style=flat-square&logo=github) +[![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/ValKmjolnir/Nasal-Interpreter) ![issue](https://img.shields.io/github/issues/ValKmjolnir/Nasal-Interpreter?style=flat-square&logo=github) ![pr](https://img.shields.io/github/issues-pr/ValKmjolnir/Nasal-Interpreter?style=flat-square&logo=github) @@ -344,7 +345,7 @@ source code: if (x<2) return x; return fib(x-1)+fib(x-2); } - for(var i=0;i<31;i+=1) + for (var i=0;i<31;i+=1) print(fib(i),'\n'); @@ -377,7 +378,7 @@ source code: --> if (x<2) return x; return fib(x-1)+fib(x-2); } - for(var i=0;i<31;i+=1) + for (var i=0;i<31;i+=1) print(fib(i),'\n'); diff --git a/doc/README_zh.md b/doc/README_zh.md index ccefecb..deb6051 100644 --- a/doc/README_zh.md +++ b/doc/README_zh.md @@ -329,7 +329,7 @@ source code: if (x<2) return x; return fib(x-1)+fib(x-2); } - for(var i=0;i<31;i+=1) + for (var i=0;i<31;i+=1) print(fib(i),'\n'); @@ -362,7 +362,7 @@ source code: --> if (x<2) return x; return fib(x-1)+fib(x-2); } - for(var i=0;i<31;i+=1) + for (var i=0;i<31;i+=1) print(fib(i),'\n'); diff --git a/doc/dev.md b/doc/dev.md index 6f1aca1..a475ca5 100644 --- a/doc/dev.md +++ b/doc/dev.md @@ -124,7 +124,7 @@ Hope you could help me! :) There's an example of byte code below: ```javascript -for(var i=0;i<4000000;i+=1); +for (var i=0;i<4000000;i+=1); ``` ```x86asm @@ -175,7 +175,7 @@ In this update i changed global and local scope from `unordered_map` to `vector` So the bytecode generator changed a lot. ```javascript -for(var i=0;i<4000000;i+=1); +for (var i=0;i<4000000;i+=1); ``` ```x86asm diff --git a/doc/dev_zh.md b/doc/dev_zh.md index 4ad4cb7..cca9432 100644 --- a/doc/dev_zh.md +++ b/doc/dev_zh.md @@ -112,7 +112,7 @@ __该项目于2019/7/25正式开始__。 下面是生成的字节码的样例: ```javascript -for(var i=0;i<4000000;i+=1); +for (var i=0;i<4000000;i+=1); ``` ```x86asm @@ -161,7 +161,7 @@ for(var i=0;i<4000000;i+=1); 在这次的更新中,我把全局变量和局部变量的存储结构从`unordered_map`变为了`vector`,从而提升执行效率。所以现在生成的字节码大变样了。 ```javascript -for(var i=0;i<4000000;i+=1); +for (var i=0;i<4000000;i+=1); ``` ```x86asm diff --git a/doc/tutorial.md b/doc/tutorial.md index 18efbf5..bbcc7cc 100644 --- a/doc/tutorial.md +++ b/doc/tutorial.md @@ -258,7 +258,7 @@ While loop and for loop is simalar to C/C++. while(condition) { continue; } -for(var i = 0; i<10; i += 1) { +for (var i = 0; i<10; i += 1) { break; } ``` @@ -469,7 +469,7 @@ Then complete this function using C++: var builtin_print(context* ctx, gc* ngc) { // find value with index begin from 1 // because local[0] is reserved for value 'me' - for(auto& i : ctx->localr[1].vec().elems) { + for (auto& i : ctx->localr[1].vec().elems) { std::cout << i; } std::cout << std::flush; @@ -495,11 +495,11 @@ var builtin_keys(context* ctx, gc* ngc) { auto res = ngc->temp = ngc->alloc(vm_vec); auto& vec = res.vec().elems; if (hash.type==vm_hash) { - for(const auto& iter : hash.hash().elems) { + for (const auto& iter : hash.hash().elems) { vec.push_back(ngc->newstr(iter.first)); } } else { - for(const auto& iter : hash.map().mapper) { + for (const auto& iter : hash.map().mapper) { vec.push_back(ngc->newstr(iter.first)); } } @@ -645,7 +645,7 @@ Then we write a test nasal file to run this fib function: use std.dylib; var dlhandle = dylib.dlopen("libfib"); var fib = dlhandle.fib; -for(var i = 1; i<30; i += 1) +for (var i = 1; i<30; i += 1) println(dylib.dlcall(fib, i)); dylib.dlclose(dlhandle.lib); ``` @@ -663,7 +663,7 @@ use std.dylib; var dlhandle = dylib.dlopen("libfib"); var fib = dlhandle.fib; var invoke = dylib.limitcall(1); # this means the called function has only one parameter -for(var i = 1; i<30; i += 1) +for (var i = 1; i<30; i += 1) println(invoke(fib, i)); dylib.dlclose(dlhandle.lib); ``` diff --git a/doc/tutorial_zh.md b/doc/tutorial_zh.md index 715782c..525ab89 100644 --- a/doc/tutorial_zh.md +++ b/doc/tutorial_zh.md @@ -250,7 +250,7 @@ while循环和for循环大体上与C/C++是一致的。 while(condition) { continue; } -for(var i = 0; i<10; i += 1) { +for (var i = 0; i<10; i += 1) { break; } ``` @@ -457,7 +457,7 @@ var builtin_print(context*, gc*); var builtin_print(context* ctx, gc* ngc) { // 局部变量的下标其实是从 1 开始的 // 因为 local[0] 是保留给 'me' 的空间 - for(auto& i : ctx->localr[1].vec().elems) { + for (auto& i : ctx->localr[1].vec().elems) { std::cout << i; } std::cout << std::flush; @@ -483,11 +483,11 @@ var builtin_keys(context* ctx, gc* ngc) { auto res = ngc->temp = ngc->alloc(vm_vec); auto& vec = res.vec().elems; if (hash.type==vm_hash) { - for(const auto& iter : hash.hash().elems) { + for (const auto& iter : hash.hash().elems) { vec.push_back(ngc->newstr(iter.first)); } } else { - for(const auto& iter : hash.map().mapper) { + for (const auto& iter : hash.map().mapper) { vec.push_back(ngc->newstr(iter.first)); } } @@ -624,7 +624,7 @@ Windows(`.dll`): use std.dylib; var dlhandle = dylib.dlopen("libfib"); var fib = dlhandle.fib; -for(var i = 1; i<30; i += 1) +for (var i = 1; i<30; i += 1) println(dylib.dlcall(fib, i)); dylib.dlclose(dlhandle.lib); ``` @@ -642,7 +642,7 @@ use std.dylib; var dlhandle = dylib.dlopen("libfib"); var fib = dlhandle.fib; var invoke = dylib.limitcall(1); # this means the called function has only one parameter -for(var i = 1; i<30; i += 1) +for (var i = 1; i<30; i += 1) println(invoke(fib, i)); dylib.dlclose(dlhandle.lib); ``` diff --git a/module/fib.cpp b/module/fib.cpp index 99f2341..3b6784d 100644 --- a/module/fib.cpp +++ b/module/fib.cpp @@ -32,7 +32,7 @@ var quick_fib(var* args, usize size, gc* ngc) { return var::num(num); } double a = 1, b = 1, res = 0; - for(double i = 1; iget_path()) { + for (auto i : node->get_path()) { if (i==node->get_path().back()) { set_last(); } @@ -64,7 +64,7 @@ bool ast_dumper::visit_vector_expr(vector_expr* node) { std::cout << "vector"; std::cout << format_location(node); push_indent(); - for(auto i : node->get_elements()) { + for (auto i : node->get_elements()) { if (i==node->get_elements().back()) { set_last(); } @@ -79,7 +79,7 @@ bool ast_dumper::visit_hash_expr(hash_expr* node) { std::cout << "hash"; std::cout << format_location(node); push_indent(); - for(auto i : node->get_members()) { + for (auto i : node->get_members()) { if (i==node->get_members().back()) { set_last(); } @@ -107,7 +107,7 @@ bool ast_dumper::visit_function(function* node) { std::cout << "function"; std::cout << format_location(node); push_indent(); - for(auto i : node->get_parameter_list()) { + for (auto i : node->get_parameter_list()) { i->accept(this); } set_last(); @@ -121,7 +121,7 @@ bool ast_dumper::visit_code_block(code_block* node) { std::cout << "block"; std::cout << format_location(node); push_indent(); - for(auto i : node->get_expressions()) { + for (auto i : node->get_expressions()) { if (i==node->get_expressions().back()) { set_last(); } @@ -231,7 +231,7 @@ bool ast_dumper::visit_call_expr(call_expr* node) { set_last(); } node->get_first()->accept(this); - for(auto i : node->get_calls()) { + for (auto i : node->get_calls()) { if (i==node->get_calls().back()) { set_last(); } @@ -260,7 +260,7 @@ bool ast_dumper::visit_call_vector(call_vector* node) { std::cout << "call_vector"; std::cout << format_location(node); push_indent(); - for(auto i : node->get_slices()) { + for (auto i : node->get_slices()) { if (i==node->get_slices().back()) { set_last(); } @@ -275,7 +275,7 @@ bool ast_dumper::visit_call_function(call_function* node) { std::cout << "call_function"; std::cout << format_location(node); push_indent(); - for(auto i : node->get_argument()) { + for (auto i : node->get_argument()) { if (i==node->get_argument().back()) { set_last(); } @@ -350,7 +350,7 @@ bool ast_dumper::visit_multi_identifier(multi_identifier* node) { std::cout << "multiple_identifier"; std::cout << format_location(node); push_indent(); - for(auto i : node->get_variables()) { + for (auto i : node->get_variables()) { if (i==node->get_variables().back()) { set_last(); } @@ -365,7 +365,7 @@ bool ast_dumper::visit_tuple_expr(tuple_expr* node) { std::cout << "tuple"; std::cout << format_location(node); push_indent(); - for(auto i : node->get_elements()) { + for (auto i : node->get_elements()) { if (i==node->get_elements().back()) { set_last(); } @@ -459,7 +459,7 @@ bool ast_dumper::visit_condition_expr(condition_expr* node) { set_last(); } node->get_if_statement()->accept(this); - for(auto i : node->get_elsif_stataments()) { + for (auto i : node->get_elsif_stataments()) { if (i==node->get_elsif_stataments().back() && !node->get_else_statement()) { set_last(); diff --git a/src/ast_format.cpp b/src/ast_format.cpp index a1f310e..f210edd 100644 --- a/src/ast_format.cpp +++ b/src/ast_format.cpp @@ -8,7 +8,7 @@ namespace nasal { bool ast_format::visit_use_stmt(use_stmt* node) { dump_formating_node_info(node, "use statement"); out << "use "; - for(auto i : node->get_path()) { + for (auto i : node->get_path()) { i->accept(this); if (i != node->get_path().back()) { out << "."; @@ -55,7 +55,7 @@ bool ast_format::visit_bool_literal(bool_literal* node) { bool ast_format::visit_vector_expr(vector_expr* node) { dump_formating_node_info(node, "vector expression"); out << "["; - for(auto i : node->get_elements()) { + for (auto i : node->get_elements()) { i->accept(this); if (i != node->get_elements().back()) { out << ", "; @@ -68,7 +68,7 @@ bool ast_format::visit_vector_expr(vector_expr* node) { bool ast_format::visit_hash_expr(hash_expr* node) { dump_formating_node_info(node, "hash expression"); out << "{"; - for(auto i : node->get_members()) { + for (auto i : node->get_members()) { i->accept(this); if (i != node->get_members().back()) { out << ", "; @@ -101,7 +101,7 @@ bool ast_format::visit_hash_pair(hash_pair* node) { bool ast_format::visit_function(function* node) { dump_formating_node_info(node, "function"); out << "func("; - for(auto i : node->get_parameter_list()) { + for (auto i : node->get_parameter_list()) { i->accept(this); if (i != node->get_parameter_list().back()) { out << ", "; @@ -120,7 +120,7 @@ bool ast_format::visit_code_block(code_block* node) { dump_formating_node_info(node, "code block"); out << "{\n"; push_indent(); - for(auto i : node->get_expressions()) { + for (auto i : node->get_expressions()) { dump_indent(); i->accept(this); if (need_dump_semi(i)) { @@ -203,7 +203,7 @@ bool ast_format::visit_unary_operator(unary_operator* node) { bool ast_format::visit_call_expr(call_expr* node) { dump_formating_node_info(node, "call expression"); node->get_first()->accept(this); - for(auto i : node->get_calls()) { + for (auto i : node->get_calls()) { i->accept(this); } return true; @@ -224,7 +224,7 @@ bool ast_format::visit_null_access(null_access* node) { bool ast_format::visit_call_vector(call_vector* node) { dump_formating_node_info(node, "call vector"); out << "["; - for(auto i : node->get_slices()) { + for (auto i : node->get_slices()) { i->accept(this); if (i != node->get_slices().back()) { out << ", "; @@ -237,7 +237,7 @@ bool ast_format::visit_call_vector(call_vector* node) { bool ast_format::visit_call_function(call_function* node) { dump_formating_node_info(node, "call function"); out << "("; - for(auto i : node->get_argument()) { + for (auto i : node->get_argument()) { i->accept(this); if (i != node->get_argument().back()) { out << ", "; @@ -295,7 +295,7 @@ bool ast_format::visit_assignment_expr(assignment_expr* node) { bool ast_format::visit_multi_identifier(multi_identifier* node) { dump_formating_node_info(node, "multi identifier"); out << "("; - for(auto i : node->get_variables()) { + for (auto i : node->get_variables()) { i->accept(this); if (i != node->get_variables().back()) { out << ", "; @@ -308,7 +308,7 @@ bool ast_format::visit_multi_identifier(multi_identifier* node) { bool ast_format::visit_tuple_expr(tuple_expr* node) { dump_formating_node_info(node, "tuple expression"); out << "("; - for(auto i : node->get_elements()) { + for (auto i : node->get_elements()) { i->accept(this); if (i != node->get_elements().back()) { out << ", "; diff --git a/src/ast_visitor.cpp b/src/ast_visitor.cpp index dacd80b..c612c6a 100644 --- a/src/ast_visitor.cpp +++ b/src/ast_visitor.cpp @@ -8,7 +8,7 @@ bool ast_visitor::visit_expr(expr* node) { } bool ast_visitor::visit_use_stmt(use_stmt* node) { - for(auto i : node->get_path()) { + for (auto i : node->get_path()) { i->accept(this); } return true; @@ -44,14 +44,14 @@ bool ast_visitor::visit_bool_literal(bool_literal* node) { } bool ast_visitor::visit_vector_expr(vector_expr* node) { - for(auto i : node->get_elements()) { + for (auto i : node->get_elements()) { i->accept(this); } return true; } bool ast_visitor::visit_hash_expr(hash_expr* node) { - for(auto i : node->get_members()) { + for (auto i : node->get_members()) { i->accept(this); } return true; @@ -65,7 +65,7 @@ bool ast_visitor::visit_hash_pair(hash_pair* node) { } bool ast_visitor::visit_function(function* node) { - for(auto i : node->get_parameter_list()) { + for (auto i : node->get_parameter_list()) { i->accept(this); } node->get_code_block()->accept(this); @@ -73,7 +73,7 @@ bool ast_visitor::visit_function(function* node) { } bool ast_visitor::visit_code_block(code_block* node) { - for(auto i : node->get_expressions()) { + for (auto i : node->get_expressions()) { i->accept(this); } return true; @@ -106,7 +106,7 @@ bool ast_visitor::visit_unary_operator(unary_operator* node) { bool ast_visitor::visit_call_expr(call_expr* node) { node->get_first()->accept(this); - for(auto i : node->get_calls()) { + for (auto i : node->get_calls()) { i->accept(this); } return true; @@ -121,14 +121,14 @@ bool ast_visitor::visit_null_access(null_access* node) { } bool ast_visitor::visit_call_vector(call_vector* node) { - for(auto i : node->get_slices()) { + for (auto i : node->get_slices()) { i->accept(this); } return true; } bool ast_visitor::visit_call_function(call_function* node) { - for(auto i : node->get_argument()) { + for (auto i : node->get_argument()) { i->accept(this); } return true; @@ -163,14 +163,14 @@ bool ast_visitor::visit_assignment_expr(assignment_expr* node) { } bool ast_visitor::visit_multi_identifier(multi_identifier* node) { - for(auto i : node->get_variables()) { + for (auto i : node->get_variables()) { i->accept(this); } return true; } bool ast_visitor::visit_tuple_expr(tuple_expr* node) { - for(auto i : node->get_elements()) { + for (auto i : node->get_elements()) { i->accept(this); } return true; @@ -214,7 +214,7 @@ bool ast_visitor::visit_forei_expr(forei_expr* node) { bool ast_visitor::visit_condition_expr(condition_expr* node) { node->get_if_statement()->accept(this); - for(auto i : node->get_elsif_stataments()) { + for (auto i : node->get_elsif_stataments()) { i->accept(this); } if (node->get_else_statement()) { diff --git a/src/cli/cli.cpp b/src/cli/cli.cpp index b2fe453..e09c4b4 100644 --- a/src/cli/cli.cpp +++ b/src/cli/cli.cpp @@ -13,7 +13,7 @@ namespace nasal::cli { cli_config parse(const std::vector& args) { cli_config result; - for(const auto& arg : args) { + for (const auto& arg : args) { if (cli_options.count(arg)) { result.options.insert(cli_options.at(arg)); } else if (!result.input_file_path.length()) { @@ -113,7 +113,7 @@ std::ostream& version(std::ostream& out) { std::srand(static_cast(std::time(nullptr))); f64 num = 0; - for(u32 i = 0; i<5; ++i) { + for (u32 i = 0; i<5; ++i) { num = (num+rand())*(1.0/(RAND_MAX+1.0)); } // give you 5% to see this easter egg diff --git a/src/main.cpp b/src/main.cpp index 7ba5e9d..3f7bc05 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -51,7 +51,7 @@ void execute(const nasal::cli::cli_config& config) { if (ld.get_file_list().size()) { std::cout << "referenced file(s):\n"; } - for(const auto& file: ld.get_file_list()) { + for (const auto& file: ld.get_file_list()) { std::cout << " " << file << "\n"; } } diff --git a/src/nasal_ast.cpp b/src/nasal_ast.cpp index 2ab1d62..18351d2 100644 --- a/src/nasal_ast.cpp +++ b/src/nasal_ast.cpp @@ -8,7 +8,7 @@ void expr::accept(ast_visitor* visitor) { } use_stmt::~use_stmt() { - for(auto i : path) { + for (auto i : path) { delete i; } } @@ -46,7 +46,7 @@ void bool_literal::accept(ast_visitor* visitor) { } vector_expr::~vector_expr() { - for(auto i : elements) { + for (auto i : elements) { delete i; } } @@ -56,7 +56,7 @@ void vector_expr::accept(ast_visitor* visitor) { } hash_expr::~hash_expr() { - for(auto i : members) { + for (auto i : members) { delete i; } } @@ -76,7 +76,7 @@ void hash_pair::accept(ast_visitor* visitor) { } function::~function() { - for(auto i : parameter_list) { + for (auto i : parameter_list) { delete i; } if (block) { @@ -89,7 +89,7 @@ void function::accept(ast_visitor* visitor) { } code_block::~code_block() { - for(auto i : expressions) { + for (auto i : expressions) { delete i; } } @@ -160,7 +160,7 @@ call_expr::~call_expr() { if(first) { delete first; } - for(auto i : calls) { + for (auto i : calls) { delete i; } } @@ -178,7 +178,7 @@ void null_access::accept(ast_visitor* visitor) { } call_vector::~call_vector() { - for(auto i : calls) { + for (auto i : calls) { delete i; } } @@ -188,7 +188,7 @@ void call_vector::accept(ast_visitor* visitor) { } call_function::~call_function() { - for(auto i : args) { + for (auto i : args) { delete i; } } @@ -243,7 +243,7 @@ void assignment_expr::accept(ast_visitor* visitor) { } multi_identifier::~multi_identifier() { - for(auto i : variables) { + for (auto i : variables) { delete i; } } @@ -253,7 +253,7 @@ void multi_identifier::accept(ast_visitor* visitor) { } tuple_expr::~tuple_expr() { - for(auto i : elements) { + for (auto i : elements) { delete i; } } @@ -340,7 +340,7 @@ condition_expr::~condition_expr() { if (if_stmt) { delete if_stmt; } - for(auto i : elsif_stmt) { + for (auto i : elsif_stmt) { delete i; } if (else_stmt) { diff --git a/src/nasal_codegen.cpp b/src/nasal_codegen.cpp index 4455082..3b50612 100644 --- a/src/nasal_codegen.cpp +++ b/src/nasal_codegen.cpp @@ -5,13 +5,13 @@ namespace nasal { void codegen::init_file_map(const std::vector& file_list) { file_map = {}; - for(usize i = 0; i(); - for(const auto& i : finder->do_find(node)) { + for (const auto& i : finder->do_find(node)) { const auto& file = i.pos_node->get_location().file; // check if symbol conflicts with native function name if (native_function_mapper.count(i.name)) { @@ -153,7 +153,7 @@ i64 codegen::upvalue_symbol_find(const std::string& name) { } auto iter = local.begin(); - for(u64 i = 0; icount(name)) { index = ((i<<16)|(*iter).at(name)); } @@ -189,7 +189,7 @@ void codegen::bool_gen(bool_literal* node) { } void codegen::vector_gen(vector_expr* node) { - for(auto child : node->get_elements()) { + for (auto child : node->get_elements()) { calc_gen(child); } emit(op_newv, node->get_elements().size(), node->get_location()); @@ -197,7 +197,7 @@ void codegen::vector_gen(vector_expr* node) { void codegen::hash_gen(hash_expr* node) { emit(op_newh, 0, node->get_location()); - for(auto child : node->get_members()) { + for (auto child : node->get_members()) { calc_gen(child->get_value()); const auto& field_name = child->get_name(); regist_string(field_name); @@ -210,7 +210,7 @@ void codegen::func_gen(function* node) { bool checked_default = false; bool checked_dynamic = false; std::unordered_map argname; - for(auto tmp : node->get_parameter_list()) { + for (auto tmp : node->get_parameter_list()) { if (tmp->get_parameter_type()== parameter::kind::default_parameter) { checked_default = true; @@ -250,7 +250,7 @@ void codegen::func_gen(function* node) { local.push_back({{"me", 0}}); // generate parameter list - for(auto tmp : node->get_parameter_list()) { + for (auto tmp : node->get_parameter_list()) { const auto& name = tmp->get_parameter_name(); if (name=="me") { die("\"me\" should not be parameter", tmp); @@ -326,7 +326,7 @@ void codegen::call_gen(call_expr* node) { if (code.size() && code.back().op==op_callb) { return; } - for(auto i : node->get_calls()) { + for (auto i : node->get_calls()) { switch(i->get_type()) { case expr_type::ast_callh: call_hash_gen(reinterpret_cast(i)); break; @@ -404,7 +404,7 @@ void codegen::call_vector_gen(call_vector* node) { return; } emit(op_slcbeg, 0, node->get_location()); - for(auto tmp : node->get_slices()) { + for (auto tmp : node->get_slices()) { if (!tmp->get_end()) { calc_gen(tmp->get_begin()); emit(op_slc, 0, tmp->get_location()); @@ -421,7 +421,7 @@ void codegen::call_func_gen(call_function* node) { if (node->get_argument().size() && node->get_argument()[0]->get_type()==expr_type::ast_pair) { emit(op_newh, 0, node->get_location()); - for(auto child : node->get_argument()) { + for (auto child : node->get_argument()) { auto pair_node = reinterpret_cast(child); calc_gen(pair_node->get_value()); const auto& field_name = pair_node->get_name(); @@ -430,7 +430,7 @@ void codegen::call_func_gen(call_function* node) { } emit(op_callfh, 0, node->get_location()); } else { - for(auto child : node->get_argument()) { + for (auto child : node->get_argument()) { calc_gen(child); } emit(op_callfv, node->get_argument().size(), node->get_location()); @@ -459,7 +459,7 @@ void codegen::mcall(expr* node) { // generate call expression until the last sub-node auto call_node = static_cast(node); calc_gen(call_node->get_first()); - for(usize i = 0; iget_calls().size()-1; ++i) { + for (usize i = 0; iget_calls().size()-1; ++i) { auto tmp = call_node->get_calls()[i]; switch(tmp->get_type()) { case expr_type::ast_callh: @@ -566,7 +566,7 @@ void codegen::multi_def(definition_expr* node) { ); return; } - for(usize i = 0; iget_name(); local.empty()? @@ -577,7 +577,7 @@ void codegen::multi_def(definition_expr* node) { } // (var a, b, c) = [0, 1, 2]; calc_gen(node->get_value()); - for(usize i = 0; iget_value()->get_location()); const auto& name = identifiers[i]->get_name(); local.empty()? @@ -787,11 +787,11 @@ void codegen::multi_assign_gen(multi_assign* node) { if (value_node->get_type()==expr_type::ast_tuple) { const auto& value_tuple = reinterpret_cast(value_node) ->get_elements(); - for(i64 i = size-1; i>=0; --i) { + for (i64 i = size-1; i>=0; --i) { calc_gen(value_tuple[i]); } auto& tuple = tuple_node->get_elements(); - for(i64 i = 0; iget_elements(); - for(i64 i = 0; iget_location()); mcall(tuple[i]); // use load operands to avoid meq's pop operand @@ -828,7 +828,7 @@ void codegen::cond_gen(condition_expr* node) { } code[ptr].num = code.size(); - for(auto tmp : node->get_elsif_stataments()) { + for (auto tmp : node->get_elsif_stataments()) { calc_gen(tmp->get_condition()); ptr = code.size(); emit(op_jf, 0, tmp->get_location()); @@ -845,7 +845,7 @@ void codegen::cond_gen(condition_expr* node) { if (node->get_else_statement()) { block_gen(node->get_else_statement()->get_code_block()); } - for(auto i:jmp_label) { + for (auto i:jmp_label) { code[i].num = code.size(); } } @@ -866,10 +866,10 @@ void codegen::loop_gen(expr* node) { } void codegen::load_continue_break(u64 continue_place, u64 break_place) { - for(auto i : continue_ptr.front()) { + for (auto i : continue_ptr.front()) { code[i].num = continue_place; } - for(auto i : break_ptr.front()) { + for (auto i : break_ptr.front()) { code[i].num = break_place; } continue_ptr.pop_front(); @@ -1287,7 +1287,7 @@ void codegen::repl_mode_info_output_gen(expr* node) { void codegen::block_gen(code_block* node) { bool is_use_statement = true; - for(auto tmp : node->get_expressions()) { + for (auto tmp : node->get_expressions()) { if (tmp->get_type()!=expr_type::ast_use) { is_use_statement = false; } @@ -1348,7 +1348,7 @@ void codegen::block_gen(code_block* node) { } void codegen::ret_gen(return_expr* node) { - for(u32 i = 0; iget_location()); emit(op_pop, 0, node->get_location()); } @@ -1418,12 +1418,12 @@ void codegen::print(std::ostream& out) { std::stack func_end_stack; // print const numbers - for(auto num : const_number_table) { + for (auto num : const_number_table) { out << " .number " << num << "\n"; } // print const strings - for(const auto& str : const_string_table) { + for (const auto& str : const_string_table) { out << " .symbol \"" << util::rawstr(str) << "\"\n"; } @@ -1440,7 +1440,7 @@ void codegen::print(std::ostream& out) { native_function.data() ); - for(u64 i = 0; i:\n"; - for(u64 j = i; j\n"; - for(const auto& i : domain.second) { + for (const auto& i : domain.second) { out << " 0x" << std::setw(4) << std::setfill('0'); out << std::hex << global.at(i) << std::dec << " "; out << i << std::endl; diff --git a/src/nasal_dbg.cpp b/src/nasal_dbg.cpp index 490b301..6f284e7 100644 --- a/src/nasal_dbg.cpp +++ b/src/nasal_dbg.cpp @@ -3,7 +3,7 @@ namespace nasal { void operand_line_counter::init_counter() { - for(usize i = 0; i op_count; std::vector opcall; u64 total = 0; - for(usize i = 0; imax_call_time? count:max_call_time; } } auto pad_length = std::to_string(max_call_time).length(); - for(usize i = 0; imax_call_time? count:max_call_time; } auto pad_length = std::to_string(max_call_time).length(); @@ -84,7 +84,7 @@ void operand_line_counter::dump_this_file_line_counter(std::ostream& os) const { os << "\ncode profiling data of " << file_name_list[0] << ":\n"; const auto& context = file_contents[0]; const auto& counter = file_line_counter[0]; - for(usize i = 0; i dbg::parse(const std::string& cmd) { } u16 dbg::file_index(const std::string& filename) const { - for(u16 i = 0; i ":" ") << src[i] << reset << "\n"; } @@ -172,7 +172,7 @@ void dbg::step_info() { ); std::clog << "\nnext bytecode:\n"; - for(u64 i = begin; i ":" ") @@ -273,7 +273,7 @@ void dbg::run(const codegen& gen, std::vector code; std::vector code_file_index; std::vector code_line; - for(const auto& i : gen.codes()) { + for (const auto& i : gen.codes()) { code.push_back(i.op); code_file_index.push_back(i.fidx); code_line.push_back(i.line); diff --git a/src/nasal_err.cpp b/src/nasal_err.cpp index f9ba2a0..401d440 100644 --- a/src/nasal_err.cpp +++ b/src/nasal_err.cpp @@ -182,7 +182,7 @@ void error::err(const std::string& stage, const usize maxlen = std::to_string(loc.end_line).length(); const std::string iden = identation(maxlen); - for(u64 line = loc.begin_line; line<=loc.end_line; ++line) { + for (u64 line = loc.begin_line; line<=loc.end_line; ++line) { // skip line 0 if (!line) { continue; @@ -211,25 +211,25 @@ void error::err(const std::string& stage, // output underline std::cerr << cyan << iden << " | " << reset; if (loc.begin_line==loc.end_line) { - for(u64 i = 0; i& vec, usize begin, usize end) { std::vector bfs; - for(auto i = begin; imark!=nas_val::gc_status::uncollected) { @@ -79,14 +79,14 @@ void gc::concurrent_mark(std::vector& vec, usize begin, usize end) { void gc::mark_context_root(std::vector& bfs_queue) { // scan global - for(usize i = 0; i < main_context_global_size; ++i) { + for (usize i = 0; i < main_context_global_size; ++i) { auto& val = main_context_global[i]; if (val.type > vm_type::vm_num) { bfs_queue.push_back(val); } } // scan now running context, this context maybe related to coroutine or main - for(var* i = running_context->stack; i <= running_context->top; ++i) { + for (var* i = running_context->stack; i <= running_context->top; ++i) { if (i->type > vm_type::vm_num) { bfs_queue.push_back(*i); } @@ -100,7 +100,7 @@ void gc::mark_context_root(std::vector& bfs_queue) { } // coroutine is running, so scan main process stack from mctx - for(var* i = main_context.stack; i <= main_context.top; ++i) { + for (var* i = main_context.stack; i <= main_context.top; ++i) { if (i->type > vm_type::vm_num) { bfs_queue.push_back(*i); } @@ -124,7 +124,7 @@ void gc::mark_var(std::vector& bfs_queue, var& value) { } void gc::mark_vec(std::vector& bfs_queue, nas_vec& vec) { - for(auto& i : vec.elems) { + for (auto& i : vec.elems) { if (i.type > vm_type::vm_num) { bfs_queue.push_back(i); } @@ -132,7 +132,7 @@ void gc::mark_vec(std::vector& bfs_queue, nas_vec& vec) { } void gc::mark_hash(std::vector& bfs_queue, nas_hash& hash) { - for(auto& i : hash.elems) { + for (auto& i : hash.elems) { if (i.second.type > vm_type::vm_num) { bfs_queue.push_back(i.second); } @@ -140,18 +140,18 @@ void gc::mark_hash(std::vector& bfs_queue, nas_hash& hash) { } void gc::mark_func(std::vector& bfs_queue, nas_func& function) { - for(auto& i : function.local) { + for (auto& i : function.local) { if (i.type > vm_type::vm_num) { bfs_queue.push_back(i); } } - for(auto& i : function.upval) { + for (auto& i : function.upval) { bfs_queue.push_back(i); } } void gc::mark_upval(std::vector& bfs_queue, nas_upval& upval) { - for(auto& i : upval.elems) { + for (auto& i : upval.elems) { if (i.type > vm_type::vm_num) { bfs_queue.push_back(i); } @@ -168,7 +168,7 @@ void gc::mark_ghost(std::vector& bfs_queue, nas_ghost& ghost) { void gc::mark_co(std::vector& bfs_queue, nas_co& co) { bfs_queue.push_back(co.ctx.funcr); bfs_queue.push_back(co.ctx.upvalr); - for(var* i = co.ctx.stack; i<=co.ctx.top; ++i) { + for (var* i = co.ctx.stack; i<=co.ctx.top; ++i) { if (i->type > vm_type::vm_num) { bfs_queue.push_back(*i); } @@ -176,7 +176,7 @@ void gc::mark_co(std::vector& bfs_queue, nas_co& co) { } void gc::mark_map(std::vector& bfs_queue, nas_map& mp) { - for(const auto& i : mp.mapper) { + for (const auto& i : mp.mapper) { if (i.second->type > vm_type::vm_num) { bfs_queue.push_back(*i.second); } @@ -211,7 +211,7 @@ void gc::extend(const vm_type type) { const u32 index = static_cast(type)-static_cast(vm_type::vm_str); status.object_size[index] += incr[index]; - for(u64 i = 0; i& constant_strings, } void gc::clear() { - for(auto i : memory) { + for (auto i : memory) { delete i; } memory.clear(); - for(u32 i = 0; iget_type()==expr_type::ast_use) { auto file_relative_path = std::string(""); const auto& path = reinterpret_cast(node)->get_path(); - for(auto i : path) { + for (auto i : path) { file_relative_path += i->get_name(); if (i!=path.back()) { file_relative_path += (util::is_windows()? "\\":"/"); @@ -56,12 +56,12 @@ std::string linker::find_real_file_path(const std::string& filename, std::vector path_list = {filename}; // generate search path from environ path - for(const auto& p : envpath) { + for (const auto& p : envpath) { path_list.push_back(fs::path(p)/filename); } // search file - for(const auto& path : path_list) { + for (const auto& path : path_list) { if (fs::exists(path)) { return path.str(); } @@ -82,7 +82,7 @@ std::string linker::find_real_file_path(const std::string& filename, return ""; } auto path_list_info = std::string(""); - for(const auto& path : path_list) { + for (const auto& path : path_list) { path_list_info += " -> " + path.str() + "\n"; } err.err("link", @@ -138,7 +138,7 @@ bool linker::import_check(expr* node) { bool linker::check_exist_or_record_file(const std::string& file) { // avoid importing the same file - for(const auto& name : imported_files) { + for (const auto& name : imported_files) { if (file==name) { return true; } @@ -148,7 +148,7 @@ bool linker::check_exist_or_record_file(const std::string& file) { } bool linker::check_self_import(const std::string& file) { - for(const auto& name : module_load_stack) { + for (const auto& name : module_load_stack) { if (file==name) { return true; } @@ -158,7 +158,7 @@ bool linker::check_self_import(const std::string& file) { std::string linker::generate_self_import_path(const std::string& filename) { std::string res = ""; - for(const auto& i : module_load_stack) { + for (const auto& i : module_load_stack) { res += "[" + i + "] -> "; } return res + "[" + filename + "]"; @@ -166,7 +166,7 @@ std::string linker::generate_self_import_path(const std::string& filename) { void linker::merge_tree(code_block* new_tree_root, code_block* old_tree_root) { // add children of add_root to the back of root - for(auto& i : old_tree_root->get_expressions()) { + for (auto& i : old_tree_root->get_expressions()) { new_tree_root->add_expression(i); } // clean old root @@ -329,7 +329,7 @@ return_expr* linker::generate_module_return(code_block* block) { auto result = new return_expr(block->get_location()); auto value = new hash_expr(block->get_location()); result->set_value(value); - for(const auto& i : finder->do_find(block)) { + for (const auto& i : finder->do_find(block)) { auto pair = new hash_pair(block->get_location()); // do not export symbol begins with '_' if (i.name.length() && i.name[0]=='_') { @@ -369,7 +369,7 @@ definition_expr* linker::generate_module_definition(code_block* block) { void linker::load(code_block* program_root, const std::string& filename) { // load imported modules std::unordered_set used_modules = {}; - for(auto& import_node : program_root->get_expressions()) { + for (auto& import_node : program_root->get_expressions()) { if (!import_check(import_node)) { break; } diff --git a/src/nasal_lexer.cpp b/src/nasal_lexer.cpp index 425b700..6800d37 100644 --- a/src/nasal_lexer.cpp +++ b/src/nasal_lexer.cpp @@ -124,7 +124,7 @@ std::string lexer::utf8_gen() { } tmp += res[ptr++]; - for(u32 i = 0; i(op) << ":" << dec; // dump immediate number(hex format) - for(i32 i = 64-8; i>=0; i -= 8) { + for (i32 i = 64-8; i>=0; i -= 8) { auto this_byte = ((num>>i)&0xff); out << hex << setw(2) << setfill('0') << this_byte << dec << " "; } diff --git a/src/nasal_parse.cpp b/src/nasal_parse.cpp index d2913b5..0009f03 100644 --- a/src/nasal_parse.cpp +++ b/src/nasal_parse.cpp @@ -103,7 +103,7 @@ bool parse::is_call(tok type) { } bool parse::check_comma(const tok* panic_set) { - for(u32 i = 0; panic_set[i]!=tok::tk_null; ++i) { + for (u32 i = 0; panic_set[i]!=tok::tk_null; ++i) { if (lookahead(panic_set[i])) { die(prevspan, "expected \",\" between scalars"); return true; @@ -987,7 +987,7 @@ for_expr* parse::for_loop() { } else { node->set_initial(calc()); } - match(tok::tk_semi, "expected \";\" in for(;;)"); + match(tok::tk_semi, "expected \";\" in for (;;)"); // conditional expression if (lookahead(tok::tk_eof)) { @@ -998,7 +998,7 @@ for_expr* parse::for_loop() { } else { node->set_condition(calc()); } - match(tok::tk_semi, "expected \";\" in for(;;)"); + match(tok::tk_semi, "expected \";\" in for (;;)"); //after loop expression if (lookahead(tok::tk_eof)) { diff --git a/src/nasal_type.cpp b/src/nasal_type.cpp index 561f68c..8cc9173 100644 --- a/src/nasal_type.cpp +++ b/src/nasal_type.cpp @@ -14,7 +14,7 @@ std::ostream& operator<<(std::ostream& out, nas_vec& vec) { vec.printed = true; usize iter = 0, size = vec.elems.size(); out << "["; - for(auto& i:vec.elems) { + for (auto& i:vec.elems) { out << i << ",]"[(++iter)==size]; } vec.printed = false; @@ -34,7 +34,7 @@ var nas_hash::get_value(const std::string& key) { if (!val.is_vec()) { return ret; } - for(auto& i : val.vec().elems) { + for (auto& i : val.vec().elems) { if (i.is_hash()) { ret = i.hash().get_value(key); } @@ -58,7 +58,7 @@ var* nas_hash::get_memory(const std::string& key) { if (!val.is_vec()) { return addr; } - for(auto& i : val.vec().elems) { + for (auto& i : val.vec().elems) { // recursively search key in `parents` if (i.is_hash()) { addr = i.hash().get_memory(key); @@ -82,7 +82,7 @@ std::ostream& operator<<(std::ostream& out, nas_hash& hash) { static const char* sep[] = {", ", "}"}; usize iter = 0, size = hash.elems.size(); out << "{"; - for(auto& i : hash.elems) { + for (auto& i : hash.elems) { out << i.first << ": " << i.second << sep[(++iter)==size]; } @@ -96,11 +96,11 @@ std::ostream& operator<<(std::ostream& out, nas_func& func) { std::vector argument_list = {}; argument_list.resize(func.keys.size()); - for(const auto& key : func.keys) { + for (const auto& key : func.keys) { argument_list[key.second-1] = key.first; } - for(const auto& key : argument_list) { + for (const auto& key : argument_list) { out << key; if (key != argument_list.back()) { out << ", "; @@ -163,7 +163,7 @@ void nas_co::clear() { if (!ctx.stack) { return; } - for(u32 i = 0; i& strs, auto map_instance = ngc.alloc(vm_type::vm_map); global_symbol_name.resize(global_symbol.size()); global[global_symbol.at("globals")] = map_instance; - for(const auto& i : global_symbol) { + for (const auto& i : global_symbol) { map_instance.map().mapper[i.first] = global + i.second; global_symbol_name[i.second] = i.first; } @@ -59,7 +59,7 @@ void vm::context_and_global_init() { ctx.top = ctx.stack - 1; /* clear main stack and global */ - for(u32 i = 0; imax_show_elems) { break; @@ -126,7 +126,7 @@ void vm::coroutine_value_info(var& val) { void vm::namespace_value_info(var& val, const usize max_show_elems) { std::clog << "{"; usize count = 0; - for(const auto& i : val.map().mapper) { + for (const auto& i : val.map().mapper) { ++count; if (count>max_show_elems) { break; @@ -194,12 +194,12 @@ void vm::function_detail_info(const nas_func& func) { std::vector argument_list = {}; argument_list.resize(func.keys.size()); - for(const auto& key : func.keys) { + for (const auto& key : func.keys) { argument_list[key.second-1] = key.first; } std::clog << "("; - for(const auto& key : argument_list) { + for (const auto& key : argument_list) { std::clog << key; if (key != argument_list.back()) { std::clog << ", "; @@ -226,7 +226,7 @@ void vm::function_call_trace() { std::stack callsite; // load call trace, from bottom to top - for(var* i = bottom; i <= top; ++i) { + for (var* i = bottom; i <= top; ++i) { // i-1 is the callsite program counter of this function // +-------+----------------+ // | func | func() {..} | <-- i + 2 @@ -250,7 +250,7 @@ void vm::function_call_trace() { // another condition may exist // have ret pc on stack, but no function at the top of the ret pc - for(var * i = top; i >= bottom; --i) { + for (var * i = top; i >= bottom; --i) { // +-------+----------------+ // | xxxx | xxxx | <-- i + 2 (not function or not exist) // +-------+----------------+ @@ -282,7 +282,7 @@ void vm::function_call_trace() { const nas_func* last = nullptr; u64 last_callsite = SIZE_MAX; u64 same_count = 0; - for(; !functions.empty() && !callsite.empty(); functions.pop(), callsite.pop()) { + for (; !functions.empty() && !callsite.empty(); functions.pop(), callsite.pop()) { auto func = functions.top(); auto place = callsite.top(); @@ -316,7 +316,7 @@ void vm::function_call_trace() { void vm::trace_back() { // generate trace back std::stack ret; - for(var* i = ctx.stack; i<=ctx.top; ++i) { + for (var* i = ctx.stack; i<=ctx.top; ++i) { if (i->is_ret() && i->ret()!=0) { ret.push(i->ret()); } @@ -335,7 +335,7 @@ void vm::trace_back() { files ); - for(u64 p = 0, same = 0, prev = 0xffffffff; !ret.empty(); prev = p, ret.pop()) { + for (u64 p = 0, same = 0, prev = 0xffffffff; !ret.empty(); prev = p, ret.pop()) { if ((p = ret.top())==prev) { ++same; continue; @@ -360,7 +360,7 @@ void vm::stack_info(const u64 limit) { std::clog << ", limit " << limit << ", total "; std::clog << (top(top-bottom+1)) << ")\n"; - for(u32 i = 0; i=bottom; ++i, --top) { + for (u32 i = 0; i=bottom; ++i, --top) { std::clog << " 0x" << std::hex << std::setw(8) << std::setfill('0') << static_cast(top-bottom) << std::dec @@ -394,7 +394,7 @@ void vm::global_state() { } std::clog << "\nglobal (0x" << std::hex << reinterpret_cast(global) << ")\n" << std::dec; - for(usize i = 0; i(i) << std::dec << " "; @@ -419,7 +419,7 @@ void vm::local_state() { std::clog << "\nlocal (0x" << std::hex << reinterpret_cast(ctx.localr) << " <+" << static_cast(ctx.localr-ctx.stack) << ">)\n" << std::dec; - for(u32 i = 0; i upval[" << i << "]:\n"; auto& uv = upval[i].upval(); - for(u32 j = 0; j argument_list = {}; argument_list.resize(func.keys.size()); - for(const auto& i : func.keys) { + for (const auto& i : func.keys) { argument_list[i.second-1] = i.first; } - for(u32 i = 0; i argument_list = {}; argument_list.resize(func.keys.size()); - for(const auto& i : func.keys) { + for (const auto& i : func.keys) { argument_list[i.second-1] = i.first; } - for(const auto& key : argument_list) { + for (const auto& key : argument_list) { if (local[func.keys.at(key)].is_none()) { result += key + ", "; } else { @@ -507,7 +507,7 @@ std::string vm::report_special_call_lack_arguments(var* local, std::string vm::report_key_not_found(const std::string& not_found, const nas_hash& hash) const { auto result = "member \"" + not_found + "\" doesn't exist in hash {"; - for(const auto& i : hash.elems) { + for (const auto& i : hash.elems) { result += i.first + ", "; } if (hash.elems.size()) { @@ -696,7 +696,7 @@ void vm::run(const codegen& gen, &&ret }; std::vector code; - for(const auto& i : gen.codes()) { + for (const auto& i : gen.codes()) { code.push_back(oprs[i.op]); imm.push_back(i.num); } @@ -705,7 +705,7 @@ void vm::run(const codegen& gen, goto *code[ctx.pc]; #else std::vector code; - for(const auto& i : gen.codes()) { + for (const auto& i : gen.codes()) { code.push_back(operand_function[i.op]); imm.push_back(i.num); } diff --git a/src/nasal_vm.h b/src/nasal_vm.h index 0335c14..71f3e40 100644 --- a/src/nasal_vm.h +++ b/src/nasal_vm.h @@ -413,7 +413,7 @@ inline void vm::o_newv() { // use top-=imm[pc]-1 here will cause error if imm[pc] is 0 ctx.top = ctx.top - imm[ctx.pc] + 1; - for(u64 i = 0; i=0) { // load dynamic argument dynamic = ngc.alloc(vm_type::vm_vec); - for(u64 i = parameter_size; i=1; --i) { + for (u64 i = min_size; i>=1; --i) { local[i] = local[i-1]; } local[0] = func.local[0]; // load "me" // load local scope & default arguments - for(u64 i = min_size + 1; i=0? ref[i]:ref[i+size]); } } @@ -1215,7 +1215,7 @@ inline void vm::o_ret() { auto size = func.func().local_size; upval.on_stack = false; upval.elems.resize(size); - for(u64 i = 0; i < size; ++i) { + for (u64 i = 0; i < size; ++i) { upval.elems[i] = local[i]; } } diff --git a/src/natives/bits_lib.cpp b/src/natives/bits_lib.cpp index 4fa6a8b..7622993 100644 --- a/src/natives/bits_lib.cpp +++ b/src/natives/bits_lib.cpp @@ -61,7 +61,7 @@ var builtin_fld(context* ctx, gc* ngc) { } u32 res = 0; auto& s = str.str(); - for(u32 i = bit; i>3]&(1<<(7-(i&7)))) { res |= 1<<(bit+len-i-1); } @@ -91,7 +91,7 @@ var builtin_sfld(context* ctx, gc* ngc) { } u32 res = 0; auto& s = str.str(); - for(u32 i = bit; i>3]&(1<<(7-(i&7)))) { res |= 1<<(bit+len-i-1); } @@ -127,7 +127,7 @@ var builtin_setfld(context* ctx, gc* ngc) { return nas_err("bits::setfld", "bitfield out of bounds"); } auto& s = str.str(); - for(u32 i = bit; i>3] |= (1<<(7-(i&7))); } else { diff --git a/src/natives/builtin.cpp b/src/natives/builtin.cpp index c1a2307..1f4416f 100644 --- a/src/natives/builtin.cpp +++ b/src/natives/builtin.cpp @@ -20,7 +20,7 @@ var builtin_unsafe(context* ctx, gc* ngc) { } var builtin_print(context* ctx, gc* ngc) { - for(auto& i : ctx->localr[1].vec().elems) { + for (auto& i : ctx->localr[1].vec().elems) { std::cout << i; } std::cout << std::flush; @@ -28,7 +28,7 @@ var builtin_print(context* ctx, gc* ngc) { } var builtin_println(context* ctx, gc* ngc) { - for(auto& i : ctx->localr[1].vec().elems) { + for (auto& i : ctx->localr[1].vec().elems) { std::cout << i; } std::cout << std::endl; @@ -53,7 +53,7 @@ var builtin_append(context* ctx, gc* ngc) { return nas_err("native::append", "\"vec\" must be vector"); } auto& v = vec.vec().elems; - for(auto& i : elem.vec().elems) { + for (auto& i : elem.vec().elems) { v.push_back(i); } return nil; @@ -112,7 +112,7 @@ var builtin_split(context* ctx, gc* ngc) { // empty separator means split every char if (!sep.length()) { - for(auto i : s) { + for (auto i : s) { vec.push_back(ngc->newstr(i)); } ngc->temp = nil; @@ -160,7 +160,7 @@ var builtin_split_with_empty_substr(context* ctx, gc* ngc) { // empty separator means split every char if (!sep.length()) { - for(auto i : s) { + for (auto i : s) { vec.push_back(ngc->newstr(i)); } ngc->temp = nil; @@ -193,7 +193,7 @@ var builtin_rand(context* ctx, gc* ngc) { return nil; } f64 num = 0; - for(u32 i = 0; i<5; ++i) { + for (u32 i = 0; i<5; ++i) { num = (num+rand())*(1.0/(RAND_MAX+1.0)); } return var::num(num); @@ -320,11 +320,11 @@ var builtin_keys(context* ctx, gc* ngc) { auto res = ngc->temp = ngc->alloc(vm_type::vm_vec); auto& vec = res.vec().elems; if (hash.is_hash()) { - for(const auto& iter : hash.hash().elems) { + for (const auto& iter : hash.hash().elems) { vec.push_back(ngc->newstr(iter.first)); } } else { - for(const auto& iter : hash.map().mapper) { + for (const auto& iter : hash.map().mapper) { vec.push_back(ngc->newstr(iter.first)); } } @@ -492,11 +492,11 @@ var builtin_values(context* ctx, gc* ngc) { auto vec = ngc->alloc(vm_type::vm_vec); auto& v = vec.vec().elems; if (hash.is_hash()) { - for(auto& i : hash.hash().elems) { + for (auto& i : hash.hash().elems) { v.push_back(i.second); } } else { - for(auto& i : hash.map().mapper) { + for (auto& i : hash.map().mapper) { v.push_back(*i.second); } } @@ -513,7 +513,7 @@ var builtin_sleep(context* ctx, gc* ngc) { // also msvc will use this Sleep(static_cast(val.num()*1e3)); #else - std::this_thread::sleep_for( + std::this_thread::sleep_for ( std::chrono::microseconds(static_cast(val.num()*1e6)) ); #endif @@ -536,9 +536,9 @@ var builtin_arch(context* ctx, gc* ngc) { std::string tohex(u32 num) { const char str16[] = "0123456789abcdef"; std::string str = ""; - for(u32 i = 0; i<4; i++, num >>= 8) { + for (u32 i = 0; i<4; i++, num >>= 8) { std::string tmp = ""; - for(u32 j = 0, b = num&0xff; j<2; j++, b >>= 4) { + for (u32 j = 0, b = num&0xff; j<2; j++, b >>= 4) { tmp.insert(0, 1, str16[b&0xf]); } str += tmp; @@ -551,7 +551,7 @@ std::string md5(const std::string& src) { usize num = ((src.length()+8)>>6)+1; usize buffsize = num<<4; buff.resize(buffsize, 0); - for(usize i = 0; i>2] |= (static_cast(src[i]))<<((i&0x3)<<3); } buff[src.length()>>2] |= 0x80<<(((src.length()%4))<<3); @@ -602,9 +602,9 @@ std::string md5(const std::string& src) { u32 atmp = 0x67452301, btmp = 0xefcdab89; u32 ctmp = 0x98badcfe, dtmp = 0x10325476; - for(u32 i = 0; i(table[i].fd); auto function_object = ngc->alloc(vm_type::vm_ghost); function_object.ghost().set( diff --git a/src/natives/fg_props.cpp b/src/natives/fg_props.cpp index 67f4927..6717a5a 100644 --- a/src/natives/fg_props.cpp +++ b/src/natives/fg_props.cpp @@ -26,7 +26,7 @@ var builtin_logprint(context* ctx, gc* ngc) { "incorrect log level " + std::to_string(level.num()) ); } - for(auto& value : elems.vec().elems) { + for (auto& value : elems.vec().elems) { out << value << " "; } out << "\n"; diff --git a/src/natives/json_lib.cpp b/src/natives/json_lib.cpp index b068f3b..dc79f6c 100644 --- a/src/natives/json_lib.cpp +++ b/src/natives/json_lib.cpp @@ -123,7 +123,7 @@ std::string json::vector_generate(nas_vec& vect) { } vect.printed = true; std::string out = "["; - for(auto& i : vect.elems) { + for (auto& i : vect.elems) { out += var_generate(i) + ","; } if (out.back()==',') { @@ -142,7 +142,7 @@ std::string json::hash_generate(nas_hash& hash) { } hash.printed = true; std::string out = "{"; - for(auto& i : hash.elems) { + for (auto& i : hash.elems) { out += "\"" + i.first + "\":"; out += var_generate(i.second) + ","; } diff --git a/src/natives/subprocess.cpp b/src/natives/subprocess.cpp index 53c6bf6..27e38d5 100644 --- a/src/natives/subprocess.cpp +++ b/src/natives/subprocess.cpp @@ -53,7 +53,7 @@ var builtin_subprocess_create(context* ctx, gc* ngc) { ); } - for(const auto& v : cmd.vec().elems) { + for (const auto& v : cmd.vec().elems) { if (!v.is_str()) { return nas_err("subprocess::create", "non-string argument found" @@ -83,7 +83,7 @@ var builtin_subprocess_create(context* ctx, gc* ngc) { ZeroMemory(pi, sizeof(PROCESS_INFORMATION)); auto command = cmd.vec().elems[0].str(); - for(usize i = 1; i()->pid = pid; - for(usize i = 0; argv[i]; ++i) { + for (usize i = 0; argv[i]; ++i) { delete argv[i]; } delete[] argv; diff --git a/src/natives/unix_lib.cpp b/src/natives/unix_lib.cpp index 3296dab..31f128a 100644 --- a/src/natives/unix_lib.cpp +++ b/src/natives/unix_lib.cpp @@ -72,7 +72,7 @@ var builtin_chdir(context* ctx, gc* ngc) { var builtin_environ(context* ctx, gc* ngc) { var res = ngc->temp = ngc->alloc(vm_type::vm_vec); auto& vec = res.vec().elems; - for(char** env = environ; *env; ++env) { + for (char** env = environ; *env; ++env) { vec.push_back(ngc->newstr(*env)); } ngc->temp = nil; diff --git a/src/repl/repl.cpp b/src/repl/repl.cpp index 7970132..d8662d8 100644 --- a/src/repl/repl.cpp +++ b/src/repl/repl.cpp @@ -28,7 +28,7 @@ std::string repl::readline(const std::string& prompt = ">>> ") { void repl::update_temp_file() { auto content = std::string(""); - for(const auto& i : source) { + for (const auto& i : source) { content += i + "\n"; } info::instance()->repl_file_source = content + " "; @@ -36,7 +36,7 @@ void repl::update_temp_file() { void repl::update_temp_file(const std::vector& src) { auto content = std::string(""); - for(const auto& i : src) { + for (const auto& i : src) { content += i + "\n"; } info::instance()->repl_file_source = content + " "; @@ -53,7 +53,7 @@ bool repl::check_need_more_input() { i64 in_curve = 0; i64 in_bracket = 0; i64 in_brace = 0; - for(const auto& t : nasal_lexer->result()) { + for (const auto& t : nasal_lexer->result()) { switch(t.type) { case tok::tk_lcurve: ++in_curve; break; case tok::tk_rcurve: --in_curve; break; @@ -85,7 +85,7 @@ int repl::check_need_more_input(std::vector& src) { i64 in_curve = 0; i64 in_bracket = 0; i64 in_brace = 0; - for(const auto& t : nasal_lexer->result()) { + for (const auto& t : nasal_lexer->result()) { switch(t.type) { case tok::tk_lcurve: ++in_curve; break; case tok::tk_rcurve: --in_curve; break; diff --git a/src/symbol_finder.cpp b/src/symbol_finder.cpp index e4a0ad5..a5b1acd 100644 --- a/src/symbol_finder.cpp +++ b/src/symbol_finder.cpp @@ -13,7 +13,7 @@ bool symbol_finder::visit_definition_expr(definition_expr* node) { } else { // multiple variable definition // example: var (a, b, c) = (0, 1, 2); - for(auto i : node->get_variables()->get_variables()) { + for (auto i : node->get_variables()->get_variables()) { symbols.push_back({i->get_name(), i}); } } diff --git a/src/util/gc_stat.cpp b/src/util/gc_stat.cpp index d6631e5..5256069 100644 --- a/src/util/gc_stat.cpp +++ b/src/util/gc_stat.cpp @@ -99,7 +99,7 @@ void gc_stat::dump_info() const { auto len = strlen(n); indent = indent0) { if (contains(tmp.val,path[i]~'['~index~']')) @@ -260,7 +260,7 @@ props.Node={ return 0; }, addChildren:func(name,cnt=0) { - for(var i=0;i=size(type)) @@ -335,7 +335,7 @@ var show = func() { }; var bar_key=keys(bars); var spin_key=keys(spinners); - for(var i=0; i<40; i+=1) { + for (var i=0; i<40; i+=1) { forindex(var j; bar_key) { var k=bar_key[j]; print("\e["~(j+1)~";1H["~k~"] "~bars[k].bar((i+1)/40)); diff --git a/std/props.nas b/std/props.nas index 202aa15..0890e40 100644 --- a/std/props.nas +++ b/std/props.nas @@ -433,7 +433,7 @@ var wrap = func(node) { } elsif (isvec(node)) { var v = node; var n = size(v); - for(var i=0; i=0;i-=1) { + for (var loop=0;loop=0;i-=1) { var rand_index=int(i*rand()); (arr[i],arr[rand_index])=(arr[rand_index],arr[i]); } # 0 1 2 3 4 5 6 7 8 var shadow=[" ","░","▒","▓","█","▀","▄","▐","▌"]; var s=""; - for(var i=0;i-0.00005;i-=0.000001) { + for (var i=0;i>-0.00005;i-=0.000001) { car_heading = props.getNode("/orientation/heading-deg",1).getValue(); lat_change = math.sin(D2R*car_heading); lon_change = -math.cos(D2R*car_heading); @@ -47,7 +47,7 @@ var road_check_func = func() { else break; } - for(var i=0;i<0.00005;i+=0.000001) { + for (var i=0;i<0.00005;i+=0.000001) { car_heading = props.getNode("/orientation/heading-deg",1).getValue(); lat_change = math.sin(D2R*car_heading); lon_change = -math.cos(D2R*car_heading); diff --git a/test/bf.nas b/test/bf.nas index 7c4c4bf..c24590d 100644 --- a/test/bf.nas +++ b/test/bf.nas @@ -170,12 +170,12 @@ var (add,mov,jt,jf,in,out)=( var codegen = func(program) { var (code,stack)=([],[]); var len=size(program); - for(var i=0;i') { append(code,mov); append(inum,0); - for(;i') { inum[-1]+=1; } elsif (chr(program[i])=='<') { @@ -239,7 +239,7 @@ var bf = func(program) { # execute setsize(paper,131072); var len=size(code); - for(pc=0;pc') { var cnt=0; - for(;i') { cnt+=1; } elsif (chr(program[i])=='<') { diff --git a/test/bfs.nas b/test/bfs.nas index 294f292..673523a 100644 --- a/test/bfs.nas +++ b/test/bfs.nas @@ -5,17 +5,17 @@ use std.unix; rand(time(0)); var pixel=[' ','#','.','*']; var map=[]; -for(var i=0;i<10;i+=1) { +for (var i=0;i<10;i+=1) { append(map,[]); - for(var j=0;j<20;j+=1) + for (var j=0;j<20;j+=1) append(map[i],(rand()>0.7)); } var prt = func() { var s="\e[0;0H+--------------------+\n"; - for(var i=0;i<10;i+=1) { + for (var i=0;i<10;i+=1) { s~="|"; - for(var j=0;j<20;j+=1) + for (var j=0;j<20;j+=1) s~=pixel[map[i][j]]; s~='|\n'; } diff --git a/test/bigloop.nas b/test/bigloop.nas index 0747cff..6b2667c 100644 --- a/test/bigloop.nas +++ b/test/bigloop.nas @@ -1 +1 @@ -for(var i=0;i<4e6;i+=1); +for (var i=0;i<4e6;i+=1); diff --git a/test/bp.nas b/test/bp.nas index 5611faa..e606b87 100644 --- a/test/bp.nas +++ b/test/bp.nas @@ -34,32 +34,32 @@ var training_set=[[0,0],[0,1],[1,0],[1,1]]; var expect=[0,1,1,0]; var hidden=[]; -for(var i=0;i0.5?-2*rand():2*rand()); hidden[i].bia=rand()>0.5?-5*rand():5*rand(); } var output=[]; -for(var i=0;i0.5?-2*rand():2*rand()); output[i].bia=rand()>0.5?-5*rand():5*rand(); } var forward = func(x) { var input=training_set[x]; - for(var i=0;i0.0005) { error=0; - for(var i=0;i<4;i+=1) { + for (var i=0;i<4;i+=1) { forward(i); error+=get_error(i); backward(i); diff --git a/test/burningship.nas b/test/burningship.nas index 277396c..7551958 100644 --- a/test/burningship.nas +++ b/test/burningship.nas @@ -8,8 +8,8 @@ var ppm = func(filename, width, height, RGB) { # P6 use binary character var fd = io.open(filename, "wb"); io.write(fd, "P6\n"~width~" "~height~"\n255\n"); - for(var i = 0; i=0;i-=1) { + for (var i=s-1;i>=0;i-=1) { var r=int(rand()*i); (vec[r],vec[i])=(vec[i],vec[r]); } @@ -21,7 +21,7 @@ var project = func(n) { var last_step=0; ts.stamp(); - for(var i=0;i1/500) { @@ -58,7 +58,7 @@ var select = func(n) { var last_step=0; ts.stamp(); - for(var i=0;i0;iter-=1) { + for (var (prev,iter)=(elem[2],size(total)-1);iter>0;iter-=1) { var t=total[iter-1][prev]; append(path,t); prev=t[2]; } if (show_table) { - for(var t=size(path)-1;t>=0;t-=1) + for (var t=size(path)-1;t>=0;t-=1) print("("~path[t][1]~","~path[t][0]~")",t==0?"":"->"); println(); } # reverse path - for(var t=0;t=127)?".":chr(s[i]); } else { - for(var i=index-cnt;i=0;i-=1) + for (var i=3;i>=0;i-=1) info~=hex[hex_index[i]]; return info~" "; } @@ -81,7 +81,7 @@ func() { return; } var info=indexprint(0); - for(var i=0;i4) { diff --git a/test/langtons-ant.nas b/test/langtons-ant.nas index adb5322..fe58ac8 100644 --- a/test/langtons-ant.nas +++ b/test/langtons-ant.nas @@ -39,8 +39,8 @@ foreach(var a; ants) { var print_map = func { var pics = [" ", "[]"]; var res = "\e[1;1H"; - for(var y = 0; y<30; y += 1) { - for(var x = 0; x<60; x += 1) { + for (var y = 0; y<30; y += 1) { + for (var x = 0; x<60; x += 1) { res ~= "\e[38;5;"~map_color[x + y*60]~";1m"; res ~= pics[map[x + y*60]] ~ "\e[0m"; } diff --git a/test/life.nas b/test/life.nas index 18e0b25..569c791 100644 --- a/test/life.nas +++ b/test/life.nas @@ -45,10 +45,10 @@ var run = func(width,height) { forindex(var j;map[i]) map[i][j]=rand()<0.45?'O':'.'; - for(var r=0;r<100;r+=1) { + for (var r=0;r<100;r+=1) { prt(map); - for(var i=0;i4) { diff --git a/test/mcpu.nas b/test/mcpu.nas index 859ad6f..b54fd14 100644 --- a/test/mcpu.nas +++ b/test/mcpu.nas @@ -58,11 +58,11 @@ var mem_size=1024*1024*4; # memory size, byte var init = func() { println("[",os.time(),"] init ",reg_size," registers."); setsize(reg,reg_size); # 8 bit address wire - for(var i=0;i0;i-=1) { + for (var i=4;i>0;i-=1) { res[s_size-4-i]=floor(lower32-floor(lower32/256)*256); lower32=floor(lower32/256); } - for(var i=4;i>0;i-=1) { + for (var i=4;i>0;i-=1) { res[s_size-i]=floor(higher32-floor(higher32/256)*256); higher32=floor(higher32/256); } @@ -149,7 +149,7 @@ var md5 = func() { # this may only work when string's length is under 1<<51 var tmp=[]; setsize(tmp,size(res)/4); - for(var i=0;i0.5?-1:1); statistics[int(size(statistics)/2+u*size(statistics)/2)]+=1; @@ -85,7 +85,7 @@ var random_generator = func() { foreach(var st; statistics) { var max_rate=100/size(statistics); var rate=st/total*100; - for(var i=size(s)-1;i>=0;i-=1) { + for (var i=size(s)-1;i>=0;i-=1) { if (rate>=max_rate) { s[i]~="█"; rate-=max_rate; @@ -96,7 +96,7 @@ var random_generator = func() { } } var tmp=""; - for(var i=0;i90?"\e[91m":"\e[32m",bar.bar(cpu_occ/100)~" ",cpu_occ,"\e[0m "); var tmp=""; - for(var i=0;i<70;i+=1) { + for (var i=0;i<70;i+=1) { tmp~="─"; } @@ -171,7 +171,7 @@ func() { foreach(var occ;cpu_occupation_log) { var max_rate=50/size(s); var rate=occ; - for(var i=size(s)-1;i>=0;i-=1) { + for (var i=size(s)-1;i>=0;i-=1) { if (rate>=max_rate) { s[i]~="█"; rate-=max_rate; @@ -191,7 +191,7 @@ func() { foreach(var occ;mem_occupation_log) { var max_rate=100/size(s); var rate=occ; - for(var i=size(s)-1;i>=0;i-=1) { + for (var i=size(s)-1;i>=0;i-=1) { if (rate>=max_rate) { s[i]~="█"; rate-=max_rate; diff --git a/test/pi.nas b/test/pi.nas index 9cbc750..c7bd03b 100644 --- a/test/pi.nas +++ b/test/pi.nas @@ -1,5 +1,5 @@ var (t,res)=(1,0); -for(var m=1;m<4e6;m+=2) +for (var m=1;m<4e6;m+=2) { res+=t/m; t=-t; diff --git a/test/prime.nas b/test/prime.nas index 063baec..4ecf9b2 100644 --- a/test/prime.nas +++ b/test/prime.nas @@ -1,14 +1,14 @@ use std.math; var is_prime = func(x) { - for(var i=2;i=i) { - for(var j=i+1;j<=math.sqrt(x);j+=1) + for (var j=i+1;j<=math.sqrt(x);j+=1) if (x/j==int(x/j)) return 0; append(primes,x); @@ -33,7 +33,7 @@ var filter = func(x) { func() { var cnt=0; - for(var i=2;i<50000;i+=1) + for (var i=2;i<50000;i+=1) if (filter(i)) cnt+=1; println(cnt); diff --git a/test/qrcode.nas b/test/qrcode.nas index 8b72019..f1e4fee 100644 --- a/test/qrcode.nas +++ b/test/qrcode.nas @@ -35,8 +35,8 @@ var code=[ # enable unicode runtime.windows.set_utf8_output(); var texture=[" ","██"]; -for(var i=0;i= `A` and mutable[i] <= `Z`) { mutable[i] += (`a` - `A`); } @@ -257,7 +257,7 @@ print(joined_list, "\n"); # var invert = func(vec) { var hash = {}; - for(var i=0; i 0) { result = result ~ dump(o[0]); } - for(i=1; i a^b&c = 0x",h[a^b&c]," (a^b)&c = 0x",h[(a^b)&c]," a^(b&c) = 0x",h[(a^(b&c))]); } } } } -for(var a=0;a<16;a+=1) { - for(var b=0;b<16;b+=1) { +for (var a=0;a<16;a+=1) { + for (var b=0;b<16;b+=1) { var temp=b; println("temp^=0x"~h[a]~" -> 0x",h[temp^=a]," temp&=0x"~h[a]~" -> 0x",h[temp&=a]," temp|=0x"~h[a]~" -> 0x",h[temp|=a]); } @@ -261,7 +261,7 @@ var closure_tester = func() { ]; }(); -for(var i = 1; i<=10; i += 1) { +for (var i = 1; i<=10; i += 1) { closure_tester[0](); if (closure_tester[1]()!=i) { die("test failed: expect " ~ i ~ ", but get " ~ closure_tester[1]()); diff --git a/test/snake.nas b/test/snake.nas index 303c8f3..225bf4e 100644 --- a/test/snake.nas +++ b/test/snake.nas @@ -9,7 +9,7 @@ var game = func(x,y) { var texture=[" ","██","\e[91m██\e[0m"]; var edge0="╔"; var edge1="╚"; - for(var i=0;i=0;i-=1) { + for (var i=6;i>=0;i-=1) { var index=int(i*rand()); (package[i],package[index])=(package[index],package[i]); } @@ -105,16 +105,16 @@ var mapgen = func(mapx,mapy) { # use in print var line=""; - for(var i=0;i=0;y-=1) { + for (var y=mapy-1;y>=0;y-=1) { # check if this line is full of blocks var tmp=0; - for(var x=0;x=1;t-=1) - for(var x=0;x=1;t-=1) + for (var x=0;x0.5) { vec[1][j]=table[-1]; continue; @@ -57,9 +57,9 @@ var map = func() { new:func(_x=10) { x=_x; vec=[[],[]]; - for(var i=0;i<2;i+=1) { + for (var i=0;i<2;i+=1) { setsize(vec[i],x); - for(var j=0;j