fix dynamic para error

This commit is contained in:
ValKmjolnir 2021-10-18 22:05:31 +08:00
parent 56280db2c7
commit 4f0acc4d63
2 changed files with 5 additions and 5 deletions

View File

@ -106,13 +106,13 @@ struct nasal_hash// 56 bytes
struct nasal_func// 112 bytes
{
uint32_t dynpara; // dynamic parameter index in hash. index 0 is reserved for 'me'.
int32_t dynpara; // dynamic parameter name index in hash.
uint32_t entry; // pc will set to entry-1 to call this function
std::vector<nasal_ref> local; // local scope with default value(nasal_ref)
std::vector<nasal_ref> upvalue; // closure
std::unordered_map<std::string,int> keys; // parameter name table
nasal_func():dynpara(0){}
nasal_func():dynpara(-1){}
void clear();
};
@ -265,7 +265,7 @@ void nasal_hash::print()
/*functions of nasal_func*/
void nasal_func::clear()
{
dynpara=0;
dynpara=-1;
local.clear();
upvalue.clear();
keys.clear();

View File

@ -665,7 +665,7 @@ inline void nasal_vm::opr_callfv()
for(uint32_t i=0;i<min_size;++i)
closure[i+1]=args[i];
// load dynamic argument if args_size>=para_size
if(func.dynpara)
if(func.dynpara>=0)
{
nasal_ref vec=gc.alloc(vm_vec);
for(uint32_t i=para_size;i<args_size;++i)
@ -690,7 +690,7 @@ inline void nasal_vm::opr_callfh()
gc.local.back().vec()->elems=func.local;
// load parameters
auto& closure=gc.local.back().vec()->elems;
if(func.dynpara)
if(func.dynpara>=0)
die("callfh: special call cannot use dynamic argument");
for(auto& i:func.keys)