mirror of
https://github.com/ValKmjolnir/Nasal-Interpreter.git
synced 2026-07-26 21:08:45 +08:00
⚡ optimize op_para and op_deft: change hashmap<string,u64> to hashmap<u32,u32>
This commit is contained in:
+7
-7
@@ -122,13 +122,13 @@ struct nasal_hash
|
|||||||
|
|
||||||
struct nasal_func
|
struct nasal_func
|
||||||
{
|
{
|
||||||
int32_t dynpara; // dynamic parameter name index in hash.
|
int32_t dynpara; // dynamic parameter name index in hash.
|
||||||
uint32_t entry; // pc will set to entry-1 to call this function
|
uint32_t entry; // pc will set to entry-1 to call this function
|
||||||
uint32_t psize; // used to load default parameters to a new function
|
uint32_t psize; // used to load default parameters to a new function
|
||||||
uint32_t lsize; // used to expand memory space for local values on stack
|
uint32_t lsize; // used to expand memory space for local values on stack
|
||||||
std::vector<nasal_ref> local; // local scope with default value(nasal_ref)
|
std::vector<nasal_ref> local; // local scope with default value(nasal_ref)
|
||||||
std::vector<nasal_ref> upvalue; // closure
|
std::vector<nasal_ref> upvalue; // closure
|
||||||
std::unordered_map<std::string,size_t> keys; // parameter name table, size_t begins from 1
|
std::unordered_map<uint32_t,uint32_t> keys; // parameter name table, size_t begins from 1
|
||||||
|
|
||||||
nasal_func():dynpara(-1),entry(0),psize(0),lsize(0){}
|
nasal_func():dynpara(-1),entry(0),psize(0),lsize(0){}
|
||||||
void clear();
|
void clear();
|
||||||
|
|||||||
+6
-5
@@ -440,7 +440,7 @@ inline void nasal_vm::opr_para()
|
|||||||
{
|
{
|
||||||
nasal_func& func=top[0].func();
|
nasal_func& func=top[0].func();
|
||||||
// func->size has 1 place reserved for "me"
|
// func->size has 1 place reserved for "me"
|
||||||
func.keys[str_table[imm[pc]]]=func.psize;
|
func.keys[imm[pc]]=func.psize;
|
||||||
func.local[func.psize++]={vm_none};
|
func.local[func.psize++]={vm_none};
|
||||||
}
|
}
|
||||||
inline void nasal_vm::opr_deft()
|
inline void nasal_vm::opr_deft()
|
||||||
@@ -448,7 +448,7 @@ inline void nasal_vm::opr_deft()
|
|||||||
nasal_ref val=top[0];
|
nasal_ref val=top[0];
|
||||||
nasal_func& func=(--top)[0].func();
|
nasal_func& func=(--top)[0].func();
|
||||||
// func->size has 1 place reserved for "me"
|
// func->size has 1 place reserved for "me"
|
||||||
func.keys[str_table[imm[pc]]]=func.psize;
|
func.keys[imm[pc]]=func.psize;
|
||||||
func.local[func.psize++]=val;
|
func.local[func.psize++]=val;
|
||||||
}
|
}
|
||||||
inline void nasal_vm::opr_dyn()
|
inline void nasal_vm::opr_dyn()
|
||||||
@@ -779,10 +779,11 @@ inline void nasal_vm::opr_callfh()
|
|||||||
|
|
||||||
for(auto& i:func.keys)
|
for(auto& i:func.keys)
|
||||||
{
|
{
|
||||||
if(hash.count(i.first))
|
const std::string& key=str_table[i.first];
|
||||||
local[i.second]=hash[i.first];
|
if(hash.count(key))
|
||||||
|
local[i.second]=hash[key];
|
||||||
else if(local[i.second].type==vm_none)
|
else if(local[i.second].type==vm_none)
|
||||||
die("callfh: lack argument(s): \""+i.first+"\"");
|
die("callfh: lack argument(s): \""+key+"\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
top[0]=upvalr;
|
top[0]=upvalr;
|
||||||
|
|||||||
+4
-1
@@ -201,4 +201,7 @@ foreach(var i;a){
|
|||||||
foreach(i;a){
|
foreach(i;a){
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
println(runtime.argv());
|
println(runtime.argv());
|
||||||
|
func(a,b,c,d="只有红茶可以吗"){
|
||||||
|
println(a,' ',b,' ',c,' ',d);
|
||||||
|
}(c:1919810,b:514,a:114);
|
||||||
Reference in New Issue
Block a user