support bytearray() builtin

This commit is contained in:
lyon 2023-05-29 12:09:23 +08:00
parent 892ae61a20
commit 41cb54ecb0
15 changed files with 52 additions and 230 deletions

View File

@ -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: ...

View File

@ -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: ...

View File

@ -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;
}

View File

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

View File

@ -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"

View File

@ -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: ...

View File

@ -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,

View File

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

View File

@ -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: ...

View File

@ -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: ...

View File

@ -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: ...

View File

@ -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;
}

View File

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

View File

@ -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"

View File

@ -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) {