mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-15 17:02:53 +08:00
rename TYPE_X to ARG_TYPE_X
This commit is contained in:
parent
233a4a21b4
commit
fd26a79fc8
@ -23,14 +23,14 @@ void PikaStdData_Dict_remove(PikaObj* self, char* key) {
|
||||
|
||||
Arg* PikaStdData_Dict___iter__(PikaObj* self) {
|
||||
obj_setInt(self, "__iter_i", 0);
|
||||
return arg_setPtr(NULL, "", TYPE_POINTER, self);
|
||||
return arg_setPtr(NULL, "", ARG_TYPE_POINTER, self);
|
||||
}
|
||||
|
||||
Arg* PikaStdData_Dict___next__(PikaObj* self) {
|
||||
int __iter_i = args_getInt(self->list, "__iter_i");
|
||||
PikaObj* pyload = obj_getObj(self, "pyload", 0);
|
||||
Arg* res = arg_copy(args_getArg_index(pyload->list, __iter_i));
|
||||
if (TYPE_POINTER == arg_getType(res)) {
|
||||
if (ARG_TYPE_POINTER == arg_getType(res)) {
|
||||
arg_deinit(res);
|
||||
return arg_setNull(NULL);
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ void PikaStdData_List_set(PikaObj* self, Arg* arg, int i) {
|
||||
|
||||
Arg* PikaStdData_List___iter__(PikaObj* self) {
|
||||
obj_setInt(self, "__iter_i", 0);
|
||||
return arg_setPtr(NULL, "", TYPE_POINTER, self);
|
||||
return arg_setPtr(NULL, "", ARG_TYPE_POINTER, self);
|
||||
}
|
||||
|
||||
Arg* PikaStdData_List___next__(PikaObj* self) {
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
Arg* PikaStdData_String___iter__(PikaObj* self) {
|
||||
obj_setInt(self, "__iter_i", 0);
|
||||
return arg_setPtr(NULL, "", TYPE_POINTER, self);
|
||||
return arg_setPtr(NULL, "", ARG_TYPE_POINTER, self);
|
||||
}
|
||||
|
||||
void PikaStdData_String_set(PikaObj* self, char* s) {
|
||||
|
@ -25,27 +25,27 @@ void PikaStdLib_SysObj_type(PikaObj* self, Arg* arg) {
|
||||
return;
|
||||
}
|
||||
ArgType type = arg_getType(arg);
|
||||
if (TYPE_INT == type) {
|
||||
if (ARG_TYPE_INT == type) {
|
||||
obj_setSysOut(self, "int");
|
||||
return;
|
||||
}
|
||||
if (TYPE_FLOAT == type) {
|
||||
if (ARG_TYPE_FLOAT == type) {
|
||||
obj_setSysOut(self, "float");
|
||||
return;
|
||||
}
|
||||
if (TYPE_STRING == type) {
|
||||
if (ARG_TYPE_STRING == type) {
|
||||
obj_setSysOut(self, "string");
|
||||
return;
|
||||
}
|
||||
if (TYPE_POINTER == type) {
|
||||
if (ARG_TYPE_POINTER == type) {
|
||||
obj_setSysOut(self, "pointer");
|
||||
return;
|
||||
}
|
||||
if (TYPE_MATE_OBJECT == type) {
|
||||
if (ARG_TYPE_MATE_OBJECT == type) {
|
||||
obj_setSysOut(self, "mate_object");
|
||||
return;
|
||||
}
|
||||
if (TYPE_METHOD == type) {
|
||||
if (ARG_TYPE_STATIC_METHOD == type) {
|
||||
obj_setSysOut(self, "method");
|
||||
return;
|
||||
}
|
||||
@ -53,10 +53,10 @@ void PikaStdLib_SysObj_type(PikaObj* self, Arg* arg) {
|
||||
|
||||
float PikaStdLib_SysObj_float(PikaObj* self, Arg* arg) {
|
||||
ArgType type = arg_getType(arg);
|
||||
if (TYPE_INT == type) {
|
||||
if (ARG_TYPE_INT == type) {
|
||||
return (float)arg_getInt(arg);
|
||||
}
|
||||
if (TYPE_FLOAT == type) {
|
||||
if (ARG_TYPE_FLOAT == type) {
|
||||
return (float)arg_getFloat(arg);
|
||||
}
|
||||
obj_setSysOut(self, "[error] convert to float type faild.");
|
||||
@ -66,10 +66,10 @@ float PikaStdLib_SysObj_float(PikaObj* self, Arg* arg) {
|
||||
|
||||
int PikaStdLib_SysObj_int(PikaObj* self, Arg* arg) {
|
||||
ArgType type = arg_getType(arg);
|
||||
if (TYPE_INT == type) {
|
||||
if (ARG_TYPE_INT == type) {
|
||||
return (int)arg_getInt(arg);
|
||||
}
|
||||
if (TYPE_FLOAT == type) {
|
||||
if (ARG_TYPE_FLOAT == type) {
|
||||
return (int)arg_getFloat(arg);
|
||||
}
|
||||
obj_setSysOut(self, "[error] convert to int type faild.");
|
||||
@ -82,12 +82,12 @@ char* PikaStdLib_SysObj_str(PikaObj* self, Arg* arg) {
|
||||
Args* buffs = New_strBuff();
|
||||
char* res = NULL;
|
||||
do {
|
||||
if (TYPE_INT == type) {
|
||||
if (ARG_TYPE_INT == type) {
|
||||
int val = arg_getInt(arg);
|
||||
res = strsFormat(buffs, 11, "%d", val);
|
||||
break;
|
||||
}
|
||||
if (TYPE_FLOAT == type) {
|
||||
if (ARG_TYPE_FLOAT == type) {
|
||||
float val = arg_getFloat(arg);
|
||||
res = strsFormat(buffs, 11, "%f", val);
|
||||
break;
|
||||
@ -100,17 +100,17 @@ char* PikaStdLib_SysObj_str(PikaObj* self, Arg* arg) {
|
||||
|
||||
Arg* PikaStdLib_SysObj_iter(PikaObj* self, Arg* arg) {
|
||||
/* a String, return a StringObj */
|
||||
if (TYPE_STRING == arg_getType(arg)) {
|
||||
if (ARG_TYPE_STRING == arg_getType(arg)) {
|
||||
obj_setStr(self, "_sobj", arg_getStr(arg));
|
||||
return arg_setMetaObj("", "PikaStdLib_StringObj",
|
||||
New_PikaStdLib_StringObj);
|
||||
}
|
||||
/* a MATE object, return itself */
|
||||
if (TYPE_MATE_OBJECT == arg_getType(arg)) {
|
||||
if (ARG_TYPE_MATE_OBJECT == arg_getType(arg)) {
|
||||
return arg_copy(arg);
|
||||
}
|
||||
/* object */
|
||||
if (TYPE_POINTER == arg_getType(arg)) {
|
||||
if (ARG_TYPE_POINTER == arg_getType(arg)) {
|
||||
PikaObj* arg_obj = arg_getPtr(arg);
|
||||
pikaVM_runAsm(arg_obj,
|
||||
"B0\n"
|
||||
@ -140,14 +140,14 @@ Arg* PikaStdLib_SysObj_range(PikaObj* self, int a1, int a2, int a3) {
|
||||
|
||||
Arg* PikaStdLib_SysObj___get__(PikaObj* self, Arg* key, Arg* obj) {
|
||||
ArgType obj_type = arg_getType(obj);
|
||||
if (TYPE_STRING == obj_type) {
|
||||
if (ARG_TYPE_STRING == obj_type) {
|
||||
int index = arg_getInt(key);
|
||||
char* str_pyload = arg_getStr(obj);
|
||||
char char_buff[] = " ";
|
||||
char_buff[0] = str_pyload[index];
|
||||
return arg_setStr(NULL, "", char_buff);
|
||||
}
|
||||
if ((TYPE_OBJECT == obj_type) || (TYPE_POINTER == obj_type)) {
|
||||
if ((ARG_TYPE_OBJECT == obj_type) || (ARG_TYPE_POINTER == obj_type)) {
|
||||
PikaObj* arg_obj = arg_getPtr(obj);
|
||||
obj_setArg(arg_obj, "__key", key);
|
||||
pikaVM_runAsm(arg_obj,
|
||||
@ -166,14 +166,14 @@ void PikaStdLib_SysObj___set__(PikaObj* self,
|
||||
char* obj_str,
|
||||
Arg* val) {
|
||||
ArgType obj_type = arg_getType(obj);
|
||||
if (TYPE_STRING == obj_type) {
|
||||
if (ARG_TYPE_STRING == obj_type) {
|
||||
int index = arg_getInt(key);
|
||||
char* str_val = arg_getStr(val);
|
||||
char* str_pyload = arg_getStr(obj);
|
||||
str_pyload[index] = str_val[0];
|
||||
obj_setStr(self, obj_str, str_pyload);
|
||||
}
|
||||
if ((TYPE_OBJECT == obj_type) || (TYPE_POINTER == obj_type)) {
|
||||
if ((ARG_TYPE_OBJECT == obj_type) || (ARG_TYPE_POINTER == obj_type)) {
|
||||
PikaObj* arg_obj = arg_getPtr(obj);
|
||||
obj_setArg(arg_obj, "__key", key);
|
||||
obj_setArg(arg_obj, "__val", val);
|
||||
|
@ -680,8 +680,8 @@ TEST(VM, RUN_NEW) {
|
||||
ArgType newObj_type = arg_getType(newObj);
|
||||
ArgType outObj_type = arg_getType(outObj);
|
||||
EXPECT_EQ(x, 1);
|
||||
EXPECT_EQ(newObj_type, TYPE_POINTER);
|
||||
EXPECT_EQ(outObj_type, TYPE_OBJECT);
|
||||
EXPECT_EQ(newObj_type, ARG_TYPE_POINTER);
|
||||
EXPECT_EQ(outObj_type, ARG_TYPE_OBJECT);
|
||||
obj_deinit(self);
|
||||
// obj_deinit(globals);
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
@ -736,7 +736,7 @@ TEST(VM, class_x_1) {
|
||||
PikaObj* test = obj_getObj(self, (char*)"test", 0);
|
||||
Arg* test_arg = obj_getArg(self, (char*)"test");
|
||||
ArgType test_arg_type = arg_getType(test_arg);
|
||||
EXPECT_EQ(test_arg_type, TYPE_OBJECT);
|
||||
EXPECT_EQ(test_arg_type, ARG_TYPE_OBJECT);
|
||||
int x = obj_getInt(test, (char*)"x");
|
||||
EXPECT_EQ(x, 1);
|
||||
obj_deinit(self);
|
||||
|
@ -34,7 +34,7 @@ TEST(arg_test, str_) {
|
||||
TEST(arg_test, ptr) {
|
||||
Arg* arg = New_arg(NULL);
|
||||
int a = 1;
|
||||
arg = arg_setPtr(arg, (char*)"test", TYPE_POINTER, &a);
|
||||
arg = arg_setPtr(arg, (char*)"test", ARG_TYPE_POINTER, &a);
|
||||
int* pa = (int*)arg_getPtr(arg);
|
||||
EXPECT_EQ(*pa, 1);
|
||||
arg_deinit(arg);
|
||||
@ -52,9 +52,9 @@ TEST(arg_test, name) {
|
||||
|
||||
TEST(arg_test, type) {
|
||||
Arg* arg = New_arg(NULL);
|
||||
arg = arg_setType(arg, TYPE_NONE);
|
||||
arg = arg_setType(arg, ARG_TYPE_NONE);
|
||||
ArgType type = arg_getType(arg);
|
||||
EXPECT_EQ(TYPE_NONE, type);
|
||||
EXPECT_EQ(ARG_TYPE_NONE, type);
|
||||
arg_deinit(arg);
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
@ -63,7 +63,7 @@ TEST(arg_test, null) {
|
||||
Arg* arg = New_arg(NULL);
|
||||
arg = arg_setNull(arg);
|
||||
ArgType type = arg_getType(arg);
|
||||
EXPECT_EQ(TYPE_NULL, type);
|
||||
EXPECT_EQ(ARG_TYPE_NULL, type);
|
||||
arg_deinit(arg);
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
|
@ -39,9 +39,9 @@ TEST(args, test2) {
|
||||
EXPECT_EQ(int64Out, 22221);
|
||||
EXPECT_EQ((uint64_t)pointer, 2222322);
|
||||
EXPECT_EQ(1, strEqu((char*)"teeeds", strOut));
|
||||
EXPECT_EQ(args_getType(args, (char*)"int64Test"), TYPE_INT);
|
||||
EXPECT_EQ(args_getType(args, (char*)"pointerTest"), TYPE_POINTER);
|
||||
EXPECT_EQ(args_getType(args, (char*)"strTest"), TYPE_STRING);
|
||||
EXPECT_EQ(args_getType(args, (char*)"int64Test"), ARG_TYPE_INT);
|
||||
EXPECT_EQ(args_getType(args, (char*)"pointerTest"), ARG_TYPE_POINTER);
|
||||
EXPECT_EQ(args_getType(args, (char*)"strTest"), ARG_TYPE_STRING);
|
||||
args_deinit(args);
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ TEST(content, init) {
|
||||
contentIn[1] = 2;
|
||||
contentIn[2] = 3;
|
||||
contentIn[3] = 4;
|
||||
uint8_t* self = content_init((char*)"name", TYPE_NONE, contentIn, 4, NULL);
|
||||
uint8_t* self = content_init((char*)"name", ARG_TYPE_NONE, contentIn, 4, NULL);
|
||||
|
||||
uint16_t typeOffset = content_typeOffset(self);
|
||||
uint16_t sizeOffset = content_sizeOffset(self);
|
||||
@ -33,7 +33,7 @@ TEST(content, init) {
|
||||
ASSERT_EQ(totleSize, 24);
|
||||
|
||||
ASSERT_EQ(hash_time33((char*)"name"), nameHash);
|
||||
ASSERT_EQ(TYPE_NONE, type);
|
||||
ASSERT_EQ(ARG_TYPE_NONE, type);
|
||||
|
||||
content_deinit(self);
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
@ -45,9 +45,9 @@ TEST(content, set) {
|
||||
contentIn[1] = 2;
|
||||
contentIn[2] = 3;
|
||||
contentIn[3] = 4;
|
||||
uint8_t* self = content_init((char*)"", TYPE_NONE, NULL, 0, NULL);
|
||||
uint8_t* self = content_init((char*)"", ARG_TYPE_NONE, NULL, 0, NULL);
|
||||
self = content_setName(self, (char*)"name");
|
||||
self = content_setType(self, TYPE_NONE);
|
||||
self = content_setType(self, ARG_TYPE_NONE);
|
||||
self = content_setContent(self, contentIn, 4);
|
||||
|
||||
uint16_t typeOffset = content_typeOffset(self);
|
||||
@ -71,15 +71,15 @@ TEST(content, set) {
|
||||
ASSERT_EQ(totleSize, 24);
|
||||
|
||||
ASSERT_EQ(hash_time33((char*)"name"), nameHash);
|
||||
ASSERT_EQ(TYPE_NONE, type);
|
||||
ASSERT_EQ(ARG_TYPE_NONE, type);
|
||||
|
||||
content_deinit(self);
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
|
||||
TEST(content, next) {
|
||||
uint8_t* c1 = content_init((char*)"c1", TYPE_NONE, NULL, 0, NULL);
|
||||
uint8_t* c2 = content_init((char*)"c2", TYPE_NONE, NULL, 0, c1);
|
||||
uint8_t* c1 = content_init((char*)"c1", ARG_TYPE_NONE, NULL, 0, NULL);
|
||||
uint8_t* c2 = content_init((char*)"c2", ARG_TYPE_NONE, NULL, 0, c1);
|
||||
uint8_t* c3 = content_getNext(c2);
|
||||
|
||||
ASSERT_EQ(c3, c1);
|
||||
@ -89,8 +89,8 @@ TEST(content, next) {
|
||||
}
|
||||
|
||||
TEST(content, setNext) {
|
||||
uint8_t* c1 = content_init((char*)"c1", TYPE_NONE, NULL, 0, NULL);
|
||||
content_setNext(c1, content_init((char*)"c2", TYPE_NONE, NULL, 0, NULL));
|
||||
uint8_t* c1 = content_init((char*)"c1", ARG_TYPE_NONE, NULL, 0, NULL);
|
||||
content_setNext(c1, content_init((char*)"c2", ARG_TYPE_NONE, NULL, 0, NULL));
|
||||
uint8_t* c2 = content_getNext(c1);
|
||||
Hash c2NameHash = content_getNameHash(c2);
|
||||
EXPECT_EQ(c2NameHash, hash_time33((char*)"c2"));
|
||||
|
@ -12,7 +12,7 @@ TEST(queue, NEW) {
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
|
||||
TEST(queue, TYPE_INT) {
|
||||
TEST(queue, ARG_TYPE_INT) {
|
||||
Queue* q = New_queue();
|
||||
queue_pushInt(q, 1);
|
||||
queue_pushInt(q, 2);
|
||||
@ -39,7 +39,7 @@ TEST(queue, arg) {
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
|
||||
TEST(queue, TYPE_FLOAT) {
|
||||
TEST(queue, ARG_TYPE_FLOAT) {
|
||||
Queue* q = New_queue();
|
||||
queue_pushFloat(q, 1.1f);
|
||||
queue_pushFloat(q, 2.2f);
|
||||
@ -70,7 +70,7 @@ TEST(queueObj, init) {
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
|
||||
TEST(queueObj, TYPE_INT) {
|
||||
TEST(queueObj, ARG_TYPE_INT) {
|
||||
QueueObj* q = New_TinyObj(NULL);
|
||||
queueObj_init(q);
|
||||
queueObj_pushInt(q, 1);
|
||||
@ -83,7 +83,7 @@ TEST(queueObj, TYPE_INT) {
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
|
||||
TEST(queueObj, TYPE_FLOAT) {
|
||||
TEST(queueObj, ARG_TYPE_FLOAT) {
|
||||
QueueObj* q = New_TinyObj(NULL);
|
||||
queueObj_init(q);
|
||||
queueObj_pushFloat(q, 1.1f);
|
||||
@ -135,7 +135,7 @@ TEST(queueObj, currentObj) {
|
||||
PikaObj* currentObj = queueObj_getCurrentObj(q);
|
||||
EXPECT_TRUE(currentObj != NULL);
|
||||
ArgType type = args_getType(q->list, (char*)"0");
|
||||
EXPECT_EQ(TYPE_OBJECT, type);
|
||||
EXPECT_EQ(ARG_TYPE_OBJECT, type);
|
||||
obj_setInt(queueObj_getCurrentObj(q), (char*)"test", 1);
|
||||
|
||||
queueObj_pushObj(q, (char*)"type2");
|
||||
|
@ -38,7 +38,7 @@ Arg* arg_setMetaObj(char* objName, char* className, NewFun objPtr) {
|
||||
Args* buffs = New_strBuff();
|
||||
Arg* argNew = New_arg(NULL);
|
||||
/* m means mate-object */
|
||||
argNew = arg_setPtr(argNew, objName, TYPE_MATE_OBJECT, (void*)objPtr);
|
||||
argNew = arg_setPtr(argNew, objName, ARG_TYPE_MATE_OBJECT, (void*)objPtr);
|
||||
args_deinit(buffs);
|
||||
return argNew;
|
||||
}
|
||||
|
@ -103,7 +103,7 @@ int32_t deinitEachSubObj(Arg* argEach, Args* handleArgs) {
|
||||
}
|
||||
ArgType type = arg_getType(argEach);
|
||||
/* deinit sub object */
|
||||
if (type == TYPE_OBJECT) {
|
||||
if (type == ARG_TYPE_OBJECT) {
|
||||
PikaObj* subObj = arg_getPtr(argEach);
|
||||
obj_deinit(subObj);
|
||||
}
|
||||
@ -327,7 +327,7 @@ void* getNewClassObjFunByName(PikaObj* obj, char* name) {
|
||||
}
|
||||
|
||||
int32_t __foreach_removeMethodInfo(Arg* argNow, Args* argList) {
|
||||
if (arg_getType(argNow) == TYPE_METHOD) {
|
||||
if (arg_getType(argNow) == ARG_TYPE_STATIC_METHOD) {
|
||||
args_removeArg(argList, argNow);
|
||||
return 0;
|
||||
}
|
||||
@ -359,7 +359,7 @@ static PikaObj* __initObj(PikaObj* obj, char* name) {
|
||||
thisClass = obj_getClassObjByNewFun(obj, name, newObjFun);
|
||||
newObj = removeMethodInfo(thisClass);
|
||||
|
||||
args_setPtrWithType(obj->list, name, TYPE_OBJECT, newObj);
|
||||
args_setPtrWithType(obj->list, name, ARG_TYPE_OBJECT, newObj);
|
||||
res = obj_getPtr(obj, name);
|
||||
goto exit;
|
||||
exit:
|
||||
@ -374,11 +374,11 @@ PikaObj* obj_getObjDirect(PikaObj* self, char* name) {
|
||||
/* finded object, check type*/
|
||||
ArgType type = args_getType(self->list, name);
|
||||
/* found mate Object */
|
||||
if (type == TYPE_MATE_OBJECT) {
|
||||
if (type == ARG_TYPE_MATE_OBJECT) {
|
||||
return __initObj(self, name);
|
||||
}
|
||||
/* found Objcet */
|
||||
if (type == TYPE_OBJECT || type == TYPE_POINTER) {
|
||||
if (type == ARG_TYPE_OBJECT || type == ARG_TYPE_POINTER) {
|
||||
return args_getPtr(self->list, name);
|
||||
}
|
||||
return NULL;
|
||||
@ -431,7 +431,7 @@ void obj_saveMethodInfo(PikaObj* self,
|
||||
/* +1 to add \0 */
|
||||
__platform_memcpy((void*)((uintptr_t)info + size_ptr), pars, size_pars + 1);
|
||||
arg = arg_setName(arg, method_name);
|
||||
arg = arg_setType(arg, TYPE_METHOD);
|
||||
arg = arg_setType(arg, ARG_TYPE_STATIC_METHOD);
|
||||
arg = arg_setContent(arg, info, size_info);
|
||||
|
||||
args_setArg(self->list, arg);
|
||||
@ -487,7 +487,7 @@ int32_t obj_removeArg(PikaObj* self, char* argPath) {
|
||||
Args* buffs = New_strBuff();
|
||||
char* argName;
|
||||
int32_t res;
|
||||
if (TYPE_OBJECT == arg_getType(obj_arg)) {
|
||||
if (ARG_TYPE_OBJECT == arg_getType(obj_arg)) {
|
||||
obj_deinit(arg_getPtr(obj_arg));
|
||||
}
|
||||
int32_t err = 0;
|
||||
|
34
src/PikaVM.c
34
src/PikaVM.c
@ -174,8 +174,8 @@ static Arg* VM_instruction_handler_NON(PikaObj* self, VMState* vs, char* data) {
|
||||
static Arg* VM_instruction_handler_NEW(PikaObj* self, VMState* vs, char* data) {
|
||||
Arg* origin_arg = obj_getArg(vs->locals, data);
|
||||
Arg* new_arg = arg_copy(origin_arg);
|
||||
origin_arg = arg_setType(origin_arg, TYPE_POINTER);
|
||||
arg_setType(new_arg, TYPE_FREE_OBJECT);
|
||||
origin_arg = arg_setType(origin_arg, ARG_TYPE_POINTER);
|
||||
arg_setType(new_arg, ARG_TYPE_FREE_OBJECT);
|
||||
return new_arg;
|
||||
}
|
||||
|
||||
@ -193,8 +193,8 @@ static Arg* VM_instruction_handler_REF(PikaObj* self, VMState* vs, char* data) {
|
||||
arg = arg_copy(obj_getArg(vs->globals, data));
|
||||
}
|
||||
ArgType arg_type = arg_getType(arg);
|
||||
if (TYPE_OBJECT == arg_type) {
|
||||
arg = arg_setType(arg, TYPE_POINTER);
|
||||
if (ARG_TYPE_OBJECT == arg_type) {
|
||||
arg = arg_setType(arg, ARG_TYPE_POINTER);
|
||||
}
|
||||
return arg;
|
||||
}
|
||||
@ -345,12 +345,12 @@ static Arg* __VM_OUT(PikaObj* self,
|
||||
hostObj = args_getPtr(vs->locals->list, "__runAs");
|
||||
}
|
||||
/* set free object to nomal object */
|
||||
if (TYPE_FREE_OBJECT == outArg_type) {
|
||||
arg_setType(outArg, TYPE_OBJECT);
|
||||
if (ARG_TYPE_FREE_OBJECT == outArg_type) {
|
||||
arg_setType(outArg, ARG_TYPE_OBJECT);
|
||||
}
|
||||
/* ouput arg to locals */
|
||||
obj_setArg(hostObj, data, outArg);
|
||||
if (TYPE_MATE_OBJECT == outArg_type) {
|
||||
if (ARG_TYPE_MATE_OBJECT == outArg_type) {
|
||||
if (is_init_obj == IS_INIT_OBJ_TRUE) {
|
||||
/* found a mate_object */
|
||||
/* init object */
|
||||
@ -427,22 +427,22 @@ static Arg* VM_instruction_handler_OPT(PikaObj* self, VMState* vs, char* data) {
|
||||
float num1_f = 0.0;
|
||||
float num2_f = 0.0;
|
||||
/* get int and float num */
|
||||
if (type_arg1 == TYPE_INT) {
|
||||
if (type_arg1 == ARG_TYPE_INT) {
|
||||
num1_i = arg_getInt(arg1);
|
||||
num1_f = (float)num1_i;
|
||||
} else if (type_arg1 == TYPE_FLOAT) {
|
||||
} else if (type_arg1 == ARG_TYPE_FLOAT) {
|
||||
num1_f = arg_getFloat(arg1);
|
||||
num1_i = (int)num1_f;
|
||||
}
|
||||
if (type_arg2 == TYPE_INT) {
|
||||
if (type_arg2 == ARG_TYPE_INT) {
|
||||
num2_i = arg_getInt(arg2);
|
||||
num2_f = (float)num2_i;
|
||||
} else if (type_arg2 == TYPE_FLOAT) {
|
||||
} else if (type_arg2 == ARG_TYPE_FLOAT) {
|
||||
num2_f = arg_getFloat(arg2);
|
||||
num2_i = (int)num2_f;
|
||||
}
|
||||
if (strEqu("+", data)) {
|
||||
if ((type_arg1 == TYPE_STRING) && (type_arg2 == TYPE_STRING)) {
|
||||
if ((type_arg1 == ARG_TYPE_STRING) && (type_arg2 == ARG_TYPE_STRING)) {
|
||||
char* num1_s = NULL;
|
||||
char* num2_s = NULL;
|
||||
Args* str_opt_buffs = New_strBuff();
|
||||
@ -454,7 +454,7 @@ static Arg* VM_instruction_handler_OPT(PikaObj* self, VMState* vs, char* data) {
|
||||
goto OPT_exit;
|
||||
}
|
||||
/* match float */
|
||||
if ((type_arg1 == TYPE_FLOAT) || type_arg2 == TYPE_FLOAT) {
|
||||
if ((type_arg1 == ARG_TYPE_FLOAT) || type_arg2 == ARG_TYPE_FLOAT) {
|
||||
outArg = arg_setFloat(outArg, "", num1_f + num2_f);
|
||||
goto OPT_exit;
|
||||
}
|
||||
@ -463,7 +463,7 @@ static Arg* VM_instruction_handler_OPT(PikaObj* self, VMState* vs, char* data) {
|
||||
goto OPT_exit;
|
||||
}
|
||||
if (strEqu("-", data)) {
|
||||
if ((type_arg1 == TYPE_FLOAT) || type_arg2 == TYPE_FLOAT) {
|
||||
if ((type_arg1 == ARG_TYPE_FLOAT) || type_arg2 == ARG_TYPE_FLOAT) {
|
||||
outArg = arg_setFloat(outArg, "", num1_f - num2_f);
|
||||
goto OPT_exit;
|
||||
}
|
||||
@ -471,7 +471,7 @@ static Arg* VM_instruction_handler_OPT(PikaObj* self, VMState* vs, char* data) {
|
||||
goto OPT_exit;
|
||||
}
|
||||
if (strEqu("*", data)) {
|
||||
if ((type_arg1 == TYPE_FLOAT) || type_arg2 == TYPE_FLOAT) {
|
||||
if ((type_arg1 == ARG_TYPE_FLOAT) || type_arg2 == ARG_TYPE_FLOAT) {
|
||||
outArg = arg_setFloat(outArg, "", num1_f * num2_f);
|
||||
goto OPT_exit;
|
||||
}
|
||||
@ -508,7 +508,7 @@ static Arg* VM_instruction_handler_OPT(PikaObj* self, VMState* vs, char* data) {
|
||||
}
|
||||
if (strEqu("==", data)) {
|
||||
/* string compire */
|
||||
if ((type_arg1 == TYPE_STRING) && (type_arg2 == TYPE_STRING)) {
|
||||
if ((type_arg1 == ARG_TYPE_STRING) && (type_arg2 == ARG_TYPE_STRING)) {
|
||||
outArg = arg_setInt(outArg, "",
|
||||
strEqu(arg_getStr(arg1), arg_getStr(arg2)));
|
||||
goto OPT_exit;
|
||||
@ -631,7 +631,7 @@ static Arg* VM_instruction_handler_EST(PikaObj* self, VMState* vs, char* data) {
|
||||
if (arg == NULL) {
|
||||
return arg_setInt(NULL, "", 0);
|
||||
}
|
||||
if (TYPE_NULL == arg_getType(arg)) {
|
||||
if (ARG_TYPE_NULL == arg_getType(arg)) {
|
||||
return arg_setInt(NULL, "", 0);
|
||||
}
|
||||
return arg_setInt(NULL, "", 1);
|
||||
|
@ -98,7 +98,7 @@ uint8_t* content_deinit(uint8_t* self) {
|
||||
|
||||
uint8_t* content_setContent(uint8_t* self, uint8_t* content, uint16_t size) {
|
||||
if (NULL == self) {
|
||||
return content_init("", TYPE_NONE, content, size, NULL);
|
||||
return content_init("", ARG_TYPE_NONE, content, size, NULL);
|
||||
}
|
||||
|
||||
Hash nameHash = content_getNameHash(self);
|
||||
@ -112,7 +112,7 @@ uint8_t* content_setContent(uint8_t* self, uint8_t* content, uint16_t size) {
|
||||
|
||||
uint8_t* content_setNameHash(uint8_t* self, Hash nameHash) {
|
||||
if (NULL == self) {
|
||||
return content_init_hash(nameHash, TYPE_NONE, NULL, 0, NULL);
|
||||
return content_init_hash(nameHash, ARG_TYPE_NONE, NULL, 0, NULL);
|
||||
}
|
||||
__arg* arg = (__arg*)self;
|
||||
arg->name_hash = nameHash;
|
||||
@ -140,7 +140,7 @@ ArgType content_getType(uint8_t* self) {
|
||||
}
|
||||
|
||||
Arg* arg_newContent(Arg* self, uint32_t size) {
|
||||
uint8_t* newContent = content_init("", TYPE_NONE, NULL, size, NULL);
|
||||
uint8_t* newContent = content_init("", ARG_TYPE_NONE, NULL, size, NULL);
|
||||
arg_freeContent(self);
|
||||
return newContent;
|
||||
}
|
||||
@ -166,15 +166,15 @@ uint8_t* arg_getContent(Arg* self) {
|
||||
}
|
||||
|
||||
Arg* arg_setInt(Arg* self, char* name, int64_t val) {
|
||||
return content_init(name, TYPE_INT, (uint8_t*)&val, sizeof(val), NULL);
|
||||
return content_init(name, ARG_TYPE_INT, (uint8_t*)&val, sizeof(val), NULL);
|
||||
}
|
||||
|
||||
Arg* arg_setNull(Arg* self) {
|
||||
return content_init("", TYPE_NULL, NULL, 0, NULL);
|
||||
return content_init("", ARG_TYPE_NULL, NULL, 0, NULL);
|
||||
}
|
||||
|
||||
Arg* arg_setFloat(Arg* self, char* name, float val) {
|
||||
return content_init(name, TYPE_FLOAT, (uint8_t*)&val, sizeof(val), NULL);
|
||||
return content_init(name, ARG_TYPE_FLOAT, (uint8_t*)&val, sizeof(val), NULL);
|
||||
}
|
||||
|
||||
float arg_getFloat(Arg* self) {
|
||||
@ -191,7 +191,7 @@ Arg* arg_setPtr(Arg* self, char* name, ArgType type, void* pointer) {
|
||||
}
|
||||
|
||||
Arg* arg_setStr(Arg* self, char* name, char* string) {
|
||||
return content_init(name, TYPE_STRING, (uint8_t*)string,
|
||||
return content_init(name, ARG_TYPE_STRING, (uint8_t*)string,
|
||||
strGetSize(string) + 1, NULL);
|
||||
}
|
||||
|
||||
@ -222,7 +222,7 @@ Hash arg_getNameHash(Arg* self) {
|
||||
|
||||
ArgType arg_getType(Arg* self) {
|
||||
if (NULL == self) {
|
||||
return TYPE_NONE;
|
||||
return ARG_TYPE_NONE;
|
||||
}
|
||||
return content_getType(self);
|
||||
}
|
||||
|
@ -33,16 +33,17 @@
|
||||
typedef uint8_t Arg;
|
||||
typedef uint32_t Hash;
|
||||
typedef enum {
|
||||
TYPE_NONE,
|
||||
TYPE_NULL,
|
||||
TYPE_INT,
|
||||
TYPE_FLOAT,
|
||||
TYPE_POINTER,
|
||||
TYPE_STRING,
|
||||
TYPE_OBJECT,
|
||||
TYPE_MATE_OBJECT,
|
||||
TYPE_FREE_OBJECT,
|
||||
TYPE_METHOD,
|
||||
ARG_TYPE_NONE,
|
||||
ARG_TYPE_NULL,
|
||||
ARG_TYPE_INT,
|
||||
ARG_TYPE_FLOAT,
|
||||
ARG_TYPE_POINTER,
|
||||
ARG_TYPE_STRING,
|
||||
ARG_TYPE_OBJECT,
|
||||
ARG_TYPE_MATE_OBJECT,
|
||||
ARG_TYPE_FREE_OBJECT,
|
||||
ARG_TYPE_METHOD,
|
||||
ARG_TYPE_STATIC_METHOD,
|
||||
} ArgType;
|
||||
|
||||
typedef struct __arg __arg;
|
||||
|
@ -58,7 +58,7 @@ void* args_getPtr(Args* self, char* name) {
|
||||
int32_t args_setPtr(Args* self, char* name, void* argPointer) {
|
||||
int32_t errCode = 0;
|
||||
Arg* argNew = New_arg(NULL);
|
||||
argNew = arg_setPtr(argNew, name, TYPE_POINTER, argPointer);
|
||||
argNew = arg_setPtr(argNew, name, ARG_TYPE_POINTER, argPointer);
|
||||
args_setArg(self, argNew);
|
||||
return errCode;
|
||||
}
|
||||
@ -110,9 +110,9 @@ int64_t args_getInt(Args* self, char* name) {
|
||||
return -999999999;
|
||||
}
|
||||
ArgType arg_type = arg_getType(arg);
|
||||
if (arg_type == TYPE_INT) {
|
||||
if (arg_type == ARG_TYPE_INT) {
|
||||
return arg_getInt(arg);
|
||||
} else if (arg_type == TYPE_FLOAT) {
|
||||
} else if (arg_type == ARG_TYPE_FLOAT) {
|
||||
return (int)arg_getFloat(arg);
|
||||
}
|
||||
return -999999999;
|
||||
@ -126,7 +126,7 @@ ArgType args_getType(Args* self, char* name) {
|
||||
Arg* arg = NULL;
|
||||
arg = args_getArg(self, name);
|
||||
if (NULL == arg) {
|
||||
return TYPE_NONE;
|
||||
return ARG_TYPE_NONE;
|
||||
}
|
||||
return arg_getType(arg);
|
||||
}
|
||||
@ -137,9 +137,9 @@ float args_getFloat(Args* self, char* name) {
|
||||
return -999999999.0;
|
||||
}
|
||||
ArgType arg_type = arg_getType(arg);
|
||||
if (arg_type == TYPE_FLOAT) {
|
||||
if (arg_type == ARG_TYPE_FLOAT) {
|
||||
return arg_getFloat(arg);
|
||||
} else if (arg_type == TYPE_INT) {
|
||||
} else if (arg_type == ARG_TYPE_INT) {
|
||||
return (float)arg_getInt(arg);
|
||||
}
|
||||
return -999999999.0;
|
||||
@ -352,30 +352,30 @@ char* args_print(Args* self, char* name) {
|
||||
char* res = NULL;
|
||||
ArgType type = args_getType(self, name);
|
||||
Args* buffs = New_strBuff();
|
||||
if (TYPE_NONE == type) {
|
||||
if (ARG_TYPE_NONE == type) {
|
||||
/* can not get arg */
|
||||
res = NULL;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if (type == TYPE_INT) {
|
||||
if (type == ARG_TYPE_INT) {
|
||||
int32_t val = args_getInt(self, name);
|
||||
res = getPrintStringFromInt(self, name, val);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if (type == TYPE_FLOAT) {
|
||||
if (type == ARG_TYPE_FLOAT) {
|
||||
float val = args_getFloat(self, name);
|
||||
res = getPrintStringFromFloat(self, name, val);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if (type == TYPE_STRING) {
|
||||
if (type == ARG_TYPE_STRING) {
|
||||
res = args_getStr(self, name);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if (type == TYPE_POINTER) {
|
||||
if (type == ARG_TYPE_POINTER) {
|
||||
void* val = args_getPtr(self, name);
|
||||
res = getPrintStringFromPtr(self, name, val);
|
||||
goto exit;
|
||||
|
Loading…
x
Reference in New Issue
Block a user