blueloveTH %!s(int64=2) %!d(string=hai) anos
pai
achega
1f7a7c8606

+ 0 - 2
include/linalg.pyi

@@ -110,8 +110,6 @@ class mat3x3:
     def trs(t: vec2, r: float, s: vec2) -> mat3x3: ...
 
     def is_affine(self) -> bool: ...
-    def inverse_affine(self) -> mat3x3: ...
-    def matmul_affine(self, other: mat3x3) -> mat3x3: ...
 
     def translation(self) -> vec2: ...
     def rotation(self) -> float: ...

+ 1 - 1
include/pocketpy/cffi.h

@@ -206,7 +206,7 @@ inline PyObject* _any_c_wrapper(VM* vm, ArgsView args){
 }
 
 template<typename T>
-inline void bind_any_c_fp(VM* vm, PyObject* obj, Str name, T fp){
+void bind_any_c_fp(VM* vm, PyObject* obj, Str name, T fp){
     static_assert(std::is_pod_v<T>);
     static_assert(std::is_pointer_v<T>);
     auto proxy = new NativeProxyFuncC(fp);

+ 13 - 0
include/pocketpy/common.h

@@ -148,4 +148,17 @@ inline PyObject* const PY_OP_YIELD = (PyObject*)0b110011;
 
 #define ADD_MODULE_PLACEHOLDER(name) namespace pkpy { inline void add_module_##name(void* vm) { (void)vm; } }
 
+#ifdef _WIN32
+
+#ifndef WIN32_LEAN_AND_MEAN
+#define WIN32_LEAN_AND_MEAN
+#endif
+
+#ifndef NOMINMAX
+#define NOMINMAX
+#endif
+
+#include <Windows.h>
+#endif
+
 } // namespace pkpy

+ 0 - 3
include/pocketpy/compiler.h

@@ -137,7 +137,4 @@ public:
     Compiler& operator=(const Compiler&) = delete;
 };
 
-#undef BC_NOARG
-#undef BC_KEEPLINE
-
 } // namespace pkpy

+ 0 - 30
include/pocketpy/linalg.h

@@ -240,36 +240,6 @@ struct Mat3x3{
         return _31 == 0.0f && _32 == 0.0f && _33 == 1.0f;
     }
 
-    Mat3x3 inverse_affine() const{
-        Mat3x3 ret;
-        float det = _11 * _22 - _12 * _21;
-        float inv_det = 1.0f / det;
-        ret._11 = _22 * inv_det;
-        ret._12 = -_12 * inv_det;
-        ret._13 = (_12 * _23 - _13 * _22) * inv_det;
-        ret._21 = -_21 * inv_det;
-        ret._22 = _11 * inv_det;
-        ret._23 = (_13 * _21 - _11 * _23) * inv_det;
-        ret._31 = 0.0f;
-        ret._32 = 0.0f;
-        ret._33 = 1.0f;
-        return ret;
-    }
-
-    Mat3x3 matmul_affine(const Mat3x3& other) const{
-        Mat3x3 ret;
-        ret._11 = _11 * other._11 + _12 * other._21;
-        ret._12 = _11 * other._12 + _12 * other._22;
-        ret._13 = _11 * other._13 + _12 * other._23 + _13;
-        ret._21 = _21 * other._11 + _22 * other._21;
-        ret._22 = _21 * other._12 + _22 * other._22;
-        ret._23 = _21 * other._13 + _22 * other._23 + _23;
-        ret._31 = 0.0f;
-        ret._32 = 0.0f;
-        ret._33 = 1.0f;
-        return ret;
-    }
-
     Vec2 translation() const { return Vec2(_13, _23); }
     float rotation() const { return atan2f(_21, _11); }
     Vec2 scale() const {

+ 3 - 73
include/pocketpy/repl.h

@@ -3,44 +3,9 @@
 #include "compiler.h"
 #include "vm.h"
 
-#ifdef _WIN32
-#define WIN32_LEAN_AND_MEAN
-#include <Windows.h>
-#endif
-
 namespace pkpy{
 
-#ifdef _WIN32
-
-inline std::string getline(bool* eof=nullptr) {
-    HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE);
-    std::wstringstream wss;
-    WCHAR buf;
-    DWORD read;
-    while (ReadConsoleW(hStdin, &buf, 1, &read, NULL) && buf != L'\n') {
-        if(eof && buf == L'\x1A') *eof = true;  // Ctrl+Z
-        wss << buf;
-    }
-    std::wstring wideInput = wss.str();
-    int length = WideCharToMultiByte(CP_UTF8, 0, wideInput.c_str(), (int)wideInput.length(), NULL, 0, NULL, NULL);
-    std::string output;
-    output.resize(length);
-    WideCharToMultiByte(CP_UTF8, 0, wideInput.c_str(), (int)wideInput.length(), &output[0], length, NULL, NULL);
-    if(!output.empty() && output.back() == '\r') output.pop_back();
-    return output;
-}
-
-#else
-
-inline std::string getline(bool* eof=nullptr){
-    std::string line;
-    if(!std::getline(std::cin, line)){
-        if(eof) *eof = true;
-    }
-    return line;
-}
-
-#endif
+std::string platform_getline(bool* eof=nullptr);
 
 class REPL {
 protected:
@@ -48,43 +13,8 @@ protected:
     std::string buffer;
     VM* vm;
 public:
-    REPL(VM* vm) : vm(vm){
-        vm->_stdout(vm, "pocketpy " PK_VERSION " (" __DATE__ ", " __TIME__ ") ");
-        vm->_stdout(vm, fmt("[", sizeof(void*)*8, " bit]" "\n"));
-        vm->_stdout(vm, "https://github.com/blueloveTH/pocketpy" "\n");
-        vm->_stdout(vm, "Type \"exit()\" to exit." "\n");
-    }
-
-    bool input(std::string line){
-        CompileMode mode = REPL_MODE;
-        if(need_more_lines){
-            buffer += line;
-            buffer += '\n';
-            int n = buffer.size();
-            if(n>=need_more_lines){
-                for(int i=buffer.size()-need_more_lines; i<buffer.size(); i++){
-                    // no enough lines
-                    if(buffer[i] != '\n') return true;
-                }
-                need_more_lines = 0;
-                line = buffer;
-                buffer.clear();
-                mode = CELL_MODE;
-            }else{
-                return true;
-            }
-        }
-        
-        try{
-            vm->exec(line, "<stdin>", mode);
-        }catch(NeedMoreLines& ne){
-            buffer += line;
-            buffer += '\n';
-            need_more_lines = ne.is_compiling_class ? 3 : 2;
-            if (need_more_lines) return true;
-        }
-        return false;
-    }
+    REPL(VM* vm);
+    bool input(std::string line);
 };
 
 } // namespace pkpy

+ 5 - 14
src/linalg.cpp

@@ -353,8 +353,11 @@ namespace pkpy{
 
         vm->bind_method<1>(type, "__eq__", [](VM* vm, ArgsView args){
             PyMat3x3& self = _CAST(PyMat3x3&, args[0]);
-            PyMat3x3& other = CAST(PyMat3x3&, args[1]);
-            return VAR(self == other);
+            if(is_non_tagged_type(args[1], PyMat3x3::_type(vm))){
+                PyMat3x3& other = _CAST(PyMat3x3&, args[1]);
+                return VAR(self == other);
+            }
+            return vm->NotImplemented;
         });
 
         vm->bind_method<0>(type, "determinant", [](VM* vm, ArgsView args){
@@ -411,18 +414,6 @@ namespace pkpy{
             return VAR(self.is_affine());
         });
 
-        vm->bind_method<0>(type, "inverse_affine", [](VM* vm, ArgsView args){
-            PyMat3x3& self = _CAST(PyMat3x3&, args[0]);
-            return VAR_T(PyMat3x3, self.inverse_affine());
-        });
-
-        vm->bind_method<1>(type, "matmul_affine", [](VM* vm, ArgsView args){
-            PyMat3x3& self = _CAST(PyMat3x3&, args[0]);
-            PyMat3x3& other = CAST(PyMat3x3&, args[1]);
-            return VAR_T(PyMat3x3, self.matmul_affine(other));
-        });
-
-
         vm->bind_method<0>(type, "translation", [](VM* vm, ArgsView args){
             PyMat3x3& self = _CAST(PyMat3x3&, args[0]);
             return VAR_T(PyVec2, self.translation());

+ 75 - 0
src/repl.cpp

@@ -0,0 +1,75 @@
+#include "pocketpy/repl.h"
+
+namespace pkpy {
+
+#ifdef _WIN32
+
+std::string platform_getline(bool* eof){
+    HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE);
+    std::wstringstream wss;
+    WCHAR buf;
+    DWORD read;
+    while (ReadConsoleW(hStdin, &buf, 1, &read, NULL) && buf != L'\n') {
+        if(eof && buf == L'\x1A') *eof = true;  // Ctrl+Z
+        wss << buf;
+    }
+    std::wstring wideInput = wss.str();
+    int length = WideCharToMultiByte(CP_UTF8, 0, wideInput.c_str(), (int)wideInput.length(), NULL, 0, NULL, NULL);
+    std::string output;
+    output.resize(length);
+    WideCharToMultiByte(CP_UTF8, 0, wideInput.c_str(), (int)wideInput.length(), &output[0], length, NULL, NULL);
+    if(!output.empty() && output.back() == '\r') output.pop_back();
+    return output;
+}
+
+#else
+
+std::string platform_getline(bool* eof){
+    std::string line;
+    if(!std::getline(std::cin, line)){
+        if(eof) *eof = true;
+    }
+    return line;
+}
+
+#endif
+
+    REPL::REPL(VM* vm) : vm(vm){
+        vm->_stdout(vm, "pocketpy " PK_VERSION " (" __DATE__ ", " __TIME__ ") ");
+        vm->_stdout(vm, fmt("[", sizeof(void*)*8, " bit]" "\n"));
+        vm->_stdout(vm, "https://github.com/blueloveTH/pocketpy" "\n");
+        vm->_stdout(vm, "Type \"exit()\" to exit." "\n");
+    }
+
+    bool REPL::input(std::string line){
+        CompileMode mode = REPL_MODE;
+        if(need_more_lines){
+            buffer += line;
+            buffer += '\n';
+            int n = buffer.size();
+            if(n>=need_more_lines){
+                for(int i=buffer.size()-need_more_lines; i<buffer.size(); i++){
+                    // no enough lines
+                    if(buffer[i] != '\n') return true;
+                }
+                need_more_lines = 0;
+                line = buffer;
+                buffer.clear();
+                mode = CELL_MODE;
+            }else{
+                return true;
+            }
+        }
+        
+        try{
+            vm->exec(line, "<stdin>", mode);
+        }catch(NeedMoreLines& ne){
+            buffer += line;
+            buffer += '\n';
+            need_more_lines = ne.is_compiling_class ? 3 : 2;
+            if (need_more_lines) return true;
+        }
+        return false;
+    }
+
+}