update
This commit is contained in:
parent
a03d8a440d
commit
e169ffc5ee
|
@ -1,8 +1,8 @@
|
||||||
#include "nasal.h"
|
#include "nasal.h"
|
||||||
|
|
||||||
resource_file resource;
|
resource_file resource;
|
||||||
nasal_lexer lexer;
|
nasal_lexer lexer;
|
||||||
nasal_parse parser;
|
nasal_parse parser;
|
||||||
abstract_syntax_tree libroot;
|
abstract_syntax_tree libroot;
|
||||||
abstract_syntax_tree root;
|
abstract_syntax_tree root;
|
||||||
abstract_syntax_tree linker;
|
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.
|
// collected: If gc collected this item,it'll be set to true.Otherwise it is false.
|
||||||
// elem: Item that this unit stores
|
// elem: Item that this unit stores
|
||||||
// refcnt: Reference counter
|
// refcnt: Reference counter
|
||||||
bool collected;
|
bool collected;
|
||||||
nasal_scalar elem;
|
nasal_scalar elem;
|
||||||
int refcnt;
|
int refcnt;
|
||||||
gc_unit()
|
gc_unit()
|
||||||
{
|
{
|
||||||
collected=true;
|
collected=true;
|
||||||
//elem=0;
|
elem.set_clear();
|
||||||
refcnt=0;
|
refcnt=0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
gc_unit(const gc_unit& tmp)
|
gc_unit(const gc_unit& tmp)
|
||||||
{
|
{
|
||||||
collected=tmp.collected;
|
collected=tmp.collected;
|
||||||
//elem=tmp.elem;
|
elem =tmp.elem;
|
||||||
refcnt=tmp.refcnt;
|
refcnt =tmp.refcnt;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
void set_clear()
|
||||||
|
{
|
||||||
|
collected=true;
|
||||||
|
elem.set_clear();
|
||||||
|
refcnt=0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -61,7 +68,7 @@ class gc_manager
|
||||||
for(int i=0;i<memory_size;++i)
|
for(int i=0;i<memory_size;++i)
|
||||||
if((memory[i].refcnt<=0) && (!memory[i].collected))
|
if((memory[i].refcnt<=0) && (!memory[i].collected))
|
||||||
{
|
{
|
||||||
memory[i].collected=true;
|
memory[i].set_clear();
|
||||||
free_space.push_back(i);
|
free_space.push_back(i);
|
||||||
std::cout<<">> [Gc] collected ";
|
std::cout<<">> [Gc] collected ";
|
||||||
prt_hex(i);
|
prt_hex(i);
|
||||||
|
|
|
@ -5,6 +5,7 @@ class nasal_runtime
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
sym_hash_map global;
|
sym_hash_map global;
|
||||||
|
// local hash_map will be used when running
|
||||||
public:
|
public:
|
||||||
nasal_runtime()
|
nasal_runtime()
|
||||||
{
|
{
|
||||||
|
@ -18,14 +19,16 @@ class nasal_runtime
|
||||||
nasal_gc.gc_init();
|
nasal_gc.gc_init();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
void before_running_init()
|
void func_proc()
|
||||||
{
|
{
|
||||||
global.set_clear();
|
|
||||||
nasal_gc.gc_init();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
void main_proc(abstract_syntax_tree& root)
|
void main_proc(abstract_syntax_tree& root)
|
||||||
{
|
{
|
||||||
|
// init
|
||||||
|
global.set_clear();
|
||||||
|
nasal_gc.gc_init();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -19,17 +19,33 @@ class nasal_function
|
||||||
function_root.set_clear();
|
function_root.set_clear();
|
||||||
return;
|
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
|
class nasal_scalar
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
int type;
|
int type;
|
||||||
std::string var_string;
|
std::string var_string;
|
||||||
double var_number;
|
double var_number;
|
||||||
std::vector<int> var_array;
|
std::vector<int> var_array;
|
||||||
std::map<std::string,int> var_hash;
|
std::map<std::string,int> var_hash;
|
||||||
nasal_function var_func;
|
nasal_function var_func;
|
||||||
public:
|
public:
|
||||||
nasal_scalar()
|
nasal_scalar()
|
||||||
{
|
{
|
||||||
|
@ -45,8 +61,9 @@ class nasal_scalar
|
||||||
type=tmp.type;
|
type=tmp.type;
|
||||||
var_string=tmp.var_string;
|
var_string=tmp.var_string;
|
||||||
var_number=tmp.var_number;
|
var_number=tmp.var_number;
|
||||||
var_array=tmp.var_array;
|
var_array =tmp.var_array;
|
||||||
var_hash=tmp.var_hash;
|
var_hash =tmp.var_hash;
|
||||||
|
var_func =tmp.var_func;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
nasal_scalar& operator=(const nasal_scalar& tmp)
|
nasal_scalar& operator=(const nasal_scalar& tmp)
|
||||||
|
@ -54,8 +71,9 @@ class nasal_scalar
|
||||||
type=tmp.type;
|
type=tmp.type;
|
||||||
var_string=tmp.var_string;
|
var_string=tmp.var_string;
|
||||||
var_number=tmp.var_number;
|
var_number=tmp.var_number;
|
||||||
var_array=tmp.var_array;
|
var_array =tmp.var_array;
|
||||||
var_hash=tmp.var_hash;
|
var_hash =tmp.var_hash;
|
||||||
|
var_func =tmp.var_func;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
void set_clear()
|
void set_clear()
|
||||||
|
@ -65,6 +83,7 @@ class nasal_scalar
|
||||||
var_number=0;
|
var_number=0;
|
||||||
var_array.clear();
|
var_array.clear();
|
||||||
var_hash.clear();
|
var_hash.clear();
|
||||||
|
var_func.set_clear();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
void set_type(const int tmp_type)
|
void set_type(const int tmp_type)
|
||||||
|
@ -96,8 +115,8 @@ class nasal_scalar
|
||||||
var_hash[member_name]=addr;
|
var_hash[member_name]=addr;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int get_type() {return type;}
|
int get_type() {return type;}
|
||||||
double get_number() {return var_number;}
|
double get_number(){return var_number;}
|
||||||
std::string get_string(){return var_string;}
|
std::string get_string(){return var_string;}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue