update
This commit is contained in:
parent
0b0b0daf11
commit
b701637db6
|
@ -4,6 +4,7 @@ nasal_resource resource;
|
||||||
nasal_lexer lexer;
|
nasal_lexer lexer;
|
||||||
nasal_parse parse;
|
nasal_parse parse;
|
||||||
std::string command;
|
std::string command;
|
||||||
|
nasal_runtime runtime;
|
||||||
|
|
||||||
void help()
|
void help()
|
||||||
{
|
{
|
||||||
|
@ -81,6 +82,25 @@ void ast_func()
|
||||||
std::cout<<">> [lexer] error(s) occurred,stop.\n";
|
std::cout<<">> [lexer] error(s) occurred,stop.\n";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
void runtime_start()
|
||||||
|
{
|
||||||
|
lexer.scanner(resource.get_file());
|
||||||
|
if(!lexer.get_error())
|
||||||
|
{
|
||||||
|
parse.set_toklist(lexer.get_token_list());
|
||||||
|
parse.main_process();
|
||||||
|
if(parse.get_error())
|
||||||
|
std::cout<<">> [parse] error(s) occurred,stop.\n";
|
||||||
|
else
|
||||||
|
{
|
||||||
|
runtime.set_root(parse.get_root());
|
||||||
|
runtime.run();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
std::cout<<">> [lexer] error(s) occurred,stop.\n";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
@ -135,9 +155,7 @@ int main()
|
||||||
else if(command=="ast")
|
else if(command=="ast")
|
||||||
ast_func();
|
ast_func();
|
||||||
else if(command=="run")
|
else if(command=="run")
|
||||||
{
|
runtime_start();
|
||||||
;
|
|
||||||
}
|
|
||||||
else if(command=="logo")
|
else if(command=="logo")
|
||||||
logo();
|
logo();
|
||||||
else if(command=="exit")
|
else if(command=="exit")
|
||||||
|
|
|
@ -29,8 +29,8 @@ public:
|
||||||
class nasal_function
|
class nasal_function
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
// this int points to the space in nasal_vm::memory_manager_memory
|
// this int points to the space in nasal_vm::garbage_collector_memory
|
||||||
std::list<int> closures;
|
int closure_addr;
|
||||||
nasal_ast function_tree;
|
nasal_ast function_tree;
|
||||||
public:
|
public:
|
||||||
nasal_function();
|
nasal_function();
|
||||||
|
@ -180,15 +180,13 @@ void nasal_hash::del_elem(std::string key)
|
||||||
/*functions of nasal_function*/
|
/*functions of nasal_function*/
|
||||||
nasal_function::nasal_function()
|
nasal_function::nasal_function()
|
||||||
{
|
{
|
||||||
closures.clear();
|
closure_addr=-1;
|
||||||
function_tree.clear();
|
function_tree.clear();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
nasal_function::~nasal_function()
|
nasal_function::~nasal_function()
|
||||||
{
|
{
|
||||||
for(std::list<int>::iterator iter=closures.begin();iter!=closures.end();++iter)
|
nasal_vm.del_reference(closure_addr);
|
||||||
nasal_vm.mem_free(*iter);
|
|
||||||
closures.clear();
|
|
||||||
function_tree.clear();
|
function_tree.clear();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,46 +1,56 @@
|
||||||
#ifndef __NASAL_RUNTIME_H__
|
#ifndef __NASAL_RUNTIME_H__
|
||||||
#define __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
|
class nasal_runtime
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
// global_scope_address is address in garbage_collector_memory,NOT memory_manager_memory
|
// global_scope_address and function_return_address are addresses in garbage_collector_memory
|
||||||
|
int function_returned_address;
|
||||||
int global_scope_address;
|
int global_scope_address;
|
||||||
nasal_ast root;
|
nasal_ast root;
|
||||||
std::stack<int> function_position;
|
// process functions are private
|
||||||
std::stack<int> running_stack;
|
int main_progress();
|
||||||
std::stack<int> closure_stack;
|
int block_progress();
|
||||||
|
int loop_progress();
|
||||||
|
int conditional_progress();
|
||||||
|
int function_progress();
|
||||||
|
int calculation();
|
||||||
public:
|
public:
|
||||||
nasal_runtime();
|
nasal_runtime();
|
||||||
~nasal_runtime();
|
~nasal_runtime();
|
||||||
|
void set_root(nasal_ast&);
|
||||||
void run();
|
void run();
|
||||||
};
|
};
|
||||||
|
|
||||||
nasal_runtime::nasal_runtime()
|
nasal_runtime::nasal_runtime()
|
||||||
{
|
{
|
||||||
root.clear();
|
this->root.clear();
|
||||||
while(!function_position.empty())
|
this->global_scope_address=-1;
|
||||||
function_position.pop();
|
|
||||||
while(!running_stack.empty())
|
|
||||||
running_stack.pop();
|
|
||||||
while(!closure_stack.empty())
|
|
||||||
closure_stack.pop();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
nasal_runtime::~nasal_runtime()
|
nasal_runtime::~nasal_runtime()
|
||||||
{
|
{
|
||||||
root.clear();
|
this->root.clear();
|
||||||
while(!function_position.empty())
|
this->global_scope_address=-1;
|
||||||
function_position.pop();
|
return;
|
||||||
while(!running_stack.empty())
|
}
|
||||||
running_stack.pop();
|
void nasal_runtime::set_root(nasal_ast& parse_result)
|
||||||
while(!closure_stack.empty())
|
{
|
||||||
closure_stack.pop();
|
this->root=parse_result;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
void nasal_runtime::run()
|
void nasal_runtime::run()
|
||||||
{
|
{
|
||||||
global_scope_address=nasal_vm.gc_alloc();
|
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).set_type(vm_closure);
|
||||||
nasal_vm.gc_get(global_scope_address).get_closure().add_scope();
|
nasal_vm.gc_get(global_scope_address).get_closure().add_scope();
|
||||||
|
|
||||||
|
@ -48,5 +58,35 @@ void nasal_runtime::run()
|
||||||
nasal_vm.del_reference(global_scope_address);
|
nasal_vm.del_reference(global_scope_address);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
int nasal_runtime::main_progress()
|
||||||
|
{
|
||||||
|
int ret_state=rt_exit_without_error;
|
||||||
|
return ret_state;
|
||||||
|
}
|
||||||
|
int nasal_runtime::block_progress()
|
||||||
|
{
|
||||||
|
int ret_state=rt_exit_without_error;
|
||||||
|
return ret_state;
|
||||||
|
}
|
||||||
|
int nasal_runtime::loop_progress()
|
||||||
|
{
|
||||||
|
int ret_state=rt_exit_without_error;
|
||||||
|
return ret_state;
|
||||||
|
}
|
||||||
|
int nasal_runtime::conditional_progress()
|
||||||
|
{
|
||||||
|
int ret_state=rt_exit_without_error;
|
||||||
|
return ret_state;
|
||||||
|
}
|
||||||
|
int nasal_runtime::function_progress()
|
||||||
|
{
|
||||||
|
int ret_state=rt_exit_without_error;
|
||||||
|
return ret_state;
|
||||||
|
}
|
||||||
|
int nasal_runtime::calculation()
|
||||||
|
{
|
||||||
|
int ret_state=rt_exit_without_error;
|
||||||
|
return ret_state;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
Loading…
Reference in New Issue