typedef unsigned char u1; typedef unsigned short u2; typedef unsigned int u4; typedef signed char s1; typedef signed short s2; typedef signed int s4; typedef struct ghent { /* hash entry */ struct ghent* next; u4 hash; char* s; /* for intern table, s follows */ } ghent; #define Hts 64 #define Htm 63 typedef struct ghtab { /* hash table */ ghent* v[Hts]; } ghtab; typedef struct gvec { /* resizable vector */ int len; char* ptr; } gvec; #define Gfeight 0x10 /* eight bytes, not four */ #define Gfobj 0x20 /* object reference */ typedef struct gfld { /* field */ ghent head; struct gcls* cls; u4 off; u2 gflags; u2 aflags; char* name; char* sig; struct gcon* conval; } gfld; typedef struct gexc { /* exception table */ u2 startpc; u2 endpc; u2 gopc; u2 catchtype; } gexc; typedef struct gcod { /* code */ u1 maxstk; u1 maxloc; u2 codec; u1* codes; u2 exceptc; gexc* excepts; } gcod; typedef struct gmeth { /* method */ ghent head; /* index by name+sig */ struct gcls* cls; char* argtypes; /* i: single, d: double, a: obj */ char rettype; /* v: void */ u2 aflags; char* name; char* sig; char* ns; /* name and sig */ gcod* code; } gmeth; #define Garr 9 #define Gfull 1 #define Gempty 0 typedef struct gcls { /* class */ ghent head; char* name; u4 status; u1 atype; /* type of array */ struct gvm* gvm; u2 conc; struct gcon* cons; u2 aflags; struct gcls* super_class; u2 ifacec; struct gcls** iface; u2 fldc; gfld* flds; ghtab ftab; u2 methc; gmeth* meths; ghtab mtab; } gcls; #define Cmagic 0xCafeBabe #define Cversion 45 #define Apublic 0x0001 #define Aprivate 0x0002 #define Aprotected 0x0004 #define Astatic 0x0008 #define Afinal 0x0010 #define Asynchronized 0x0020 #define Athreadsafe 0x0040 #define Atransient 0x0080 #define Anative 0x0100 #define Ainterface 0x0200 #define Aabstract 0x0400 typedef struct gfram { /* stack frame */ struct gvm* vm; struct gfram* prev; struct gfram* next; struct gcls* cl; /* this class */ gmeth* me; /* this method */ gcod* co; /* this code */ u1* bc; /* this bytecodes */ u4* stk; /* my op stack */ u4* loc; /* my locals */ u1* mstk; /* objects on my op stack ? */ u1* mloc; /* objects on my locals ? */ u4 sp; /* op stack pointer */ u4 pc; /* program counter */ struct gobj* ex; /* pending exception */ } gfram; typedef struct gvm { /* ganja virtual machine */ ghtab itab; /* interned str */ ghtab ctab; /* classes by name */ gfram first; gfram cur; } gvm; #define LI(p) ( p ? ++((gobj*)p)->ref : 0 , 0 ) #define UL(p) ( p ? --((gobj*)p)->ref ? 0 : g_delete((gobj*)p) : 0 ) typedef struct gobj { /* base object */ u4 ref; /* ref count */ gcls* cls; } gobj; #define Gtarray 1 #define Gtboolean 4 #define Gtchar 5 #define Gtfloat 6 #define Gtdouble 7 #define Gtbyte 8 #define Gtshort 9 #define Gtint 10 #define Gtlong 11 typedef struct garr { /* array object */ u4 ref; /* ref count */ gcls* cls; /* null for array */ u4 atype; u4 depth; /* 0 if of atype, 1 if ptrs to atype, ... */ u4 length; /* data follows at this+1 */ } garr; typedef struct gstr { /* string object */ u4 ref; /* ref count */ gcls* cls; struct garr* garr; }; #define ConClass 7 #define ConFieldR 9 #define ConMethodR 10 #define ConString 8 #define ConInteger 3 #define ConFloat 4 #define ConLong 5 #define ConDouble 6 #define ConImethodR 11 #define ConNameType 12 #define ConAsciz 1 #define GCcls(i) (c->cons[i].u.c.clsp) #define GCasc(i) (c->cons[i].u.a.p) #define GCint(j) (c->cons[j].u.i.i) #define GChi(i) (c->cons[i].u.l.hi) #define GClo(i) (c->cons[i].u.l.lo) #define GCtag(i) (c->cons[i].tag) #define GCcon(i) (c->cons+i) union gconu { struct { u2 len; char* p; } a; /* asciz */ struct { u2 len; u2* p; } u; /* unicode */ struct { u2 namei; gcls* clsp; } c; /* class */ struct { u2 clsi; u2 nati; gcls* cachec; void* cache;} r; /* field/meth ref */ struct { u2 namei; u2 sigi; char* ns; } n; /* name and type */ struct { u2 stri; } s; /* string object */ struct { u4 i; } i; /* int */ struct { float f; } f; /* float */ struct { u4 hi, lo; } l; /* long */ struct { double d; } d; /* double */ }; typedef struct gcon { /* constant pool entry */ u1 tag; union gconu u; } gcon; enum gerr { GcannotOpenFile= 9901, GbadClassFile, };