From b52aa85f1319225cc97dc8132c934521cdecfe3d Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Thu, 10 Nov 2022 16:00:21 +0800 Subject: [PATCH] adjust builtins --- src/builtins.h | 5 +++++ src/vm.h | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/builtins.h b/src/builtins.h index bf013aca..05c79d86 100644 --- a/src/builtins.h +++ b/src/builtins.h @@ -21,6 +21,7 @@ def __str4split(self, sep): res.append(self) return res str.split = __str4split +del __str4split list.__repr__ = lambda self: '[' + ', '.join([repr(i) for i in self]) + ']' tuple.__repr__ = lambda self: '(' + ', '.join([repr(i) for i in self]) + ')' @@ -29,6 +30,7 @@ def __list4extend(self, other): for i in other: self.append(i) list.extend = __list4extend +del __list4extend def __list4__mul__(self, n): a = [] @@ -36,6 +38,7 @@ def __list4__mul__(self, n): a.extend(self) return a list.__mul__ = __list4__mul__ +del __list4__mul__ def __iterable4__eq__(self, other): if len(self) != len(other): @@ -46,6 +49,7 @@ def __iterable4__eq__(self, other): return True list.__eq__ = __iterable4__eq__ tuple.__eq__ = __iterable4__eq__ +del __iterable4__eq__ def __iterable4__contains__(self, item): for i in self: @@ -54,6 +58,7 @@ def __iterable4__contains__(self, item): return False list.__contains__ = __iterable4__contains__ tuple.__contains__ = __iterable4__contains__ +del __iterable4__contains__ # https://github.com/python/cpython/blob/main/Objects/dictobject.c class dict: diff --git a/src/vm.h b/src/vm.h index 3dcd2a55..bb85fa57 100644 --- a/src/vm.h +++ b/src/vm.h @@ -469,7 +469,7 @@ public: PyVar newModule(_Str name, bool saveToPath=true) { PyVar obj = newObject(_tp_module, (_Int)-2); setAttr(obj, "__name__", PyStr(name)); - _modules[name] = obj; + if(saveToPath) _modules[name] = obj; return obj; } @@ -607,7 +607,7 @@ public: this->None = newObject(_types["NoneType"], (_Int)0); this->True = newObject(_tp_bool, true); this->False = newObject(_tp_bool, false); - this->builtins = newModule("__builtins__"); + this->builtins = newModule("builtins"); this->_main = newModule("__main__", false); setAttr(_tp_type, __base__, _tp_object);