From c040be716702a04b51e7a8a0c79a6831a7990b08 Mon Sep 17 00:00:00 2001 From: Valk Richard Li <48872266+ValKmjolnir@users.noreply.github.com> Date: Fri, 28 Aug 2020 08:06:56 -0700 Subject: [PATCH] update --- version3.0/nasal_runtime.h | 99 +++++++++++++++++++++++++++++++------- 1 file changed, 81 insertions(+), 18 deletions(-) diff --git a/version3.0/nasal_runtime.h b/version3.0/nasal_runtime.h index cf7ff70..7c89926 100644 --- a/version3.0/nasal_runtime.h +++ b/version3.0/nasal_runtime.h @@ -32,20 +32,31 @@ private: // generate function and return gc place of this function int function_generation(nasal_ast&,int); + /* + functions after this note may have parameter named 'local_scope_addr' + if no local scope existing when calling these functions,use -1 + */ + // main expression block running process int main_progress(); // function/loop/conditional expression block running process - int block_progress(); + int block_progress(nasal_ast&,int); // run loop - int loop_progress(); + int loop_progress(nasal_ast&,int); // run conditional - int conditional_progress(); + int conditional_progress(nasal_ast&,int); // run function - int function_progress(); + int function_progress(nasal_ast&,int); // get scalars in complex data structure like vector/hash/function/closure(scope) - int call_nasal_scalar(nasal_ast&,int); + int call_scalar(nasal_ast&,int); + int call_vector(nasal_ast&,int,int); + int call_hash(nasal_ast&,int,int); + int call_function(nasal_ast&,int,int); // get scalars' memory place in complex data structure like vector/hash/function/closure(scope) int call_scalar_mem(nasal_ast&,int); + int call_vector_mem(nasal_ast&,int,int); + int call_hash_mem(nasal_ast&,int,int); + int call_function_mem(nasal_ast&,int,int); // calculate scalars int calculation(nasal_ast&,int); public: @@ -76,12 +87,17 @@ void nasal_runtime::set_root(nasal_ast& parse_result) } void nasal_runtime::run() { + int returned_statement; + time_t begin_time,end_time; this->global_scope_address=nasal_vm.gc_alloc(); nasal_vm.gc_get(global_scope_address).set_type(vm_closure); nasal_vm.gc_get(global_scope_address).get_closure().add_scope(); - + begin_time=std::time(NULL); + returned_statement=main_progress(); + end_time=std::time(NULL); nasal_vm.gc_get(global_scope_address).get_closure().del_scope(); nasal_vm.del_reference(global_scope_address); + std::cout<<">> [runtime] process exited after "<=0) @@ -197,7 +236,19 @@ int nasal_runtime::call_nasal_scalar(nasal_ast& node,int local_scope_addr=-1) // unfinished return -1; } -int nasal_runtime::call_scalar_mem(nasal_ast& node,int local_scope_addr=-1) +int nasal_runtime::call_vector(nasal_ast& node,int base_value_addr,int local_scope_addr) +{ + return -1; +} +int nasal_runtime::call_hash(nasal_ast& node,int base_value_addr,int local_scope_addr) +{ + return -1; +} +int nasal_runtime::call_function(nasal_ast& node,int base_value_addr,int local_scope_addr) +{ + return -1; +} +int nasal_runtime::call_scalar_mem(nasal_ast& node,int local_scope_addr) { int mem_address=-1; if(local_scope_addr>=0) @@ -212,7 +263,19 @@ int nasal_runtime::call_scalar_mem(nasal_ast& node,int local_scope_addr=-1) // unfinished return mem_address; } -int nasal_runtime::calculation(nasal_ast& node,int local_scope_addr=-1) +int nasal_runtime::call_vector_mem(nasal_ast& node,int base_mem_addr,int local_scope_addr) +{ + return -1; +} +int nasal_runtime::call_hash_mem(nasal_ast& node,int base_mem_addr,int local_scope_addr) +{ + return -1; +} +int nasal_runtime::call_function_mem(nasal_ast& node,int base_mem_addr,int local_scope_addr) +{ + return -1; +} +int nasal_runtime::calculation(nasal_ast& node,int local_scope_addr) { // after this process, a new address(in nasal_vm.garbage_collector_memory) will be returned int ret_address=-1; @@ -228,7 +291,7 @@ int nasal_runtime::calculation(nasal_ast& node,int local_scope_addr=-1) else if(calculation_type==ast_function) ret_address=function_generation(node,local_scope_addr); else if(calculation_type==ast_call) - ret_address=call_nasal_scalar(node,local_scope_addr); + ret_address=call_scalar(node,local_scope_addr); else if(calculation_type==ast_add) { int left_gc_addr=calculation(node.get_children()[0],local_scope_addr);