mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-15 17:02:53 +08:00
add obj_getNativeMethod API
This commit is contained in:
parent
b254dd02f9
commit
072df471c6
@ -1311,3 +1311,22 @@ TEST(pikaMain, class_demo_1_file) {
|
||||
obj_deinit(self);
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
|
||||
TEST(pikaMain, get_native_method) {
|
||||
/* init */
|
||||
pikaMemInfo.heapUsedMax = 0;
|
||||
PikaObj* pikaMain = newRootObj((char*)"pikaMain", New_PikaMain);
|
||||
__platform_printf((char*)"BEGIN\r\n");
|
||||
/* do some thing */
|
||||
Method print_method = obj_getNativeMethod(pikaMain, (char*)"print");
|
||||
Args args = {0};
|
||||
args_setStr(&args, (char*)"val", (char*)"test");
|
||||
print_method(pikaMain, &args);
|
||||
args_deinit_stack(&args);
|
||||
/* assert */
|
||||
EXPECT_STREQ(log_buff[0], (char*)"test\r\n");
|
||||
EXPECT_STREQ(log_buff[1], (char*)"BEGIN\r\n");
|
||||
/* deinit */
|
||||
obj_deinit(pikaMain);
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ static void print_no_end(PikaObj* self, Args* args) {
|
||||
// obj_setSysOut(self, res);
|
||||
}
|
||||
|
||||
static void print(PikaObj* self, Args* args) {
|
||||
void print(PikaObj* self, Args* args) {
|
||||
obj_setErrorCode(self, 0);
|
||||
char* res = args_print(args, "val");
|
||||
if (NULL == res) {
|
||||
|
@ -275,7 +275,7 @@ PikaObj* obj_getClassObjByNewFun(PikaObj* context,
|
||||
return thisClass;
|
||||
}
|
||||
|
||||
Arg* obj_getMethod(PikaObj* obj, char* methodPath) {
|
||||
Arg* obj_getMethodArg(PikaObj* obj, char* methodPath) {
|
||||
Arg* method = NULL;
|
||||
char* methodName = strPointToLastToken(methodPath, '.');
|
||||
method = obj_getArg(obj, methodName);
|
||||
@ -393,6 +393,13 @@ Method methodArg_getPtr(Arg* method_arg) {
|
||||
return ptr;
|
||||
}
|
||||
|
||||
Method obj_getNativeMethod(PikaObj* self, char* method_name) {
|
||||
Arg* method_arg = obj_getMethodArg(self, method_name);
|
||||
Method res = methodArg_getPtr(method_arg);
|
||||
arg_deinit(method_arg);
|
||||
return res;
|
||||
}
|
||||
|
||||
ByteCodeFrame* methodArg_getBytecodeFrame(Arg* method_arg) {
|
||||
uint32_t size_ptr = sizeof(void*);
|
||||
void* info = arg_getContent(method_arg) + size_ptr;
|
||||
@ -733,8 +740,6 @@ char* method_getStr(Args* args, char* argName) {
|
||||
return args_getStr(args, argName);
|
||||
}
|
||||
|
||||
|
||||
|
||||
PikaObj* New_PikaObj(void) {
|
||||
PikaObj* self = pikaMalloc(sizeof(PikaObj));
|
||||
/* List */
|
||||
|
@ -156,7 +156,7 @@ int32_t obj_isArgExist(PikaObj* self, char* argPath);
|
||||
PikaObj* obj_getClassObjByNewFun(PikaObj* self, char* name, NewFun newClassFun);
|
||||
PikaObj* newRootObj(char* name, NewFun newObjFun);
|
||||
PikaObj* obj_getClassObj(PikaObj* obj);
|
||||
Arg* obj_getMethod(PikaObj* obj, char* methodPath);
|
||||
Arg* obj_getMethodArg(PikaObj* obj, char* methodPath);
|
||||
|
||||
void obj_setErrorCode(PikaObj* self, int32_t errCode);
|
||||
int32_t obj_getErrorCode(PikaObj* self);
|
||||
@ -210,12 +210,13 @@ void obj_shellLineProcess(PikaObj* self,
|
||||
__obj_shellLineHandler_t __lineHandler_fun,
|
||||
struct shell_config* cfg);
|
||||
|
||||
/*
|
||||
/*
|
||||
need implament :
|
||||
__platform_fopen()
|
||||
__platform_fwrite()
|
||||
__platform_fclose()
|
||||
*/
|
||||
int pikaCompile(char* output_file_name, char* py_lines);
|
||||
Method obj_getNativeMethod(PikaObj* self, char* method_name);
|
||||
|
||||
#endif
|
||||
|
@ -213,9 +213,9 @@ static Arg* VM_instruction_handler_RUN(PikaObj* self, VMState* vs, char* data) {
|
||||
goto RUN_exit;
|
||||
}
|
||||
/* get method in local */
|
||||
method_arg = obj_getMethod(method_host_obj, methodPath);
|
||||
method_arg = obj_getMethodArg(method_host_obj, methodPath);
|
||||
if (NULL == method_arg) {
|
||||
method_arg = obj_getMethod(vs->globals, methodPath);
|
||||
method_arg = obj_getMethodArg(vs->globals, methodPath);
|
||||
}
|
||||
/* assert method*/
|
||||
if (NULL == method_arg) {
|
||||
@ -357,7 +357,7 @@ static Arg* __VM_OUT(PikaObj* self,
|
||||
PikaObj* new_obj = obj_getObj(hostObj, data, 0);
|
||||
/* run __init__() when init obj */
|
||||
Arg* init_method_arg = NULL;
|
||||
init_method_arg = obj_getMethod(new_obj, "__init__");
|
||||
init_method_arg = obj_getMethodArg(new_obj, "__init__");
|
||||
if (NULL != init_method_arg) {
|
||||
arg_deinit(init_method_arg);
|
||||
// pikaVM_runAsm(new_obj,
|
||||
|
Loading…
x
Reference in New Issue
Block a user