From a91826607cd713f903e13c43875a16a09064c5f4 Mon Sep 17 00:00:00 2001 From: ValKmjolnir Date: Wed, 24 Aug 2022 22:08:47 +0800 Subject: [PATCH] :zap: optimize header file, now modules could generate smaller dynamic libs. --- main.cpp | 12 ++++++++++++ module/fib.cpp | 1 + module/keyboard.cpp | 2 ++ module/nasocket.cpp | 2 ++ nasal.h | 42 ------------------------------------------ nasal_builtin.h | 28 ++++++++++++++++++++++------ nasal_codegen.h | 5 +++++ nasal_dbg.h | 1 + nasal_err.h | 1 + nasal_gc.h | 10 ++++++++++ nasal_import.h | 6 ++++++ nasal_lexer.h | 3 +++ nasal_opt.h | 2 ++ nasal_parse.h | 2 ++ nasal_vm.h | 3 +++ 15 files changed, 72 insertions(+), 48 deletions(-) diff --git a/main.cpp b/main.cpp index 143bcb8..e0d6b8c 100644 --- a/main.cpp +++ b/main.cpp @@ -1,4 +1,16 @@ #include "nasal.h" +#include "nasal_err.h" +#include "nasal_lexer.h" +#include "nasal_ast.h" +#include "nasal_parse.h" +#include "nasal_import.h" +#include "nasal_opt.h" +#include "nasal_gc.h" +#include "nasal_builtin.h" +#include "nasal_codegen.h" +#include "nasal_vm.h" +#include "nasal_dbg.h" +#include const u32 VM_LEXINFO =0x01; const u32 VM_ASTINFO =0x02; diff --git a/module/fib.cpp b/module/fib.cpp index d9ffc30..69cca46 100644 --- a/module/fib.cpp +++ b/module/fib.cpp @@ -1,5 +1,6 @@ #include #include "../nasal.h" +#include "../nasal_gc.h" double fibonaci(double x){ if(x<=2) diff --git a/module/keyboard.cpp b/module/keyboard.cpp index 1731b9a..81ec122 100644 --- a/module/keyboard.cpp +++ b/module/keyboard.cpp @@ -1,4 +1,6 @@ #include "../nasal.h" +#include "../nasal_gc.h" +#include #include #ifdef _WIN32 #include diff --git a/module/nasocket.cpp b/module/nasocket.cpp index 18cdbc2..c8060dd 100644 --- a/module/nasocket.cpp +++ b/module/nasocket.cpp @@ -1,4 +1,6 @@ #include "../nasal.h" +#include "../nasal_gc.h" +#include #ifdef _WIN32 #include diff --git a/nasal.h b/nasal.h index 7e1bd26..6c4bf80 100644 --- a/nasal.h +++ b/nasal.h @@ -2,43 +2,12 @@ #define __NASAL_H__ #define __nasver "10.1" -#ifndef _MSC_VER -#include -#include -#else -#include -#include -#endif - #include -#include -#include #include -#include #include -#include -#include #include -#include -#include #include -#include -#include -#include #include -#include -#include -#include - -#include -#include - -#ifdef _WIN32 -#include -#else -#include -#include -#endif using i32=std::int32_t; using i64=std::int64_t; @@ -184,16 +153,5 @@ string rawstr(const string& str,const usize maxlen=0) ret=ret.substr(0,maxlen)+"..."; return ret; } -#include "nasal_err.h" -#include "nasal_lexer.h" -#include "nasal_ast.h" -#include "nasal_parse.h" -#include "nasal_import.h" -#include "nasal_opt.h" -#include "nasal_gc.h" -#include "nasal_builtin.h" -#include "nasal_codegen.h" -#include "nasal_vm.h" -#include "nasal_dbg.h" #endif diff --git a/nasal_builtin.h b/nasal_builtin.h index 37c5099..d25ec3c 100644 --- a/nasal_builtin.h +++ b/nasal_builtin.h @@ -1,17 +1,33 @@ #ifndef __NASAL_BUILTIN_H__ #define __NASAL_BUILTIN_H__ +#include "nasal_gc.h" + +#ifndef _MSC_VER +#include +#include +#else +#include +#include +#endif + +#include +#include +#include +#include + +#ifdef _WIN32 +#include +#else +#include +#include +#endif + #if defined __APPLE__ #include #define environ (*_NSGetEnviron()) #endif -nas_ref nas_err(const string& err_f,const string& info) -{ - std::cerr<<"[vm] "<& elems) { for(auto& i:elems) diff --git a/nasal_codegen.h b/nasal_codegen.h index 4f146b6..6ace060 100644 --- a/nasal_codegen.h +++ b/nasal_codegen.h @@ -1,6 +1,11 @@ #ifndef __NASAL_CODEGEN_H__ #define __NASAL_CODEGEN_H__ +#include +#include +#include +#include + enum op_code:u8 { op_exit, // stop the virtual machine diff --git a/nasal_dbg.h b/nasal_dbg.h index f22704c..eb30c02 100644 --- a/nasal_dbg.h +++ b/nasal_dbg.h @@ -2,6 +2,7 @@ #define __NASAL_DBG_H__ #include "nasal_vm.h" +#include class nasal_dbg:public nasal_vm { diff --git a/nasal_err.h b/nasal_err.h index 8726e71..f7bf77a 100644 --- a/nasal_err.h +++ b/nasal_err.h @@ -3,6 +3,7 @@ #include #include +#include // MSVC need this to use std::getline #include class fstreamline diff --git a/nasal_gc.h b/nasal_gc.h index 2b4a616..0597222 100644 --- a/nasal_gc.h +++ b/nasal_gc.h @@ -1,6 +1,9 @@ #ifndef __NASAL_GC_H__ #define __NASAL_GC_H__ +#include +#include + enum vm_type:u8{ /* none-gc object */ vm_none=0, @@ -714,4 +717,11 @@ void nasal_gc::ctxreserve() stack=mctx.stack; cort=nullptr; } + +// use to print error log and return error value +nas_ref nas_err(const string& err_f,const string& info) +{ + std::cerr<<"[vm] "< +#else +#include +#endif + #ifdef _MSC_VER #define F_OK 0 #endif diff --git a/nasal_lexer.h b/nasal_lexer.h index 2db0e8e..ce1f299 100644 --- a/nasal_lexer.h +++ b/nasal_lexer.h @@ -1,6 +1,9 @@ #ifndef __NASAL_LEXER_H__ #define __NASAL_LEXER_H__ +#include +#include + #ifdef _MSC_VER #define S_ISREG(m) (((m)&0xF000)==0x8000) #endif diff --git a/nasal_opt.h b/nasal_opt.h index ef393ef..ee3ed97 100644 --- a/nasal_opt.h +++ b/nasal_opt.h @@ -1,6 +1,8 @@ #ifndef __NASAL_OPT_H__ #define __NASAL_OPT_H__ +#include + void const_str(nasal_ast& root) { auto& vec=root.child(); diff --git a/nasal_parse.h b/nasal_parse.h index bd88612..16dc80e 100644 --- a/nasal_parse.h +++ b/nasal_parse.h @@ -1,6 +1,8 @@ #ifndef __NASAL_PARSE_H__ #define __NASAL_PARSE_H__ +#include + /* _,,,_ .' `'. diff --git a/nasal_vm.h b/nasal_vm.h index 161d433..04d24f9 100644 --- a/nasal_vm.h +++ b/nasal_vm.h @@ -1,6 +1,9 @@ #ifndef __NASAL_VM_H__ #define __NASAL_VM_H__ +#include +#include + class nasal_vm { protected: