use New_Class() back, and Class()need to be generate

This commit is contained in:
lyon1998 2021-10-18 17:33:55 +08:00
parent d000966b2e
commit 6c7eb7e55a
20 changed files with 55 additions and 58 deletions

View File

@ -67,9 +67,9 @@ void checker_objMemChecker(PikaObj *(*NewFun)(Args *), char *objName)
int32_t main()
{
checker_objMemChecker(TinyObj, "tiny");
checker_objMemChecker(BaseObj, "base");
checker_objMemChecker(PikaStdLib_SysObj, "sys");
checker_objMemChecker(New_TinyObj, "tiny");
checker_objMemChecker(New_BaseObj, "base");
checker_objMemChecker(New_PikaStdLib_SysObj, "sys");
{
Arg *arg = New_arg(NULL);
checker_printMemUsage("void arg");

View File

@ -20,7 +20,7 @@ PikaObj *New_LED(Args *args)
/* Derive from the tiny object class.
Tiny object can not import sub object.
Tiny object is the smallest object. */
PikaObj *self = TinyObj(args);
PikaObj *self = New_TinyObj(args);
/* bind the method */
class_defineMethod(self, "on()", onMethod);
@ -35,7 +35,7 @@ PikaObj *New_MYROOT(Args *args)
/* Derive from the base object class .
BaseObj is the smallest object that can
import sub object. */
PikaObj *self = BaseObj(args);
PikaObj *self = New_BaseObj(args);
/* new led object bellow root object */
obj_newObj(self, "led", "LED", New_LED);

View File

@ -16,7 +16,7 @@ PikaObj *New_TEST(Args *args)
/* Derive from the tiny object class.
Tiny object can not import sub object.
Tiny object is the smallest object. */
PikaObj *self = TinyObj(args);
PikaObj *self = New_TinyObj(args);
/* bind the method */
class_defineMethod(self, "add(val1:int, val2:int)->int", addMethod);
@ -30,7 +30,7 @@ PikaObj *New_MYROOT(Args *args)
/* Derive from the base object class .
BaseObj is the smallest object that can
import sub object. */
PikaObj *self = BaseObj(args);
PikaObj *self = New_BaseObj(args);
/* new led object bellow root object */
obj_newObj(self, "test", "TEST", New_TEST);

View File

@ -15,7 +15,7 @@ PikaObj *New_USART(Args *args)
/* Derive from the tiny object class.
Tiny object can not import sub object.
Tiny object is the smallest object. */
PikaObj *self = TinyObj(args);
PikaObj *self = New_TinyObj(args);
/* bind the method */
class_defineMethod(self, "send(data:str)", sendMethod);
@ -29,7 +29,7 @@ PikaObj *New_MYROOT(Args *args)
/* Derive from the base object class .
BaseObj is the smallest object that can
import sub object. */
PikaObj *self = BaseObj(args);
PikaObj *self = New_BaseObj(args);
/* new led object bellow root object */
obj_newObj(self, "usart", "USART", New_USART);

View File

@ -27,7 +27,7 @@ PikaObj *New_USART(Args *args)
/* Derive from the tiny object class.
Tiny object can not import sub object.
Tiny object is the smallest object. */
PikaObj *self = TinyObj(args);
PikaObj *self = New_TinyObj(args);
/* setArgs */
obj_setInt(self, "speed", 9600);
@ -65,7 +65,7 @@ PikaObj *New_MYROOT(Args *args)
/* Derive from the base object class .
BaseObj is the smallest object that can
import sub object. */
PikaObj *self = BaseObj(args);
PikaObj *self = New_BaseObj(args);
/* new object bellow root object */
obj_newObj(self, "usart1", "USART", New_USART);

View File

@ -11,7 +11,7 @@ void obj_runWithInfo(PikaObj *self, char *cmd)
int main()
{
/* new root object */
PikaObj *root = newRootObj("root", PikaStdLib_SysObj);
PikaObj *root = newRootObj("root", New_PikaStdLib_SysObj);
obj_runWithInfo(root, "set('a',1)");
obj_runWithInfo(root, "print(a)");

View File

@ -15,7 +15,7 @@ TEST(VM, num1) {
Args* buffs = New_strBuff();
char* pikaAsm = pikaParseLineToAsm(buffs, line, NULL);
printf("%s", pikaAsm);
PikaObj* self = newRootObj((char*)"root", PikaStdLib_SysObj);
PikaObj* self = newRootObj((char*)"root", New_PikaStdLib_SysObj);
args_deinit(pikaVM_runAsm(self, pikaAsm));
obj_deinit(self);
args_deinit(buffs);
@ -27,7 +27,7 @@ TEST(VM, a_1) {
Args* buffs = New_strBuff();
char* pikaAsm = pikaParseLineToAsm(buffs, line, NULL);
printf("%s", pikaAsm);
PikaObj* self = newRootObj((char*)"root", PikaStdLib_SysObj);
PikaObj* self = newRootObj((char*)"root", New_PikaStdLib_SysObj);
args_deinit(pikaVM_runAsm(self, pikaAsm));
ASSERT_EQ(obj_getInt(self, (char*)"a"), 1);
@ -42,7 +42,7 @@ TEST(VM, a_1d1) {
Args* buffs = New_strBuff();
char* pikaAsm = pikaParseLineToAsm(buffs, line, NULL);
printf("%s", pikaAsm);
PikaObj* self = newRootObj((char*)"root", PikaStdLib_SysObj);
PikaObj* self = newRootObj((char*)"root", New_PikaStdLib_SysObj);
args_deinit(pikaVM_runAsm(self, pikaAsm));
ASSERT_FLOAT_EQ(obj_getFloat(self, (char*)"a"), 1.1);
@ -57,7 +57,7 @@ TEST(VM, str_xy) {
Args* buffs = New_strBuff();
char* pikaAsm = pikaParseLineToAsm(buffs, line, NULL);
printf("%s", pikaAsm);
PikaObj* self = newRootObj((char*)"root", PikaStdLib_SysObj);
PikaObj* self = newRootObj((char*)"root", New_PikaStdLib_SysObj);
args_deinit(pikaVM_runAsm(self, pikaAsm));
ASSERT_STREQ(obj_getStr(self, (char*)"a"), (char*)"xy");
@ -72,7 +72,7 @@ TEST(VM, str_xy_space) {
Args* buffs = New_strBuff();
char* pikaAsm = pikaParseLineToAsm(buffs, line, NULL);
printf("%s", pikaAsm);
PikaObj* self = newRootObj((char*)"root", PikaStdLib_SysObj);
PikaObj* self = newRootObj((char*)"root", New_PikaStdLib_SysObj);
args_deinit(pikaVM_runAsm(self, pikaAsm));
ASSERT_STREQ(obj_getStr(self, (char*)"a"), (char*)"xy ");
@ -83,7 +83,7 @@ TEST(VM, str_xy_space) {
}
TEST(VM, ref_a_b) {
PikaObj* self = newRootObj((char*)"root", PikaStdLib_SysObj);
PikaObj* self = newRootObj((char*)"root", New_PikaStdLib_SysObj);
Args* buffs = New_strBuff();
args_deinit(pikaVM_runAsm(
@ -98,7 +98,7 @@ TEST(VM, ref_a_b) {
}
TEST(VM, Run_add) {
PikaObj* self = newRootObj((char*)"root", PikaMath_Operator);
PikaObj* self = newRootObj((char*)"root", New_PikaMath_Operator);
Args* buffs = New_strBuff();
args_deinit(pikaVM_runAsm(
@ -112,7 +112,7 @@ TEST(VM, Run_add) {
}
TEST(VM, Run_add_multy) {
PikaObj* self = newRootObj((char*)"root", PikaMath_Operator);
PikaObj* self = newRootObj((char*)"root", New_PikaMath_Operator);
Args* buffs = New_strBuff();
args_deinit(
@ -128,7 +128,7 @@ TEST(VM, Run_add_multy) {
}
TEST(VM, Run_add_1_2_3) {
PikaObj* self = newRootObj((char*)"root", PikaMath_Operator);
PikaObj* self = newRootObj((char*)"root", New_PikaMath_Operator);
Args* buffs = New_strBuff();
args_deinit(pikaVM_runAsm(
@ -149,7 +149,7 @@ TEST(VM, JEZ) {
"0 JEZ 2\n"
"B0\n"
"B0\n";
PikaObj* self = TinyObj(NULL);
PikaObj* self = New_TinyObj(NULL);
int lineAddr = 0;
int size = strGetSize(pikaAsm);
Args* sysRes = New_args(NULL);
@ -171,7 +171,7 @@ TEST(VM, JMP) {
"0 JMP 2\n"
"B0\n"
"B0\n";
PikaObj* self = TinyObj(NULL);
PikaObj* self = New_TinyObj(NULL);
int lineAddr = 0;
int size = strGetSize(pikaAsm);
Args* sysRes = New_args(NULL);
@ -193,7 +193,7 @@ TEST(VM, JMP_back1) {
"0 JMP -1\n"
"B0\n"
"B0\n";
PikaObj* self = TinyObj(NULL);
PikaObj* self = New_TinyObj(NULL);
int lineAddr = 0;
int size = strGetSize(pikaAsm);
Args* sysRes = New_args(NULL);
@ -224,7 +224,7 @@ TEST(VM, WHILE) {
char* pikaAsm = pikaParseMultiLineToAsm(buffs, (char*)lines);
printf("%s", pikaAsm);
pikaMemInfo.heapUsedMax = 0;
PikaObj* self = TinyObj(NULL);
PikaObj* self = New_TinyObj(NULL);
Args* runRes = pikaVM_runAsm(self, pikaAsm);
EXPECT_EQ(obj_getInt(self, (char*)"a"), 0);
EXPECT_EQ(obj_getInt(self, (char*)"b"), 1);

View File

@ -43,7 +43,7 @@ void add(PikaObj* obj, Args* args) {
}
PikaObj* New_PikaObj_test(Args* args) {
PikaObj* self = PikaStdLib_SysObj(args);
PikaObj* self = New_PikaStdLib_SysObj(args);
class_defineMethod(self, (char*)"hello(name:str, isShow:int)", hello);
class_defineMethod(
self, (char*)"hello2(name1:str, name2:str, name3:str, isShow:int)",
@ -65,7 +65,7 @@ PikaObj* New_USART(Args* args) {
/* Derive from the tiny object class.
Tiny object can not import sub object.
Tiny object is the smallest object. */
PikaObj* self = TinyObj(args);
PikaObj* self = New_TinyObj(args);
/* bind the method */
class_defineMethod(self, (char*)"send(data:str)", sendMethod);
@ -78,7 +78,7 @@ PikaObj* New_MYROOT1(Args* args) {
/* Derive from the base object class .
BaseObj is the smallest object that can
import sub object. */
PikaObj* self = BaseObj(args);
PikaObj* self = New_BaseObj(args);
/* new led object bellow root object */
obj_newObj(self, (char*)"usart", (char*)"USART", (NewFun)New_USART);
@ -98,7 +98,7 @@ TEST(object_test, test10) {
}
TEST(object_test, test1) {
PikaObj* process = newRootObj((char*)"sys", PikaStdLib_SysObj);
PikaObj* process = newRootObj((char*)"sys", New_PikaStdLib_SysObj);
float floatTest = 12.231;
obj_bindFloat(process, (char*)"testFloatBind", &floatTest);
EXPECT_TRUE(
@ -137,7 +137,7 @@ TEST(object_test, test6) {
}
TEST(object_test, test8) {
PikaObj* sys = newRootObj((char*)"sys", PikaStdLib_SysObj);
PikaObj* sys = newRootObj((char*)"sys", New_PikaStdLib_SysObj);
obj_run(sys, (char*)"a=1");
obj_run(sys, (char*)"remove('a')");
obj_deinit(sys);
@ -145,9 +145,9 @@ TEST(object_test, test8) {
}
TEST(object_test, test9) {
PikaObj* sys = newRootObj((char*)"sys", PikaStdLib_SysObj);
PikaObj* sys = newRootObj((char*)"sys", New_PikaStdLib_SysObj);
obj_run(sys, (char*)"ls()");
obj_setPtr(sys, (char*)"baseClass", (void*)TinyObj);
obj_setPtr(sys, (char*)"baseClass", (void*)New_TinyObj);
obj_run(sys, (char*)"ls()");
obj_deinit(sys);
EXPECT_EQ(pikaMemNow(), 0);
@ -176,7 +176,7 @@ TEST(object_test, voidRun) {
}
TEST(object_test, printa) {
PikaObj* root = newRootObj((char*)"root", BaseObj);
PikaObj* root = newRootObj((char*)"root", New_BaseObj);
obj_run(root, (char*)"a = 2");
obj_run(root, (char*)"print(a)");
char* sysOut = obj_getSysOut(root);
@ -186,7 +186,7 @@ TEST(object_test, printa) {
}
TEST(object_test, copyArg) {
PikaObj* root = newRootObj((char*)"root", BaseObj);
PikaObj* root = newRootObj((char*)"root", New_BaseObj);
Arg* arg = New_arg(NULL);
arg = arg_setInt(arg, (char*)"a", 1);
obj_setArg(root, (char*)"a", arg);

View File

@ -65,14 +65,14 @@ TEST(queue, str) {
}
TEST(queueObj, init) {
QueueObj* q = TinyObj(NULL);
QueueObj* q = New_TinyObj(NULL);
queueObj_init(q);
obj_deinit(q);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(queueObj, INT) {
QueueObj* q = TinyObj(NULL);
QueueObj* q = New_TinyObj(NULL);
queueObj_init(q);
queueObj_pushInt(q, 1);
queueObj_pushInt(q, 2);
@ -85,7 +85,7 @@ TEST(queueObj, INT) {
}
TEST(queueObj, FLOAT) {
QueueObj* q = TinyObj(NULL);
QueueObj* q = New_TinyObj(NULL);
queueObj_init(q);
queueObj_pushFloat(q, 1.1f);
queueObj_pushFloat(q, 2.2f);
@ -98,7 +98,7 @@ TEST(queueObj, FLOAT) {
}
TEST(queueObj, str) {
QueueObj* q = TinyObj(NULL);
QueueObj* q = New_TinyObj(NULL);
queueObj_init(q);
queueObj_pushStr(q, (char*)"abc");
queueObj_pushStr(q, (char*)"123");
@ -111,7 +111,7 @@ TEST(queueObj, str) {
}
TEST(queueObj, obj) {
QueueObj* q = TinyObj(NULL);
QueueObj* q = New_TinyObj(NULL);
queueObj_init(q);
queueObj_pushObj(q, (char*)"type1");
queueObj_pushObj(q, (char*)"type2");
@ -129,7 +129,7 @@ TEST(queueObj, obj) {
}
TEST(queueObj, currentObj) {
QueueObj* q = TinyObj(NULL);
QueueObj* q = New_TinyObj(NULL);
queueObj_init(q);
queueObj_pushObj(q, (char*)"type1");

View File

@ -6,7 +6,7 @@ extern "C" {
}
TEST(sysObj, print) {
PikaObj* obj = newRootObj((char*)"test", PikaStdLib_SysObj);
PikaObj* obj = newRootObj((char*)"test", New_PikaStdLib_SysObj);
Args* res = obj_runDirect(obj, (char*)"print('hello world')");
char* sysOut = args_getSysOut(res);
int errCode = args_getErrorCode(res);
@ -19,7 +19,7 @@ TEST(sysObj, print) {
}
TEST(sysObj, noMethod) {
PikaObj* obj = newRootObj((char*)"test", PikaStdLib_SysObj);
PikaObj* obj = newRootObj((char*)"test", New_PikaStdLib_SysObj);
Args* res = obj_runDirect(obj, (char*)"printttt('hello world')");
char* sysOut = args_getSysOut(res);
int errCode = args_getErrorCode(res);

View File

@ -28,15 +28,12 @@ int32_t obj_newObj(PikaObj* self,
char* objName,
char* className,
NewFun newFunPtr) {
/* class means subprocess init */
/* add mate Obj, no inited */
Arg* mateObj = arg_setMetaObj(objName, className, newFunPtr);
args_setArg(self->attributeList, mateObj);
return 0;
}
static void print(PikaObj* self, Args* args) {
obj_setErrorCode(self, 0);
char* res = args_print(args, "val");
@ -49,8 +46,8 @@ static void print(PikaObj* self, Args* args) {
obj_setSysOut(self, res);
}
PikaObj* BaseObj(Args* args) {
PikaObj* self = TinyObj(args);
PikaObj* New_BaseObj(Args* args) {
PikaObj* self = New_TinyObj(args);
class_defineMethod(self, "print(val:any)", print);
return self;
}

View File

@ -9,7 +9,7 @@
#include "TinyObj.h"
#include "dataMemory.h"
PikaObj* BaseObj(Args* args);
PikaObj* New_BaseObj(Args* args);
int32_t obj_newObjFromClassLoader(PikaObj* self,
char* objPath,
char* classPath);

View File

@ -150,7 +150,7 @@ AST* pikaParseLine(char* line, Stack* blockStack) {
for (int i = 0; i < blockDeepthLast - blockDeepth; i++) {
QueueObj* exitBlock = obj_getObj(ast, "exitBlock", 0);
if (NULL == exitBlock) {
obj_newObj(ast, "exitBlock", "", TinyObj);
obj_newObj(ast, "exitBlock", "", New_TinyObj);
exitBlock = obj_getObj(ast, "exitBlock", 0);
queueObj_init(exitBlock);
}

View File

@ -13,7 +13,7 @@ void _beforDinit(PikaObj* self) {
/* override in user code */
}
PikaObj* TinyObj(Args* args) {
PikaObj* New_TinyObj(Args* args) {
PikaObj* self = pikaMalloc(sizeof(PikaObj));
/* List */

View File

@ -6,5 +6,5 @@
#ifndef __TYNYOBJ__H
#define __TYNYOBJ__H
#include "PikaObj.h"
PikaObj* TinyObj(Args* args);
PikaObj* New_TinyObj(Args* args);
#endif

View File

@ -2,7 +2,7 @@
#include "BaseObj.h"
#include "dataQueue.h"
QueueObj* New_queueObj() {
PikaObj* self = TinyObj(NULL);
PikaObj* self = New_TinyObj(NULL);
queueObj_init(self);
return self;
}
@ -19,7 +19,7 @@ int32_t queueObj_pushObj(QueueObj* self, char* className) {
char *topStr = fast_itoa(buff, top);
/* add top */
obj_setInt(self, "top", top + 1);
return obj_newObj(self, topStr, className, TinyObj);
return obj_newObj(self, topStr, className, New_TinyObj);
}
PikaObj* queueObj_getCurrentObj(QueueObj* self) {

View File

@ -112,7 +112,7 @@ impl ClassInfo {
pub fn script_fn(&self) -> String {
let mut script_fn = String::new();
script_fn.push_str("PikaObj * pikaScriptInit(){\r\n");
script_fn.push_str(" PikaObj * pikaMain = newRootObj(\"pikaMain\", PikaMain);\r\n");
script_fn.push_str(" PikaObj * pikaMain = newRootObj(\"pikaMain\", New_PikaMain);\r\n");
script_fn.push_str(&self.script_list.content);
script_fn.push_str(" obj_run(pikaMain, \"\");\r\n");
script_fn.push_str(" return pikaMain;\r\n");
@ -124,7 +124,7 @@ impl ClassInfo {
let mut new_class_fn = String::new();
let new_class_fn_head = format!("{}{{\n", self.new_class_fn_name());
new_class_fn.push_str(&new_class_fn_head);
let derive = format!(" PikaObj *self = {}(args);\n", self.super_class_name);
let derive = format!(" PikaObj *self = New_{}(args);\n", self.super_class_name);
new_class_fn.push_str(&derive);
for (_, import_info) in self.import_list.iter() {
new_class_fn.push_str(&import_info.import_fn());
@ -143,7 +143,7 @@ impl ClassInfo {
}
pub fn new_class_fn_name(&self) -> String {
return format!("PikaObj *{}(Args *args)", self.this_class_name);
return format!("PikaObj *New_{}(Args *args)", self.this_class_name);
}
pub fn method_impl_declear(&self) -> String {

View File

@ -29,7 +29,7 @@ impl ImportInfo {
}
pub fn import_fn(&self) -> String {
return format!(
" obj_import(self, \"{}\", {});\n",
" obj_import(self, \"{}\", New_{});\n",
self.import_class_name, self.import_class_name
);
}

View File

@ -36,7 +36,7 @@ impl ObjectInfo {
let mut new_object_fn = String::new();
/* do not generate new object for pikaMain class */
let new_fn = format!(
" obj_newObj(self, \"{}\", \"{}\", {});\n",
" obj_newObj(self, \"{}\", \"{}\", New_{});\n",
self.name, self.import_class_name, self.import_class_name
);
new_object_fn.push_str(&new_fn);