diff --git a/nasal_gc.h b/nasal_gc.h index 2602347..d9a239c 100644 --- a/nasal_gc.h +++ b/nasal_gc.h @@ -70,6 +70,7 @@ struct nasal_ref // number and string can be translated to each other double to_number(); std::string to_string(); + void print(); inline uint32_t ret (); inline int64_t& cnt (); inline double& num (); @@ -171,17 +172,7 @@ void nasal_vec::print() std::cout<<'['; for(auto& i:elems) { - switch(i.type) - { - case vm_none: std::cout<<"undefined"; break; - case vm_nil: std::cout<<"nil"; break; - case vm_num: std::cout<print(); break; - case vm_hash: i.hash()->print(); break; - case vm_func: std::cout<<"func(..){..}";break; - case vm_obj: std::cout<<""; break; - } + i.print(); std::cout<<",]"[(++iter)==elems.size()]; } --depth; @@ -244,18 +235,7 @@ void nasal_hash::print() for(auto& i:elems) { std::cout<print(); break; - case vm_hash: tmp.hash()->print(); break; - case vm_func: std::cout<<"func(..){..}";break; - case vm_obj: std::cout<<""; break; - } + i.second.print(); std::cout<<",}"[(++iter)==elems.size()]; } --depth; @@ -307,6 +287,20 @@ std::string nasal_ref::to_string() return std::to_string(num()); return ""; } +void nasal_ref::print() +{ + switch(type) + { + case vm_none: std::cout<<"undefined"; break; + case vm_nil: std::cout<<"nil"; break; + case vm_num: std::cout<str());break; + case vm_vec: this->vec()->print(); break; + case vm_hash: this->hash()->print(); break; + case vm_func: std::cout<<"func(..){..}";break; + case vm_obj: std::cout<<""; break; + } +} inline uint32_t nasal_ref::ret (){return value.ret; } inline int64_t& nasal_ref::cnt (){return value.cnt; } inline double& nasal_ref::num (){return value.num; }