update
This commit is contained in:
parent
577546763f
commit
e41f728589
16
main.cpp
16
main.cpp
|
@ -78,12 +78,12 @@ void execute(const std::string& file,const uint16_t cmd)
|
|||
if(parse.err())
|
||||
die("parse",file);
|
||||
if(cmd&VM_ASTINFO)
|
||||
parse.get_root().print(0);
|
||||
parse.ast().print(0);
|
||||
// first used file is itself
|
||||
import.link(parse.get_root(),file);
|
||||
import.link(parse.ast(),file);
|
||||
if(import.err())
|
||||
die("import",file);
|
||||
codegen.compile(import.get_root(),import.get_file());
|
||||
codegen.compile(import.ast(),import.get_file());
|
||||
if(codegen.err())
|
||||
die("code",file);
|
||||
if(cmd&VM_CODEINFO)
|
||||
|
@ -107,16 +107,15 @@ void execute(const std::string& file,const uint16_t cmd)
|
|||
|
||||
int main(int argc,const char* argv[])
|
||||
{
|
||||
std::string filename;
|
||||
uint16_t cmd=0;
|
||||
if(argc==2 && (!strcmp(argv[1],"-v") || !strcmp(argv[1],"--version")))
|
||||
logo();
|
||||
else if(argc==2 && (!strcmp(argv[1],"-h") || !strcmp(argv[1],"--help")))
|
||||
help_cmd();
|
||||
else if(argc==2 && argv[1][0]!='-')
|
||||
cmd|=VM_EXEC;
|
||||
execute(argv[1],VM_EXEC);
|
||||
else if(argc>=3)
|
||||
{
|
||||
uint16_t cmd=0;
|
||||
for(int i=1;i<argc-1;++i)
|
||||
{
|
||||
std::string s(argv[i]);
|
||||
|
@ -133,12 +132,9 @@ int main(int argc,const char* argv[])
|
|||
else
|
||||
cmderr();
|
||||
}
|
||||
execute(argv[argc-1],cmd);
|
||||
}
|
||||
else
|
||||
cmderr();
|
||||
if(argv[argc-1][0]=='-')
|
||||
cmderr();
|
||||
if(cmd)
|
||||
execute(argv[argc-1],cmd);
|
||||
return 0;
|
||||
}
|
|
@ -18,14 +18,14 @@ private:
|
|||
public:
|
||||
uint32_t err(){return error;}
|
||||
void link(nasal_ast&,const std::string&);
|
||||
const nasal_ast& get_root(){return import_ast;}
|
||||
const nasal_ast& ast(){return import_ast;}
|
||||
const std::vector<std::string>& get_file(){return filename_table;}
|
||||
};
|
||||
|
||||
void nasal_import::die(const std::string& filename,const char* error_stage)
|
||||
void nasal_import::die(const std::string& file,const char* stage)
|
||||
{
|
||||
++error;
|
||||
std::cout<<"[import] in <\""<<filename<<"\">: error(s) occurred in "<<error_stage<<".\n";
|
||||
std::cout<<"[import] in <\""<<file<<"\">: error(s) occurred in "<<stage<<".\n";
|
||||
}
|
||||
|
||||
bool nasal_import::check_import(const nasal_ast& node)
|
||||
|
@ -95,7 +95,7 @@ nasal_ast nasal_import::file_import(nasal_ast& node)
|
|||
die(filename,"parser");
|
||||
return tmp;
|
||||
}
|
||||
tmp=std::move(import_par.get_root());
|
||||
tmp=std::move(import_par.ast());
|
||||
// check if tmp has 'import'
|
||||
return load(tmp,filename_table.size()-1);
|
||||
}
|
||||
|
|
|
@ -127,13 +127,16 @@ void nasal_lexer::open(const std::string& filename)
|
|||
std::cout<<"[lexer] cannot open file <"<<filename<<">.\n";
|
||||
return;
|
||||
}
|
||||
while(!fin.eof())
|
||||
{
|
||||
char c=fin.get();
|
||||
if(fin.eof())
|
||||
break;
|
||||
res+=c;
|
||||
}
|
||||
std::stringstream ss;
|
||||
ss<<fin.rdbuf();
|
||||
res=ss.str();
|
||||
// while(!fin.eof())
|
||||
// {
|
||||
// char c=fin.get();
|
||||
// if(fin.eof())
|
||||
// break;
|
||||
// res+=c;
|
||||
// }
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -101,7 +101,7 @@ private:
|
|||
public:
|
||||
uint32_t err(){return error;}
|
||||
void compile(const std::vector<token>&);
|
||||
nasal_ast& get_root(){return root;}
|
||||
nasal_ast& ast(){return root;}
|
||||
};
|
||||
void nasal_parse::compile(const std::vector<token>& toks)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue