visual update
This commit is contained in:
parent
e54ef9620f
commit
f26719e1d3
|
@ -417,10 +417,10 @@ nasal_ref builtin_size(nasal_ref* local,nasal_gc& gc)
|
||||||
double num;
|
double num;
|
||||||
switch(val.type)
|
switch(val.type)
|
||||||
{
|
{
|
||||||
case vm_num: num=val.num(); break;
|
case vm_num: num=val.num(); break;
|
||||||
case vm_str: num=val.str().length(); break;
|
case vm_str: num=val.str().length();break;
|
||||||
case vm_vec: num=val.vec().elems.size(); break;
|
case vm_vec: num=val.vec().size(); break;
|
||||||
case vm_hash: num=val.hash().elems.size();break;
|
case vm_hash: num=val.hash().size(); break;
|
||||||
}
|
}
|
||||||
return {vm_num,num};
|
return {vm_num,num};
|
||||||
}
|
}
|
||||||
|
|
23
nasal_dbg.h
23
nasal_dbg.h
|
@ -151,24 +151,19 @@ void nasal_dbg::interact()
|
||||||
else
|
else
|
||||||
err();
|
err();
|
||||||
}
|
}
|
||||||
else if(res.size()==3)
|
else if(res.size()==3 && (res[0]=="bk" || res[0]=="break"))
|
||||||
{
|
{
|
||||||
if(res[0]=="bk" || res[0]=="break")
|
bk_fidx=get_fileindex(res[1]);
|
||||||
|
if(bk_fidx==65535)
|
||||||
{
|
{
|
||||||
bk_fidx=get_fileindex(res[1]);
|
printf("cannot find file named \"%s\"\n",res[1].c_str());
|
||||||
if(bk_fidx==65535)
|
bk_fidx=0;
|
||||||
{
|
|
||||||
printf("cannot find file named \"%s\"\n",res[1].c_str());
|
|
||||||
bk_fidx=0;
|
|
||||||
}
|
|
||||||
int tmp=atoi(res[2].c_str());
|
|
||||||
if(tmp<=0)
|
|
||||||
printf("incorrect line number \"%s\"\n",res[2].c_str());
|
|
||||||
else
|
|
||||||
bk_line=tmp;
|
|
||||||
}
|
}
|
||||||
|
int tmp=atoi(res[2].c_str());
|
||||||
|
if(tmp<=0)
|
||||||
|
printf("incorrect line number \"%s\"\n",res[2].c_str());
|
||||||
else
|
else
|
||||||
err();
|
bk_line=tmp;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
err();
|
err();
|
||||||
|
|
31
nasal_gc.h
31
nasal_gc.h
|
@ -98,22 +98,24 @@ struct nasal_ref
|
||||||
|
|
||||||
struct nasal_vec
|
struct nasal_vec
|
||||||
{
|
{
|
||||||
uint32_t depth;
|
bool printed;
|
||||||
std::vector<nasal_ref> elems;
|
std::vector<nasal_ref> elems;
|
||||||
|
|
||||||
nasal_vec():depth(0){}
|
nasal_vec():printed(false){}
|
||||||
void print();
|
void print();
|
||||||
|
size_t size(){return elems.size();}
|
||||||
nasal_ref get_val(const int);
|
nasal_ref get_val(const int);
|
||||||
nasal_ref* get_mem(const int);
|
nasal_ref* get_mem(const int);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct nasal_hash
|
struct nasal_hash
|
||||||
{
|
{
|
||||||
uint32_t depth;
|
bool printed;
|
||||||
std::unordered_map<std::string,nasal_ref> elems;
|
std::unordered_map<std::string,nasal_ref> elems;
|
||||||
|
|
||||||
nasal_hash():depth(0){}
|
nasal_hash():printed(false){}
|
||||||
void print();
|
void print();
|
||||||
|
size_t size(){return elems.size();}
|
||||||
nasal_ref get_val(const std::string&);
|
nasal_ref get_val(const std::string&);
|
||||||
nasal_ref* get_mem(const std::string&);
|
nasal_ref* get_mem(const std::string&);
|
||||||
};
|
};
|
||||||
|
@ -140,7 +142,7 @@ struct nasal_upval
|
||||||
std::vector<nasal_ref> elems;
|
std::vector<nasal_ref> elems;
|
||||||
|
|
||||||
nasal_upval(){onstk=true;stk=nullptr;size=0;}
|
nasal_upval(){onstk=true;stk=nullptr;size=0;}
|
||||||
nasal_ref& operator[](const int);
|
nasal_ref& operator[](const int i){return onstk?stk[i]:elems[i];}
|
||||||
void clear(){onstk=true;elems.clear();size=0;}
|
void clear(){onstk=true;elems.clear();size=0;}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -198,12 +200,12 @@ nasal_ref* nasal_vec::get_mem(const int index)
|
||||||
}
|
}
|
||||||
void nasal_vec::print()
|
void nasal_vec::print()
|
||||||
{
|
{
|
||||||
if(!elems.size() || depth>3)
|
if(!elems.size() || printed)
|
||||||
{
|
{
|
||||||
std::cout<<(elems.size()?"[..]":"[]");
|
std::cout<<(elems.size()?"[..]":"[]");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
++depth;
|
printed=true;
|
||||||
size_t iter=0;
|
size_t iter=0;
|
||||||
std::cout<<'[';
|
std::cout<<'[';
|
||||||
for(auto& i:elems)
|
for(auto& i:elems)
|
||||||
|
@ -211,7 +213,7 @@ void nasal_vec::print()
|
||||||
i.print();
|
i.print();
|
||||||
std::cout<<",]"[(++iter)==elems.size()];
|
std::cout<<",]"[(++iter)==elems.size()];
|
||||||
}
|
}
|
||||||
--depth;
|
printed=false;
|
||||||
}
|
}
|
||||||
|
|
||||||
nasal_ref nasal_hash::get_val(const std::string& key)
|
nasal_ref nasal_hash::get_val(const std::string& key)
|
||||||
|
@ -254,12 +256,12 @@ nasal_ref* nasal_hash::get_mem(const std::string& key)
|
||||||
}
|
}
|
||||||
void nasal_hash::print()
|
void nasal_hash::print()
|
||||||
{
|
{
|
||||||
if(!elems.size() || depth>3)
|
if(!elems.size() || printed)
|
||||||
{
|
{
|
||||||
std::cout<<(elems.size()?"{..}":"{}");
|
std::cout<<(elems.size()?"{..}":"{}");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
++depth;
|
printed=true;
|
||||||
size_t iter=0;
|
size_t iter=0;
|
||||||
std::cout<<'{';
|
std::cout<<'{';
|
||||||
for(auto& i:elems)
|
for(auto& i:elems)
|
||||||
|
@ -268,7 +270,7 @@ void nasal_hash::print()
|
||||||
i.second.print();
|
i.second.print();
|
||||||
std::cout<<",}"[(++iter)==elems.size()];
|
std::cout<<",}"[(++iter)==elems.size()];
|
||||||
}
|
}
|
||||||
--depth;
|
printed=false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void nasal_func::clear()
|
void nasal_func::clear()
|
||||||
|
@ -279,13 +281,6 @@ void nasal_func::clear()
|
||||||
keys.clear();
|
keys.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
nasal_ref& nasal_upval::operator[](const int index)
|
|
||||||
{
|
|
||||||
if(onstk)
|
|
||||||
return stk[index];
|
|
||||||
return elems[index];
|
|
||||||
}
|
|
||||||
|
|
||||||
nasal_val::nasal_val(uint8_t val_type)
|
nasal_val::nasal_val(uint8_t val_type)
|
||||||
{
|
{
|
||||||
mark=GC_COLLECTED;
|
mark=GC_COLLECTED;
|
||||||
|
|
|
@ -37,6 +37,14 @@ void calc_const(nasal_ast& root)
|
||||||
auto& vec=root.child();
|
auto& vec=root.child();
|
||||||
for(auto& i:vec)
|
for(auto& i:vec)
|
||||||
calc_const(i);
|
calc_const(i);
|
||||||
|
if(vec.size()==1 && root.type()==ast_neg && vec[0].type()==ast_num)
|
||||||
|
{
|
||||||
|
double res=-vec[0].num();
|
||||||
|
root.set_num(res);
|
||||||
|
root.child().clear();
|
||||||
|
root.set_type(ast_num);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if(vec.size()!=2)
|
if(vec.size()!=2)
|
||||||
return;
|
return;
|
||||||
if(root.type()!=ast_add &&
|
if(root.type()!=ast_add &&
|
||||||
|
|
10
nasal_vm.h
10
nasal_vm.h
|
@ -154,8 +154,8 @@ void nasal_vm::valinfo(nasal_ref& val)
|
||||||
case vm_num: printf("| num | ");std::cout<<val.num()<<'\n';break;
|
case vm_num: printf("| num | ");std::cout<<val.num()<<'\n';break;
|
||||||
case vm_str: printf("| str | <0x%lx> %s\n",(uint64_t)p,rawstr(val.str()).c_str());break;
|
case vm_str: printf("| str | <0x%lx> %s\n",(uint64_t)p,rawstr(val.str()).c_str());break;
|
||||||
case vm_func: printf("| func | <0x%lx> entry:0x%x\n",(uint64_t)p,val.func().entry);break;
|
case vm_func: printf("| func | <0x%lx> entry:0x%x\n",(uint64_t)p,val.func().entry);break;
|
||||||
case vm_vec: printf("| vec | <0x%lx> [%lu val]\n",(uint64_t)p,val.vec().elems.size());break;
|
case vm_vec: printf("| vec | <0x%lx> [%lu val]\n",(uint64_t)p,val.vec().size());break;
|
||||||
case vm_hash: printf("| hash | <0x%lx> {%lu val}\n",(uint64_t)p,val.hash().elems.size());break;
|
case vm_hash: printf("| hash | <0x%lx> {%lu val}\n",(uint64_t)p,val.hash().size());break;
|
||||||
case vm_obj: printf("| obj | <0x%lx> obj:0x%lx\n",(uint64_t)p,(uint64_t)val.obj().ptr);break;
|
case vm_obj: printf("| obj | <0x%lx> obj:0x%lx\n",(uint64_t)p,(uint64_t)val.obj().ptr);break;
|
||||||
default: printf("| err | <0x%lx> unknown object\n",(uint64_t)p);break;
|
default: printf("| err | <0x%lx> unknown object\n",(uint64_t)p);break;
|
||||||
}
|
}
|
||||||
|
@ -582,7 +582,7 @@ inline void nasal_vm::opr_counter()
|
||||||
}
|
}
|
||||||
inline void nasal_vm::opr_findex()
|
inline void nasal_vm::opr_findex()
|
||||||
{
|
{
|
||||||
if(++gc.top[0].cnt()>=gc.top[-1].vec().elems.size())
|
if(++gc.top[0].cnt()>=gc.top[-1].vec().size())
|
||||||
{
|
{
|
||||||
pc=imm[pc]-1;
|
pc=imm[pc]-1;
|
||||||
return;
|
return;
|
||||||
|
@ -676,7 +676,7 @@ inline void nasal_vm::opr_callfv()
|
||||||
if(local[-1].type!=vm_func)
|
if(local[-1].type!=vm_func)
|
||||||
die("callfv: must call a function");
|
die("callfv: must call a function");
|
||||||
|
|
||||||
nasal_func& func=local[-1].func();
|
auto& func=local[-1].func();
|
||||||
nasal_ref tmp=local[-1];
|
nasal_ref tmp=local[-1];
|
||||||
local[-1]=gc.funcr;
|
local[-1]=gc.funcr;
|
||||||
gc.funcr=tmp;
|
gc.funcr=tmp;
|
||||||
|
@ -716,7 +716,7 @@ inline void nasal_vm::opr_callfh()
|
||||||
if(gc.top[-1].type!=vm_func)
|
if(gc.top[-1].type!=vm_func)
|
||||||
die("callfh: must call a function");
|
die("callfh: must call a function");
|
||||||
|
|
||||||
nasal_func& func=gc.top[-1].func();
|
auto& func=gc.top[-1].func();
|
||||||
nasal_ref tmp=gc.top[-1];
|
nasal_ref tmp=gc.top[-1];
|
||||||
gc.top[-1]=gc.funcr;
|
gc.top[-1]=gc.funcr;
|
||||||
gc.funcr=tmp;
|
gc.funcr=tmp;
|
||||||
|
|
|
@ -151,4 +151,5 @@ curve2();
|
||||||
curve3();
|
curve3();
|
||||||
curve4();
|
curve4();
|
||||||
curve5();
|
curve5();
|
||||||
curve6();
|
curve6();
|
||||||
|
println("🟩🟥");
|
Loading…
Reference in New Issue