Skip to content

Commit

Permalink
update test/calc.nas & print function of nasal_vec/nasal_hash
Browse files Browse the repository at this point in the history
  • Loading branch information
ValKmjolnir committed Feb 11, 2022
1 parent 3e7ba4d commit 0ccd3c9
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 53 deletions.
22 changes: 6 additions & 16 deletions nasal_gc.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,17 +157,12 @@ nasal_ref* nasal_vec::get_mem(const int index)
void nasal_vec::print()
{
static int depth=0;
if(!elems.size())
if(!elems.size() || depth>8)
{
std::cout<<"[]";
return;
}
if(++depth>16)
{
std::cout<<"[..]";
--depth;
std::cout<<(elems.size()?"[..]":"[]");
return;
}
++depth;
size_t iter=0;
std::cout<<'[';
for(auto& i:elems)
Expand Down Expand Up @@ -219,17 +214,12 @@ nasal_ref* nasal_hash::get_mem(const std::string& key)
void nasal_hash::print()
{
static int depth=0;
if(!elems.size())
{
std::cout<<"{}";
return;
}
if(++depth>16)
if(!elems.size() || depth>8)
{
std::cout<<"{..}";
--depth;
std::cout<<(elems.size()?"{..}":"{}");
return;
}
++depth;
size_t iter=0;
std::cout<<'{';
for(auto& i:elems)
Expand Down
120 changes: 83 additions & 37 deletions test/calc.nas
Original file line number Diff line number Diff line change
@@ -1,50 +1,96 @@
import("lib.nas");
var filename=[
"main.cpp",
"nasal_err.h",
"nasal_ast.h",
"nasal_builtin.h",
"nasal_codegen.h",
"nasal_opt.h",
"nasal_gc.h",
"nasal_import.h",
"nasal_lexer.h",
"nasal_parse.h",
"nasal_vm.h",
"nasal_dbg.h",
"nasal.h"
var source=[
"main.cpp ",
"nasal_err.h ",
"nasal_ast.h ",
"nasal_builtin.h ",
"nasal_codegen.h ",
"nasal_opt.h ",
"nasal_gc.h ",
"nasal_import.h ",
"nasal_lexer.h ",
"nasal_parse.h ",
"nasal_vm.h ",
"nasal_dbg.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 (cnt,len,ch)=(0,size(s),c[0]);
for(var i=0;i<len;i+=1)
cnt+=(s[i]==ch);
return cnt;
}
func(){
var (bytes,line,semi)=(0,0,0);
forindex(var i;filename){
var s=io.fin(filename[i]);
var (line_cnt,semi_cnt)=(count(s,'\n'),count(s,';'));
println(filename[i],space[i],'| ',line_cnt,' \tline | ',semi_cnt,' \tsemi');

var calc=func(codetype,files){
println(codetype);
var (bytes,line,semi,line_cnt,semi_cnt)=(0,0,0,0,0);
forindex(var i;files){
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);
line+=line_cnt;
semi+=semi_cnt;
}
println('total: | ',line,' \tline | ',semi,' \tsemi');
println('bytes: | ',bytes,' bytes| ',int(bytes/1024),' \tkb');
}();
println('total: | ',line,' \tline | ',semi,' \tsemi');
println('bytes: | ',bytes,'\tbytes| ',int(bytes/1024),' \tkb');
}

calc("source code:",source);
calc("lib:",lib);
calc("test file:",testfile);
calc("module:",module);

0 comments on commit 0ccd3c9

Please sign in to comment.