update test/calc.nas & print function of nasal_vec/nasal_hash
This commit is contained in:
parent
3e7ba4d774
commit
0ccd3c9bd0
22
nasal_gc.h
22
nasal_gc.h
|
@ -157,17 +157,12 @@ nasal_ref* nasal_vec::get_mem(const int index)
|
||||||
void nasal_vec::print()
|
void nasal_vec::print()
|
||||||
{
|
{
|
||||||
static int depth=0;
|
static int depth=0;
|
||||||
if(!elems.size())
|
if(!elems.size() || depth>8)
|
||||||
{
|
{
|
||||||
std::cout<<"[]";
|
std::cout<<(elems.size()?"[..]":"[]");
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(++depth>16)
|
|
||||||
{
|
|
||||||
std::cout<<"[..]";
|
|
||||||
--depth;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
++depth;
|
||||||
size_t iter=0;
|
size_t iter=0;
|
||||||
std::cout<<'[';
|
std::cout<<'[';
|
||||||
for(auto& i:elems)
|
for(auto& i:elems)
|
||||||
|
@ -219,17 +214,12 @@ nasal_ref* nasal_hash::get_mem(const std::string& key)
|
||||||
void nasal_hash::print()
|
void nasal_hash::print()
|
||||||
{
|
{
|
||||||
static int depth=0;
|
static int depth=0;
|
||||||
if(!elems.size())
|
if(!elems.size() || depth>8)
|
||||||
{
|
{
|
||||||
std::cout<<"{}";
|
std::cout<<(elems.size()?"{..}":"{}");
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(++depth>16)
|
|
||||||
{
|
|
||||||
std::cout<<"{..}";
|
|
||||||
--depth;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
++depth;
|
||||||
size_t iter=0;
|
size_t iter=0;
|
||||||
std::cout<<'{';
|
std::cout<<'{';
|
||||||
for(auto& i:elems)
|
for(auto& i:elems)
|
||||||
|
|
120
test/calc.nas
120
test/calc.nas
|
@ -1,50 +1,96 @@
|
||||||
import("lib.nas");
|
import("lib.nas");
|
||||||
var filename=[
|
var source=[
|
||||||
"main.cpp",
|
"main.cpp ",
|
||||||
"nasal_err.h",
|
"nasal_err.h ",
|
||||||
"nasal_ast.h",
|
"nasal_ast.h ",
|
||||||
"nasal_builtin.h",
|
"nasal_builtin.h ",
|
||||||
"nasal_codegen.h",
|
"nasal_codegen.h ",
|
||||||
"nasal_opt.h",
|
"nasal_opt.h ",
|
||||||
"nasal_gc.h",
|
"nasal_gc.h ",
|
||||||
"nasal_import.h",
|
"nasal_import.h ",
|
||||||
"nasal_lexer.h",
|
"nasal_lexer.h ",
|
||||||
"nasal_parse.h",
|
"nasal_parse.h ",
|
||||||
"nasal_vm.h",
|
"nasal_vm.h ",
|
||||||
"nasal_dbg.h",
|
"nasal_dbg.h ",
|
||||||
"nasal.h"
|
"nasal.h "
|
||||||
];
|
];
|
||||||
var space=[
|
|
||||||
" ",
|
var lib=[
|
||||||
" ",
|
"stl/lib.nas ",
|
||||||
" ",
|
"stl/list.nas ",
|
||||||
"",
|
"stl/queue.nas ",
|
||||||
"",
|
"stl/result.nas ",
|
||||||
" ",
|
"stl/sort.nas ",
|
||||||
" ",
|
"stl/stack.nas "
|
||||||
" ",
|
|
||||||
" ",
|
|
||||||
" ",
|
|
||||||
" ",
|
|
||||||
" ",
|
|
||||||
" "
|
|
||||||
];
|
];
|
||||||
|
|
||||||
|
var testfile=[
|
||||||
|
"test/ascii-art.nas ",
|
||||||
|
"test/auto_crash.nas ",
|
||||||
|
"test/bf.nas ",
|
||||||
|
"test/bfconvertor.nas ",
|
||||||
|
"test/bfs.nas ",
|
||||||
|
"test/bigloop.nas ",
|
||||||
|
"test/bp.nas ",
|
||||||
|
"test/calc.nas ",
|
||||||
|
"test/choice.nas ",
|
||||||
|
"test/class.nas ",
|
||||||
|
"test/exception.nas ",
|
||||||
|
"test/fib.nas ",
|
||||||
|
"test/filesystem.nas ",
|
||||||
|
"test/hexdump.nas ",
|
||||||
|
"test/json.nas ",
|
||||||
|
"test/leetcode1319.nas ",
|
||||||
|
"test/lexer.nas ",
|
||||||
|
"test/life.nas ",
|
||||||
|
"test/loop.nas ",
|
||||||
|
"test/mandel.nas ",
|
||||||
|
"test/mandelbrot.nas ",
|
||||||
|
"test/module_test.nas ",
|
||||||
|
"test/nasal_test.nas ",
|
||||||
|
"test/pi.nas ",
|
||||||
|
"test/prime.nas ",
|
||||||
|
"test/props.nas ",
|
||||||
|
"test/quick_sort.nas ",
|
||||||
|
"test/scalar.nas ",
|
||||||
|
"test/trait.nas ",
|
||||||
|
"test/turingmachine.nas",
|
||||||
|
"test/ycombinator.nas "
|
||||||
|
];
|
||||||
|
|
||||||
|
var module=[
|
||||||
|
"module/fib.cpp "
|
||||||
|
];
|
||||||
|
|
||||||
|
var getname=func(s){
|
||||||
|
var (len,ch)=(size(s),' '[0]);
|
||||||
|
for(var i=0;i<len and s[i]!=ch;i+=1);
|
||||||
|
return substr(s,0,i);
|
||||||
|
}
|
||||||
|
|
||||||
var count=func(s,c){
|
var count=func(s,c){
|
||||||
var (cnt,len,ch)=(0,size(s),c[0]);
|
var (cnt,len,ch)=(0,size(s),c[0]);
|
||||||
for(var i=0;i<len;i+=1)
|
for(var i=0;i<len;i+=1)
|
||||||
cnt+=(s[i]==ch);
|
cnt+=(s[i]==ch);
|
||||||
return cnt;
|
return cnt;
|
||||||
}
|
}
|
||||||
func(){
|
|
||||||
var (bytes,line,semi)=(0,0,0);
|
var calc=func(codetype,files){
|
||||||
forindex(var i;filename){
|
println(codetype);
|
||||||
var s=io.fin(filename[i]);
|
var (bytes,line,semi,line_cnt,semi_cnt)=(0,0,0,0,0);
|
||||||
var (line_cnt,semi_cnt)=(count(s,'\n'),count(s,';'));
|
forindex(var i;files){
|
||||||
println(filename[i],space[i],'| ',line_cnt,' \tline | ',semi_cnt,' \tsemi');
|
var s=io.fin(getname(files[i]));
|
||||||
|
(line_cnt,semi_cnt)=(count(s,'\n'),count(s,';'));
|
||||||
|
println(files[i],'| ',line_cnt,' \tline | ',semi_cnt,' \tsemi');
|
||||||
bytes+=size(s);
|
bytes+=size(s);
|
||||||
line+=line_cnt;
|
line+=line_cnt;
|
||||||
semi+=semi_cnt;
|
semi+=semi_cnt;
|
||||||
}
|
}
|
||||||
println('total: | ',line,' \tline | ',semi,' \tsemi');
|
println('total: | ',line,' \tline | ',semi,' \tsemi');
|
||||||
println('bytes: | ',bytes,' bytes| ',int(bytes/1024),' \tkb');
|
println('bytes: | ',bytes,'\tbytes| ',int(bytes/1024),' \tkb');
|
||||||
}();
|
}
|
||||||
|
|
||||||
|
calc("source code:",source);
|
||||||
|
calc("lib:",lib);
|
||||||
|
calc("test file:",testfile);
|
||||||
|
calc("module:",module);
|
Loading…
Reference in New Issue