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 *
@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: ...
@ -146,3 +184,267 @@ class RangeObj:
@PIKA_C_MACRO_IF("0")
class StringObj:
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=eventloop.once1"
// "--gtest_filter=parser.fn_fn"
// "--gtest_filter=builtin.isinstance"
"--gtest_filter=builtin.isinstance"
// "--gtest_filter=VM.run_def_add"
// "--gtest_filter=parser.slice_fn"
],

View File

@ -1,143 +1,181 @@
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: ...
@ -146,3 +184,267 @@ class RangeObj:
@PIKA_C_MACRO_IF("0")
class StringObj:
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);
Arg* _builtin_class(char* sRunPath);
Arg* methodArg_super(Arg* method_arg) {
Arg* methodArg_super(Arg* aThis) {
Arg* aSuper = NULL;
if (!arg_isConstructor(method_arg)) {
return NULL;
PikaObj* builtins = 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;
int32_t pc = method_store->ptr - bcframe->instruct_array.content_start;
char* sSuper = _find_super_class_name(bcframe, pc);
aSuper = _builtin_class(sSuper);
if (NULL != aSuper) {
arg_deinit(method_arg);
arg_deinit(aSuper);
return NULL;
/* map TinyObj to object */
if (strEqu(sSuper, "TinyObj")) {
sSuper = "object";
}
PikaObj* context = method_store->def_context;
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) {
arg_deinit(method_arg);
arg_deinit(aThis);
}
return aSuper;
}

View File

@ -1828,14 +1828,11 @@ static char* _find_self_name(VMState* vm) {
}
#endif
PikaObj* New_builtins_object(Args* args);
Arg* _builtin_class(char* sRunPath) {
/* return tiny obj */
if (strEqu(sRunPath, "TinyObj")) {
return arg_newMetaObj(New_TinyObj);
}
if (strEqu(sRunPath, "object")) {
return arg_newMetaObj(New_TinyObj);
return arg_newMetaObj(New_builtins_object);
}
return NULL;
@ -2936,9 +2933,9 @@ static Arg* VM_instruction_handler_OPT(PikaObj* self,
#if !PIKA_NANO_ENABLE
if (argType_isObject(op.t1) && argType_isObject(op.t2)) {
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 {
op.res = arg_setInt(op.res, "", 0);
op.res = arg_setBool(op.res, "", pika_false);
}
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({"key": "value"}, dict) == True
assert isinstance(3.14, float) == True
assert isinstance(object(), object) == True
class BaseClass:
class MyClass:
pass
class BaseClass(object):
def __init__(self):
self.a = 1
@ -18,6 +22,8 @@ base_instance = BaseClass()
derived_instance = DerivedClass()
# 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(derived_instance, BaseClass) == True

View File

@ -1,6 +1,3 @@
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include "BaseObj.h"
#include "PikaCompiler.h"
#include "PikaObj.h"
@ -8,12 +5,14 @@
#include "dataStrs.h"
#include "libpikabinder.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};
char* exe = argv0;
printf(
"Usage:\r\n"
char *exe = argv0;
printf("Usage:\r\n"
" %s"
" - [Binding C modules and compile all from main.py]\r\n"
" %s test.py"
@ -29,28 +28,31 @@ void help(char* argv0) {
}
/* fake implement */
PikaObj* __pikaMain;
PikaObj *__pikaMain;
void New_PikaStdData_List(void) {}
void New_PikaStdData_Dict(void) {}
void New_PikaStdData_Tuple(void) {}
void New_PikaStdData_String(void) {}
void New_PikaStdData_ByteArray(void) {}
int strGetSizeUtf8(char* str){return 0;}
void PikaStdData_Tuple___init__(PikaObj *self){}
void PikaStdData_List___init__(PikaObj *self){}
void PikaStdData_List_append(PikaObj *self, Arg* arg){}
void PikaStdData_Dict___init__(PikaObj* self){}
void PikaStdData_Dict_set(PikaObj* self, char* key, Arg* val){}
PikaObj* New_PikaStdLib_SysObj(Args* args) {return NULL;};
PikaObj* New_builtins(Args* args) {return NULL;};
PikaObj* New_builtins_RangeObj(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;}
int PikaStdData_FILEIO_init(PikaObj* self, char* path, char* mode){return 0;}
int strGetSizeUtf8(char *str) { return 0; }
void PikaStdData_Tuple___init__(PikaObj *self) {}
void PikaStdData_List___init__(PikaObj *self) {}
void PikaStdData_List_append(PikaObj *self, Arg *arg) {}
void PikaStdData_Dict___init__(PikaObj *self) {}
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_builtins(Args *args) { return NULL; };
PikaObj *New_builtins_RangeObj(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;
}
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) {
int parc = argc - 1;
PikaMaker* maker = New_PikaMaker();
PikaMaker *maker = New_PikaMaker();
/* --add-file xxx --add-file yyy */
// __platform_printf("parc: %d\r\n", parc);
@ -102,9 +104,9 @@ static int _do_main(int argc, char** argv) {
/* example: ./rust-msc-latest-linux main.py */
if (1 == parc) {
char* module_entry = argv[1];
char *module_entry = argv[1];
/* remove subfix */
char* subfix = strrchr(module_entry, '.');
char *subfix = strrchr(module_entry, '.');
if (subfix) {
*subfix = '\0';
}
@ -117,9 +119,9 @@ static int _do_main(int argc, char** argv) {
/* example ./rust-msc-latest-linux main.py -o out.a */
if (3 == parc) {
if (0 == strcmp(argv[2], "-o")) {
char* module_entry = argv[1];
char *module_entry = argv[1];
/* remove subfix */
char* subfix = strrchr(module_entry, '.');
char *subfix = strrchr(module_entry, '.');
if (subfix) {
*subfix = '\0';
}
@ -134,17 +136,17 @@ static int _do_main(int argc, char** argv) {
if (2 == parc) {
if (0 == strcmp(argv[1], "--docgen")) {
Args buffs = {0};
char* file_path = argv[2];
char* file_name = strsPathGetFileName(&buffs, file_path);
char *file_path = argv[2];
char *file_name = strsPathGetFileName(&buffs, file_path);
printf("file_name: %s\r\n", file_name);
char* file_folder = strsPathGetFolder(&buffs, file_path);
char* file_name_no_ext = strsGetFirstToken(&buffs, file_name, '.');
char *file_folder = strsPathGetFolder(&buffs, file_path);
char *file_name_no_ext = strsGetFirstToken(&buffs, file_name, '.');
printf("file_name_no_ext: %s\r\n", file_name_no_ext);
char* file_out_name = strsAppend(&buffs, file_name_no_ext, ".md");
char *file_out_name = strsAppend(&buffs, file_name_no_ext, ".md");
printf("file_out_name: %s\r\n", file_out_name);
char* file_out_path = strsPathJoin(&buffs, file_folder, file_out_name);
Parser* parser = New_parser();
printf("generating doc %s: %s\r\n", file_path,file_out_path);
char *file_out_path = strsPathJoin(&buffs, file_folder, file_out_name);
Parser *parser = New_parser();
printf("generating doc %s: %s\r\n", file_path, file_out_path);
parser_file2DocFile(parser, file_path, file_out_path);
strsDeinit(&buffs);
parser_deinit(parser);
@ -156,10 +158,10 @@ static int _do_main(int argc, char** argv) {
if (4 == parc) {
if (0 == strcmp(argv[1], "--docgen") && 0 == strcmp(argv[3], "-o")) {
Args buffs = {0};
char* file_path = argv[2];
char* file_out_path = argv[4];
Parser* parser = New_parser();
printf("generating doc %s: %s\r\n", file_path,file_out_path);
char *file_path = argv[2];
char *file_out_path = argv[4];
Parser *parser = New_parser();
printf("generating doc %s: %s\r\n", file_path, file_out_path);
parser_file2DocFile(parser, file_path, file_out_path);
strsDeinit(&buffs);
parser_deinit(parser);
@ -172,16 +174,15 @@ static int _do_main(int argc, char** argv) {
if (0 == strcmp(argv[1], "-c")) {
Args buffs = {0};
/* compile only */
char* module_entry = argv[2];
char* module_out = strsCopy(&buffs, module_entry);
char* subfix = strrchr(module_out, '.');
char *module_entry = argv[2];
char *module_out = strsCopy(&buffs, module_entry);
char *subfix = strrchr(module_out, '.');
if (subfix) {
*subfix = '\0';
}
module_out = strsAppend(&buffs, module_out, ".py.o");
printf("compiling %s to %s...\r\n", module_entry, module_out);
PIKA_RES res =
pikaCompileFileWithOutputName(module_out, module_entry);
PIKA_RES res = pikaCompileFileWithOutputName(module_out, module_entry);
strsDeinit(&buffs);
return res;
}
@ -191,7 +192,7 @@ static int _do_main(int argc, char** argv) {
if (4 == parc) {
if (0 == strcmp(argv[1], "-c") && 0 == strcmp(argv[3], "-o")) {
/* compile only */
char* module_entry = argv[2];
char *module_entry = argv[2];
printf("compiling %s to %s...\r\n", module_entry, argv[4]);
PIKA_RES res = pikaCompileFileWithOutputName(argv[4], module_entry);
return res;
@ -205,27 +206,27 @@ static int _do_main(int argc, char** argv) {
return -1;
}
int main(int argc, char** argv) {
char* buf = NULL;
FILE* pika_studio = NULL;
int main(int argc, char **argv) {
char *buf = NULL;
FILE *pika_studio = NULL;
if (argc == 1) {
pika_studio = __platform_fopen("pika.studio", "r");
if (NULL != pika_studio) {
buf = __platform_malloc(1024);
__platform_fread(buf, 1, 1024, pika_studio);
/* find <args> </args> */
char* start = strstr(buf, "<args>");
char* end = strstr(buf, "</args>");
char *start = strstr(buf, "<args>");
char *end = strstr(buf, "</args>");
if (start && end) {
start += 6;
*end = '\0';
__platform_printf("args: %s\r\n", start);
/* split args */
char* args[32] = {0};
char *args[32] = {0};
args[0] = argv[0];
char* p = start;
char *p = start;
while (p < end) {
char* q = strchr(p, ' ');
char *q = strchr(p, ' ');
if (q) {
*q = '\0';
args[argc++] = p;