From e169ffc5ee1c5c42e88b121e1439291c1b023c8f Mon Sep 17 00:00:00 2001 From: Valk Richard Li <48872266+ValKmjolnir@users.noreply.github.com> Date: Sat, 15 Feb 2020 17:02:04 +0800 Subject: [PATCH] update --- version2.0/main.cpp | 6 +++--- version2.0/nasal_gc.h | 19 +++++++++++++------ version2.0/nasal_runtime.h | 9 ++++++--- version2.0/nasal_scalar.h | 39 ++++++++++++++++++++++++++++---------- 4 files changed, 51 insertions(+), 22 deletions(-) diff --git a/version2.0/main.cpp b/version2.0/main.cpp index 8983f1e..f16bb15 100644 --- a/version2.0/main.cpp +++ b/version2.0/main.cpp @@ -1,8 +1,8 @@ #include "nasal.h" -resource_file resource; -nasal_lexer lexer; -nasal_parse parser; +resource_file resource; +nasal_lexer lexer; +nasal_parse parser; abstract_syntax_tree libroot; abstract_syntax_tree root; abstract_syntax_tree linker; diff --git a/version2.0/nasal_gc.h b/version2.0/nasal_gc.h index cea2723..0e4b09d 100644 --- a/version2.0/nasal_gc.h +++ b/version2.0/nasal_gc.h @@ -6,21 +6,28 @@ struct gc_unit // collected: If gc collected this item,it'll be set to true.Otherwise it is false. // elem: Item that this unit stores // refcnt: Reference counter - bool collected; + bool collected; nasal_scalar elem; - int refcnt; + int refcnt; gc_unit() { collected=true; - //elem=0; + elem.set_clear(); refcnt=0; return; } gc_unit(const gc_unit& tmp) { collected=tmp.collected; - //elem=tmp.elem; - refcnt=tmp.refcnt; + elem =tmp.elem; + refcnt =tmp.refcnt; + return; + } + void set_clear() + { + collected=true; + elem.set_clear(); + refcnt=0; return; } }; @@ -61,7 +68,7 @@ class gc_manager for(int i=0;i> [Gc] collected "; prt_hex(i); diff --git a/version2.0/nasal_runtime.h b/version2.0/nasal_runtime.h index e9d43dd..5e7505b 100644 --- a/version2.0/nasal_runtime.h +++ b/version2.0/nasal_runtime.h @@ -5,6 +5,7 @@ class nasal_runtime { private: sym_hash_map global; + // local hash_map will be used when running public: nasal_runtime() { @@ -18,14 +19,16 @@ class nasal_runtime nasal_gc.gc_init(); return; } - void before_running_init() + void func_proc() { - global.set_clear(); - nasal_gc.gc_init(); return; } void main_proc(abstract_syntax_tree& root) { + // init + global.set_clear(); + nasal_gc.gc_init(); + return; } }; diff --git a/version2.0/nasal_scalar.h b/version2.0/nasal_scalar.h index ddf711c..af6b2e4 100644 --- a/version2.0/nasal_scalar.h +++ b/version2.0/nasal_scalar.h @@ -19,17 +19,33 @@ class nasal_function function_root.set_clear(); return; } + void set_clear() + { + local_scope.clear(); + function_root.set_clear(); + return; + } + nasal_function& operator=(const nasal_function& tmp) + { + local_scope=tmp.local_scope; + function_root=tmp.function_root; + return *this; + } + std::map& get_local_scope() + { + return local_scope; + } }; class nasal_scalar { private: int type; - std::string var_string; - double var_number; - std::vector var_array; + std::string var_string; + double var_number; + std::vector var_array; std::map var_hash; - nasal_function var_func; + nasal_function var_func; public: nasal_scalar() { @@ -45,8 +61,9 @@ class nasal_scalar type=tmp.type; var_string=tmp.var_string; var_number=tmp.var_number; - var_array=tmp.var_array; - var_hash=tmp.var_hash; + var_array =tmp.var_array; + var_hash =tmp.var_hash; + var_func =tmp.var_func; return; } nasal_scalar& operator=(const nasal_scalar& tmp) @@ -54,8 +71,9 @@ class nasal_scalar type=tmp.type; var_string=tmp.var_string; var_number=tmp.var_number; - var_array=tmp.var_array; - var_hash=tmp.var_hash; + var_array =tmp.var_array; + var_hash =tmp.var_hash; + var_func =tmp.var_func; return *this; } void set_clear() @@ -65,6 +83,7 @@ class nasal_scalar var_number=0; var_array.clear(); var_hash.clear(); + var_func.set_clear(); return; } void set_type(const int tmp_type) @@ -96,8 +115,8 @@ class nasal_scalar var_hash[member_name]=addr; return; } - int get_type() {return type;} - double get_number() {return var_number;} + int get_type() {return type;} + double get_number(){return var_number;} std::string get_string(){return var_string;} };