Эх сурвалжийг харах

support bytearray() builtin

lyon 2 жил өмнө
parent
commit
41cb54ecb0

+ 2 - 0
package/PikaStdLib/PikaStdData.pyi

@@ -1,6 +1,7 @@
 from PikaObj import *
 import builtins
 
+
 class Tuple:
     def __init__(self): ...
 
@@ -141,6 +142,7 @@ class String:
 class ByteArray(builtins.bytearray):
     pass
 
+
 class FILEIO:
     def init(self, path: str, mode: str) -> int: ...
     def read(self, *size) -> any: ...

+ 0 - 10
package/PikaStdLib/PikaStdLib.pyi

@@ -17,13 +17,3 @@ class MemChecker:
 
 class SysObj:
     pass
-
-
-@PIKA_C_MACRO_IF("0")
-class RangeObj:
-    def __next__(self) -> any: ...
-
-
-@PIKA_C_MACRO_IF("0")
-class StringObj:
-    def __next__(self) -> any: ...

+ 0 - 13
package/PikaStdLib/PikaStdLib_RangeObj.c

@@ -1,14 +1 @@
 #include "PikaObj.h"
-
-Arg* PikaStdLib_RangeObj___next__(PikaObj* self) {
-    RangeData* _ = (RangeData*)args_getStruct(self->list, "_");
-    int end = _->end;
-    int step = _->step;
-    /* exit */
-    if (_->i >= end) {
-        return arg_newNone();
-    }
-    Arg* res = arg_newInt(_->i);
-    _->i += step;
-    return res;
-}

+ 0 - 4
package/PikaStdLib/PikaStdLib_StringObj.c

@@ -1,5 +1 @@
 #include "PikaObj.h"
-
-Arg* PikaStdLib_StringObj___next__(PikaObj* self) {
-    return arg_newNone();
-}

+ 0 - 2
package/PikaStdLib/PikaStdLib_SysObj.c

@@ -1,6 +1,4 @@
 #include "PikaStdLib_SysObj.h"
 #include "PikaStdData_FILEIO.h"
-#include "PikaStdLib_RangeObj.h"
-#include "PikaStdLib_StringObj.h"
 #include "PikaVM.h"
 #include "dataStrs.h"

+ 18 - 84
package/PikaStdLib/builtins.pyi

@@ -1,187 +1,121 @@
 from PikaObj import *
 
 
-@staticmethod
 def int(arg: any, *base) -> int: ...
 
 
-@staticmethod
 def bool(arg: any) -> bool: ...
 
 
-@staticmethod
 def float(arg: any) -> float: ...
 
 
-@staticmethod
 def str(arg: any) -> str: ...
 
 
-@staticmethod
 def iter(arg: any) -> any: ...
 
 
-@staticmethod
 def range(*ax) -> any: ...
 
 
-@staticmethod
 def print(*val, **ops): ...
 
 
-@staticmethod
 def __setitem__(obj: any, key: any, val: any) -> any: ...
 
 
-@staticmethod
 def __getitem__(obj: any, key: any) -> any: ...
 
 
-@staticmethod
-@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
 def type(arg: any) -> any: ...
 
 
-@staticmethod
-@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
 def isinstance(object: any, classinfo: any) -> bool: ...
 
 
-@staticmethod
 def len(arg: any) -> int: ...
 
 
-@staticmethod
-@PIKA_C_MACRO_IF("PIKA_BUILTIN_STRUCT_ENABLE")
 def list(*val) -> any: ...
 
 
-@staticmethod
-@PIKA_C_MACRO_IF("PIKA_BUILTIN_STRUCT_ENABLE")
 def dict(*val) -> any: ...
 
 
-@staticmethod
-@PIKA_C_MACRO_IF("PIKA_BUILTIN_STRUCT_ENABLE")
 def tuple(arg: any) -> any: ...
 
 
-@staticmethod
-@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
 def hex(val: int) -> str: ...
 
 
-@staticmethod
-@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
 def ord(val: str) -> int: ...
 
 
-@staticmethod
-@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
 def chr(val: int) -> str: ...
 
 
-@staticmethod
-@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
 def bytes(val: any) -> bytes: ...
 
 
-@staticmethod
-@PIKA_C_MACRO_IF("PIKA_SYNTAX_FORMAT_ENABLE")
 def cformat(fmt: str, *var) -> str: ...
 
 
-@staticmethod
-@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
 def id(obj: any) -> int: ...
 
 
-@staticmethod
-@PIKA_C_MACRO_IF("PIKA_FILEIO_ENABLE")
 def open(path: str, mode: str) -> object: ...
 
 
-@staticmethod
-@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
 def dir(obj: any) -> list: ...
 
 
-@staticmethod
-@PIKA_C_MACRO_IF("PIKA_EXEC_ENABLE")
 def exec(code: str): ...
 
 
-@staticmethod
-@PIKA_C_MACRO_IF("PIKA_EXEC_ENABLE")
 def eval(code: str) -> any: ...
 
 
-@staticmethod
-@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
 def getattr(obj: object, name: str) -> any: ...
 
 
-@staticmethod
-@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
 def setattr(obj: object, name: str, val: any): ...
 
 
-@staticmethod
-@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
 def hasattr(obj: object, name: str) -> int: ...
 
 
-@staticmethod
-@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
 def exit(): ...
 
 
-@staticmethod
-@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
 def input(*info) -> str: ...
 
 
-@staticmethod
-@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
 def abs(val: any) -> any: ...
 
 
-@staticmethod
-@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
 def max(*val) -> any: ...
 
 
-@staticmethod
-@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
 def min(*val) -> any: ...
 
 
-@staticmethod
-@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
 def help(name: str): ...
 
 
-@staticmethod
-@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
 def reboot(): ...
 
 
-@staticmethod
-@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
 def clear(): ...
 
 
-@staticmethod
-@PIKA_C_MACRO_IF("PIKA_GC_MARK_SWEEP_ENABLE")
 def gcdump(): ...
 
 
-@PIKA_C_MACRO_IF("0")
 class RangeObj:
     def __next__(self) -> any: ...
 
 
-@PIKA_C_MACRO_IF("0")
 class StringObj:
     def __next__(self) -> any: ...
 
@@ -190,6 +124,24 @@ class object:
     pass
 
 
+class bytearray:
+    def __init__(self, bytes: any):
+        """ convert a bytes to ByteArray """
+
+    def __iter__(self) -> any:
+        """ support for loop """
+
+    def __next__(self) -> any:
+        """ support for loop """
+
+    def __getitem__(self, __key: int) -> int:
+        """ support [] index """
+
+    def __setitem__(self, __key: int, __val: int): ...
+    def __str__(self) -> str: ...
+    def decode(self) -> str: ...
+
+
 class BaseException:
     pass
 
@@ -448,21 +400,3 @@ class BytesWarning(Warning):
 
 class ResourceWarning(Warning):
     pass
-
-
-class bytearray:
-    def __init__(self, bytes: any):
-        """ convert a bytes to ByteArray """
-
-    def __iter__(self) -> any:
-        """ support for loop """
-
-    def __next__(self) -> any:
-        """ support for loop """
-
-    def __getitem__(self, __key: int) -> int:
-        """ support [] index """
-
-    def __setitem__(self, __key: int, __val: int): ...
-    def __str__(self) -> str: ...
-    def decode(self) -> str: ...

+ 2 - 2
port/linux/.vscode/launch.json

@@ -24,9 +24,9 @@
                 // "--gtest_filter=lua.eval"
                 // "--gtest_filter=eventloop.once1"
                 // "--gtest_filter=parser.fn_fn"
-                "--gtest_filter=builtin.getitem"
+                // "--gtest_filter=builtin.getitem"
                 // "--gtest_filter=except.isinstance"
-                // "--gtest_filter=VM.run_def_add"
+                // "--gtest_filter=vm.range_1"
                 // "--gtest_filter=parser.slice_fn"
             ],
             "stopAtEntry": false,

+ 3 - 0
port/linux/.vscode/settings.json

@@ -130,5 +130,8 @@
     },
     "[python]": {
         "editor.defaultFormatter": "ms-python.autopep8"
+    },
+    "[c]": {
+        "editor.defaultFormatter": "llvm-vs-code-extensions.vscode-clangd"
     }
 }

+ 2 - 0
port/linux/package/pikascript/PikaStdData.pyi

@@ -1,6 +1,7 @@
 from PikaObj import *
 import builtins
 
+
 class Tuple:
     def __init__(self): ...
 
@@ -141,6 +142,7 @@ class String:
 class ByteArray(builtins.bytearray):
     pass
 
+
 class FILEIO:
     def init(self, path: str, mode: str) -> int: ...
     def read(self, *size) -> any: ...

+ 0 - 10
port/linux/package/pikascript/PikaStdLib.pyi

@@ -17,13 +17,3 @@ class MemChecker:
 
 class SysObj:
     pass
-
-
-@PIKA_C_MACRO_IF("0")
-class RangeObj:
-    def __next__(self) -> any: ...
-
-
-@PIKA_C_MACRO_IF("0")
-class StringObj:
-    def __next__(self) -> any: ...

+ 18 - 84
port/linux/package/pikascript/builtins.pyi

@@ -1,187 +1,121 @@
 from PikaObj import *
 
 
-@staticmethod
 def int(arg: any, *base) -> int: ...
 
 
-@staticmethod
 def bool(arg: any) -> bool: ...
 
 
-@staticmethod
 def float(arg: any) -> float: ...
 
 
-@staticmethod
 def str(arg: any) -> str: ...
 
 
-@staticmethod
 def iter(arg: any) -> any: ...
 
 
-@staticmethod
 def range(*ax) -> any: ...
 
 
-@staticmethod
 def print(*val, **ops): ...
 
 
-@staticmethod
 def __setitem__(obj: any, key: any, val: any) -> any: ...
 
 
-@staticmethod
 def __getitem__(obj: any, key: any) -> any: ...
 
 
-@staticmethod
-@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
 def type(arg: any) -> any: ...
 
 
-@staticmethod
-@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
 def isinstance(object: any, classinfo: any) -> bool: ...
 
 
-@staticmethod
 def len(arg: any) -> int: ...
 
 
-@staticmethod
-@PIKA_C_MACRO_IF("PIKA_BUILTIN_STRUCT_ENABLE")
 def list(*val) -> any: ...
 
 
-@staticmethod
-@PIKA_C_MACRO_IF("PIKA_BUILTIN_STRUCT_ENABLE")
 def dict(*val) -> any: ...
 
 
-@staticmethod
-@PIKA_C_MACRO_IF("PIKA_BUILTIN_STRUCT_ENABLE")
 def tuple(arg: any) -> any: ...
 
 
-@staticmethod
-@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
 def hex(val: int) -> str: ...
 
 
-@staticmethod
-@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
 def ord(val: str) -> int: ...
 
 
-@staticmethod
-@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
 def chr(val: int) -> str: ...
 
 
-@staticmethod
-@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
 def bytes(val: any) -> bytes: ...
 
 
-@staticmethod
-@PIKA_C_MACRO_IF("PIKA_SYNTAX_FORMAT_ENABLE")
 def cformat(fmt: str, *var) -> str: ...
 
 
-@staticmethod
-@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
 def id(obj: any) -> int: ...
 
 
-@staticmethod
-@PIKA_C_MACRO_IF("PIKA_FILEIO_ENABLE")
 def open(path: str, mode: str) -> object: ...
 
 
-@staticmethod
-@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
 def dir(obj: any) -> list: ...
 
 
-@staticmethod
-@PIKA_C_MACRO_IF("PIKA_EXEC_ENABLE")
 def exec(code: str): ...
 
 
-@staticmethod
-@PIKA_C_MACRO_IF("PIKA_EXEC_ENABLE")
 def eval(code: str) -> any: ...
 
 
-@staticmethod
-@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
 def getattr(obj: object, name: str) -> any: ...
 
 
-@staticmethod
-@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
 def setattr(obj: object, name: str, val: any): ...
 
 
-@staticmethod
-@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
 def hasattr(obj: object, name: str) -> int: ...
 
 
-@staticmethod
-@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
 def exit(): ...
 
 
-@staticmethod
-@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
 def input(*info) -> str: ...
 
 
-@staticmethod
-@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
 def abs(val: any) -> any: ...
 
 
-@staticmethod
-@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
 def max(*val) -> any: ...
 
 
-@staticmethod
-@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
 def min(*val) -> any: ...
 
 
-@staticmethod
-@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
 def help(name: str): ...
 
 
-@staticmethod
-@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
 def reboot(): ...
 
 
-@staticmethod
-@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
 def clear(): ...
 
 
-@staticmethod
-@PIKA_C_MACRO_IF("PIKA_GC_MARK_SWEEP_ENABLE")
 def gcdump(): ...
 
 
-@PIKA_C_MACRO_IF("0")
 class RangeObj:
     def __next__(self) -> any: ...
 
 
-@PIKA_C_MACRO_IF("0")
 class StringObj:
     def __next__(self) -> any: ...
 
@@ -190,6 +124,24 @@ class object:
     pass
 
 
+class bytearray:
+    def __init__(self, bytes: any):
+        """ convert a bytes to ByteArray """
+
+    def __iter__(self) -> any:
+        """ support for loop """
+
+    def __next__(self) -> any:
+        """ support for loop """
+
+    def __getitem__(self, __key: int) -> int:
+        """ support [] index """
+
+    def __setitem__(self, __key: int, __val: int): ...
+    def __str__(self) -> str: ...
+    def decode(self) -> str: ...
+
+
 class BaseException:
     pass
 
@@ -448,21 +400,3 @@ class BytesWarning(Warning):
 
 class ResourceWarning(Warning):
     pass
-
-
-class bytearray:
-    def __init__(self, bytes: any):
-        """ convert a bytes to ByteArray """
-
-    def __iter__(self) -> any:
-        """ support for loop """
-
-    def __next__(self) -> any:
-        """ support for loop """
-
-    def __getitem__(self, __key: int) -> int:
-        """ support [] index """
-
-    def __setitem__(self, __key: int, __val: int): ...
-    def __str__(self) -> str: ...
-    def decode(self) -> str: ...

+ 0 - 13
port/linux/package/pikascript/pikascript-lib/PikaStdLib/PikaStdLib_RangeObj.c

@@ -1,14 +1 @@
 #include "PikaObj.h"
-
-Arg* PikaStdLib_RangeObj___next__(PikaObj* self) {
-    RangeData* _ = (RangeData*)args_getStruct(self->list, "_");
-    int end = _->end;
-    int step = _->step;
-    /* exit */
-    if (_->i >= end) {
-        return arg_newNone();
-    }
-    Arg* res = arg_newInt(_->i);
-    _->i += step;
-    return res;
-}

+ 0 - 4
port/linux/package/pikascript/pikascript-lib/PikaStdLib/PikaStdLib_StringObj.c

@@ -1,5 +1 @@
 #include "PikaObj.h"
-
-Arg* PikaStdLib_StringObj___next__(PikaObj* self) {
-    return arg_newNone();
-}

+ 0 - 2
port/linux/package/pikascript/pikascript-lib/PikaStdLib/PikaStdLib_SysObj.c

@@ -1,6 +1,4 @@
 #include "PikaStdLib_SysObj.h"
 #include "PikaStdData_FILEIO.h"
-#include "PikaStdLib_RangeObj.h"
-#include "PikaStdLib_StringObj.h"
 #include "PikaVM.h"
 #include "dataStrs.h"

+ 7 - 2
src/PikaObj.c

@@ -556,6 +556,7 @@ Arg* _obj_getPropArg(PikaObj* obj, char* name) {
             break;
         }
         int size = prop->methodGroupCount;
+        pika_assert(size >= 0);
         /* binary search */
         if (size == 0) {
             goto next;
@@ -2867,12 +2868,17 @@ void builtins_remove(PikaObj* self, char* argPath) {
 
 Arg* _type(Arg* arg);
 Arg* builtins_type(PikaObj* self, Arg* arg) {
+#if PIKA_NANO_ENABLE
+    pika_platform_printf("PIKA_NANO_ENABLE is not enable");
+    return NULL;
+#else
     if (NULL == arg) {
         obj_setSysOut(self, "[error] type: arg no found.");
         obj_setErrorCode(self, 1);
         return NULL;
     }
     return _type(arg);
+#endif
 }
 
 pika_float builtins_float(PikaObj* self, Arg* arg) {
@@ -3756,9 +3762,8 @@ PikaObj* obj_getBuiltins(void) {
     return newNormalObj(New_builtins);
 }
 
-
 void builtins_bytearray___init__(PikaObj* self, Arg* bytes) {
-    obj_setArg(self, "raw", bytes);
+    obj_setArg_noCopy(self, "raw", builtins_bytes(self, bytes));
 }
 
 Arg* builtins_bytearray___iter__(PikaObj* self) {