Proteus中8259的仿真[无dos,纯手工]
OOC-GCC基本结构图[0.6][终于有时间整点相关的文档了]

OOC-GCC新的测试用例[0.6]

pingf posted @ Fri, 25 Mar 2011 04:57:50 -1100 in 未分类 , 3541 readers

这个例子主要用来掩饰如何实现继承关系[v0.6]

http://code.google.com/p/ooc-gcc/downloads/list

 

//
#include "inc/core/OOStd.h"
 
CLASS(Human){
    int age;
    int gender;
    STATIC(Human)
    iFn sayHi;
};
ASM(Human,NULL,NULL,NULL,NULL) 
 
CLASS_EX(Human,Mom){    
    STATIC_EX(Human,Mom)  
};
int Mom_sayHi(Mom * THIS){
    printf("Hi,Mom age:%d gender:%s\n",THIS->age,THIS->gender?"male":"female");
    return 0;
} 

int Mom_reload(Mom * THIS,void *PARAM){
    printf("%s %p\n",__func__,THIS);
    THIS->age=36;
    THIS->gender=0;
    return 0;
}
int Mom_unload(Mom * THIS,void *PARAM){
    printf("%s %p\n",__func__,THIS);
    return 0;
}
 
int Mom_reloadStatic(StaticMom * THIS,void *PARAM){
    printf("%s %p\n",__func__,THIS);
    THIS->sayHi=(void *)Mom_sayHi;
    return 0;
}
int Mom_unloadStatic(StaticMom * THIS,void *PARAM){
    printf("%s %p\n",__func__,THIS);
    THIS->sayHi=NULL;
    return 0;
}
ASM_EX(Human,Mom,Mom_reload,Mom_unload,Mom_reloadStatic,Mom_unloadStatic)

CLASS_EX(Mom,Kid){
    int id;
    STATIC_EX(Mom,Kid) 
};

int Kid_sayHi(Kid * THIS){
    printf("Hi,Kid%d age:%d gender:%s\n",THIS->id,THIS->age,THIS->gender?"male":"female");
    return 0;
}

int Kid_reload(Kid * THIS,void *PARAM){
    static int id=0;
    printf("%s %p\n",__func__,THIS);
    THIS->age=3;
    THIS->gender=1;
    THIS->id=++id;
    return 0;
}
int Kid_unload(Kid * THIS,void *PARAM){
    printf("%s %p\n",__func__,THIS);
    return 0;
}
 
int Kid_reloadStatic(StaticKid * THIS,void *PARAM){
    printf("%s %p\n",__func__,THIS);
    THIS->sayHi=(void *)Kid_sayHi;
    return 0;
}
int Kid_unloadStatic(StaticKid * THIS,void *PARAM){
    printf("%s %p\n",__func__,THIS);
    THIS->sayHi=NULL;
    return 0;
}
ASM_EX(Mom,Kid,Kid_reload,Kid_unload,Kid_reloadStatic,Kid_unloadStatic)
 
int main(){
     
    printf("\n-----------\n");
    Mom * m=newMom(NULL);
    printf("\n-----------\n");
    StaticMom *stm=ST(m);
    Kid *k1=newKid(NULL);
    printf("\n-----------\n");
    Kid *k2=newKid(NULL);
    printf("\n-----------\n");
    Kid *k3=newKid(NULL);
    printf("\n-----------\n");
    stm->sayHi(m);
    printf("\n-----------\n");
    StaticKid *stk=ST(k1);
    stk->sayHi(k1);
    printf("\n-----------\n");
    stk->sayHi(k2);
    printf("\n-----------\n");
    stk->sayHi(k3);
    printf("\n-----------\n");
    delKid(&k1,NULL);
    printf("\n-----------\n");
    delKid(&k2,NULL);
    printf("\n-----------\n");
    delKid(&k3,NULL);
    printf("\n-----------\n");
    delMom(&m,NULL);
    printf("\n-----------\n");
    
    return 0;
}
正确的输出为,
-----------
Mom_reloadStatic 003E2BF0
Mom_reload 003E2BD0

-----------
Mom_reload 003E2C18
Mom_reloadStatic 003E2C40
Kid_reloadStatic 003E2C40
Kid_reload 003E2C18

-----------
Mom_reload 003E2C80
Kid_reload 003E2C80

-----------
Mom_reload 003E2CA8
Kid_reload 003E2CA8

-----------
Hi,Mom age:36 gender:female

-----------
Hi,Kid1 age:3 gender:male

-----------
Hi,Kid2 age:3 gender:male

-----------
Hi,Kid3 age:3 gender:male

-----------
Kid_unload 003E2C18
Mom_unload 003E2C18

-----------
Kid_unload 003E2C80
Mom_unload 003E2C80

-----------
Kid_unload 003E2CA8
Kid_unloadStatic 003E2C40
Mom_unloadStatic 003E2C40
Mom_unload 003E2CA8

-----------
Mom_unload 003E2BD0
Mom_unloadStatic 003E2BF0

-----------

Time Elapsed
Seconds : 0
Microseconds : 0
另外内存分配检测Log输出为
[,][;]
+,0x003E2BD0,20;
+,0x003E4CF0,8;
+,0x003E2BF0,32;
+,0x003E2C18,28;
+,0x003E2C40,52;
+,0x003E2C80,28;
+,0x003E2CA8,28;
-,0x003E2C18;
-,0x003E2C80;
-,0x003E2C40;
-,0x003E2CA8;
-,0x003E2BF0;
-,0x003E4CF0;
-,0x003E2BD0;
!,0;
最后的0表示分配的都释放了,而前面的数据可以配合graphviz来实现一些图表
具体文件见项目地址,我一直比较懒,懒得用svn,git这些工具,因为这个目前依旧是自己自娱自乐
P.S.
注意编译时要开启-fms-extensions[GCC 4.5]或-fplan9-extensions[GCC 4.6]
Avatar_small
纵横天下 said:
Wed, 30 Mar 2011 02:52:11 -1100

如果继续增强,我觉得比GObject还好哈!

Avatar_small
pingf said:
Wed, 30 Mar 2011 21:06:44 -1100

@纵横天下:
再说一下我对GObejct的看法,
GObject并没有利用GCC所有的性能,也不是为用C设计的,
GObject其实是构建在一个类型系统之上的,并不是说靠它去模拟OO,而是按照它的风格保证高级OO语言的调用
GObject的一些实用的函数应该算是GLib的,而不是GObject的
GObject的很多东西其实可以设计的更加简单
另外说一下我对我这个东西以后的愿景,
我这个是方便设计OO的宏而已,本身不能跟GObject比,这是一种风格而已,目的是为了方便C程序的编写.
希望以后能完成一个JLib的库(对应GLib的功能)封装常见的数据结构和算法(其实这个早期的版本有很多数据结构的实现,包括哈希表,avl树等比较高级的,不过没啥文档.....)
希望以后在此基础上完成JObject框架(对应GObject),包括类型检测,注册,转换什么的,还有山寨下Qt的信号槽的设计(当然只是简单的山寨)
希望以后在此基础上重写Lua(当然Lua本身其实已经非常棒了,严格的ansi c适合单片机的移植,这个只是自己玩的一种想法)
..........
愿景太多太宏伟了,但仅仅是源于一个比较折腾的念头,从代码级自力更生!

Avatar_small
pingf said:
Wed, 30 Mar 2011 21:14:13 -1100

@纵横天下:
以后的设计的库以J打头的原因不是像Qt那般因为大写的Q那么具有艺术气息,也不是要山寨Java的某些功能,
更不是像GOjbect之类要与gnome,gimp配合.....
只是因为J是最容易按下的(右手食指默认键位.力道最猛的(大拇指不算))

ludo king said:
Thu, 26 Jul 2018 22:01:49 -1100

The information you share is very useful. It is closely related to my work and has helped me grow. Thank you!

JAC Model Paper said:
Wed, 31 Aug 2022 23:09:08 -1100

JAC Model Paper 2023 Pdf Download for Jharkhand Academic Council Ranchi Board Mock Test Question Paper for Class 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 (Matric), Intermediate ( Class 11 & 12) Theory, Objective (MCQ) and Bit Questions to Hindi Medium, English Medium & Urdu Medium Students. JAC Model Paper New Exam Scheme or Question Pattern for Sammittive Assignment Exams (SA1 & SA2): Very Long Answer (VLA), Long Answer (LA), Small Answer (SA), Very Small Answer (VSA), Single Answer, Multiple Choice and etc.


Login *


loading captcha image...
(type the code from the image)
or Ctrl+Enter