update main.cpp and bug fix
This commit is contained in:
parent
e6457651d3
commit
27e25f84ec
40
main.cpp
40
main.cpp
|
@ -18,8 +18,8 @@ void help()
|
||||||
#endif
|
#endif
|
||||||
<<"nasal <option>\n"
|
<<"nasal <option>\n"
|
||||||
<<"option:\n"
|
<<"option:\n"
|
||||||
<<" -h, --help | get help.\n"
|
<<" -h, --help | get help.\n"
|
||||||
<<" -v, --version | get version of nasal interpreter.\n\n"
|
<<" -v, --version | get version of nasal interpreter.\n\n"
|
||||||
<<"nasal <file>\n"
|
<<"nasal <file>\n"
|
||||||
<<"file:\n"
|
<<"file:\n"
|
||||||
<<" input file name to execute script file.\n\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[])
|
int main(int argc,const char* argv[])
|
||||||
{
|
{
|
||||||
if(!argc)
|
if(argc<=1)
|
||||||
return 0;
|
|
||||||
if(argc==1)
|
|
||||||
{
|
{
|
||||||
logo();
|
logo();
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -134,28 +132,22 @@ int main(int argc,const char* argv[])
|
||||||
err();
|
err();
|
||||||
return 0;
|
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;
|
uint32_t cmd=0;
|
||||||
for(int i=1;i<argc-1;++i)
|
for(int i=1;i<argc-1;++i)
|
||||||
{
|
{
|
||||||
std::string s(argv[i]);
|
if(cmdlst.count(argv[i]))
|
||||||
if(s=="--lex" || s=="-l")
|
cmd|=cmdlst[argv[i]];
|
||||||
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;
|
|
||||||
else
|
else
|
||||||
err();
|
err();
|
||||||
}
|
}
|
||||||
|
|
|
@ -116,10 +116,10 @@ const char* ast_name[]=
|
||||||
"if",
|
"if",
|
||||||
"elsif",
|
"elsif",
|
||||||
"else",
|
"else",
|
||||||
"multi_id",
|
"multi-id",
|
||||||
"multi_scalar",
|
"multi-scalar",
|
||||||
"def",
|
"def",
|
||||||
"multi_assign",
|
"multi-assign",
|
||||||
"continue",
|
"continue",
|
||||||
"break",
|
"break",
|
||||||
"return",
|
"return",
|
||||||
|
|
|
@ -769,32 +769,18 @@ void nasal_codegen::for_gen(const nasal_ast& ast)
|
||||||
case ast_null:break;
|
case ast_null:break;
|
||||||
case ast_def:def_gen(ast[0]);break;
|
case ast_def:def_gen(ast[0]);break;
|
||||||
case ast_multi_assign:multi_assign_gen(ast[0]);break;
|
case ast_multi_assign:multi_assign_gen(ast[0]);break;
|
||||||
case ast_nil:
|
case ast_nil:case ast_num:case ast_str:case ast_func:break;
|
||||||
case ast_num:
|
case ast_vec:case ast_hash:
|
||||||
case ast_str:
|
|
||||||
case ast_func:break;
|
|
||||||
case ast_vec:
|
|
||||||
case ast_hash:
|
|
||||||
case ast_call:
|
case ast_call:
|
||||||
case ast_equal:
|
case ast_equal:case ast_addeq:case ast_subeq:
|
||||||
case ast_addeq:
|
case ast_multeq:case ast_diveq:case ast_lnkeq:
|
||||||
case ast_subeq:
|
case ast_neg:case ast_not:
|
||||||
case ast_multeq:
|
case ast_add:case ast_sub:
|
||||||
case ast_diveq:
|
case ast_mult:case ast_div:
|
||||||
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_link:
|
||||||
case ast_cmpeq:
|
case ast_cmpeq:case ast_neq:
|
||||||
case ast_neq:
|
case ast_leq:case ast_less:
|
||||||
case ast_leq:
|
case ast_geq:case ast_grt:
|
||||||
case ast_less:
|
|
||||||
case ast_geq:
|
|
||||||
case ast_grt:
|
|
||||||
case ast_trino:
|
case ast_trino:
|
||||||
calc_gen(ast[0]);
|
calc_gen(ast[0]);
|
||||||
gen(op_pop,0,ast[0].line());
|
gen(op_pop,0,ast[0].line());
|
||||||
|
|
|
@ -57,7 +57,7 @@ struct nasal_ref
|
||||||
double num;
|
double num;
|
||||||
nasal_ref* addr;
|
nasal_ref* addr;
|
||||||
nasal_val* gcobj;
|
nasal_val* gcobj;
|
||||||
}value;
|
} value;
|
||||||
|
|
||||||
// vm_none/vm_nil
|
// vm_none/vm_nil
|
||||||
nasal_ref(const uint8_t t=vm_none):type(t){}
|
nasal_ref(const uint8_t t=vm_none):type(t){}
|
||||||
|
|
|
@ -143,6 +143,8 @@ var curve6=func(){
|
||||||
print('\n');
|
print('\n');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(os.platform()=="windows")
|
||||||
|
system("chcp 65001");
|
||||||
trans_ttf("just for test");
|
trans_ttf("just for test");
|
||||||
trans_ttf(" ValKmjolnir ");
|
trans_ttf(" ValKmjolnir ");
|
||||||
trans_ttf("just for fun");
|
trans_ttf("just for fun");
|
||||||
|
@ -151,5 +153,4 @@ curve2();
|
||||||
curve3();
|
curve3();
|
||||||
curve4();
|
curve4();
|
||||||
curve5();
|
curve5();
|
||||||
curve6();
|
curve6();
|
||||||
println("🟩🟥");
|
|
|
@ -61,5 +61,7 @@ var bfs=func(begin,end)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(os.platform()=="windows")
|
||||||
|
system("chcp 65001");
|
||||||
print("\ec");
|
print("\ec");
|
||||||
bfs([0,0],[9,19]);
|
bfs([0,0],[9,19]);
|
|
@ -36,6 +36,8 @@ var prt=func()
|
||||||
|
|
||||||
func()
|
func()
|
||||||
{
|
{
|
||||||
|
if(os.platform()=="windows")
|
||||||
|
system("chcp 65001");
|
||||||
print("\ec");
|
print("\ec");
|
||||||
rand(time(0));
|
rand(time(0));
|
||||||
map=new_map();
|
map=new_map();
|
||||||
|
|
Loading…
Reference in New Issue