From 022460755fb14ded255e3a7d422b64b477d0cdad Mon Sep 17 00:00:00 2001 From: ValKmjolnir Date: Tue, 12 Apr 2022 18:26:54 +0800 Subject: [PATCH] optimize codes --- nasal_ast.h | 7 +++---- nasal_builtin.h | 2 +- nasal_codegen.h | 2 +- nasal_gc.h | 5 +++-- nasal_lexer.h | 5 ++--- nasal_parse.h | 2 +- 6 files changed, 11 insertions(+), 12 deletions(-) diff --git a/nasal_ast.h b/nasal_ast.h index b333a3a..a87fbb0 100644 --- a/nasal_ast.h +++ b/nasal_ast.h @@ -135,7 +135,7 @@ private: std::string _str; std::vector _child; public: - nasal_ast(const uint32_t l=0,const uint32_t t=ast_null):_line(l),_type(t){} + nasal_ast(const uint32_t l=0,const uint32_t t=ast_null):_line(l),_type(t),_num(0){} nasal_ast(const nasal_ast&); nasal_ast(nasal_ast&&); void print(int,bool); @@ -162,13 +162,12 @@ public: inline std::vector& child(){return _child;} }; -nasal_ast::nasal_ast(const nasal_ast& tmp) +nasal_ast::nasal_ast(const nasal_ast& tmp): + _str(tmp._str),_child(tmp._child) { _line=tmp._line; _type=tmp._type; _num =tmp._num; - _str =tmp._str; - _child=tmp._child; } nasal_ast::nasal_ast(nasal_ast&& tmp) diff --git a/nasal_builtin.h b/nasal_builtin.h index 8b39648..8eb104a 100644 --- a/nasal_builtin.h +++ b/nasal_builtin.h @@ -88,7 +88,7 @@ nas_native(builtin_platform); nas_native(builtin_gc); nas_native(builtin_md5); -nasal_ref builtin_err(const char* func_name,std::string info) +nasal_ref builtin_err(const char* func_name,const std::string info) { std::cerr<<"[vm] "< upvalue; // closure std::unordered_map keys; // parameter name table, size_t begins from 1 - nasal_func():dynpara(-1){} + nasal_func():dynpara(-1),entry(0),psize(0),lsize(0){} void clear(); }; @@ -151,6 +151,7 @@ struct nasal_obj { enum obj_type { + null, file=1, dir, dylib, @@ -166,7 +167,7 @@ struct nasal_obj typedef void (*dest)(void*); dest destructor; - nasal_obj():ptr(nullptr),destructor(nullptr){} + nasal_obj():type(obj_type::null),ptr(nullptr),destructor(nullptr){} ~nasal_obj(){clear();} void clear() { diff --git a/nasal_lexer.h b/nasal_lexer.h index 592eb9c..d469122 100644 --- a/nasal_lexer.h +++ b/nasal_lexer.h @@ -93,12 +93,11 @@ struct token uint32_t column; uint32_t type; std::string str; - token(uint32_t l=0,uint32_t c=0,uint32_t t=tok_null,std::string s="") + token(uint32_t l=0,uint32_t c=0,uint32_t t=tok_null,const std::string s=""):str(s) { line=l; column=c; type=t; - str=s; } }; @@ -119,7 +118,7 @@ private: std::string num_gen(); std::string str_gen(); public: - nasal_lexer(nasal_err& e):nerr(e){} + nasal_lexer(nasal_err& e):line(0),column(0),ptr(0),nerr(e){} void scan(const std::string&); void print(); const std::vector& get_tokens() const {return tokens;} diff --git a/nasal_parse.h b/nasal_parse.h index f5b92d8..ecd4b65 100644 --- a/nasal_parse.h +++ b/nasal_parse.h @@ -98,7 +98,7 @@ private: nasal_ast break_expr(); nasal_ast ret_expr(); public: - nasal_parse(nasal_err& e):nerr(e){} + nasal_parse(nasal_err& e):ptr(0),in_func(0),in_loop(0),tokens(nullptr),nerr(e){} void print(){root.print(0);} void compile(const nasal_lexer&); nasal_ast& ast(){return root;}