mirror of
https://github.com/ValKmjolnir/Nasal-Interpreter.git
synced 2026-07-26 12:59:05 +08:00
update
This commit is contained in:
+15
-1
@@ -8,7 +8,7 @@ nasal_number: basic type(double)
|
||||
nasal_string: basic type(std::string)
|
||||
nasal_vector: elems[i] -> address in memory -> value address in gc
|
||||
nasal_hash: elems[key] -> address in memory -> value address in gc
|
||||
nasal_function: closure -> address in memory ->value address in gc(type: nasal_closure)
|
||||
nasal_function: closure -> value address in gc(type: nasal_closure)
|
||||
nasal_closure: std::list<std::map<std::string,int>> -> std::map<std::string,int> -> (int) -> address in memory -> value address in gc
|
||||
*/
|
||||
|
||||
@@ -68,6 +68,7 @@ public:
|
||||
~nasal_closure();
|
||||
void add_scope();
|
||||
void del_scope();
|
||||
void add_new_value(std::string,int);
|
||||
int get_value_address(std::string);
|
||||
int get_mem_address(std::string);
|
||||
};
|
||||
@@ -316,6 +317,19 @@ void nasal_closure::del_scope()
|
||||
this->elems.pop_back();
|
||||
return;
|
||||
}
|
||||
void nasal_closure::add_new_value(std::string key,int value_address)
|
||||
{
|
||||
int new_mem_address=nasal_vm.mem_alloc();
|
||||
nasal_vm.mem_init(new_mem_address,value_address);
|
||||
if(elems.back().find(key)!=elems.back().end())
|
||||
{
|
||||
// if this value already exists,delete the old value and update a new value
|
||||
int old_mem_address=elems.back()[key];
|
||||
nasal_vm.mem_free(old_mem_address);
|
||||
}
|
||||
elems.back()[key]=new_mem_address;
|
||||
return;
|
||||
}
|
||||
int nasal_closure::get_value_address(std::string key)
|
||||
{
|
||||
int ret_address=-1;
|
||||
|
||||
Reference in New Issue
Block a user