change STACK_MAX_DEPTH to nasal_gc::stack_depth
This commit is contained in:
parent
c12e812651
commit
4503239731
|
@ -631,7 +631,7 @@ nasal_ref builtin_keys(nasal_ref* local,nasal_gc& gc)
|
||||||
if(hash.type!=vm_hash)
|
if(hash.type!=vm_hash)
|
||||||
return builtin_err("keys","\"hash\" must be hash");
|
return builtin_err("keys","\"hash\" must be hash");
|
||||||
// push vector into local scope to avoid being sweeped
|
// push vector into local scope to avoid being sweeped
|
||||||
if(gc.top+1>=gc.stack+STACK_MAX_DEPTH-1)
|
if(gc.top+1>=gc.stack+nasal_gc::stack_depth-1)
|
||||||
return builtin_err("keys","expand temporary space error:stackoverflow");
|
return builtin_err("keys","expand temporary space error:stackoverflow");
|
||||||
(++gc.top)[0]=gc.alloc(vm_vec);
|
(++gc.top)[0]=gc.alloc(vm_vec);
|
||||||
auto& vec=gc.top[0].vec().elems;
|
auto& vec=gc.top[0].vec().elems;
|
||||||
|
|
|
@ -293,14 +293,14 @@ nasal_ref builtin_split(nasal_ref* local,nasal_gc& gc)
|
||||||
size_t source_len=source.length();
|
size_t source_len=source.length();
|
||||||
|
|
||||||
// push it to local scope to avoid being sweeped
|
// push it to local scope to avoid being sweeped
|
||||||
if(gc.top+1>=gc.stack+STACK_MAX_DEPTH-1)
|
if(gc.top+1>=gc.stack+nasal_gc::stack_depth-1)
|
||||||
return builtin_err("split","expand temporary space error:stackoverflow");
|
return builtin_err("split","expand temporary space error:stackoverflow");
|
||||||
(++gc.top)[0]=gc.alloc(vm_vec);
|
(++gc.top)[0]=gc.alloc(vm_vec);
|
||||||
|
|
||||||
std::vector<nasal_ref>& vec=gc.top[0].vec().elems;
|
std::vector<nasal_ref>& vec=gc.top[0].vec().elems;
|
||||||
if(!delimeter_len)
|
if(!delimeter_len)
|
||||||
{
|
{
|
||||||
for(int i=0;i<source_len;++i)
|
for(size_t i=0;i<source_len;++i)
|
||||||
{
|
{
|
||||||
vec.push_back(gc.alloc(vm_str));
|
vec.push_back(gc.alloc(vm_str));
|
||||||
vec.back().str()=source[i];
|
vec.back().str()=source[i];
|
||||||
|
@ -310,11 +310,11 @@ nasal_ref builtin_split(nasal_ref* local,nasal_gc& gc)
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string tmp="";
|
std::string tmp="";
|
||||||
for(int i=0;i<source_len;++i)
|
for(size_t i=0;i<source_len;++i)
|
||||||
{
|
{
|
||||||
bool check_delimeter=false;
|
bool check_delimeter=false;
|
||||||
if(source[i]==delimeter[0])
|
if(source[i]==delimeter[0])
|
||||||
for(int j=0;j<delimeter_len;++j)
|
for(size_t j=0;j<delimeter_len;++j)
|
||||||
{
|
{
|
||||||
if(i+j>=source_len || source[i+j]!=delimeter[j])
|
if(i+j>=source_len || source[i+j]!=delimeter[j])
|
||||||
break;
|
break;
|
||||||
|
@ -598,7 +598,7 @@ nasal_ref builtin_keys(nasal_ref* local,nasal_gc& gc)
|
||||||
if(hash.type!=vm_hash)
|
if(hash.type!=vm_hash)
|
||||||
return builtin_err("keys","\"hash\" must be hash");
|
return builtin_err("keys","\"hash\" must be hash");
|
||||||
// push vector into local scope to avoid being sweeped
|
// push vector into local scope to avoid being sweeped
|
||||||
if(gc.top+1>=gc.stack+STACK_MAX_DEPTH-1)
|
if(gc.top+1>=gc.stack+nasal_gc::stack_depth-1)
|
||||||
return builtin_err("keys","expand temporary space error:stackoverflow");
|
return builtin_err("keys","expand temporary space error:stackoverflow");
|
||||||
(++gc.top)[0]=gc.alloc(vm_vec);
|
(++gc.top)[0]=gc.alloc(vm_vec);
|
||||||
auto& vec=gc.top[0].vec().elems;
|
auto& vec=gc.top[0].vec().elems;
|
||||||
|
@ -1010,8 +1010,8 @@ nasal_ref builtin_sleep(nasal_ref* local,nasal_gc& gc)
|
||||||
}
|
}
|
||||||
nasal_ref builtin_pipe(nasal_ref* local,nasal_gc& gc)
|
nasal_ref builtin_pipe(nasal_ref* local,nasal_gc& gc)
|
||||||
{
|
{
|
||||||
int fd[2];
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
|
int fd[2];
|
||||||
nasal_ref res=gc.alloc(vm_vec);
|
nasal_ref res=gc.alloc(vm_vec);
|
||||||
if(pipe(fd)==-1)
|
if(pipe(fd)==-1)
|
||||||
return builtin_err("pipe","failed to create pipe");
|
return builtin_err("pipe","failed to create pipe");
|
||||||
|
@ -1099,7 +1099,7 @@ nasal_ref builtin_chdir(nasal_ref* local,nasal_gc& gc)
|
||||||
nasal_ref builtin_environ(nasal_ref* local,nasal_gc& gc)
|
nasal_ref builtin_environ(nasal_ref* local,nasal_gc& gc)
|
||||||
{
|
{
|
||||||
char** env=environ;
|
char** env=environ;
|
||||||
if(gc.top+1>=gc.stack+STACK_MAX_DEPTH-1)
|
if(gc.top+1>=gc.stack+nasal_gc::stack_depth-1)
|
||||||
return builtin_err("environ","expand temporary space error:stackoverflow");
|
return builtin_err("environ","expand temporary space error:stackoverflow");
|
||||||
(++gc.top)[0]=gc.alloc(vm_vec);
|
(++gc.top)[0]=gc.alloc(vm_vec);
|
||||||
auto& vec=gc.top[0].vec().elems;
|
auto& vec=gc.top[0].vec().elems;
|
||||||
|
|
|
@ -431,7 +431,7 @@ void nasal_codegen::func_gen(const nasal_ast& ast)
|
||||||
block_gen(block);
|
block_gen(block);
|
||||||
in_iterloop.pop();
|
in_iterloop.pop();
|
||||||
code[local_label].num=local.back().size();
|
code[local_label].num=local.back().size();
|
||||||
if(local.back().size()>=STACK_MAX_DEPTH)
|
if(local.back().size()>=nasal_gc::stack_depth)
|
||||||
die("too many local variants: "+std::to_string(local.back().size())+".",block.line());
|
die("too many local variants: "+std::to_string(local.back().size())+".",block.line());
|
||||||
local.pop_back();
|
local.pop_back();
|
||||||
|
|
||||||
|
@ -549,7 +549,7 @@ void nasal_codegen::mcall(const nasal_ast& ast)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
calc_gen(ast[0]);
|
calc_gen(ast[0]);
|
||||||
for(int i=1;i<ast.size()-1;++i)
|
for(size_t i=1;i<ast.size()-1;++i)
|
||||||
{
|
{
|
||||||
const nasal_ast& tmp=ast[i];
|
const nasal_ast& tmp=ast[i];
|
||||||
switch(tmp.type())
|
switch(tmp.type())
|
||||||
|
@ -1134,7 +1134,7 @@ void nasal_codegen::compile(const nasal_parse& parse,const nasal_import& import)
|
||||||
gen(op_intg,global.size(),0);
|
gen(op_intg,global.size(),0);
|
||||||
block_gen(parse.ast()); // generate main block
|
block_gen(parse.ast()); // generate main block
|
||||||
gen(op_exit,0,0);
|
gen(op_exit,0,0);
|
||||||
if(global.size()>=STACK_MAX_DEPTH)
|
if(global.size()>=nasal_gc::stack_depth)
|
||||||
die("too many global variants: "+std::to_string(global.size())+".",0);
|
die("too many global variants: "+std::to_string(global.size())+".",0);
|
||||||
nerr.chkerr();
|
nerr.chkerr();
|
||||||
}
|
}
|
||||||
|
|
|
@ -370,14 +370,15 @@ inline nasal_func& nasal_ref::func (){return *value.gcobj->ptr.func; }
|
||||||
inline nasal_upval& nasal_ref::upval(){return *value.gcobj->ptr.upval;}
|
inline nasal_upval& nasal_ref::upval(){return *value.gcobj->ptr.upval;}
|
||||||
inline nasal_obj& nasal_ref::obj (){return *value.gcobj->ptr.obj; }
|
inline nasal_obj& nasal_ref::obj (){return *value.gcobj->ptr.obj; }
|
||||||
|
|
||||||
const uint32_t STACK_MAX_DEPTH=8191;
|
|
||||||
const nasal_ref zero={vm_num,(double)0};
|
const nasal_ref zero={vm_num,(double)0};
|
||||||
const nasal_ref one ={vm_num,(double)1};
|
const nasal_ref one ={vm_num,(double)1};
|
||||||
const nasal_ref nil ={vm_nil,(double)0};
|
const nasal_ref nil ={vm_nil,(double)0};
|
||||||
|
|
||||||
struct nasal_gc
|
struct nasal_gc
|
||||||
{
|
{
|
||||||
|
static const uint32_t stack_depth=8192; // depth of value stack
|
||||||
nasal_ref funcr; // function register
|
nasal_ref funcr; // function register
|
||||||
nasal_ref stack[STACK_MAX_DEPTH+1];// 1 reserved to avoid stack overflow
|
nasal_ref stack[stack_depth]; // the last one is reserved to avoid stack overflow
|
||||||
nasal_ref* top; // stack top
|
nasal_ref* top; // stack top
|
||||||
std::vector<nasal_ref> strs; // reserved address for const vm_str
|
std::vector<nasal_ref> strs; // reserved address for const vm_str
|
||||||
std::vector<nasal_val*> memory; // gc memory
|
std::vector<nasal_val*> memory; // gc memory
|
||||||
|
|
|
@ -135,7 +135,7 @@ void nasal_vm::init(
|
||||||
files=filenames.data();
|
files=filenames.data();
|
||||||
files_size=filenames.size();
|
files_size=filenames.size();
|
||||||
/* set canary and program counter */
|
/* set canary and program counter */
|
||||||
canary=gc.stack+STACK_MAX_DEPTH-1;
|
canary=gc.stack+nasal_gc::stack_depth-1; // gc.stack[nasal_gc::stack_depth-1]
|
||||||
mem_addr=nullptr;
|
mem_addr=nullptr;
|
||||||
pc=0;
|
pc=0;
|
||||||
localr=nullptr;
|
localr=nullptr;
|
||||||
|
|
Loading…
Reference in New Issue