add builtin exception for builtins.pyi

This commit is contained in:
pikastech 2023-05-22 15:19:59 +08:00
parent 794392244e
commit e536665ff6
7 changed files with 858 additions and 234 deletions

View File

@ -1,143 +1,181 @@
from PikaObj import * from PikaObj import *
@staticmethod @staticmethod
def int(arg: any, *base) -> int: ... def int(arg: any, *base) -> int: ...
@staticmethod @staticmethod
def bool(arg: any) -> bool: ... def bool(arg: any) -> bool: ...
@staticmethod @staticmethod
def float(arg: any) -> float: ... def float(arg: any) -> float: ...
@staticmethod @staticmethod
def str(arg: any) -> str: ... def str(arg: any) -> str: ...
@staticmethod @staticmethod
def iter(arg: any) -> any: ... def iter(arg: any) -> any: ...
@staticmethod @staticmethod
def range(*ax) -> any: ... def range(*ax) -> any: ...
@staticmethod @staticmethod
def print(*val, **ops): ... def print(*val, **ops): ...
@staticmethod @staticmethod
def __setitem__(obj: any, key: any, val: any) -> any: ... def __setitem__(obj: any, key: any, val: any) -> any: ...
@staticmethod @staticmethod
def __getitem__(obj: any, key: any) -> any: ... def __getitem__(obj: any, key: any) -> any: ...
@staticmethod @staticmethod
@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE") @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
def type(arg: any) -> any: ... def type(arg: any) -> any: ...
@staticmethod @staticmethod
@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE") @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
def isinstance(object: any, classinfo: any) -> bool: ... def isinstance(object: any, classinfo: any) -> bool: ...
@staticmethod @staticmethod
def len(arg: any) -> int: ... def len(arg: any) -> int: ...
@staticmethod @staticmethod
@PIKA_C_MACRO_IF("PIKA_BUILTIN_STRUCT_ENABLE") @PIKA_C_MACRO_IF("PIKA_BUILTIN_STRUCT_ENABLE")
def list(*val) -> any: ... def list(*val) -> any: ...
@staticmethod @staticmethod
@PIKA_C_MACRO_IF("PIKA_BUILTIN_STRUCT_ENABLE") @PIKA_C_MACRO_IF("PIKA_BUILTIN_STRUCT_ENABLE")
def dict(*val) -> any: ... def dict(*val) -> any: ...
@staticmethod @staticmethod
@PIKA_C_MACRO_IF("PIKA_BUILTIN_STRUCT_ENABLE") @PIKA_C_MACRO_IF("PIKA_BUILTIN_STRUCT_ENABLE")
def tuple(arg: any) -> any: ... def tuple(arg: any) -> any: ...
@staticmethod @staticmethod
@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE") @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
def hex(val: int) -> str: ... def hex(val: int) -> str: ...
@staticmethod @staticmethod
@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE") @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
def ord(val: str) -> int: ... def ord(val: str) -> int: ...
@staticmethod @staticmethod
@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE") @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
def chr(val: int) -> str: ... def chr(val: int) -> str: ...
@staticmethod @staticmethod
@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE") @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
def bytes(val: any) -> bytes: ... def bytes(val: any) -> bytes: ...
@staticmethod @staticmethod
@PIKA_C_MACRO_IF("PIKA_SYNTAX_FORMAT_ENABLE") @PIKA_C_MACRO_IF("PIKA_SYNTAX_FORMAT_ENABLE")
def cformat(fmt: str, *var) -> str: ... def cformat(fmt: str, *var) -> str: ...
@staticmethod @staticmethod
@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE") @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
def id(obj: any) -> int: ... def id(obj: any) -> int: ...
@staticmethod @staticmethod
@PIKA_C_MACRO_IF("PIKA_FILEIO_ENABLE") @PIKA_C_MACRO_IF("PIKA_FILEIO_ENABLE")
def open(path: str, mode: str) -> object: ... def open(path: str, mode: str) -> object: ...
@staticmethod @staticmethod
@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE") @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
def dir(obj: any) -> list: ... def dir(obj: any) -> list: ...
@staticmethod @staticmethod
@PIKA_C_MACRO_IF("PIKA_EXEC_ENABLE") @PIKA_C_MACRO_IF("PIKA_EXEC_ENABLE")
def exec(code: str): ... def exec(code: str): ...
@staticmethod @staticmethod
@PIKA_C_MACRO_IF("PIKA_EXEC_ENABLE") @PIKA_C_MACRO_IF("PIKA_EXEC_ENABLE")
def eval(code: str) -> any: ... def eval(code: str) -> any: ...
@staticmethod @staticmethod
@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE") @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
def getattr(obj: object, name: str) -> any: ... def getattr(obj: object, name: str) -> any: ...
@staticmethod @staticmethod
@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE") @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
def setattr(obj: object, name: str, val: any): ... def setattr(obj: object, name: str, val: any): ...
@staticmethod @staticmethod
@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE") @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
def hasattr(obj: object, name: str) -> int: ... def hasattr(obj: object, name: str) -> int: ...
@staticmethod @staticmethod
@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE") @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
def exit(): ... def exit(): ...
@staticmethod @staticmethod
@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE") @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
def input(*info) -> str: ... def input(*info) -> str: ...
@staticmethod @staticmethod
@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE") @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
def abs(val: any) -> any: ... def abs(val: any) -> any: ...
@staticmethod @staticmethod
@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE") @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
def max(*val) -> any: ... def max(*val) -> any: ...
@staticmethod @staticmethod
@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE") @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
def min(*val) -> any: ... def min(*val) -> any: ...
@staticmethod @staticmethod
@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE") @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
def help(name: str): ... def help(name: str): ...
@staticmethod @staticmethod
@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE") @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
def reboot(): ... def reboot(): ...
@staticmethod @staticmethod
@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE") @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
def clear(): ... def clear(): ...
@staticmethod @staticmethod
@PIKA_C_MACRO_IF("PIKA_GC_MARK_SWEEP_ENABLE") @PIKA_C_MACRO_IF("PIKA_GC_MARK_SWEEP_ENABLE")
def gcdump(): ... def gcdump(): ...
@PIKA_C_MACRO_IF("0") @PIKA_C_MACRO_IF("0")
class RangeObj: class RangeObj:
def __next__(self) -> any: ... def __next__(self) -> any: ...
@ -146,3 +184,267 @@ class RangeObj:
@PIKA_C_MACRO_IF("0") @PIKA_C_MACRO_IF("0")
class StringObj: class StringObj:
def __next__(self) -> any: ... def __next__(self) -> any: ...
class object:
pass
class BaseException(object):
pass
class Exception(BaseException):
pass
class SystemExit(BaseException):
pass
class KeyboardInterrupt(BaseException):
pass
class GeneratorExit(BaseException):
pass
class Exception(BaseException):
pass
class StopIteration(Exception):
pass
class StopAsyncIteration(Exception):
pass
class ArithmeticError(Exception):
pass
class FloatingPointError(ArithmeticError):
pass
class OverflowError(ArithmeticError):
pass
class ZeroDivisionError(ArithmeticError):
pass
class AssertionError(Exception):
pass
class AttributeError(Exception):
pass
class BufferError(Exception):
pass
class EOFError(Exception):
pass
class ImportError(Exception):
pass
class ModuleNotFoundError(ImportError):
pass
class LookupError(Exception):
pass
class IndexError(LookupError):
pass
class KeyError(LookupError):
pass
class MemoryError(Exception):
pass
class NameError(Exception):
pass
class UnboundLocalError(NameError):
pass
class OSError(Exception):
pass
class BlockingIOError(OSError):
pass
class ChildProcessError(OSError):
pass
class ConnectionError(OSError):
pass
class BrokenPipeError(ConnectionError):
pass
class ConnectionAbortedError(ConnectionError):
pass
class ConnectionRefusedError(ConnectionError):
pass
class ConnectionResetError(ConnectionError):
pass
class FileExistsError(OSError):
pass
class FileNotFoundError(OSError):
pass
class InterruptedError(OSError):
pass
class IsADirectoryError(OSError):
pass
class NotADirectoryError(OSError):
pass
class PermissionError(OSError):
pass
class ProcessLookupError(OSError):
pass
class TimeoutError(OSError):
pass
class ReferenceError(Exception):
pass
class RuntimeError(Exception):
pass
class NotImplementedError(RuntimeError):
pass
class RecursionError(RuntimeError):
pass
class SyntaxError(Exception):
pass
class IndentationError(SyntaxError):
pass
class TabError(IndentationError):
pass
class SystemError(Exception):
pass
class TypeError(Exception):
pass
class ValueError(Exception):
pass
class UnicodeError(ValueError):
pass
class UnicodeDecodeError(UnicodeError):
pass
class UnicodeEncodeError(UnicodeError):
pass
class UnicodeTranslateError(UnicodeError):
pass
class Warning(Exception):
pass
class DeprecationWarning(Warning):
pass
class PendingDeprecationWarning(Warning):
pass
class RuntimeWarning(Warning):
pass
class SyntaxWarning(Warning):
pass
class UserWarning(Warning):
pass
class FutureWarning(Warning):
pass
class ImportWarning(Warning):
pass
class UnicodeWarning(Warning):
pass
class BytesWarning(Warning):
pass
class ResourceWarning(Warning):
pass

View File

@ -24,7 +24,7 @@
// "--gtest_filter=lua.eval" // "--gtest_filter=lua.eval"
// "--gtest_filter=eventloop.once1" // "--gtest_filter=eventloop.once1"
// "--gtest_filter=parser.fn_fn" // "--gtest_filter=parser.fn_fn"
// "--gtest_filter=builtin.isinstance" "--gtest_filter=builtin.isinstance"
// "--gtest_filter=VM.run_def_add" // "--gtest_filter=VM.run_def_add"
// "--gtest_filter=parser.slice_fn" // "--gtest_filter=parser.slice_fn"
], ],

View File

@ -1,143 +1,181 @@
from PikaObj import * from PikaObj import *
@staticmethod @staticmethod
def int(arg: any, *base) -> int: ... def int(arg: any, *base) -> int: ...
@staticmethod @staticmethod
def bool(arg: any) -> bool: ... def bool(arg: any) -> bool: ...
@staticmethod @staticmethod
def float(arg: any) -> float: ... def float(arg: any) -> float: ...
@staticmethod @staticmethod
def str(arg: any) -> str: ... def str(arg: any) -> str: ...
@staticmethod @staticmethod
def iter(arg: any) -> any: ... def iter(arg: any) -> any: ...
@staticmethod @staticmethod
def range(*ax) -> any: ... def range(*ax) -> any: ...
@staticmethod @staticmethod
def print(*val, **ops): ... def print(*val, **ops): ...
@staticmethod @staticmethod
def __setitem__(obj: any, key: any, val: any) -> any: ... def __setitem__(obj: any, key: any, val: any) -> any: ...
@staticmethod @staticmethod
def __getitem__(obj: any, key: any) -> any: ... def __getitem__(obj: any, key: any) -> any: ...
@staticmethod @staticmethod
@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE") @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
def type(arg: any) -> any: ... def type(arg: any) -> any: ...
@staticmethod @staticmethod
@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE") @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
def isinstance(object: any, classinfo: any) -> bool: ... def isinstance(object: any, classinfo: any) -> bool: ...
@staticmethod @staticmethod
def len(arg: any) -> int: ... def len(arg: any) -> int: ...
@staticmethod @staticmethod
@PIKA_C_MACRO_IF("PIKA_BUILTIN_STRUCT_ENABLE") @PIKA_C_MACRO_IF("PIKA_BUILTIN_STRUCT_ENABLE")
def list(*val) -> any: ... def list(*val) -> any: ...
@staticmethod @staticmethod
@PIKA_C_MACRO_IF("PIKA_BUILTIN_STRUCT_ENABLE") @PIKA_C_MACRO_IF("PIKA_BUILTIN_STRUCT_ENABLE")
def dict(*val) -> any: ... def dict(*val) -> any: ...
@staticmethod @staticmethod
@PIKA_C_MACRO_IF("PIKA_BUILTIN_STRUCT_ENABLE") @PIKA_C_MACRO_IF("PIKA_BUILTIN_STRUCT_ENABLE")
def tuple(arg: any) -> any: ... def tuple(arg: any) -> any: ...
@staticmethod @staticmethod
@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE") @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
def hex(val: int) -> str: ... def hex(val: int) -> str: ...
@staticmethod @staticmethod
@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE") @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
def ord(val: str) -> int: ... def ord(val: str) -> int: ...
@staticmethod @staticmethod
@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE") @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
def chr(val: int) -> str: ... def chr(val: int) -> str: ...
@staticmethod @staticmethod
@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE") @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
def bytes(val: any) -> bytes: ... def bytes(val: any) -> bytes: ...
@staticmethod @staticmethod
@PIKA_C_MACRO_IF("PIKA_SYNTAX_FORMAT_ENABLE") @PIKA_C_MACRO_IF("PIKA_SYNTAX_FORMAT_ENABLE")
def cformat(fmt: str, *var) -> str: ... def cformat(fmt: str, *var) -> str: ...
@staticmethod @staticmethod
@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE") @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
def id(obj: any) -> int: ... def id(obj: any) -> int: ...
@staticmethod @staticmethod
@PIKA_C_MACRO_IF("PIKA_FILEIO_ENABLE") @PIKA_C_MACRO_IF("PIKA_FILEIO_ENABLE")
def open(path: str, mode: str) -> object: ... def open(path: str, mode: str) -> object: ...
@staticmethod @staticmethod
@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE") @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
def dir(obj: any) -> list: ... def dir(obj: any) -> list: ...
@staticmethod @staticmethod
@PIKA_C_MACRO_IF("PIKA_EXEC_ENABLE") @PIKA_C_MACRO_IF("PIKA_EXEC_ENABLE")
def exec(code: str): ... def exec(code: str): ...
@staticmethod @staticmethod
@PIKA_C_MACRO_IF("PIKA_EXEC_ENABLE") @PIKA_C_MACRO_IF("PIKA_EXEC_ENABLE")
def eval(code: str) -> any: ... def eval(code: str) -> any: ...
@staticmethod @staticmethod
@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE") @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
def getattr(obj: object, name: str) -> any: ... def getattr(obj: object, name: str) -> any: ...
@staticmethod @staticmethod
@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE") @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
def setattr(obj: object, name: str, val: any): ... def setattr(obj: object, name: str, val: any): ...
@staticmethod @staticmethod
@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE") @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
def hasattr(obj: object, name: str) -> int: ... def hasattr(obj: object, name: str) -> int: ...
@staticmethod @staticmethod
@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE") @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
def exit(): ... def exit(): ...
@staticmethod @staticmethod
@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE") @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
def input(*info) -> str: ... def input(*info) -> str: ...
@staticmethod @staticmethod
@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE") @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
def abs(val: any) -> any: ... def abs(val: any) -> any: ...
@staticmethod @staticmethod
@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE") @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
def max(*val) -> any: ... def max(*val) -> any: ...
@staticmethod @staticmethod
@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE") @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
def min(*val) -> any: ... def min(*val) -> any: ...
@staticmethod @staticmethod
@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE") @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
def help(name: str): ... def help(name: str): ...
@staticmethod @staticmethod
@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE") @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
def reboot(): ... def reboot(): ...
@staticmethod @staticmethod
@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE") @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
def clear(): ... def clear(): ...
@staticmethod @staticmethod
@PIKA_C_MACRO_IF("PIKA_GC_MARK_SWEEP_ENABLE") @PIKA_C_MACRO_IF("PIKA_GC_MARK_SWEEP_ENABLE")
def gcdump(): ... def gcdump(): ...
@PIKA_C_MACRO_IF("0") @PIKA_C_MACRO_IF("0")
class RangeObj: class RangeObj:
def __next__(self) -> any: ... def __next__(self) -> any: ...
@ -146,3 +184,267 @@ class RangeObj:
@PIKA_C_MACRO_IF("0") @PIKA_C_MACRO_IF("0")
class StringObj: class StringObj:
def __next__(self) -> any: ... def __next__(self) -> any: ...
class object:
pass
class BaseException(object):
pass
class Exception(BaseException):
pass
class SystemExit(BaseException):
pass
class KeyboardInterrupt(BaseException):
pass
class GeneratorExit(BaseException):
pass
class Exception(BaseException):
pass
class StopIteration(Exception):
pass
class StopAsyncIteration(Exception):
pass
class ArithmeticError(Exception):
pass
class FloatingPointError(ArithmeticError):
pass
class OverflowError(ArithmeticError):
pass
class ZeroDivisionError(ArithmeticError):
pass
class AssertionError(Exception):
pass
class AttributeError(Exception):
pass
class BufferError(Exception):
pass
class EOFError(Exception):
pass
class ImportError(Exception):
pass
class ModuleNotFoundError(ImportError):
pass
class LookupError(Exception):
pass
class IndexError(LookupError):
pass
class KeyError(LookupError):
pass
class MemoryError(Exception):
pass
class NameError(Exception):
pass
class UnboundLocalError(NameError):
pass
class OSError(Exception):
pass
class BlockingIOError(OSError):
pass
class ChildProcessError(OSError):
pass
class ConnectionError(OSError):
pass
class BrokenPipeError(ConnectionError):
pass
class ConnectionAbortedError(ConnectionError):
pass
class ConnectionRefusedError(ConnectionError):
pass
class ConnectionResetError(ConnectionError):
pass
class FileExistsError(OSError):
pass
class FileNotFoundError(OSError):
pass
class InterruptedError(OSError):
pass
class IsADirectoryError(OSError):
pass
class NotADirectoryError(OSError):
pass
class PermissionError(OSError):
pass
class ProcessLookupError(OSError):
pass
class TimeoutError(OSError):
pass
class ReferenceError(Exception):
pass
class RuntimeError(Exception):
pass
class NotImplementedError(RuntimeError):
pass
class RecursionError(RuntimeError):
pass
class SyntaxError(Exception):
pass
class IndentationError(SyntaxError):
pass
class TabError(IndentationError):
pass
class SystemError(Exception):
pass
class TypeError(Exception):
pass
class ValueError(Exception):
pass
class UnicodeError(ValueError):
pass
class UnicodeDecodeError(UnicodeError):
pass
class UnicodeEncodeError(UnicodeError):
pass
class UnicodeTranslateError(UnicodeError):
pass
class Warning(Exception):
pass
class DeprecationWarning(Warning):
pass
class PendingDeprecationWarning(Warning):
pass
class RuntimeWarning(Warning):
pass
class SyntaxWarning(Warning):
pass
class UserWarning(Warning):
pass
class FutureWarning(Warning):
pass
class ImportWarning(Warning):
pass
class UnicodeWarning(Warning):
pass
class BytesWarning(Warning):
pass
class ResourceWarning(Warning):
pass

View File

@ -981,25 +981,41 @@ char* methodArg_getName(Arg* method_arg, char* buffs, size_t size) {
char* _find_super_class_name(ByteCodeFrame* bcframe, int32_t pc_start); char* _find_super_class_name(ByteCodeFrame* bcframe, int32_t pc_start);
Arg* _builtin_class(char* sRunPath); Arg* _builtin_class(char* sRunPath);
Arg* methodArg_super(Arg* method_arg) { Arg* methodArg_super(Arg* aThis) {
Arg* aSuper = NULL; Arg* aSuper = NULL;
if (!arg_isConstructor(method_arg)) { PikaObj* builtins = NULL;
return NULL; ArgType type = arg_getType(aThis);
if (!argType_isConstructor(type)) {
aSuper = NULL;
goto __exit;
} }
MethodProp* method_store = (MethodProp*)arg_getContent(method_arg); if (type == ARG_TYPE_METHOD_CONSTRUCTOR) {
builtins = obj_getBuiltins();
MethodProp* method_store = (MethodProp*)arg_getContent(aThis);
ByteCodeFrame* bcframe = method_store->bytecode_frame; ByteCodeFrame* bcframe = method_store->bytecode_frame;
int32_t pc = method_store->ptr - bcframe->instruct_array.content_start; int32_t pc = method_store->ptr - bcframe->instruct_array.content_start;
char* sSuper = _find_super_class_name(bcframe, pc); char* sSuper = _find_super_class_name(bcframe, pc);
aSuper = _builtin_class(sSuper); /* map TinyObj to object */
if (NULL != aSuper) { if (strEqu(sSuper, "TinyObj")) {
arg_deinit(method_arg); sSuper = "object";
arg_deinit(aSuper);
return NULL;
} }
PikaObj* context = method_store->def_context; PikaObj* context = method_store->def_context;
aSuper = obj_getMethodArgWithFullPath(context, sSuper); aSuper = obj_getMethodArgWithFullPath(context, sSuper);
if (NULL == aSuper) {
aSuper = obj_getMethodArgWithFullPath(builtins, sSuper);
}
goto __exit;
}
if (type == ARG_TYPE_METHOD_CONSTRUCTOR) {
aSuper = NULL;
goto __exit;
}
__exit:
if (NULL != builtins) {
obj_deinit(builtins);
}
if (NULL != aSuper) { if (NULL != aSuper) {
arg_deinit(method_arg); arg_deinit(aThis);
} }
return aSuper; return aSuper;
} }

View File

@ -1828,14 +1828,11 @@ static char* _find_self_name(VMState* vm) {
} }
#endif #endif
PikaObj* New_builtins_object(Args* args);
Arg* _builtin_class(char* sRunPath) { Arg* _builtin_class(char* sRunPath) {
/* return tiny obj */ /* return tiny obj */
if (strEqu(sRunPath, "TinyObj")) { if (strEqu(sRunPath, "TinyObj")) {
return arg_newMetaObj(New_TinyObj); return arg_newMetaObj(New_builtins_object);
}
if (strEqu(sRunPath, "object")) {
return arg_newMetaObj(New_TinyObj);
} }
return NULL; return NULL;
@ -2936,9 +2933,9 @@ static Arg* VM_instruction_handler_OPT(PikaObj* self,
#if !PIKA_NANO_ENABLE #if !PIKA_NANO_ENABLE
if (argType_isObject(op.t1) && argType_isObject(op.t2)) { if (argType_isObject(op.t1) && argType_isObject(op.t2)) {
if (arg_getPtr(op.a1) == arg_getPtr(op.a2)) { if (arg_getPtr(op.a1) == arg_getPtr(op.a2)) {
op.res = arg_setInt(op.res, "", 1); op.res = arg_setBool(op.res, "", pika_true);
} else { } else {
op.res = arg_setInt(op.res, "", 0); op.res = arg_setBool(op.res, "", pika_false);
} }
goto exit; goto exit;
} }

View File

@ -4,8 +4,12 @@ assert isinstance("Hello, world!", str) == True
assert isinstance([1, 2, 3, 4, 5], list) == True assert isinstance([1, 2, 3, 4, 5], list) == True
assert isinstance({"key": "value"}, dict) == True assert isinstance({"key": "value"}, dict) == True
assert isinstance(3.14, float) == True assert isinstance(3.14, float) == True
assert isinstance(object(), object) == True
class BaseClass: class MyClass:
pass
class BaseClass(object):
def __init__(self): def __init__(self):
self.a = 1 self.a = 1
@ -18,6 +22,8 @@ base_instance = BaseClass()
derived_instance = DerivedClass() derived_instance = DerivedClass()
# Instances of DerivedClass should also be instances of BaseClass # Instances of DerivedClass should also be instances of BaseClass
assert isinstance(MyClass(), object) == True
assert isinstance(base_instance, object) == True
assert isinstance(base_instance, BaseClass) == True assert isinstance(base_instance, BaseClass) == True
assert isinstance(derived_instance, BaseClass) == True assert isinstance(derived_instance, BaseClass) == True

View File

@ -1,6 +1,3 @@
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include "BaseObj.h" #include "BaseObj.h"
#include "PikaCompiler.h" #include "PikaCompiler.h"
#include "PikaObj.h" #include "PikaObj.h"
@ -8,12 +5,14 @@
#include "dataStrs.h" #include "dataStrs.h"
#include "libpikabinder.h" #include "libpikabinder.h"
#include "pikascript/pikascript-core/dataStrs.h" #include "pikascript/pikascript-core/dataStrs.h"
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
void help(char *argv0) { void help(char *argv0) {
Args buffs = {0}; Args buffs = {0};
char *exe = argv0; char *exe = argv0;
printf( printf("Usage:\r\n"
"Usage:\r\n"
" %s" " %s"
" - [Binding C modules and compile all from main.py]\r\n" " - [Binding C modules and compile all from main.py]\r\n"
" %s test.py" " %s test.py"
@ -41,11 +40,14 @@ void PikaStdData_List___init__(PikaObj *self){}
void PikaStdData_List_append(PikaObj *self, Arg *arg) {} void PikaStdData_List_append(PikaObj *self, Arg *arg) {}
void PikaStdData_Dict___init__(PikaObj *self) {} void PikaStdData_Dict___init__(PikaObj *self) {}
void PikaStdData_Dict_set(PikaObj *self, char *key, Arg *val) {} void PikaStdData_Dict_set(PikaObj *self, char *key, Arg *val) {}
PikaObj *New_builtins_object(Args *args);
PikaObj *New_PikaStdLib_SysObj(Args *args) { return NULL; }; PikaObj *New_PikaStdLib_SysObj(Args *args) { return NULL; };
PikaObj *New_builtins(Args *args) { return NULL; }; PikaObj *New_builtins(Args *args) { return NULL; };
PikaObj *New_builtins_RangeObj(Args *args) { return NULL; } PikaObj *New_builtins_RangeObj(Args *args) { return NULL; }
PikaObj *New_PikaStdData_FILEIO(Args *args) { return NULL; } PikaObj *New_PikaStdData_FILEIO(Args *args) { return NULL; }
char* string_slice(Args* outBuffs, char* str, int start, int end) {return NULL;} char *string_slice(Args *outBuffs, char *str, int start, int end) {
return NULL;
}
int PikaStdData_FILEIO_init(PikaObj *self, char *path, char *mode) { return 0; } int PikaStdData_FILEIO_init(PikaObj *self, char *path, char *mode) { return 0; }
static int _do_main(int argc, char **argv) { static int _do_main(int argc, char **argv) {
@ -180,8 +182,7 @@ static int _do_main(int argc, char** argv) {
} }
module_out = strsAppend(&buffs, module_out, ".py.o"); module_out = strsAppend(&buffs, module_out, ".py.o");
printf("compiling %s to %s...\r\n", module_entry, module_out); printf("compiling %s to %s...\r\n", module_entry, module_out);
PIKA_RES res = PIKA_RES res = pikaCompileFileWithOutputName(module_out, module_entry);
pikaCompileFileWithOutputName(module_out, module_entry);
strsDeinit(&buffs); strsDeinit(&buffs);
return res; return res;
} }