update main.cpp and bug fix

This commit is contained in:
ValKmjolnir 2022-03-20 18:28:45 +08:00
parent e6457651d3
commit 27e25f84ec
7 changed files with 37 additions and 54 deletions

View File

@ -18,8 +18,8 @@ void help()
#endif
<<"nasal <option>\n"
<<"option:\n"
<<" -h, --help | get help.\n"
<<" -v, --version | get version of nasal interpreter.\n\n"
<<" -h, --help | get help.\n"
<<" -v, --version | get version of nasal interpreter.\n\n"
<<"nasal <file>\n"
<<"file:\n"
<<" input file name to execute script file.\n\n"
@ -114,9 +114,7 @@ void execute(const std::string& file,const uint32_t cmd)
int main(int argc,const char* argv[])
{
if(!argc)
return 0;
if(argc==1)
if(argc<=1)
{
logo();
return 0;
@ -134,28 +132,22 @@ int main(int argc,const char* argv[])
err();
return 0;
}
std::unordered_map<std::string,uint32_t> cmdlst={
{"--lex",VM_LEXINFO},{"-l",VM_LEXINFO},
{"--ast",VM_ASTINFO},{"-a",VM_ASTINFO},
{"--code",VM_CODEINFO},{"-c",VM_CODEINFO},
{"--exec",VM_EXEC},{"-e",VM_EXEC},
{"--opcnt",VM_OPCALLNUM|VM_EXEC},{"-o",VM_OPCALLNUM|VM_EXEC},
{"--time",VM_EXECTIME},{"-t",VM_EXECTIME},
{"--detail",VM_DBGINFO|VM_EXEC},{"-d",VM_DBGINFO|VM_EXEC},
{"--optimize",VM_OPTIMIZE},{"-op",VM_OPTIMIZE},
{"--debug",VM_DEBUG},{"-dbg",VM_DEBUG}
};
uint32_t cmd=0;
for(int i=1;i<argc-1;++i)
{
std::string s(argv[i]);
if(s=="--lex" || s=="-l")
cmd|=VM_LEXINFO;
else if(s=="--ast" || s=="-a")
cmd|=VM_ASTINFO;
else if(s=="--code" || s=="-c")
cmd|=VM_CODEINFO;
else if(s=="--exec" || s=="-e")
cmd|=VM_EXEC;
else if(s=="--opcnt" || s=="-o")
cmd|=VM_OPCALLNUM|VM_EXEC;
else if(s=="--time" || s=="-t")
cmd|=VM_EXECTIME;
else if(s=="--detail" || s=="-d")
cmd|=VM_DBGINFO|VM_EXEC;
else if(s=="--optimize" || s=="-op")
cmd|=VM_OPTIMIZE;
else if(s=="--debug" || s=="-dbg")
cmd|=VM_DEBUG;
if(cmdlst.count(argv[i]))
cmd|=cmdlst[argv[i]];
else
err();
}

View File

@ -116,10 +116,10 @@ const char* ast_name[]=
"if",
"elsif",
"else",
"multi_id",
"multi_scalar",
"multi-id",
"multi-scalar",
"def",
"multi_assign",
"multi-assign",
"continue",
"break",
"return",

View File

@ -769,32 +769,18 @@ void nasal_codegen::for_gen(const nasal_ast& ast)
case ast_null:break;
case ast_def:def_gen(ast[0]);break;
case ast_multi_assign:multi_assign_gen(ast[0]);break;
case ast_nil:
case ast_num:
case ast_str:
case ast_func:break;
case ast_vec:
case ast_hash:
case ast_nil:case ast_num:case ast_str:case ast_func:break;
case ast_vec:case ast_hash:
case ast_call:
case ast_equal:
case ast_addeq:
case ast_subeq:
case ast_multeq:
case ast_diveq:
case ast_lnkeq:
case ast_neg:
case ast_not:
case ast_add:
case ast_sub:
case ast_mult:
case ast_div:
case ast_equal:case ast_addeq:case ast_subeq:
case ast_multeq:case ast_diveq:case ast_lnkeq:
case ast_neg:case ast_not:
case ast_add:case ast_sub:
case ast_mult:case ast_div:
case ast_link:
case ast_cmpeq:
case ast_neq:
case ast_leq:
case ast_less:
case ast_geq:
case ast_grt:
case ast_cmpeq:case ast_neq:
case ast_leq:case ast_less:
case ast_geq:case ast_grt:
case ast_trino:
calc_gen(ast[0]);
gen(op_pop,0,ast[0].line());

View File

@ -57,7 +57,7 @@ struct nasal_ref
double num;
nasal_ref* addr;
nasal_val* gcobj;
}value;
} value;
// vm_none/vm_nil
nasal_ref(const uint8_t t=vm_none):type(t){}

View File

@ -143,6 +143,8 @@ var curve6=func(){
print('\n');
}
}
if(os.platform()=="windows")
system("chcp 65001");
trans_ttf("just for test");
trans_ttf(" ValKmjolnir ");
trans_ttf("just for fun");
@ -151,5 +153,4 @@ curve2();
curve3();
curve4();
curve5();
curve6();
println("🟩🟥");
curve6();

View File

@ -61,5 +61,7 @@ var bfs=func(begin,end)
return;
}
if(os.platform()=="windows")
system("chcp 65001");
print("\ec");
bfs([0,0],[9,19]);

View File

@ -36,6 +36,8 @@ var prt=func()
func()
{
if(os.platform()=="windows")
system("chcp 65001");
print("\ec");
rand(time(0));
map=new_map();