From e9fd953273b37235dc34b31e03e086b3168a34b5 Mon Sep 17 00:00:00 2001 From: Valk Richard Li <48872266+ValKmjolnir@users.noreply.github.com> Date: Fri, 20 Nov 2020 00:18:17 +0800 Subject: [PATCH] update --- README.md | 4 ++++ main.cpp | 20 ++++++++++---------- nasal_codegen.h | 5 ++++- nasal_misc.h | 20 -------------------- 4 files changed, 18 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index b825911..a8eb746 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,10 @@ So i tried to write a new interpreter to help them checking syntax error and eve I wrote the lexer, parser and runtime(nasal virtual machine/ast-runtime virtual machine) to help checking errors. They found it easier for them to check errors before copying nasal-codes in nasal-console in Flightgear to test. + +# How to Compile + +> g++ -std=c++11 main.cpp -o main.exe # Lexical Analysis diff --git a/main.cpp b/main.cpp index 4179578..3a8f2c6 100644 --- a/main.cpp +++ b/main.cpp @@ -2,7 +2,7 @@ nasal_lexer lexer; nasal_parse parse; -nasal_import preprocessor; +nasal_import import; nasal_codegen code_generator; std::string inputfile="null"; nasal_runtime runtime; @@ -96,13 +96,13 @@ void runtime_start() die("parse",inputfile); return; } - preprocessor.preprocessing(parse.get_root()); - if(preprocessor.get_error()) + import.link(parse.get_root()); + if(import.get_error()) { die("import",inputfile); return; } - runtime.set_root(preprocessor.get_root()); + runtime.set_root(import.get_root()); runtime.run(); return; } @@ -123,14 +123,14 @@ void codegen_start() die("parse",inputfile); return; } - preprocessor.preprocessing(parse.get_root()); - if(preprocessor.get_error()) + import.link(parse.get_root()); + if(import.get_error()) { die("import",inputfile); return; } - runtime.set_root(preprocessor.get_root()); - code_generator.output_exec(inputfile+".naexec",preprocessor.get_root()); + runtime.set_root(import.get_root()); + code_generator.output_exec(inputfile+".naexec",import.get_root()); if(code_generator.get_error()) { die("code",inputfile); @@ -141,13 +141,13 @@ void codegen_start() void execution_start() { - code_generator.load_exec(inputfile,preprocessor.get_root()); + code_generator.load_exec(inputfile,import.get_root()); if(code_generator.get_error()) { die("code",inputfile); return; } - runtime.set_root(preprocessor.get_root()); + runtime.set_root(import.get_root()); runtime.run(); return; } diff --git a/nasal_codegen.h b/nasal_codegen.h index 24b7902..afbf254 100644 --- a/nasal_codegen.h +++ b/nasal_codegen.h @@ -10,11 +10,14 @@ enum op_code op_pushstr, op_newvec,op_newhash,op_newfunc, op_vecappend,op_hashappend, + op_para,op_defaultpara,op_dynamicpara, op_unot,op_usub, op_add,op_sub,op_mul,op_div,op_lnk, op_eq,op_neq,op_less,op_leq,op_grt,op_geq, + op_pop, op_jmp,op_jmptrue,op_jmpfalse, - op_gccall,op_gccallvec,op_gccallhash,op_gccallfunc,op_builtincall,op_slice, + op_gccall,op_gccallvec,op_gccallhash,op_gccallfunc,op_builtincall, + op_slice,op_slice2, op_memcall,op_memcallvec,op_memcallhash, op_return, op_end diff --git a/nasal_misc.h b/nasal_misc.h index 205a4aa..0c46d5b 100644 --- a/nasal_misc.h +++ b/nasal_misc.h @@ -178,26 +178,6 @@ void prt_hex(const int ptr) } else std::cout<<"0x"; - /* - int: 00000000 00000000 00000000 00000000 - int: 0x00 00 00 00 - example: - a=0x13 57 9b df - a=00010011 01010111 10011011 11011111 - a & 0x00 00 00 0f: - 00010011 01010111 10011011 11011111 - and 00000000 00000000 00000000 00001111 - --------------------------------------- - 00000000 00000000 00000000 00001111 - a>>=4: - 00000001 00110101 01111001 10111101 - a & 0x00 00 00 0f - 00000001 00110101 01111001 10111101 - and 00000000 00000000 00000000 00001111 - --------------------------------------- - 00000000 00000000 00000000 00001101 - then convert 0~15 to 0~9 a~f - */ for(int j=7;j>=0;--j) { int tmp=(tmp_plc & 0x0000000f);