diff --git a/src/nasal_codegen.cpp b/src/nasal_codegen.cpp index 1b3c6d6..f2a8649 100644 --- a/src/nasal_codegen.cpp +++ b/src/nasal_codegen.cpp @@ -1181,13 +1181,15 @@ const error& codegen::compile(parse& parse, linker& import) { // check global variables size if (global.size()>=STACK_DEPTH/2) { err.err("code", - "too many global variables: " + std::to_string(global.size())); + "too many global variables: " + std::to_string(global.size()) + ); } // check generated code size if (code.size()>0xffffff) { err.err("code", - "bytecode size overflow: " + std::to_string(code.size())); + "bytecode size overflow: " + std::to_string(code.size()) + ); } return err; } diff --git a/src/nasal_gc.cpp b/src/nasal_gc.cpp index b1bec6a..b85986d 100644 --- a/src/nasal_gc.cpp +++ b/src/nasal_gc.cpp @@ -536,7 +536,9 @@ void gc::extend(u8 type) { } void gc::init( - const std::vector& s, const std::vector& argv) { + const std::vector& constant_strings, + const std::vector& argv +) { // initialize counters worktime = 0; for(u8 i = 0; iunmut = 1; - strs[i].str() = s[i]; + strs[i].str() = constant_strings[i]; } // record arguments env_argv.resize(argv.size()); for(usize i = 0; iunmut = 1; env_argv[i].str() = argv[i]; diff --git a/src/nasal_gc.h b/src/nasal_gc.h index 4b5c85c..590d1ed 100644 --- a/src/nasal_gc.h +++ b/src/nasal_gc.h @@ -66,7 +66,7 @@ struct nas_val; // nas_val includes gc-managed types struct var { public: - u8 type; + u8 type = vm_none; union { u32 ret; i64 cnt; diff --git a/src/repl.cpp b/src/repl.cpp index 52aaded..602bf81 100644 --- a/src/repl.cpp +++ b/src/repl.cpp @@ -10,6 +10,9 @@ namespace nasal { namespace repl { void repl::add_command_history(const std::string& history) { + if (command_history.size() && command_history.back()==history) { + return; + } command_history.push_back(history); if (command_history.size()>1000) { command_history.pop_front(); @@ -74,16 +77,12 @@ void repl::help() { } bool repl::run() { - using clk = std::chrono::high_resolution_clock; - const auto den = clk::duration::period::den; - auto nasal_lexer = std::unique_ptr(new lexer); auto nasal_parser = std::unique_ptr(new parse); auto nasal_linker = std::unique_ptr(new linker); auto nasal_opt = std::unique_ptr(new optimizer); auto nasal_codegen = std::unique_ptr(new codegen); - auto start = clk::now(); update_temp_file(); if (nasal_lexer->scan("").geterr()) { return false; @@ -102,9 +101,6 @@ bool repl::run() { return false; } - auto end = clk::now(); - std::clog << "[compile time: " << (end-start).count()*1000.0/den << " ms]\n"; - // TODO: gc init stage in this run may cause memory leak, // because constant strings will be generated again. // but we could not delete old strings, they maybe still on stack.