visual update
This commit is contained in:
parent
e54ef9620f
commit
f26719e1d3
|
@ -419,8 +419,8 @@ nasal_ref builtin_size(nasal_ref* local,nasal_gc& gc)
|
|||
{
|
||||
case vm_num: num=val.num(); break;
|
||||
case vm_str: num=val.str().length();break;
|
||||
case vm_vec: num=val.vec().elems.size(); break;
|
||||
case vm_hash: num=val.hash().elems.size();break;
|
||||
case vm_vec: num=val.vec().size(); break;
|
||||
case vm_hash: num=val.hash().size(); break;
|
||||
}
|
||||
return {vm_num,num};
|
||||
}
|
||||
|
|
|
@ -151,9 +151,7 @@ void nasal_dbg::interact()
|
|||
else
|
||||
err();
|
||||
}
|
||||
else if(res.size()==3)
|
||||
{
|
||||
if(res[0]=="bk" || res[0]=="break")
|
||||
else if(res.size()==3 && (res[0]=="bk" || res[0]=="break"))
|
||||
{
|
||||
bk_fidx=get_fileindex(res[1]);
|
||||
if(bk_fidx==65535)
|
||||
|
@ -170,9 +168,6 @@ void nasal_dbg::interact()
|
|||
else
|
||||
err();
|
||||
}
|
||||
else
|
||||
err();
|
||||
}
|
||||
}
|
||||
|
||||
void nasal_dbg::run(
|
||||
|
|
31
nasal_gc.h
31
nasal_gc.h
|
@ -98,22 +98,24 @@ struct nasal_ref
|
|||
|
||||
struct nasal_vec
|
||||
{
|
||||
uint32_t depth;
|
||||
bool printed;
|
||||
std::vector<nasal_ref> elems;
|
||||
|
||||
nasal_vec():depth(0){}
|
||||
nasal_vec():printed(false){}
|
||||
void print();
|
||||
size_t size(){return elems.size();}
|
||||
nasal_ref get_val(const int);
|
||||
nasal_ref* get_mem(const int);
|
||||
};
|
||||
|
||||
struct nasal_hash
|
||||
{
|
||||
uint32_t depth;
|
||||
bool printed;
|
||||
std::unordered_map<std::string,nasal_ref> elems;
|
||||
|
||||
nasal_hash():depth(0){}
|
||||
nasal_hash():printed(false){}
|
||||
void print();
|
||||
size_t size(){return elems.size();}
|
||||
nasal_ref get_val(const std::string&);
|
||||
nasal_ref* get_mem(const std::string&);
|
||||
};
|
||||
|
@ -140,7 +142,7 @@ struct nasal_upval
|
|||
std::vector<nasal_ref> elems;
|
||||
|
||||
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;}
|
||||
};
|
||||
|
||||
|
@ -198,12 +200,12 @@ nasal_ref* nasal_vec::get_mem(const int index)
|
|||
}
|
||||
void nasal_vec::print()
|
||||
{
|
||||
if(!elems.size() || depth>3)
|
||||
if(!elems.size() || printed)
|
||||
{
|
||||
std::cout<<(elems.size()?"[..]":"[]");
|
||||
return;
|
||||
}
|
||||
++depth;
|
||||
printed=true;
|
||||
size_t iter=0;
|
||||
std::cout<<'[';
|
||||
for(auto& i:elems)
|
||||
|
@ -211,7 +213,7 @@ void nasal_vec::print()
|
|||
i.print();
|
||||
std::cout<<",]"[(++iter)==elems.size()];
|
||||
}
|
||||
--depth;
|
||||
printed=false;
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
if(!elems.size() || depth>3)
|
||||
if(!elems.size() || printed)
|
||||
{
|
||||
std::cout<<(elems.size()?"{..}":"{}");
|
||||
return;
|
||||
}
|
||||
++depth;
|
||||
printed=true;
|
||||
size_t iter=0;
|
||||
std::cout<<'{';
|
||||
for(auto& i:elems)
|
||||
|
@ -268,7 +270,7 @@ void nasal_hash::print()
|
|||
i.second.print();
|
||||
std::cout<<",}"[(++iter)==elems.size()];
|
||||
}
|
||||
--depth;
|
||||
printed=false;
|
||||
}
|
||||
|
||||
void nasal_func::clear()
|
||||
|
@ -279,13 +281,6 @@ void nasal_func::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)
|
||||
{
|
||||
mark=GC_COLLECTED;
|
||||
|
|
|
@ -37,6 +37,14 @@ void calc_const(nasal_ast& root)
|
|||
auto& vec=root.child();
|
||||
for(auto& i:vec)
|
||||
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)
|
||||
return;
|
||||
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_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_vec: printf("| vec | <0x%lx> [%lu val]\n",(uint64_t)p,val.vec().elems.size());break;
|
||||
case vm_hash: printf("| hash | <0x%lx> {%lu val}\n",(uint64_t)p,val.hash().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().size());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;
|
||||
}
|
||||
|
@ -582,7 +582,7 @@ inline void nasal_vm::opr_counter()
|
|||
}
|
||||
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;
|
||||
return;
|
||||
|
@ -676,7 +676,7 @@ inline void nasal_vm::opr_callfv()
|
|||
if(local[-1].type!=vm_func)
|
||||
die("callfv: must call a function");
|
||||
|
||||
nasal_func& func=local[-1].func();
|
||||
auto& func=local[-1].func();
|
||||
nasal_ref tmp=local[-1];
|
||||
local[-1]=gc.funcr;
|
||||
gc.funcr=tmp;
|
||||
|
@ -716,7 +716,7 @@ inline void nasal_vm::opr_callfh()
|
|||
if(gc.top[-1].type!=vm_func)
|
||||
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];
|
||||
gc.top[-1]=gc.funcr;
|
||||
gc.funcr=tmp;
|
||||
|
|
|
@ -152,3 +152,4 @@ curve3();
|
|||
curve4();
|
||||
curve5();
|
||||
curve6();
|
||||
println("🟩🟥");
|
Loading…
Reference in New Issue