diff --git a/nasal.ebnf b/doc/nasal.ebnf similarity index 100% rename from nasal.ebnf rename to doc/nasal.ebnf diff --git a/main.cpp b/main.cpp index caf4ef6..732413c 100644 --- a/main.cpp +++ b/main.cpp @@ -12,14 +12,14 @@ #include "nasal_dbg.h" #include -const u32 VM_LEXINFO =0x01; -const u32 VM_ASTINFO =0x02; -const u32 VM_CODEINFO=0x04; -const u32 VM_EXECTIME=0x08; -const u32 VM_EXEC =0x10; -const u32 VM_DETAIL =0x20; -const u32 VM_DEBUG =0x40; -const u32 VM_OPTIMIZE=0x80; +const u32 VM_TOKEN =0x01; +const u32 VM_AST =0x02; +const u32 VM_CODE =0x04; +const u32 VM_TIME =0x08; +const u32 VM_EXEC =0x10; +const u32 VM_DETAIL=0x20; +const u32 VM_DEBUG =0x40; +const u32 VM_OPT =0x80; void help() { @@ -92,7 +92,7 @@ void execute(const string& file,const std::vector& argv,const u32 cmd) // lexer scans file to get tokens lexer.scan(file); - if(cmd&VM_LEXINFO) + if(cmd&VM_TOKEN) lexer.print(); // parser gets lexer's token list to compile @@ -100,20 +100,20 @@ void execute(const string& file,const std::vector& argv,const u32 cmd) // linker gets parser's ast and load import files to this ast linker.link(parse,file,cmd&VM_DETAIL); // optimizer does simple optimization on ast - if(cmd&VM_OPTIMIZE) + if(cmd&VM_OPT) optimize(parse.ast()); - if(cmd&VM_ASTINFO) + if(cmd&VM_AST) parse.print(); // code generator gets parser's ast and linker's import file list to generate code gen.compile(parse,linker); - if(cmd&VM_CODEINFO) + if(cmd&VM_CODE) gen.print(); // run if(cmd&VM_DEBUG) nasal_dbg(nerr).run(gen,linker,argv); - else if(cmd&VM_EXECTIME) + else if(cmd&VM_TIME) { auto start=std::chrono::high_resolution_clock::now(); vm.run(gen,linker,argv,cmd&VM_DETAIL); @@ -145,13 +145,13 @@ i32 main(i32 argc,const char* argv[]) return 0; } std::unordered_map cmdlst={ - {"--lex",VM_LEXINFO},{"-l",VM_LEXINFO}, - {"--ast",VM_ASTINFO},{"-a",VM_ASTINFO}, - {"--code",VM_CODEINFO},{"-c",VM_CODEINFO}, + {"--lex",VM_TOKEN},{"-l",VM_TOKEN}, + {"--ast",VM_AST},{"-a",VM_AST}, + {"--code",VM_CODE},{"-c",VM_CODE}, {"--exec",VM_EXEC},{"-e",VM_EXEC}, - {"--time",VM_EXECTIME|VM_EXEC},{"-t",VM_EXECTIME|VM_EXEC}, + {"--time",VM_TIME|VM_EXEC},{"-t",VM_TIME|VM_EXEC}, {"--detail",VM_DETAIL|VM_EXEC},{"-d",VM_DETAIL|VM_EXEC}, - {"--optimize",VM_OPTIMIZE},{"-o",VM_OPTIMIZE}, + {"--optimize",VM_OPT},{"-o",VM_OPT}, {"--debug",VM_DEBUG},{"-dbg",VM_DEBUG} }; u32 cmd=0; diff --git a/makefile b/makefile index 688ede4..e246b5b 100644 --- a/makefile +++ b/makefile @@ -15,58 +15,58 @@ SRC=\ nasal_dbg.h\ nasal.h -CPPSTANDARD=-std=c++11 +STD=-std=c++11 nasal:$(SRC) - $(CXX) $(CPPSTANDARD) -O3 main.cpp -o nasal -fno-exceptions -ldl -Wshadow -Wall + $(CXX) $(STD) -O3 main.cpp -o nasal -fno-exceptions -ldl -Wshadow -Wall nasal.exe:$(SRC) - $(CXX) $(CPPSTANDARD) -O3 main.cpp -o nasal.exe -fno-exceptions -Wshadow -Wall -static + $(CXX) $(STD) -O3 main.cpp -o nasal.exe -fno-exceptions -Wshadow -Wall -static stable-release:$(SRC) - $(CXX) $(CPPSTANDARD) -O2 main.cpp -o nasal -fno-exceptions -ldl -Wshadow -Wall + $(CXX) $(STD) -O2 main.cpp -o nasal -fno-exceptions -ldl -Wshadow -Wall stable-release-mingw:$(SRC) - $(CXX) $(CPPSTANDARD) -O2 main.cpp -o nasal.exe -fno-exceptions -Wshadow -Wall -static + $(CXX) $(STD) -O2 main.cpp -o nasal.exe -fno-exceptions -Wshadow -Wall -static test:nasal - @ ./nasal -op -e test/ascii-art.nas - @ ./nasal -op -c test/auto_crash.nas - @ ./nasal -op -a -c test/bf.nas - @ ./nasal -op -a -c test/bfcolored.nas - @ ./nasal -op -a -c test/bfconvertor.nas - @ ./nasal -op -e -d test/bfs.nas - @ ./nasal -op -t test/bigloop.nas - @ ./nasal -op -e test/bp.nas - @ ./nasal -op -e -d test/calc.nas - @ ./nasal -op -e test/choice.nas - @ ./nasal -op -e test/class.nas - @ ./nasal -op -d test/coroutine.nas - @ ./nasal -op -e test/diff.nas - -@ ./nasal -op -d test/exception.nas - @ ./nasal -op -t -d test/fib.nas - @ ./nasal -op -e test/filesystem.nas - @ ./nasal -op -e -d test/hexdump.nas - @ ./nasal -op -c test/httptest.nas - @ ./nasal -op -e test/json.nas - @ ./nasal -op -e test/leetcode1319.nas - @ ./nasal -op -e -d test/lexer.nas - @ ./nasal -op -e -d test/life.nas - @ ./nasal -op -t test/loop.nas - @ ./nasal -op -t -d test/mandel.nas - @ ./nasal -op -t -d test/mandelbrot.nas - @ ./nasal -op -t -d test/md5.nas - @ ./nasal -op -t -d test/md5compare.nas - -@ ./nasal -op -d test/module_test.nas - @ ./nasal -op -e test/nasal_test.nas - @ ./nasal -op -c test/occupation.nas - @ ./nasal -op -t -d test/pi.nas - @ ./nasal -op -c test/ppmgen.nas - @ ./nasal -op -t -d test/prime.nas - @ ./nasal -op -e test/qrcode.nas - @ ./nasal -op -t -d test/quick_sort.nas - @ ./nasal -op -e test/scalar.nas hello world - -@ ./nasal -op -c -t test/snake.nas - @ ./nasal -op -c -e test/trait.nas - -@ ./nasal -op -c -t test/tetris.nas - @ ./nasal -op -c -t -d test/turingmachine.nas - @ ./nasal -op -c -t -d test/ycombinator.nas - @ ./nasal -op -d test/wavecollapse.nas \ No newline at end of file + @ ./nasal -o -e test/ascii-art.nas + @ ./nasal -o -c test/auto_crash.nas + @ ./nasal -o -a -c test/bf.nas + @ ./nasal -o -a -c test/bfcolored.nas + @ ./nasal -o -a -c test/bfconvertor.nas + @ ./nasal -o -e -d test/bfs.nas + @ ./nasal -o -t test/bigloop.nas + @ ./nasal -o -e test/bp.nas + @ ./nasal -o -e -d test/calc.nas + @ ./nasal -o -e test/choice.nas + @ ./nasal -o -e test/class.nas + @ ./nasal -o -d test/coroutine.nas + @ ./nasal -o -e test/diff.nas + -@ ./nasal -o -d test/exception.nas + @ ./nasal -o -t -d test/fib.nas + @ ./nasal -o -e test/filesystem.nas + @ ./nasal -o -e -d test/hexdump.nas + @ ./nasal -o -c test/httptest.nas + @ ./nasal -o -e test/json.nas + @ ./nasal -o -e test/leetcode1319.nas + @ ./nasal -o -e -d test/lexer.nas + @ ./nasal -o -e -d test/life.nas + @ ./nasal -o -t test/loop.nas + @ ./nasal -o -t -d test/mandel.nas + @ ./nasal -o -t -d test/mandelbrot.nas + @ ./nasal -o -t -d test/md5.nas + @ ./nasal -o -t -d test/md5compare.nas + -@ ./nasal -o -d test/module_test.nas + @ ./nasal -o -e test/nasal_test.nas + @ ./nasal -o -c test/occupation.nas + @ ./nasal -o -t -d test/pi.nas + @ ./nasal -o -c test/ppmgen.nas + @ ./nasal -o -t -d test/prime.nas + @ ./nasal -o -e test/qrcode.nas + @ ./nasal -o -t -d test/quick_sort.nas + @ ./nasal -o -e test/scalar.nas hello world + -@ ./nasal -o -c -t test/snake.nas + @ ./nasal -o -c -e test/trait.nas + -@ ./nasal -o -c -t test/tetris.nas + @ ./nasal -o -c -t -d test/turingmachine.nas + @ ./nasal -o -c -t -d test/ycombinator.nas + @ ./nasal -o -d test/wavecollapse.nas \ No newline at end of file diff --git a/nasal_vm.h b/nasal_vm.h index b108a3b..b378d59 100644 --- a/nasal_vm.h +++ b/nasal_vm.h @@ -138,8 +138,8 @@ public: void nasal_vm::init( const std::vector& strs, - const std::vector& nums, - const std::vector& code, + const std::vector& nums, + const std::vector& code, const std::vector& filenames, const std::vector& argv) {