#ifndef __NASAL_RUNTIME_H__ #define __NASAL_RUNTIME_H__ enum runtime_returned_state { rt_return=1, rt_break, rt_continue, rt_error, rt_exit_without_error }; class nasal_runtime { private: // global_scope_address and function_return_address are addresses in garbage_collector_memory int function_returned_address; int global_scope_address; nasal_ast root; // if error occurred,this value will add 1 int error; // generate number and return gc place of this number int number_generation(nasal_ast&); // generate string and return gc place of this string int string_generation(nasal_ast&); // generate vector and return gc place of this vector int vector_generation(nasal_ast&,int); // generate hash and return gc place of this hash int hash_generation(nasal_ast&,int); // 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(nasal_ast&,int); // run loop int loop_progress(nasal_ast&,int); // run conditional int conditional_progress(nasal_ast&,int); // run function int function_progress(nasal_ast&,int); // get scalars in complex data structure like vector/hash/function/closure(scope) 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: nasal_runtime(); ~nasal_runtime(); void set_root(nasal_ast&); void run(); }; nasal_runtime::nasal_runtime() { error=0; this->root.clear(); this->global_scope_address=-1; return; } nasal_runtime::~nasal_runtime() { error=0; this->root.clear(); this->global_scope_address=-1; return; } void nasal_runtime::set_root(nasal_ast& parse_result) { this->root=parse_result; return; } 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) { nasal_vm.add_reference(local_scope_addr); ref_of_this_function.set_closure_addr(local_scope_addr); } return new_addr; } int nasal_runtime::main_progress() { int ret_state=rt_exit_without_error; int expr_number=root.get_children().size(); int process_returned_value_addr=-1; for(int i=0;i> [runtime] main_progress:cannot use break in main progress."<> [runtime] main_progress:cannot use continue in main progress."<> [runtime] main_progress:error occurred when executing main progress."<> [runtime] block_progress:error occurred when executing sub-progress."<=0) value_address=nasal_vm.gc_get(local_scope_addr).get_closure().get_value_address(node.get_children()[0].get_str()); if(value_address<0) value_address=nasal_vm.gc_get(global_scope_address).get_closure().get_value_address(node.get_children()[0].get_str()); if(value_address<0) { std::cout<<">> [runtime] call_nasal_scalar:cannot find value named \'"<> [runtime] call_vector:incorrect value type,expected a vector/hash."<> [runtime] call_hash:incorrect value type,expected a hash."<> [runtime] call_function:incorrect value type,expected a function."<=0) mem_address=nasal_vm.gc_get(local_scope_addr).get_closure().get_mem_address(node.get_children()[0].get_str()); if(mem_address<0) mem_address=nasal_vm.gc_get(global_scope_address).get_closure().get_mem_address(node.get_children()[0].get_str()); if(mem_address<0) { std::cout<<">> [runtime] call_nasal_mem:cannot find value named \'"<> [runtime] call_vector_mem:incorrect value type,expected a vector/hash."<> [runtime] call_hash_mem:incorrect value type,expected a hash."<> [runtime] call_function_mem:incorrect value type,expected a function."<> [runtime] calculation:incorrect values are used in calculation."<