From af3d93ab640e2bb0318227d7db0cb538c73448f1 Mon Sep 17 00:00:00 2001 From: ValKmjolnir Date: Mon, 2 Jun 2025 13:43:00 +0800 Subject: [PATCH] :art: format --- doc/dev.md | 30 ++++++------- doc/dev_zh.md | 32 ++++++------- doc/tutorial.md | 8 ++-- doc/tutorial_zh.md | 8 ++-- src/nasal_ast.cpp | 2 +- src/nasal_codegen.cpp | 2 +- src/nasal_dbg.cpp | 6 +-- src/nasal_err.cpp | 2 +- src/nasal_err.h | 2 +- src/nasal_gc.cpp | 4 +- src/nasal_import.cpp | 2 +- src/nasal_lexer.cpp | 24 +++++----- src/nasal_parse.cpp | 52 +++++++++++----------- src/nasal_vm.cpp | 2 +- src/natives/builtin.cpp | 4 +- src/natives/dylib_lib.cpp | 2 +- src/natives/io_lib.cpp | 2 +- src/natives/json_lib.cpp | 12 ++--- src/repl/repl.cpp | 4 +- src/util/util.cpp | 8 ++-- std/fg_env.nas | 10 ++--- std/file.nas | 6 +-- std/lib.nas | 6 +-- std/mat.nas | 2 +- std/phi.nas | 4 +- std/process_bar.nas | 4 +- std/udp.nas | 4 +- test/bfconvertor.nas | 2 +- test/bfs.nas | 2 +- test/bp.nas | 2 +- test/coroutine.nas | 4 +- test/datalog.nas | 2 +- test/diff.nas | 2 +- test/filesystem.nas | 2 +- test/flush_screen.nas | 2 +- test/for_subprocess_test/infinite_loop.nas | 2 +- test/httptest.nas | 24 +++++----- test/jsonrpc.nas | 8 ++-- test/langtons-ant.nas | 2 +- test/leetcode1319.nas | 2 +- test/lexer.nas | 18 ++++---- test/loop.nas | 4 +- test/mcpu.nas | 2 +- test/occupation.nas | 8 ++-- test/quick_sort.nas | 6 +-- test/sample.nas | 4 +- test/snake.nas | 10 ++--- test/tetris.nas | 4 +- test/turingmachine.nas | 2 +- test/udptest.nas | 4 +- test/watchdog.nas | 4 +- tools/file2ppm.nas | 2 +- tools/push.nas | 2 +- 53 files changed, 185 insertions(+), 185 deletions(-) diff --git a/doc/dev.md b/doc/dev.md index a475ca5..047b628 100644 --- a/doc/dev.md +++ b/doc/dev.md @@ -40,15 +40,15 @@ These two expressions have the same first set,so `LL(1)` is useless for this lan Problems mentioned above have been solved for a long time, but recently i found a new problem here: ```javascript -var f=func(x,y,z){return x+y+z} -(a,b,c)=(0,1,2); +var f = func(x, y, z) { return x + y + z } +(a, b, c) = (0, 1, 2); ``` This will be recognized as this: ```javascript -var f=func(x,y,z){return x+y+z}(a,b,c) -=(0,1,2); +var f = func(x, y, z) { return x + y + z }(a, b, c) += (0, 1, 2); ``` and causes fatal syntax error. @@ -58,9 +58,9 @@ I think this is a serious design fault. To avoid this syntax error, change program like this, just add a semicolon: ```javascript -var f=func(x,y,z){return x+y+z}; - ^ here -(a,b,c)=(0,1,2); +var f = func(x, y, z) { return x + y + z }; + ^ here +(a, b, c) = (0, 1, 2); ``` ### version 1.0 parser (last update 2019/10/14) @@ -222,8 +222,8 @@ Better use `callfv` instead of `callfh`, making this process slow. ```javascript -var f=func(x,y){return x+y;} -f(1024,2048); +var f = func(x, y) { return x + y; } +f(1024, 2048); ``` ```x86asm @@ -530,12 +530,12 @@ func <0x2a3>: Now we add coroutine in this runtime: ```javascript -var coroutine={ - create: func(function){return __cocreate;}, - resume: func(co) {return __coresume;}, - yield: func(args...) {return __coyield; }, - status: func(co) {return __costatus;}, - running:func() {return __corun; } +var coroutine = { + create: func(function) { return __cocreate; }, + resume: func(co) { return __coresume; }, + yield: func(args...) { return __coyield; }, + status: func(co) { return __costatus; }, + running: func() { return __corun; } }; ``` diff --git a/doc/dev_zh.md b/doc/dev_zh.md index cca9432..44828c9 100644 --- a/doc/dev_zh.md +++ b/doc/dev_zh.md @@ -40,23 +40,23 @@ 上面这个问题已经解决很久了,不过我最近发现了一个新的语法问题: ```javascript -var f=func(x,y,z){return x+y+z} -(a,b,c)=(0,1,2); +var f = func(x, y, z) { return x + y + z } +(a, b, c) = (0, 1, 2); ``` 这种写法会被错误识别合并成下面这种: ```javascript -var f=func(x,y,z){return x+y+z}(a,b,c) -=(0,1,2); +var f = func(x, y, z) { return x + y + z }(a, b, c) += (0, 1, 2); ``` 语法分析器会认为这是个严重的语法错误。我在Flightgear中也测试了这个代码,它内置的语法分析器也认为这是错误语法。当然我认为这是语法设计中的一个比较严重的缺漏。为了避免这个语法问题,只需要添加一个分号就可以了: ```javascript -var f=func(x,y,z){return x+y+z}; - ^ 就是这里 -(a,b,c)=(0,1,2); +var f = func(x, y, z) { return x + y + z }; + ^ 就是这里 +(a, b, c) = (0, 1, 2); ``` ### version 1.0 parser (last update 2019/10/14) @@ -193,15 +193,15 @@ for (var i=0;i<4000000;i+=1); 2021/6/3 update: -修复了垃圾收集器还是他妈的会重复收集的bug,这次我设计了三个标记状态来保证垃圾是被正确收集了。 +修复了垃圾收集器还是会重复收集的bug,这次我设计了三个标记状态来保证垃圾是被正确收集了。 将`callf`指令拆分为`callfv`和`callfh`。并且`callfv`将直接从`val_stack`获取传参,而不是先通过一个`vm_vec`把参数收集起来再传入,后者是非常低效的做法。 建议更多使用`callfv`而不是`callfh`,因为`callfh`只能从栈上获取参数并整合为`vm_hash`之后才能传给该指令进行处理,拖慢执行速度。 ```javascript -var f=func(x,y){return x+y;} -f(1024,2048); +var f = func(x, y) { return x + y; } +f(1024, 2048); ``` ```x86asm @@ -475,12 +475,12 @@ func <0x2a3>: 在这个版本中我们给nasal加入了协程: ```javascript -var coroutine={ - create: func(function){return __cocreate;}, - resume: func(co) {return __coresume;}, - yield: func(args...) {return __coyield; }, - status: func(co) {return __costatus;}, - running:func() {return __corun; } +var coroutine = { + create: func(function) { return __cocreate; }, + resume: func(co) { return __coresume; }, + yield: func(args...) { return __coyield; }, + status: func(co) { return __costatus; }, + running: func() { return __corun; } }; ``` diff --git a/doc/tutorial.md b/doc/tutorial.md index bbcc7cc..709cdee 100644 --- a/doc/tutorial.md +++ b/doc/tutorial.md @@ -67,7 +67,7 @@ __`vec`__ has unlimited length and can store all types of values. ```javascript var vec = []; -var vec = [0, nil, {}, [], func(){return 0}]; +var vec = [0, nil, {}, [], func() { return 0 }]; append(vec, 0, 1, 2); ``` @@ -255,7 +255,7 @@ if (1) { While loop and for loop is simalar to C/C++. ```javascript -while(condition) { +while (condition) { continue; } for (var i = 0; i<10; i += 1) { @@ -327,7 +327,7 @@ var fib = func(f) { }( func(f) { return func(x) { - if(x<2) return x; + if (x<2) return x; return f(f)(x-1)+f(f)(x-2); } } @@ -597,7 +597,7 @@ var fib(var* args, usize size, gc* ngc) { // if you want your function safer, try this // nas_err will print the error info on screen // and return vm_null for runtime to interrupt - if(num.type!=vm_num) { + if (num.type!=vm_num) { return nas_err("extern_fib", "\"num\" must be number"); } // ok, you must know that vm_num now is not managed by gc diff --git a/doc/tutorial_zh.md b/doc/tutorial_zh.md index 525ab89..3099096 100644 --- a/doc/tutorial_zh.md +++ b/doc/tutorial_zh.md @@ -64,7 +64,7 @@ __`vec`__ 有不受限制的长度并且可以存储所有类型的数据。(当 ```javascript var vec = []; -var vec = [0, nil, {}, [], func(){return 0}]; +var vec = [0, nil, {}, [], func() { return 0 }]; append(vec, 0, 1, 2); ``` @@ -247,7 +247,7 @@ if (1) { while循环和for循环大体上与C/C++是一致的。 ```javascript -while(condition) { +while (condition) { continue; } for (var i = 0; i<10; i += 1) { @@ -314,7 +314,7 @@ var fib = func(f) { }( func(f) { return func(x) { - if(x<2) return x; + if (x<2) return x; return f(f)(x-1)+f(f)(x-2); } } @@ -579,7 +579,7 @@ var fib(var* args, usize size, gc* ngc) { var num = args[0]; // 如果你想让这个函数有更强的稳定性,那么一定要进行合法性检查 // nas_err会输出错误信息并返回错误类型让虚拟机终止执行 - if(num.type!=vm_num) { + if (num.type!=vm_num) { return nas_err("extern_fib", "\"num\" must be number"); } // vm_num作为普通的数字类型,不是内存管理的对象,所以无需申请 diff --git a/src/nasal_ast.cpp b/src/nasal_ast.cpp index 18351d2..41954a1 100644 --- a/src/nasal_ast.cpp +++ b/src/nasal_ast.cpp @@ -157,7 +157,7 @@ void unary_operator::accept(ast_visitor* visitor) { } call_expr::~call_expr() { - if(first) { + if (first) { delete first; } for (auto i : calls) { diff --git a/src/nasal_codegen.cpp b/src/nasal_codegen.cpp index 3b50612..3b742c6 100644 --- a/src/nasal_codegen.cpp +++ b/src/nasal_codegen.cpp @@ -291,7 +291,7 @@ void codegen::func_gen(function* node) { // var f = func(a, arg...) {return(arg)} auto arg = std::string("arg"); // this is used to avoid confliction with defined parameter - while(local_symbol_find(arg)>=0) { + while (local_symbol_find(arg)>=0) { arg = "0" + arg; } regist_symbol(arg); diff --git a/src/nasal_dbg.cpp b/src/nasal_dbg.cpp index 6f284e7..56a62ab 100644 --- a/src/nasal_dbg.cpp +++ b/src/nasal_dbg.cpp @@ -95,7 +95,7 @@ void operand_line_counter::dump_this_file_line_counter(std::ostream& os) const { std::vector dbg::parse(const std::string& cmd) { std::vector res; usize last = 0, pos = cmd.find(" ", 0); - while(pos!=std::string::npos) { + while (pos!=std::string::npos) { if (pos>last) { res.push_back(cmd.substr(last, pos-last)); } @@ -202,7 +202,7 @@ void dbg::interact() { next = false; std::string cmd; step_info(); - while(true) { + while (true) { std::clog << ">> "; std::getline(std::cin, cmd); auto res = parse(cmd); @@ -279,7 +279,7 @@ void dbg::run(const codegen& gen, code_line.push_back(i.line); imm.push_back(i.num); } - while(operand_function[code[ctx.pc]]) { + while (operand_function[code[ctx.pc]]) { interact(); counter.add_operand_counter(code[ctx.pc]); counter.add_code_line_counter(code_file_index[ctx.pc], code_line[ctx.pc]); diff --git a/src/nasal_err.cpp b/src/nasal_err.cpp index 401d440..ca8a0ed 100644 --- a/src/nasal_err.cpp +++ b/src/nasal_err.cpp @@ -150,7 +150,7 @@ void filestream::load(const std::string& f) { std::exit(1); } - while(!in.eof()) { + while (!in.eof()) { std::string line; std::getline(in, line); res.push_back(line); diff --git a/src/nasal_err.h b/src/nasal_err.h index 11e27bf..bec17c0 100644 --- a/src/nasal_err.h +++ b/src/nasal_err.h @@ -54,7 +54,7 @@ private: } std::string leftpad(u64 num, usize len) { auto tmp = std::to_string(num); - while(tmp.length()& vec, usize begin, usize end) { } mark_var(bfs, value); } - while(!bfs.empty()) { + while (!bfs.empty()) { var value = bfs.back(); bfs.pop_back(); if (value.type<=vm_type::vm_num || diff --git a/src/nasal_import.cpp b/src/nasal_import.cpp index 8d9e0c0..a3c6228 100644 --- a/src/nasal_import.cpp +++ b/src/nasal_import.cpp @@ -19,7 +19,7 @@ linker::linker(): show_path_flag(false), this_file("") { const auto seperator = util::is_windows()? ';':':'; const auto PATH = std::string(env_get_path); usize last = 0, position = PATH.find(seperator, 0); - while(position!=std::string::npos) { + while (position!=std::string::npos) { std::string dirpath = PATH.substr(last, position-last); if (dirpath.length()) { envpath.push_back(dirpath); diff --git a/src/nasal_lexer.cpp b/src/nasal_lexer.cpp index 6800d37..37e16e3 100644 --- a/src/nasal_lexer.cpp +++ b/src/nasal_lexer.cpp @@ -59,7 +59,7 @@ bool lexer::is_calc_opr(char c) { void lexer::skip_note() { // avoid note, after this process ptr will point to '\n' // so next loop line counter+1 - while(++ptr [0~9][0~9]*(.[0~9]*)(e|E(+|-)0|[1~9][0~9]*) std::string str = ""; - while(ptradd_expression(expression()); if (lookahead(tok::tk_semi)) { match(tok::tk_semi); @@ -114,7 +114,7 @@ bool parse::check_comma(const tok* panic_set) { bool parse::check_tuple() { u64 check_ptr = ptr, curve = 1, bracket = 0, brace = 0; - while(toks[++check_ptr].type!=tok::tk_eof && curve) { + while (toks[++check_ptr].type!=tok::tk_eof && curve) { switch(toks[check_ptr].type) { case tok::tk_lcurve: ++curve; break; case tok::tk_lbracket: ++bracket; break; @@ -167,7 +167,7 @@ bool parse::check_in_curve_multi_definition() { bool parse::check_special_call() { // special call means like this: function_name(a:1, b:2, c:3); u64 check_ptr = ptr, curve = 1, bracket = 0, brace = 0; - while(toks[++check_ptr].type!=tok::tk_eof && curve) { + while (toks[++check_ptr].type!=tok::tk_eof && curve) { switch(toks[check_ptr].type) { case tok::tk_lcurve: ++curve; break; case tok::tk_lbracket: ++bracket;break; @@ -216,7 +216,7 @@ use_stmt* parse::use_stmt_gen() { auto node = new use_stmt(toks[ptr].loc); match(tok::tk_use); node->add_path(id()); - while(lookahead(tok::tk_dot)) { + while (lookahead(tok::tk_dot)) { match(tok::tk_dot); node->add_path(id()); } @@ -276,7 +276,7 @@ vector_expr* parse::vec() { }; auto node = new vector_expr(toks[ptr].loc); match(tok::tk_lbracket); - while(!lookahead(tok::tk_rbracket)) { + while (!lookahead(tok::tk_rbracket)) { node->add_element(calc()); if (lookahead(tok::tk_comma)) { match(tok::tk_comma); @@ -294,7 +294,7 @@ vector_expr* parse::vec() { hash_expr* parse::hash() { auto node = new hash_expr(toks[ptr].loc); match(tok::tk_lbrace); - while(!lookahead(tok::tk_rbrace)) { + while (!lookahead(tok::tk_rbrace)) { node->add_member(pair()); if (lookahead(tok::tk_comma)) { match(tok::tk_comma); @@ -342,7 +342,7 @@ function* parse::func() { void parse::params(function* func_node) { match(tok::tk_lcurve); - while(!lookahead(tok::tk_rcurve)) { + while (!lookahead(tok::tk_rcurve)) { auto param = new parameter(toks[ptr].loc); param->set_parameter_name(toks[ptr].str); match(tok::tk_id); @@ -428,7 +428,7 @@ code_block* parse::expression_block() { auto node = new code_block(toks[ptr].loc); if (lookahead(tok::tk_lbrace)) { match(tok::tk_lbrace); - while(!lookahead(tok::tk_rbrace) && !lookahead(tok::tk_eof)) { + while (!lookahead(tok::tk_rbrace) && !lookahead(tok::tk_eof)) { node->add_expression(expression()); if (lookahead(tok::tk_semi)) { match(tok::tk_semi); @@ -496,7 +496,7 @@ expr* parse::calc() { expr* parse::bitwise_or() { auto node = bitwise_xor(); - while(lookahead(tok::tk_btor)) { + while (lookahead(tok::tk_btor)) { auto tmp = new binary_operator(toks[ptr].loc); tmp->set_operator_type(binary_operator::kind::bitwise_or); tmp->set_left(node); @@ -511,7 +511,7 @@ expr* parse::bitwise_or() { expr* parse::bitwise_xor() { auto node = bitwise_and(); - while(lookahead(tok::tk_btxor)) { + while (lookahead(tok::tk_btxor)) { auto tmp = new binary_operator(toks[ptr].loc); tmp->set_operator_type(binary_operator::kind::bitwise_xor); tmp->set_left(node); @@ -526,7 +526,7 @@ expr* parse::bitwise_xor() { expr* parse::bitwise_and() { auto node = or_expr(); - while(lookahead(tok::tk_btand)) { + while (lookahead(tok::tk_btand)) { auto tmp = new binary_operator(toks[ptr].loc); tmp->set_operator_type(binary_operator::kind::bitwise_and); tmp->set_left(node); @@ -541,7 +541,7 @@ expr* parse::bitwise_and() { expr* parse::or_expr() { auto node = and_expr(); - while(lookahead(tok::tk_or)) { + while (lookahead(tok::tk_or)) { auto tmp = new binary_operator(toks[ptr].loc); tmp->set_operator_type(binary_operator::kind::condition_or); tmp->set_left(node); @@ -556,7 +556,7 @@ expr* parse::or_expr() { expr* parse::and_expr() { auto node = cmp_expr(); - while(lookahead(tok::tk_and)) { + while (lookahead(tok::tk_and)) { auto tmp = new binary_operator(toks[ptr].loc); tmp->set_operator_type(binary_operator::kind::condition_and); tmp->set_left(node); @@ -571,7 +571,7 @@ expr* parse::and_expr() { expr* parse::cmp_expr() { auto node = null_chain_expr(); - while(tok::tk_cmpeq<=toks[ptr].type && toks[ptr].type<=tok::tk_geq) { + while (tok::tk_cmpeq<=toks[ptr].type && toks[ptr].type<=tok::tk_geq) { auto tmp = new binary_operator(toks[ptr].loc); switch(toks[ptr].type) { case tok::tk_cmpeq: tmp->set_operator_type(binary_operator::kind::cmpeq); break; @@ -594,7 +594,7 @@ expr* parse::cmp_expr() { expr* parse::null_chain_expr() { auto node = additive_expr(); - while(lookahead(tok::tk_quesques)) { + while (lookahead(tok::tk_quesques)) { auto tmp = new binary_operator(toks[ptr].loc); tmp->set_operator_type(binary_operator::kind::null_chain); tmp->set_left(node); @@ -609,7 +609,7 @@ expr* parse::null_chain_expr() { expr* parse::additive_expr() { auto node = multive_expr(); - while(lookahead(tok::tk_add) || + while (lookahead(tok::tk_add) || lookahead(tok::tk_sub) || lookahead(tok::tk_floater)) { auto tmp = new binary_operator(toks[ptr].loc); @@ -633,7 +633,7 @@ expr* parse::multive_expr() { expr* node=(lookahead(tok::tk_sub) || lookahead(tok::tk_not) || lookahead(tok::tk_floater))? unary():scalar(); - while(lookahead(tok::tk_mult) || lookahead(tok::tk_div)) { + while (lookahead(tok::tk_mult) || lookahead(tok::tk_div)) { auto tmp = new binary_operator(toks[ptr].loc); if (lookahead(tok::tk_mult)) { tmp->set_operator_type(binary_operator::kind::mult); @@ -718,14 +718,14 @@ expr* parse::scalar() { return null(); } // check call and avoid ambiguous syntax: - // var f = func(){} + // var f = func() {} // (var a, b, c) = (1, 2, 3); // will be incorrectly recognized like: - // var f = func(){}(var a, b, c) + // var f = func() {}(var a, b, c) if (is_call(toks[ptr].type) && !check_in_curve_multi_definition()) { auto call_node = new call_expr(toks[ptr].loc); call_node->set_first(node); - while(is_call(toks[ptr].type)) { + while (is_call(toks[ptr].type)) { call_node->add_call(call_scalar()); } node = call_node; @@ -776,7 +776,7 @@ call_vector* parse::callv() { }; auto node = new call_vector(toks[ptr].loc); match(tok::tk_lbracket); - while(!lookahead(tok::tk_rbracket)) { + while (!lookahead(tok::tk_rbracket)) { node->add_slice(subvec()); if (lookahead(tok::tk_comma)) { match(tok::tk_comma); @@ -807,7 +807,7 @@ call_function* parse::callf() { auto node = new call_function(toks[ptr].loc); bool special_call=check_special_call(); match(tok::tk_lcurve); - while(!lookahead(tok::tk_rcurve)) { + while (!lookahead(tok::tk_rcurve)) { node->add_argument(special_call?pair():calc()); if (lookahead(tok::tk_comma)) match(tok::tk_comma); @@ -883,7 +883,7 @@ multi_identifier* parse::outcurve_def() { multi_identifier* parse::multi_id() { auto node = new multi_identifier(toks[ptr].loc); - while(!lookahead(tok::tk_eof)) { + while (!lookahead(tok::tk_eof)) { // only identifier is allowed here node->add_var(id()); if (lookahead(tok::tk_comma)) { @@ -909,7 +909,7 @@ tuple_expr* parse::multi_scalar() { }; auto node = new tuple_expr(toks[ptr].loc); match(tok::tk_lcurve); - while(!lookahead(tok::tk_rcurve)) { + while (!lookahead(tok::tk_rcurve)) { node->add_element(calc()); if (lookahead(tok::tk_comma)) { match(tok::tk_comma); @@ -1068,7 +1068,7 @@ iter_expr* parse::iter_gen() { // call expression auto tmp = new call_expr(id_node->get_location()); tmp->set_first(id_node); - while(is_call(toks[ptr].type)) { + while (is_call(toks[ptr].type)) { tmp->add_call(call_scalar()); } node->set_call(tmp); @@ -1090,7 +1090,7 @@ condition_expr* parse::cond() { node->set_if_statement(ifnode); // generate elsif - while(lookahead(tok::tk_elsif)) { + while (lookahead(tok::tk_elsif)) { auto elsifnode = new if_expr(toks[ptr].loc); match(tok::tk_elsif); match(tok::tk_lcurve); diff --git a/src/nasal_vm.cpp b/src/nasal_vm.cpp index de07bb4..746a89d 100644 --- a/src/nasal_vm.cpp +++ b/src/nasal_vm.cpp @@ -709,7 +709,7 @@ void vm::run(const codegen& gen, code.push_back(operand_function[i.op]); imm.push_back(i.num); } - while(code[ctx.pc]) { + while (code[ctx.pc]) { if (interrupt_ptr && interrupt_ptr->load()) { throw std::runtime_error("VM execution interrupted by timeout"); } diff --git a/src/natives/builtin.cpp b/src/natives/builtin.cpp index 1f4416f..45b079f 100644 --- a/src/natives/builtin.cpp +++ b/src/natives/builtin.cpp @@ -121,7 +121,7 @@ var builtin_split(context* ctx, gc* ngc) { usize last = 0; usize pos = s.find(sep, 0); - while(pos!=std::string::npos) { + while (pos!=std::string::npos) { if (pos>last) { vec.push_back(ngc->newstr(s.substr(last, pos-last))); } @@ -169,7 +169,7 @@ var builtin_split_with_empty_substr(context* ctx, gc* ngc) { usize last = 0; usize pos = s.find(sep, 0); - while(pos!=std::string::npos) { + while (pos!=std::string::npos) { if (pos>=last) { vec.push_back(ngc->newstr(s.substr(last, pos-last))); } diff --git a/src/natives/dylib_lib.cpp b/src/natives/dylib_lib.cpp index cb7dd10..ecf64b4 100644 --- a/src/natives/dylib_lib.cpp +++ b/src/natives/dylib_lib.cpp @@ -27,7 +27,7 @@ std::vector possible_dylib_path() { std::vector env_path_vec = {"."}; usize last = 0; usize pos = env_path.find(sep, 0); - while(pos != std::string::npos) { + while (pos != std::string::npos) { if (pos > last) { env_path_vec.push_back(env_path.substr(last, pos - last)); } diff --git a/src/natives/io_lib.cpp b/src/natives/io_lib.cpp index 8723a06..b012288 100644 --- a/src/natives/io_lib.cpp +++ b/src/natives/io_lib.cpp @@ -158,7 +158,7 @@ var builtin_readln(context* ctx, gc* ngc) { } auto result = ngc->alloc(vm_type::vm_str); char c; - while((c = fgetc(file_descriptor.ghost().get()))!=EOF) { + while ((c = fgetc(file_descriptor.ghost().get()))!=EOF) { if (c=='\r') { continue; } diff --git a/src/natives/json_lib.cpp b/src/natives/json_lib.cpp index dc79f6c..2fdab27 100644 --- a/src/natives/json_lib.cpp +++ b/src/natives/json_lib.cpp @@ -165,7 +165,7 @@ std::string json::stringify(var& object) { } void json::next() { - while(ptr& src) { } bool repl::check_need_more_input() { - while(true) { + while (true) { update_temp_file(); auto nasal_lexer = std::make_unique(); if (nasal_lexer->scan("").geterr()) { @@ -160,7 +160,7 @@ void repl::execute() { std::cout << " (" << __DATE__ << " " << __TIME__ << ")\n"; help(); - while(true) { + while (true) { auto line = readline(); if (!line.length()) { continue; diff --git a/src/util/util.cpp b/src/util/util.cpp index 6f8a4bd..ce4a0ca 100644 --- a/src/util/util.cpp +++ b/src/util/util.cpp @@ -188,7 +188,7 @@ f64 hex_to_f64(const char* str) { f64 oct_to_f64(const char* str) { f64 ret = 0; - while('0'<=*str && *str<'8') { + while ('0'<=*str && *str<'8') { ret = ret*8+(*str++-'0'); } if (*str) { @@ -206,7 +206,7 @@ f64 oct_to_f64(const char* str) { f64 dec_to_f64(const char* str) { f64 ret = 0, num_pow = 0; bool negative = false; - while('0'<=*str && *str<='9') { + while ('0'<=*str && *str<='9') { ret = ret*10+(*str++-'0'); } if (!*str) { @@ -217,7 +217,7 @@ f64 dec_to_f64(const char* str) { return nan(""); } num_pow = 0.1; - while('0'<=*str && *str<='9') { + while ('0'<=*str && *str<='9') { ret += num_pow*(*str++-'0'); num_pow *= 0.1; } @@ -238,7 +238,7 @@ f64 dec_to_f64(const char* str) { return nan(""); } num_pow = 0; - while('0'<=*str && *str<='9') { + while ('0'<=*str && *str<='9') { num_pow = num_pow*10+(*str++-'0'); } if (*str) { diff --git a/std/fg_env.nas b/std/fg_env.nas index 35ef603..7f518e3 100644 --- a/std/fg_env.nas +++ b/std/fg_env.nas @@ -63,7 +63,7 @@ var add_event = func(name,interval,function) { fg_globals.event[name]=coroutine.create(func { var timestamp=maketimestamp(); timestamp.stamp(); - while(timestamp.elapsedMSec()0.001) { + while (total>0.001) { epoch+=1; if (epoch>1e4) { println("Training failed after ",epoch," epoch."); diff --git a/std/phi.nas b/std/phi.nas index 8d7ca39..cf41ef4 100644 --- a/std/phi.nas +++ b/std/phi.nas @@ -37,7 +37,7 @@ var _connect = func(hostname, port) { socket.IPPROTO_TCP ); var ip_info = hostname~":"~port; - while((var err = socket.connect(sd, hostname, port))==socket.SOCKET_ERROR) { + while ((var err = socket.connect(sd, hostname, port))==socket.SOCKET_ERROR) { println(_get_time(), " failed to connect ", ip_info, ": ", socket.errno()); unix.sleep(1); } @@ -67,7 +67,7 @@ var new = func(hostname, port) { # get total message var total_source = message.str; # 0\r\n\r\n is the tail of chunked http info - while(find("0\r\n\r\n", total_source)<0) { + while (find("0\r\n\r\n", total_source)<0) { message = socket.recv(sd, 1024); total_source ~= message.str; } diff --git a/std/process_bar.nas b/std/process_bar.nas index 3b40bb9..71bac7d 100644 --- a/std/process_bar.nas +++ b/std/process_bar.nas @@ -112,11 +112,11 @@ var spinner = func() { for (var i=0;i 0 and size(hostname) != 0) { - while(socket.bind(client, hostname, port)<0) { + while (socket.bind(client, hostname, port)<0) { println("[",os.time(),"] failed to bind socket "~client~" at ", hostname, ":", port, "."); unix.sleep(retry_delay); println("[",os.time(),"] retrying..."); diff --git a/test/bfconvertor.nas b/test/bfconvertor.nas index 2e4232c..34a556c 100644 --- a/test/bfconvertor.nas +++ b/test/bfconvertor.nas @@ -209,7 +209,7 @@ var bf = func(program) { f~="print(chr(paper[ptr]));\n"; } elsif (c=='[') { f~=padding(size(stack)); - f~="while(paper[ptr]) {\n"; + f~="while (paper[ptr]) {\n"; append(stack,0); } elsif (c==']') { if (!size(stack)) { diff --git a/test/bfs.nas b/test/bfs.nas index 673523a..b13cece 100644 --- a/test/bfs.nas +++ b/test/bfs.nas @@ -32,7 +32,7 @@ var bfs = func(begin,end) { map[end[0]][end[1]]=0; if (map[1][0]==1 and map[0][1]==1) map[1][0]=0; - while(!que.empty()) { + while (!que.empty()) { var vertex=que.front(); que.pop(); foreach(var i;move) { diff --git a/test/bp.nas b/test/bp.nas index e606b87..8ece24d 100644 --- a/test/bp.nas +++ b/test/bp.nas @@ -107,7 +107,7 @@ var backward = func(x) { } var (cnt,error)=(0,100); -while(error>0.0005) { +while (error>0.0005) { error=0; for (var i=0;i<4;i+=1) { forward(i); diff --git a/test/coroutine.nas b/test/coroutine.nas index fdb352a..9934a8c 100644 --- a/test/coroutine.nas +++ b/test/coroutine.nas @@ -15,7 +15,7 @@ var fib = func() { var (a, b) = (1, 1); coroutine.yield(a); coroutine.yield(b); - while(1) { + while (1) { (a, b) = (b, a + b); coroutine.yield(b); } @@ -95,7 +95,7 @@ println("[2] ok\n"); # pressure test for (var t = 0; t < 10; t += 1) { var productor = func() { - while(1) { + while (1) { coroutine.yield(i); } } diff --git a/test/datalog.nas b/test/datalog.nas index 1594cb1..2434ded 100644 --- a/test/datalog.nas +++ b/test/datalog.nas @@ -83,7 +83,7 @@ var select = func(n) { var left=0; var right=size(message)-1; var data=c[2]; - while(left<=right) { + while (left<=right) { var mid=int((left+right)/2); var res=message[mid][0]; if (data==res) { diff --git a/test/diff.nas b/test/diff.nas index 88eaf74..9fe9d10 100644 --- a/test/diff.nas +++ b/test/diff.nas @@ -42,7 +42,7 @@ var myers = func(src,dst,show_table=0) { var (total,path,vec)=([],[],[[0,0,-1]]); visited[0]=1; - while(size(vec)) { + while (size(vec)) { append(total,vec); var tmp=[]; forindex(var i;vec) { diff --git a/test/filesystem.nas b/test/filesystem.nas index 515b48f..fa28268 100644 --- a/test/filesystem.nas +++ b/test/filesystem.nas @@ -7,7 +7,7 @@ var files = func(path) { return []; var dd=unix.opendir(path); var res=[]; - while(var n=unix.readdir(dd)) + while (var n=unix.readdir(dd)) append(res,n); unix.closedir(dd); return res; diff --git a/test/flush_screen.nas b/test/flush_screen.nas index 780d34a..bfb8c32 100644 --- a/test/flush_screen.nas +++ b/test/flush_screen.nas @@ -10,7 +10,7 @@ var chars = "abcdefghijklmnopqrstuvwxyz" ~ chars = split("", chars); print("\ec"); -while(1) { +while (1) { var key = libkey.nonblock(); if (key!=nil and chr(key)=="q") { break; diff --git a/test/for_subprocess_test/infinite_loop.nas b/test/for_subprocess_test/infinite_loop.nas index bfba824..d4c35ba 100644 --- a/test/for_subprocess_test/infinite_loop.nas +++ b/test/for_subprocess_test/infinite_loop.nas @@ -1,7 +1,7 @@ use std.unix; var count = 0; -while(1) { +while (1) { unix.sleep(0.1); count += 0.1; println("process running time: ", count); diff --git a/test/httptest.nas b/test/httptest.nas index 27fdf24..9e59fca 100644 --- a/test/httptest.nas +++ b/test/httptest.nas @@ -10,7 +10,7 @@ var http = func() { return { establish:func(ip,port) { sd=socket.socket(socket.AF_INET,socket.SOCK_STREAM,socket.IPPROTO_IP); - while(socket.bind(sd,ip,port)<0) { + while (socket.bind(sd,ip,port)<0) { println("[",os.time(),"] failed to bind socket "~sd~" at IP: "~ip~" port: "~port~"."); unix.sleep(5); println("[",os.time(),"] retrying..."); @@ -98,7 +98,7 @@ var html_read_file = func(filename) { s=char(file_text[index]); } - while(1) { + while (1) { if (next()>=len) break; if (s==">") @@ -111,7 +111,7 @@ var html_read_file = func(filename) { content~=""~s~""; elsif (s=="_" or ("a"[0]<=s[0] and s[0]<="z"[0]) or ("A"[0]<=s[0] and s[0]<="Z"[0]) or s[0]<0 or s[0]>=128) { var tmp=""~s; # generate a new string - while(1) { + while (1) { if (next()>=len) break; if (s=="_" or ("a"[0]<=s[0] and s[0]<="z"[0]) or ("A"[0]<=s[0] and s[0]<="Z"[0]) or ("0"[0]<=s[0] and s[0]<="9"[0]) or s[0]<0 or s[0]>=128) @@ -138,7 +138,7 @@ var html_read_file = func(filename) { } if (s=="o") { content~="o"; - while(1) { + while (1) { if (next()>=len) break; if ("0"[0]<=s[0] and s[0]<="7"[0]) @@ -150,7 +150,7 @@ var html_read_file = func(filename) { prev(); } elsif (s=="x") { content~="x"; - while(1) { + while (1) { if (next()>=len) break; if (("0"[0]<=s[0] and s[0]<="9"[0]) or ("a"[0]<=s[0] and s[0]<='f') or ("A"[0]<=s[0] or s[0]<="F")) @@ -161,7 +161,7 @@ var html_read_file = func(filename) { content~=""; prev(); } elsif (("0"[0]<=s[0] and s[0]<="9"[0]) or s=="." or s=="e") { - while("0"[0]<=s[0] and s[0]<="9"[0]) { + while ("0"[0]<=s[0] and s[0]<="9"[0]) { content~=s; if (next()>=len) break; @@ -171,7 +171,7 @@ var html_read_file = func(filename) { if (next()>=len) break; } - while("0"[0]<=s[0] and s[0]<="9"[0]) { + while ("0"[0]<=s[0] and s[0]<="9"[0]) { content~=s; if (next()>=len) break; @@ -186,7 +186,7 @@ var html_read_file = func(filename) { break; } } - while("0"[0]<=s[0] and s[0]<="9"[0]) { + while ("0"[0]<=s[0] and s[0]<="9"[0]) { content~=s; if (next()>=len) break; @@ -200,7 +200,7 @@ var html_read_file = func(filename) { } elsif (s=="\"" or s=="'" or s=="`") { var quot=s~""; # generate a new string content~=""~s; - while(1) { + while (1) { if (next()>=len) break; if (s==quot) { @@ -221,7 +221,7 @@ var html_read_file = func(filename) { } } elsif (s=="#") { content~=""~s; - while(1) { + while (1) { if (next()>=len) break; if (s=="\n" or s=="\r") { @@ -282,12 +282,12 @@ var respond={ var files = func() { var res={}; var dd=unix.opendir("./test"); - while((var name=unix.readdir(dd))!=nil) + while ((var name=unix.readdir(dd))!=nil) res[name]=1; return res; }(); -while(1) { +while (1) { var client=http.accept(); var data=http.recv(client); if (data==nil) { diff --git a/test/jsonrpc.nas b/test/jsonrpc.nas index e51e38d..7073d5b 100644 --- a/test/jsonrpc.nas +++ b/test/jsonrpc.nas @@ -25,7 +25,7 @@ var jsonRPC = func() { }, connect:func(ip,port) { sd=socket.socket(socket.AF_INET,socket.SOCK_STREAM,socket.IPPROTO_IP); - while(socket.connect(sd,ip,port)<0) { + while (socket.connect(sd,ip,port)<0) { println("[",gettime(),"] failed to connect socket ",sd," to ",ip,":",port); unix.sleep(5); } @@ -75,9 +75,9 @@ var server = func(ip,port) { }; jsonRPC.establish(ip,port); - while(1) { + while (1) { var client=jsonRPC.accept(); - while(1) { + while (1) { var data=jsonRPC.recv(client); if (data!=nil) { data=json.parse(data); @@ -112,7 +112,7 @@ var client = func(ip,port) { var params=[["a","b"],["1","2"]]; var server=jsonRPC.connect(ip,port); - while(1) { + while (1) { unix.sleep(5); var data=json.stringify({jsonrpc:2.0, id:call_id, method:methods[rand()*size(methods)],params:params[rand()*size(params)]}); jsonRPC.send(server, data); diff --git a/test/langtons-ant.nas b/test/langtons-ant.nas index fe58ac8..4ba1ac6 100644 --- a/test/langtons-ant.nas +++ b/test/langtons-ant.nas @@ -91,7 +91,7 @@ var move = func { map = temp_map; } -while(1) { +while (1) { print_map(); move(); unix.sleep(1/24); diff --git a/test/leetcode1319.nas b/test/leetcode1319.nas index 2ae7b5f..6cf331d 100644 --- a/test/leetcode1319.nas +++ b/test/leetcode1319.nas @@ -3,7 +3,7 @@ var n=4; var input=[[0,1],[0,2],[1,2]]; var find_root = func(x,parent) { - while(parent[x]!=nil) + while (parent[x]!=nil) x=parent[x]; return x; } diff --git a/test/lexer.nas b/test/lexer.nas index 211ed04..06e6a5a 100644 --- a/test/lexer.nas +++ b/test/lexer.nas @@ -13,7 +13,7 @@ var lexer = func(file) { } return { jmp_note:func() { - while(ptr0.5?-1:1); @@ -127,7 +127,7 @@ func() { var bar=process_bar.high_resolution_bar(48); print("\ec"); - while(limited_loop!=0) { + while (limited_loop!=0) { limited_loop=limited_loop<0?limited_loop:limited_loop-1; var mem=mem_occupation(); var mem_occ=(mem.MemTotal-mem.MemFree)/mem.MemTotal*100; @@ -135,7 +135,7 @@ func() { mem_occ=0; } var cpu_occ=nil; - while((cpu_occ=coroutine.resume(co)[0])==nil) { + while ((cpu_occ=coroutine.resume(co)[0])==nil) { var key=libkey.nonblock(); coroutine.resume(rd); if (key!=nil and chr(key)=="q") diff --git a/test/quick_sort.nas b/test/quick_sort.nas index 64d8210..095bf9f 100644 --- a/test/quick_sort.nas +++ b/test/quick_sort.nas @@ -6,11 +6,11 @@ var var_sort = func() { var base=left+int(rand()*(right-left)); (vec[left],vec[base])=(vec[base],vec[left]); var (i,j,tmp)=(left,right,vec[left]); - while(i does not exist"); @@ -75,7 +75,7 @@ while(1) { # check if active every 0.5s var exited = false; - while(1) { + while (1) { unix.sleep(0.5); if (!subprocess.active(subproc)) { exited = true; diff --git a/tools/file2ppm.nas b/tools/file2ppm.nas index f84e288..94b6578 100644 --- a/tools/file2ppm.nas +++ b/tools/file2ppm.nas @@ -21,7 +21,7 @@ if (size(arg)<1) { var content = io.readfile(arg[0], "r"); var tail_len = 0; -while(math.mod(size(content), 256*3)!=0) { +while (math.mod(size(content), 256*3)!=0) { content ~= "A"; tail_len += 1; } diff --git a/tools/push.nas b/tools/push.nas index 61aefea..ad0b889 100644 --- a/tools/push.nas +++ b/tools/push.nas @@ -3,7 +3,7 @@ use std.unix; println("[", os.time(), "] (=.=) auto push, please wait..."); -while(system("git push")!=0) { +while (system("git push")!=0) { println("[", os.time(), "] (ToT) failed to push, retrying..."); unix.sleep(0.5); }