update
This commit is contained in:
parent
a03d8a440d
commit
e169ffc5ee
|
@ -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;
|
||||
|
|
|
@ -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<memory_size;++i)
|
||||
if((memory[i].refcnt<=0) && (!memory[i].collected))
|
||||
{
|
||||
memory[i].collected=true;
|
||||
memory[i].set_clear();
|
||||
free_space.push_back(i);
|
||||
std::cout<<">> [Gc] collected ";
|
||||
prt_hex(i);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -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<std::string,int>& get_local_scope()
|
||||
{
|
||||
return local_scope;
|
||||
}
|
||||
};
|
||||
|
||||
class nasal_scalar
|
||||
{
|
||||
private:
|
||||
int type;
|
||||
std::string var_string;
|
||||
double var_number;
|
||||
std::vector<int> var_array;
|
||||
std::string var_string;
|
||||
double var_number;
|
||||
std::vector<int> var_array;
|
||||
std::map<std::string,int> 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;}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue