Nasal-Interpreter/test/calc.nas

115 lines
2.8 KiB
Plaintext
Raw Normal View History

var source=[
"main.cpp ",
"nasal_ast.h ",
"nasal_builtin.h ",
"nasal_codegen.h ",
"nasal_dbg.h ",
"nasal_err.h ",
"nasal_gc.h ",
"nasal_import.h ",
"nasal_lexer.h ",
"nasal_opt.h ",
"nasal_parse.h ",
"nasal_vm.h ",
"nasal.h "
2022-01-16 22:48:00 +08:00
];
var lib=[
"fg_env.nas ",
"file.nas ",
"lib.nas ",
"list.nas ",
"log.nas ",
"module.nas ",
"process_bar.nas ",
"queue.nas ",
"result.nas ",
"sort.nas ",
"stack.nas "
2022-01-16 22:48:00 +08:00
];
var testfile=[
"ascii-art.nas ",
"auto_crash.nas ",
"bf.nas ",
"bfcolored.nas ",
"bfconvertor.nas ",
"bfs.nas ",
"bigloop.nas ",
"bp.nas ",
"calc.nas ",
"choice.nas ",
"class.nas ",
"coroutine.nas ",
"diff.nas ",
"exception.nas ",
"fib.nas ",
"filesystem.nas ",
"hexdump.nas ",
"httptest.nas ",
"json.nas ",
"leetcode1319.nas ",
"lexer.nas ",
"life.nas ",
"loop.nas ",
"mandel.nas ",
"mandelbrot.nas ",
"md5.nas ",
"md5compare.nas ",
"module_test.nas ",
"nasal_test.nas ",
"occupation.nas ",
"pi.nas ",
"prime.nas ",
"qrcode.nas ",
"quick_sort.nas ",
"scalar.nas ",
"snake.nas ",
"tetris.nas ",
"trait.nas ",
"turingmachine.nas",
"utf8chk.nas ",
"wavecollapse.nas ",
"ycombinator.nas "
];
var module=[
"fib.cpp ",
"keyboard.cpp ",
"nasocket.cpp ",
"libfib.nas ",
"libkey.nas ",
"libsock.nas "
];
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);
}
2022-01-16 22:48:00 +08:00
var count=func(s,c){
var (cnt,len,ch)=(0,size(s),c[0]);
for(var i=0;i<len;i+=1)
2022-01-16 22:48:00 +08:00
cnt+=(s[i]==ch);
return cnt;
}
var calc=func(codetype,files,path=""){
println(codetype);
var (bytes,line,semi,line_cnt,semi_cnt)=(0,0,0,0,0);
forindex(var i;files){
var s=io.fin(getname(path~files[i]));
(line_cnt,semi_cnt)=(count(s,'\n'),count(s,';'));
println(files[i],'| ',line_cnt,'\tline | ',semi_cnt,' \tsemi');
2022-01-16 22:48:00 +08:00
bytes+=size(s);
line+=line_cnt;
semi+=semi_cnt;
}
println('total: | ',line,'\tline | ',semi,' \tsemi');
println(' | ',int(bytes/1024),'\tkb');
return int(bytes/1024);
}
var all=calc("source code:",source)+calc("lib:",lib,"stl/")+calc("test file:",testfile,"test/")+calc("module:",module,"module/");
println('\ntotal: | ',all,'\tkb');