diff --git a/CMakeLists.txt b/CMakeLists.txt index 36a1860..c45022b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,6 +28,8 @@ set(NASAL_OBJECT_SOURCE_FILE ${CMAKE_SOURCE_DIR}/src/natives/regex_lib.cpp ${CMAKE_SOURCE_DIR}/src/natives/unix_lib.cpp ${CMAKE_SOURCE_DIR}/src/repl/repl.cpp + ${CMAKE_SOURCE_DIR}/src/util/fs.cpp + ${CMAKE_SOURCE_DIR}/src/util/util.cpp ${CMAKE_SOURCE_DIR}/src/ast_dumper.cpp ${CMAKE_SOURCE_DIR}/src/ast_visitor.cpp ${CMAKE_SOURCE_DIR}/src/nasal_ast.cpp diff --git a/makefile b/makefile index 61d4400..305a89e 100644 --- a/makefile +++ b/makefile @@ -36,8 +36,10 @@ NASAL_HEADER = \ src/natives/json_lib.h\ src/natives/unix_lib.h\ src/natives/coroutine.h\ + src/natives/regex_lib.h\ src/repl/repl.h\ - src/natives/regex_lib.h + src/util/fs.h\ + src/util/util.h NASAL_OBJECT = \ build/nasal_err.o\ @@ -65,9 +67,11 @@ NASAL_OBJECT = \ build/nasal_type.o\ build/nasal_vm.o\ build/nasal_dbg.o\ - build/repl.o\ build/regex_lib.o\ + build/repl.o\ build/cli.o\ + build/fs.o\ + build/util.o\ build/main.o @@ -94,6 +98,12 @@ build/nasal_misc.o: src/nasal.h src/nasal_misc.cpp | build build/cli.o: src/cli/cli.h src/cli/cli.cpp | build $(CXX) $(CXXFLAGS) src/cli/cli.cpp -o build/cli.o +build/util.o: src/util/util.h src/util/util.cpp | build + $(CXX) $(CXXFLAGS) src/util/util.cpp -o build/util.o + +build/fs.o: src/nasal.h src/util/fs.h src/util/fs.cpp | build + $(CXX) $(CXXFLAGS) src/util/fs.cpp -o build/fs.o + build/repl.o: $(NASAL_HEADER) src/repl/repl.h src/repl/repl.cpp | build $(CXX) $(CXXFLAGS) src/repl/repl.cpp -o build/repl.o @@ -111,12 +121,14 @@ build/nasal_import.o: \ src/nasal_ast.h\ src/nasal_lexer.h\ src/nasal_parse.h\ + src/util/fs.h\ src/nasal_import.h src/nasal_import.cpp | build $(CXX) $(CXXFLAGS) src/nasal_import.cpp -o build/nasal_import.o build/nasal_lexer.o: \ src/nasal.h\ src/repl/repl.h\ + src/util/fs.h\ src/nasal_err.h\ src/nasal_lexer.h src/nasal_lexer.cpp | build $(CXX) $(CXXFLAGS) src/nasal_lexer.cpp -o build/nasal_lexer.o @@ -160,6 +172,7 @@ build/io_lib.o: \ src/nasal.h\ src/nasal_type.h\ src/nasal_gc.h\ + src/util/fs.h\ src/natives/io_lib.h src/natives/io_lib.cpp | build $(CXX) $(CXXFLAGS) src/natives/io_lib.cpp -o build/io_lib.o diff --git a/src/main.cpp b/src/main.cpp index d7082e9..f1eaca2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -21,19 +21,6 @@ #include #include -const u32 VM_RAW_AST = 1; -const u32 VM_AST = 1<<1; -const u32 VM_CODE = 1<<2; -const u32 VM_TIME = 1<<3; -const u32 VM_EXEC = 1<<4; -const u32 VM_DETAIL = 1<<5; -const u32 VM_DEBUG = 1<<6; -const u32 VM_SYMINFO = 1<<7; -const u32 VM_PROFILE = 1<<8; -const u32 VM_PROF_ALL = 1<<9; -const u32 VM_REF_FILE = 1<<10; -const u32 VM_LIMIT = 1<<11; - std::ostream& help(std::ostream& out) { out << "\n" diff --git a/src/nasal.h b/src/nasal.h index 225ee82..3820844 100644 --- a/src/nasal.h +++ b/src/nasal.h @@ -55,27 +55,4 @@ i32 utf8_hdchk(const char); std::string char_to_hex(const char); std::string rawstr(const std::string&, const usize maxlen = 0); -namespace fs { - -class path { -private: - std::string file_system_path; - -public: - path(const path&) = default; - path(const std::string& file_path): file_system_path(file_path) {} - path& operator/(const path&); - const char* c_str() const { - return file_system_path.c_str(); - } - const std::string& str() const { - return file_system_path; - } -}; - -bool exists(const path&); -bool is_regular(const path&); - -} - } \ No newline at end of file diff --git a/src/nasal_import.cpp b/src/nasal_import.cpp index b5273e5..294bd91 100644 --- a/src/nasal_import.cpp +++ b/src/nasal_import.cpp @@ -1,5 +1,6 @@ #include "nasal_import.h" #include "symbol_finder.h" +#include "util/fs.h" #include #include diff --git a/src/nasal_import.h b/src/nasal_import.h index 420d6d6..36a0061 100644 --- a/src/nasal_import.h +++ b/src/nasal_import.h @@ -13,6 +13,7 @@ #include "nasal_lexer.h" #include "nasal_parse.h" #include "symbol_finder.h" +#include "util/fs.h" #include #include diff --git a/src/nasal_lexer.cpp b/src/nasal_lexer.cpp index 751692e..f98be38 100644 --- a/src/nasal_lexer.cpp +++ b/src/nasal_lexer.cpp @@ -6,6 +6,7 @@ #include "nasal_lexer.h" #include "repl/repl.h" +#include "util/fs.h" namespace nasal { diff --git a/src/nasal_misc.cpp b/src/nasal_misc.cpp index 77da7dc..24428b0 100644 --- a/src/nasal_misc.cpp +++ b/src/nasal_misc.cpp @@ -1,12 +1,5 @@ #include "nasal.h" -#ifndef _MSC_VER -#include -#else -#include -#endif -#include - #ifdef _MSC_VER #pragma warning (disable:4996) #endif @@ -277,32 +270,4 @@ std::string rawstr(const std::string& str, const usize maxlen) { return ret; } -namespace fs { - -path& path::operator/(const path& another) { - this->file_system_path += is_windows()? "\\":"/"; - this->file_system_path += another.file_system_path; - return *this; -} - -bool exists(const path& file_path) { -#ifdef _MSC_VER - #define F_OK 0 // fuck msc -#endif - return access(file_path.c_str(), F_OK)==0; -} - -bool is_regular(const path& file_path) { -#ifdef _MSC_VER - #define S_ISREG(m) (((m)&0xF000)==0x8000) -#endif - struct stat buffer; - if (stat(file_path.c_str(), &buffer)!=0) { - return false; - } - return S_ISREG(buffer.st_mode); -} - -} - } diff --git a/src/natives/io_lib.cpp b/src/natives/io_lib.cpp index 7f9b469..389a6a5 100644 --- a/src/natives/io_lib.cpp +++ b/src/natives/io_lib.cpp @@ -1,4 +1,5 @@ #include "natives/io_lib.h" +#include "util/fs.h" #include diff --git a/src/util/fs.cpp b/src/util/fs.cpp new file mode 100644 index 0000000..941ec9f --- /dev/null +++ b/src/util/fs.cpp @@ -0,0 +1,38 @@ +#ifndef _MSC_VER +#include +#else +#include +#endif + +#include + +#include "util/fs.h" +#include "nasal.h" + +namespace nasal::fs { + +path& path::operator/(const path& another) { + this->file_system_path += is_windows()? "\\":"/"; + this->file_system_path += another.file_system_path; + return *this; +} + +bool exists(const path& file_path) { +#ifdef _MSC_VER + #define F_OK 0 // fuck msc +#endif + return access(file_path.c_str(), F_OK)==0; +} + +bool is_regular(const path& file_path) { +#ifdef _MSC_VER + #define S_ISREG(m) (((m)&0xF000)==0x8000) +#endif + struct stat buffer; + if (stat(file_path.c_str(), &buffer)!=0) { + return false; + } + return S_ISREG(buffer.st_mode); +} + +} \ No newline at end of file diff --git a/src/util/fs.h b/src/util/fs.h new file mode 100644 index 0000000..9e25df6 --- /dev/null +++ b/src/util/fs.h @@ -0,0 +1,27 @@ +#pragma once + +#include +#include + +namespace nasal::fs { + +class path { +private: + std::string file_system_path; + +public: + path(const path&) = default; + path(const std::string& file_path): file_system_path(file_path) {} + path& operator/(const path&); + const char* c_str() const { + return file_system_path.c_str(); + } + const std::string& str() const { + return file_system_path; + } +}; + +bool exists(const path&); +bool is_regular(const path&); + +} \ No newline at end of file diff --git a/src/util/util.cpp b/src/util/util.cpp new file mode 100644 index 0000000..8e1ec44 --- /dev/null +++ b/src/util/util.cpp @@ -0,0 +1,3 @@ +#include "util/util.h" + +namespace nasal::util {} \ No newline at end of file diff --git a/src/util/util.h b/src/util/util.h new file mode 100644 index 0000000..4724961 --- /dev/null +++ b/src/util/util.h @@ -0,0 +1,3 @@ +#pragma + +namespace nasal::util {} \ No newline at end of file diff --git a/test/md5compare.nas b/test/md5compare.nas index c5c17fc..bf74269 100644 --- a/test/md5compare.nas +++ b/test/md5compare.nas @@ -47,6 +47,12 @@ var compare = func() { }; }(); +var add_all_cpp_files = func(vec, path) { + foreach(var p; file.find_all_files_with_extension(path,"cpp","h")) { + append(vec, path~"/"~p); + } +} + var filechecksum = func() { var files = []; foreach(var p; file.find_all_files_with_extension("./test","nas")) { @@ -61,9 +67,11 @@ var filechecksum = func() { foreach(var p; file.find_all_files_with_extension(".","md")) { append(files, "./"~p); } - foreach(var p; file.find_all_files_with_extension("./src","cpp","h")) { - append(files, "./src/"~p); - } + add_all_cpp_files(files, "./src"); + add_all_cpp_files(files, "./src/cli"); + add_all_cpp_files(files, "./src/natives"); + add_all_cpp_files(files, "./src/repl"); + add_all_cpp_files(files, "./src/util"); foreach(var p; file.find_all_files_with_extension("./doc","md")) { append(files, "./doc/"~p); }