diff --git a/lib.nas b/lib.nas index 44ae13e..77cbf0f 100644 --- a/lib.nas +++ b/lib.nas @@ -202,9 +202,7 @@ var values=func(hash){ # println has the same function as print. # but it will output a '\n' after using print. var println=func(elems...){ - __builtin_print(elems); - elems=['\n']; - return __builtin_print(elems); + return __builtin_println(elems); } var isfunc=func(f){ diff --git a/makefile b/makefile index 30cdd01..09d21d4 100644 --- a/makefile +++ b/makefile @@ -34,6 +34,7 @@ test:nasal -@ ./nasal -op -t -d -o test/md5compare.nas -@ ./nasal -op -d test/module_test.nas @ ./nasal -op -e test/nasal_test.nas + @ ./nasal -op -c test/occupation.nas @ ./nasal -op -t -d test/pi.nas @ ./nasal -op -t -d test/prime.nas @ ./nasal -op -e test/qrcode.nas diff --git a/nasal_builtin.h b/nasal_builtin.h index 091b37f..937d4b6 100644 --- a/nasal_builtin.h +++ b/nasal_builtin.h @@ -10,6 +10,7 @@ // to add new builtin function, declare it here and write the definition below #define nas_native(name) nasal_ref name(nasal_ref*,nasal_gc&) nas_native(builtin_print); +nas_native(builtin_println); nas_native(builtin_abort); nas_native(builtin_append); nas_native(builtin_setsize); @@ -114,6 +115,7 @@ struct } builtin[]= { {"__builtin_print", builtin_print }, + {"__builtin_println", builtin_println }, {"__builtin_abort", builtin_abort }, {"__builtin_append", builtin_append }, {"__builtin_setsize", builtin_setsize }, @@ -205,13 +207,9 @@ struct {nullptr, nullptr } }; -nasal_ref builtin_print(nasal_ref* local,nasal_gc& gc) +inline void print_core(std::vector& elems) { - // get arguments - // local[0] is reserved for 'me' - nasal_ref vec=local[1]; - // main process - for(auto& i:vec.vec().elems) + for(auto& i:elems) switch(i.type) { case vm_none: std::cout<<"null"; break; @@ -224,10 +222,25 @@ nasal_ref builtin_print(nasal_ref* local,nasal_gc& gc) case vm_obj: std::cout<<""; break; case vm_co: std::cout<<""; break; } +} +nasal_ref builtin_print(nasal_ref* local,nasal_gc& gc) +{ + // get arguments + // local[0] is reserved for 'me' + nasal_ref vec=local[1]; + // main process + print_core(vec.vec().elems); std::cout<90?"\e[91m":"\e[32m",cpu_occ,"\e[0m"); + println("Memory total(GB) : \e[36m",mem.MemTotal/1024/1024,"\e[0m"); + println("Memory free(GB) : \e[36m",mem.MemFree/1024/1024,"\e[0m"); + println("Memory occupation(%): ",mem_occ>30?"\e[91m":"\e[32m",mem_occ,"\e[0m"); + } +}(); \ No newline at end of file