📝 add src/util
This commit is contained in:
parent
764a0c6b4b
commit
c840d70a9c
|
@ -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
|
||||
|
|
17
makefile
17
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
|
||||
|
||||
|
|
13
src/main.cpp
13
src/main.cpp
|
@ -21,19 +21,6 @@
|
|||
#include <thread>
|
||||
#include <cstdlib>
|
||||
|
||||
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"
|
||||
|
|
23
src/nasal.h
23
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&);
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
#include "nasal_import.h"
|
||||
#include "symbol_finder.h"
|
||||
#include "util/fs.h"
|
||||
|
||||
#include <memory>
|
||||
#include <unordered_set>
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include "nasal_lexer.h"
|
||||
#include "nasal_parse.h"
|
||||
#include "symbol_finder.h"
|
||||
#include "util/fs.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <sstream>
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include "nasal_lexer.h"
|
||||
#include "repl/repl.h"
|
||||
#include "util/fs.h"
|
||||
|
||||
namespace nasal {
|
||||
|
||||
|
|
|
@ -1,12 +1,5 @@
|
|||
#include "nasal.h"
|
||||
|
||||
#ifndef _MSC_VER
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#include <io.h>
|
||||
#endif
|
||||
#include <sys/stat.h>
|
||||
|
||||
#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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "natives/io_lib.h"
|
||||
#include "util/fs.h"
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
#ifndef _MSC_VER
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#include <io.h>
|
||||
#endif
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
#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);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
#pragma once
|
||||
|
||||
#include <cstring>
|
||||
#include <sstream>
|
||||
|
||||
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&);
|
||||
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
#include "util/util.h"
|
||||
|
||||
namespace nasal::util {}
|
|
@ -0,0 +1,3 @@
|
|||
#pragma
|
||||
|
||||
namespace nasal::util {}
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue