nothing changed

This commit is contained in:
Li Haokun 2021-08-24 19:34:52 +08:00 committed by GitHub
parent ef9b781961
commit 385f0af17e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 12 deletions

View File

@ -46,6 +46,7 @@ void logo()
void die(const char* stage,std::string& filename)
{
std::cout<<"["<<stage<<"] in <"<<filename<<">: error(s) occurred,stop.\n";
exit(1);
return;
}
@ -59,10 +60,7 @@ void execute(std::string& file,std::string& command)
lexer.openfile(file);
lexer.scanner();
if(lexer.get_error())
{
die("lexer",file);
return;
}
if(command=="--lex" || command=="-l")
{
lexer.print_token();
@ -70,10 +68,7 @@ void execute(std::string& file,std::string& command)
}
parse.main_process(lexer.get_token_list());
if(parse.get_error())
{
die("parse",file);
return;
}
if(command=="--ast" || command=="-a")
{
parse.get_root().print_ast(0);
@ -82,16 +77,10 @@ void execute(std::string& file,std::string& command)
// first used file is itself
import.link(parse.get_root(),file);
if(import.get_error())
{
die("import",file);
return;
}
codegen.main_progress(import.get_root(),import.get_file());
if(codegen.get_error())
{
die("code",file);
return;
}
if(command=="--code" || command=="-c")
{
codegen.print_byte_code();
@ -149,6 +138,7 @@ int main(int argc,const char* argv[])
std::cout
<<"invalid argument(s).\n"
<<"use nasal -h to get help.\n";
exit(1);
}
return 0;
}

39
test/trait.nas Normal file
View File

@ -0,0 +1,39 @@
import("lib.nas");
var trait={
get:func{return me.val;},
set:func(x){me.val=x;}
};
var class={
new:func(){
return {
val:nil,
parents:[trait]
};
}
};
var class2={
new:func(){
return {
val:nil,
parents:[trait],
set:func(x){me.val=typeof(x);}
};
}
};
var class_obj=[];
for(var i=0;i<10;i+=1){
append(class_obj,class.new());
class_obj[i].set(i);
}
for(var i=0;i<10;i+=1){
append(class_obj,class2.new());
class_obj[10+i].set(i);
}
foreach(var object;class_obj){
println(object.get(),' ',keys(object));
}