diff --git a/main.cpp b/main.cpp index 860058e..8f21d52 100644 --- a/main.cpp +++ b/main.cpp @@ -46,6 +46,7 @@ void logo() void die(const char* stage,std::string& filename) { std::cout<<"["<: 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; } \ No newline at end of file diff --git a/test/trait.nas b/test/trait.nas new file mode 100644 index 0000000..0f00688 --- /dev/null +++ b/test/trait.nas @@ -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)); +} \ No newline at end of file