Uppercase internal SYSTEM.H types address, int*, uint*. Phase 1.

This commit is contained in:
David Brown 2016-11-08 11:48:33 +00:00
parent 1935f63cd6
commit baeb2db81f
205 changed files with 8388 additions and 8311 deletions

View file

@ -33,22 +33,22 @@ void *alloca(size_t size);
#if defined (o__64) && !defined(_WIN64)
// LP64
typedef long int64;
typedef unsigned long uint64;
typedef long INT64;
typedef unsigned long UINT64;
#else
// ILP32 or LLP64
typedef long long int64;
typedef unsigned long long uint64;
typedef long long INT64;
typedef unsigned long long UINT64;
#endif
typedef int int32;
typedef unsigned int uint32;
typedef int INT32;
typedef unsigned int UINT32;
typedef short int int16;
typedef unsigned short int uint16;
typedef short int INT16;
typedef unsigned short int UINT16;
typedef signed char int8;
typedef unsigned char uint8;
typedef signed char INT8;
typedef unsigned char UINT8;
// The compiler uses 'import' and 'export' which translate to 'extern' and
@ -63,29 +63,41 @@ typedef unsigned char uint8;
#define NIL ((void*)0)
#define __MAXEXT 16
#define POINTER__typ ((address*)(1)) // not NIL and not a valid type
#define POINTER__typ ((ADDRESS*)(1)) // not NIL and not a valid type
// Oberon types
typedef int8 BOOLEAN;
typedef int8 SYSTEM_BYTE;
typedef uint8 CHAR;
typedef INT8 BOOLEAN;
typedef INT8 SYSTEM_BYTE;
typedef UINT8 CHAR;
typedef float REAL;
typedef double LONGREAL;
typedef void* SYSTEM_PTR;
// 'address' is a synonym for an int of pointer size
// 'ADDRESS' is a synonym for an integer of pointer size
#if defined (o__64)
#define address int64
#define ADDRESS INT64
#else
#define address int32
#define ADDRESS INT32
#endif
// Temporary build support - which changing lowercase int* and address to uppercase
#define int8 INT8
#define int16 INT16
#define int32 INT32
#define int64 INT64
#define uint8 UINT8
#define uint16 UINT16
#define uint32 UINT32
#define uint64 UINT64
#define address ADDRESS
@ -96,30 +108,30 @@ typedef void* SYSTEM_PTR;
// OS Memory allocation interfaces are in PlatformXXX.Mod
extern address Platform_OSAllocate (address size);
extern void Platform_OSFree (address addr);
extern ADDRESS Platform_OSAllocate (ADDRESS size);
extern void Platform_OSFree (ADDRESS addr);
// Assertions and Halts
extern void Platform_Halt(int32 x);
extern void Platform_AssertFail(int32 x);
extern void Platform_Halt(INT32 x);
extern void Platform_AssertFail(INT32 x);
#define __HALT(x) Platform_Halt(x)
#define __ASSERT(cond, x) if (!(cond)) Platform_AssertFail((int32)(x))
#define __ASSERT(cond, x) if (!(cond)) Platform_AssertFail((INT32)(x))
// Index checking
static inline int64 __XF(uint64 i, uint64 ub) {if (i >= ub) {__HALT(-2);} return i;}
static inline INT64 __XF(UINT64 i, UINT64 ub) {if (i >= ub) {__HALT(-2);} return i;}
#define __X(i, ub) (((i)<(ub))?i:(__HALT(-2),0))
// Range checking, and checked SHORT and CHR functions
static inline int64 __RF(uint64 i, uint64 ub) {if (i >= ub) {__HALT(-8);} return i;}
static inline INT64 __RF(UINT64 i, UINT64 ub) {if (i >= ub) {__HALT(-8);} return i;}
#define __R(i, ub) (((i)<(ub))?i:(__HALT(-8),0))
#define __SHORT(x, ub) ((int)((uint64)(x)+(ub)<(ub)+(ub)?(x):(__HALT(-8),0)))
#define __SHORT(x, ub) ((int)((UINT64)(x)+(ub)<(ub)+(ub)?(x):(__HALT(-8),0)))
#define __SHORTF(x, ub) ((int)(__RF((x)+(ub),(ub)+(ub))-(ub)))
#define __CHR(x) ((CHAR)__R(x, 256))
#define __CHRF(x) ((CHAR)__RF(x, 256))
@ -129,10 +141,10 @@ static inline int64 __RF(uint64 i, uint64 ub) {if (i >= ub) {__HALT(-8);} return
// Signal handling in SYSTEM.c
#ifndef _WIN32
extern void SystemSetHandler(int s, address h);
extern void SystemSetHandler(int s, ADDRESS h);
#else
extern void SystemSetInterruptHandler(address h);
extern void SystemSetQuitHandler (address h);
extern void SystemSetInterruptHandler(ADDRESS h);
extern void SystemSetQuitHandler (ADDRESS h);
#endif
@ -140,7 +152,7 @@ static inline int64 __RF(uint64 i, uint64 ub) {if (i >= ub) {__HALT(-8);} return
// String comparison
static inline int __str_cmp(CHAR *x, CHAR *y){
int64 i = 0;
INT64 i = 0;
CHAR ch1, ch2;
do {ch1 = x[i]; ch2 = y[i]; i++;
if (!ch1) return -(int)ch2;
@ -164,8 +176,8 @@ static inline int __str_cmp(CHAR *x, CHAR *y){
#define __VAL(t, x) (*(t*)&(x))
#define __GET(a, x, t) x=*(t*)(address)(a)
#define __PUT(a, x, t) *(t*)(address)(a)=x
#define __GET(a, x, t) x=*(t*)(ADDRESS)(a)
#define __PUT(a, x, t) *(t*)(ADDRESS)(a)=x
#define __LSHL(x, n, s) ((int##s)((uint##s)(x)<<(n)))
#define __LSHR(x, n, s) ((int##s)((uint##s)(x)>>(n)))
@ -175,33 +187,33 @@ static inline int __str_cmp(CHAR *x, CHAR *y){
#define __ROTR(x, n, s) ((int##s)((uint##s)(x)>>(n)|(uint##s)(x)<<(s-(n))))
#define __ROT(x, n, s) ((n)>=0? __ROTL(x, n, s): __ROTR(x, -(n), s))
#define __ASHL(x, n) ((int64)(x)<<(n))
#define __ASHR(x, n) ((int64)(x)>>(n))
#define __ASHL(x, n) ((INT64)(x)<<(n))
#define __ASHR(x, n) ((INT64)(x)>>(n))
#define __ASH(x, n) ((n)>=0?__ASHL(x,n):__ASHR(x,-(n)))
static inline int64 SYSTEM_ASH(int64 x, int64 n) {return __ASH(x,n);}
#define __ASHF(x, n) SYSTEM_ASH((int64)(x), (int64)(n))
static inline INT64 SYSTEM_ASH(INT64 x, INT64 n) {return __ASH(x,n);}
#define __ASHF(x, n) SYSTEM_ASH((INT64)(x), (INT64)(n))
#define __MOVE(s, d, n) memcpy((char*)(address)(d),(char*)(address)(s),n)
#define __MOVE(s, d, n) memcpy((char*)(ADDRESS)(d),(char*)(ADDRESS)(s),n)
extern int64 SYSTEM_DIV(int64 x, int64 y);
extern INT64 SYSTEM_DIV(INT64 x, INT64 y);
#define __DIVF(x, y) SYSTEM_DIV(x, y)
#define __DIV(x, y) (((x)>0 && (y)>0) ? (x)/(y) : __DIVF(x, y))
extern int64 SYSTEM_MOD(int64 x, int64 y);
extern INT64 SYSTEM_MOD(INT64 x, INT64 y);
#define __MODF(x, y) SYSTEM_MOD(x, y)
#define __MOD(x, y) (((x)>0 && (y)>0) ? (x)%(y) : __MODF(x, y))
extern int64 SYSTEM_ENTIER (double x);
extern INT64 SYSTEM_ENTIER (double x);
#define __ENTIER(x) SYSTEM_ENTIER(x)
#define __ABS(x) (((x)<0)?-(x):(x))
static inline int32 SYSTEM_ABS64(int64 i) {return i >= 0 ? i : -i;}
static inline int64 SYSTEM_ABS32(int32 i) {return i >= 0 ? i : -i;}
static inline INT32 SYSTEM_ABS64(INT64 i) {return i >= 0 ? i : -i;}
static inline INT64 SYSTEM_ABS32(INT32 i) {return i >= 0 ? i : -i;}
#define __ABSF(x) ((sizeof(x) <= 4) ? SYSTEM_ABS32(x) : SYSTEM_ABS64(x))
static inline double SYSTEM_ABSD(double i) {return i >= 0.0 ? i : -i;}
@ -216,7 +228,7 @@ static inline double SYSTEM_ABSD(double i) {return i >= 0.0 ? i : -i;}
#define __SETRNG(l, h, size) ((~(uint##size)0<<(l))&~(uint##size)0>>(size-1-(h)))
#define __MASK(x, m) ((x)&~(m))
#define __BIT(x, n) (*(uint64*)(x)>>(n)&1)
#define __BIT(x, n) (*(UINT64*)(x)>>(n)&1)
@ -227,8 +239,8 @@ static inline double SYSTEM_ABSD(double i) {return i >= 0.0 ? i : -i;}
#define __WITHCHK __HALT(-7)
#define __IS(tag, typ, level) (*(tag-(__BASEOFF-level))==(address)typ##__typ)
#define __TYPEOF(p) (*(((address**)(p))-1))
#define __IS(tag, typ, level) (*(tag-(__BASEOFF-level))==(ADDRESS)typ##__typ)
#define __TYPEOF(p) (*(((ADDRESS**)(p))-1))
#define __ISP(p, typ, level) __IS(__TYPEOF(p),typ,level)
@ -257,67 +269,67 @@ extern void Heap_INCREF();
// Main module initialisation, registration and finalisation
extern void Platform_Init(int32 argc, address argv);
extern void Platform_Init(INT32 argc, ADDRESS argv);
extern void Heap_FINALL();
#define __INIT(argc, argv) static void *m; Platform_Init(argc, (address)&argv);
#define __INIT(argc, argv) static void *m; Platform_Init(argc, (ADDRESS)&argv);
#define __REGMAIN(name, enum) m = Heap_REGMOD((CHAR*)name,enum)
#define __FINI Heap_FINALL(); return 0
// Memory allocation
extern SYSTEM_PTR Heap_NEWBLK (address size);
extern SYSTEM_PTR Heap_NEWREC (address tag);
extern SYSTEM_PTR SYSTEM_NEWARR(address*, address, int, int, int, ...);
extern SYSTEM_PTR Heap_NEWBLK (ADDRESS size);
extern SYSTEM_PTR Heap_NEWREC (ADDRESS tag);
extern SYSTEM_PTR SYSTEM_NEWARR(ADDRESS*, ADDRESS, int, int, int, ...);
#define __SYSNEW(p, len) p = Heap_NEWBLK((address)(len))
#define __NEW(p, t) p = Heap_NEWREC((address)t##__typ)
#define __SYSNEW(p, len) p = Heap_NEWBLK((ADDRESS)(len))
#define __NEW(p, t) p = Heap_NEWREC((ADDRESS)t##__typ)
#define __NEWARR SYSTEM_NEWARR
/* Type handling */
extern void SYSTEM_INHERIT(address *t, address *t0);
extern void SYSTEM_ENUMP (void *adr, address n, void (*P)());
extern void SYSTEM_ENUMR (void *adr, address *typ, address size, address n, void (*P)());
extern void SYSTEM_INHERIT(ADDRESS *t, ADDRESS *t0);
extern void SYSTEM_ENUMP (void *adr, ADDRESS n, void (*P)());
extern void SYSTEM_ENUMR (void *adr, ADDRESS *typ, ADDRESS size, ADDRESS n, void (*P)());
#define __TDESC(t, m, n) \
static struct t##__desc { \
address tproc[m]; /* Proc for each ptr field */ \
address tag; \
address next; /* Module table type list points here */ \
address level; \
address module; \
ADDRESS tproc[m]; /* Proc for each ptr field */ \
ADDRESS tag; \
ADDRESS next; /* Module table type list points here */ \
ADDRESS level; \
ADDRESS module; \
char name[24]; \
address basep[__MAXEXT]; /* List of bases this extends */ \
address reserved; \
address blksz; /* xxx_typ points here */ \
address ptr[n+1]; /* Offsets of ptrs up to -ve sentinel */ \
ADDRESS basep[__MAXEXT]; /* List of bases this extends */ \
ADDRESS reserved; \
ADDRESS blksz; /* xxx_typ points here */ \
ADDRESS ptr[n+1]; /* Offsets of ptrs up to -ve sentinel */ \
} t##__desc
#define __BASEOFF (__MAXEXT+1) // blksz as index to base.
#define __TPROC0OFF (__BASEOFF+24/sizeof(address)+5) // blksz as index to tproc IFF m=1.
#define __TPROC0OFF (__BASEOFF+24/sizeof(ADDRESS)+5) // blksz as index to tproc IFF m=1.
#define __EOM 1
#define __TDFLDS(name, size) {__EOM}, 1, 0, 0, 0, name, {0}, 0, size
#define __ENUMP(adr, n, P) SYSTEM_ENUMP(adr, (address)(n), P)
#define __ENUMR(adr, typ, size, n, P) SYSTEM_ENUMR(adr, typ, (address)(size), (address)(n), P)
#define __ENUMP(adr, n, P) SYSTEM_ENUMP(adr, (ADDRESS)(n), P)
#define __ENUMR(adr, typ, size, n, P) SYSTEM_ENUMR(adr, typ, (ADDRESS)(size), (ADDRESS)(n), P)
#define __INITYP(t, t0, level) \
t##__typ = (address*)&t##__desc.blksz; \
memcpy(t##__desc.basep, t0##__typ - __BASEOFF, level*sizeof(address)); \
t##__desc.basep[level] = (address)t##__typ; \
t##__desc.module = (address)m; \
t##__typ = (ADDRESS*)&t##__desc.blksz; \
memcpy(t##__desc.basep, t0##__typ - __BASEOFF, level*sizeof(ADDRESS)); \
t##__desc.basep[level] = (ADDRESS)t##__typ; \
t##__desc.module = (ADDRESS)m; \
if(t##__desc.blksz!=sizeof(struct t)) __HALT(-15); \
t##__desc.blksz = (t##__desc.blksz+5*sizeof(address)-1)/(4*sizeof(address))*(4*sizeof(address)); \
Heap_REGTYP(m, (address)&t##__desc.next); \
t##__desc.blksz = (t##__desc.blksz+5*sizeof(ADDRESS)-1)/(4*sizeof(ADDRESS))*(4*sizeof(ADDRESS)); \
Heap_REGTYP(m, (ADDRESS)&t##__desc.next); \
SYSTEM_INHERIT(t##__typ, t0##__typ)
// Oberon-2 type bound procedures support
#define __INITBP(t, proc, num) *(t##__typ-(__TPROC0OFF+num))=(address)proc
#define __SEND(typ, num, funtyp, parlist) ((funtyp)((address)*(typ-(__TPROC0OFF+num))))parlist
#define __INITBP(t, proc, num) *(t##__typ-(__TPROC0OFF+num))=(ADDRESS)proc
#define __SEND(typ, num, funtyp, parlist) ((funtyp)((ADDRESS)*(typ-(__TPROC0OFF+num))))parlist