blueloveTH hace 2 años
padre
commit
70e8a60f8b
Se han modificado 4 ficheros con 16 adiciones y 21 borrados
  1. 1 1
      amalgamate.py
  2. 12 18
      src/io.h
  3. 1 1
      src/requests.h
  4. 2 1
      src/vm.h

+ 1 - 1
amalgamate.py

@@ -9,7 +9,7 @@ pipeline = [
 	["common.h", "memory.h", "vector.h", "str.h", "tuplelist.h", "namedict.h", "error.h", "lexer.h"],
 	["obj.h", "codeobject.h", "frame.h"],
 	["gc.h", "vm.h", "ceval.h", "expr.h", "compiler.h", "repl.h"],
-	["iter.h", "cffi.h", "requests.h", "io.h", "_generated.h", "pocketpy.h"]
+	["_generated.h", "iter.h", "cffi.h", "requests.h", "io.h", "pocketpy.h"]
 ]
 
 copied = set()

+ 12 - 18
src/io.h

@@ -10,17 +10,6 @@
 #include <filesystem>
 
 namespace pkpy{
-
-inline Bytes _read_file_cwd(const Str& name){
-    std::filesystem::path path(name.sv());
-    bool exists = std::filesystem::exists(path);
-    if(!exists) return Bytes();
-    std::ifstream ifs(path, std::ios::binary);
-    std::vector<char> buffer(std::istreambuf_iterator<char>(ifs), {});
-    ifs.close();
-    return Bytes(std::move(buffer));
-}
-
 struct FileIO {
     PY_CLASS(FileIO, io, FileIO)
 
@@ -94,6 +83,16 @@ struct FileIO {
 };
 
 inline void add_module_io(VM* vm){
+    _read_file_cwd = [](const Str& name){
+        std::filesystem::path path(name.sv());
+        bool exists = std::filesystem::exists(path);
+        if(!exists) return Bytes();
+        std::ifstream ifs(path, std::ios::binary);
+        std::vector<char> buffer(std::istreambuf_iterator<char>(ifs), {});
+        ifs.close();
+        return Bytes(std::move(buffer));
+    };
+
     PyObject* mod = vm->new_module("io");
     FileIO::register_class(vm, mod);
     vm->bind_builtin_func<2>("open", [](VM* vm, ArgsView args){
@@ -182,13 +181,8 @@ inline void add_module_os(VM* vm){
 #else
 
 namespace pkpy{
-inline void add_module_io(VM* vm){}
-inline void add_module_os(VM* vm){}
-
-inline Bytes _read_file_cwd(const Str& name){
-    return Bytes();
-}
-
+inline void add_module_io(void* vm){}
+inline void add_module_os(void* vm){}
 } // namespace pkpy
 
 #endif

+ 1 - 1
src/requests.h

@@ -100,6 +100,6 @@ inline void add_module_requests(VM* vm){
 
 #else
 
-inline void add_module_requests(VM* vm){ }
+inline void add_module_requests(void* vm){ }
 
 #endif

+ 2 - 1
src/vm.h

@@ -24,7 +24,8 @@ namespace pkpy{
 #define POPX()            (s_data.popx())
 #define STACK_VIEW(n)     (s_data.view(n))
 
-Bytes _read_file_cwd(const Str& name);
+typedef Bytes (*ReadFileCwdFunc)(const Str& name);
+inline ReadFileCwdFunc _read_file_cwd = [](const Str& name) { return Bytes(); };
 
 #define DEF_NATIVE_2(ctype, ptype)                                      \
     template<> inline ctype py_cast<ctype>(VM* vm, PyObject* obj) {     \