Skip to content

Commit

Permalink
* SYSTEM: getting rid of excessive use of SYSTEM_ADRINT in favor of m…
Browse files Browse the repository at this point in the history
…ore native types SYSTEM_PTR (void*)
  • Loading branch information
Oleg-N-Cher committed Nov 22, 2023
1 parent 97d7bd5 commit e6af4de
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 65 deletions.
8 changes: 4 additions & 4 deletions Mod/Lib/Kernel.cp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ IMPORT SYSTEM, Heap, Platform, Out := Console;
TYPE
CString = SYSTEM.ADRINT;
HaltProcedure = PROCEDURE(code: INTEGER; mod: CString; pos: INTEGER);
SignalHandler = PROCEDURE(signal: INTEGER);
SignalHandler = PROCEDURE (signal: INTEGER);

VAR
HaltCode-: INTEGER;
Expand All @@ -15,9 +15,9 @@ VAR

(* Ctrl/C handling *)

PROCEDURE -SetInterruptHandler* (h: SignalHandler) "SystemSetInterruptHandler((SYSTEM_ADRINT)h)";
PROCEDURE -SetQuitHandler* (h: SignalHandler) "SystemSetQuitHandler((SYSTEM_ADRINT)h)";
PROCEDURE -SetBadInstructionHandler*(h: SignalHandler) "SystemSetBadInstructionHandler((SYSTEM_ADRINT)h)";
PROCEDURE- SetInterruptHandler* (h: SignalHandler) "SystemSetInterruptHandler(h)";
PROCEDURE- SetQuitHandler* (h: SignalHandler) "SystemSetQuitHandler(h)";
PROCEDURE- SetBadInstructionHandler*(h: SignalHandler) "SystemSetBadInstructionHandler(h)";


PROCEDURE DisplayHaltCode(code: INTEGER);
Expand Down
66 changes: 33 additions & 33 deletions Mod/Lib/SYSTEM.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ INTEGER SYSTEM_DIV(INTEGER x, INTEGER y)
if (x > 0) return -1 + (x - 1) / y;
else return x / y;
}
__HALT(-12, "SYSTEM.c", 48); return 0; // noreturn
__HALT(-12, "SYSTEM.c", 51); return 0; // noreturn
}

LONGINT SYSTEM_DIVL(LONGINT x, LONGINT y)
Expand All @@ -61,7 +61,7 @@ LONGINT SYSTEM_DIVL(LONGINT x, LONGINT y)
if (x > 0) return -1 + (x - 1) / y;
else return x / y;
}
__HALT(-12, "SYSTEM.c", 61); return 0; // noreturn
__HALT(-12, "SYSTEM.c", 64); return 0; // noreturn
}

INTEGER SYSTEM_MOD(INTEGER x, INTEGER y)
Expand All @@ -74,7 +74,7 @@ INTEGER SYSTEM_MOD(INTEGER x, INTEGER y)
if (x > 0) return y + 1 + (x - 1) % y;
else return x % y;
}
__HALT(-12, "SYSTEM.c", 74); return 0; // noreturn
__HALT(-12, "SYSTEM.c", 77); return 0; // noreturn
}

LONGINT SYSTEM_MODL(LONGINT x, LONGINT y)
Expand All @@ -87,7 +87,7 @@ LONGINT SYSTEM_MODL(LONGINT x, LONGINT y)
if (x > 0) return y + 1 + (x - 1) % y;
else return x % y;
}
__HALT(-12, "SYSTEM.c", 87); return 0; // noreturn
__HALT(-12, "SYSTEM.c", 90); return 0; // noreturn
}

INTEGER SYSTEM_ENTIER(REAL x)
Expand Down Expand Up @@ -156,15 +156,15 @@ void SYSTEM_UNPK (SHORTREAL *x, INTEGER *n)
}


void SYSTEM_INHERIT(SYSTEM_ADRINT *t, SYSTEM_ADRINT *t0)
void SYSTEM_INHERIT (SYSTEM_PTR *t, SYSTEM_PTR *t0)
{
t -= __TPROC0OFF;
t0 -= __TPROC0OFF;
while (*t0 != __EOM) {*t = *t0; t--; t0--;}
while (*t0 != (SYSTEM_PTR)__EOM) {*t = *t0; t--; t0--;}
}


void SYSTEM_ENUMP(void *adr, SYSTEM_ADRINT n, void (*P)(void*))
void SYSTEM_ENUMP (void *adr, SYSTEM_ADRINT n, void (*P)(void*))
{
while (n > 0) {
P(*((void**)(adr)));
Expand All @@ -173,15 +173,15 @@ void SYSTEM_ENUMP(void *adr, SYSTEM_ADRINT n, void (*P)(void*))
}
}

void SYSTEM_ENUMR(void *adr, SYSTEM_ADRINT *typ, SYSTEM_ADRINT size, SYSTEM_ADRINT n, void (*P)(void*))
void SYSTEM_ENUMR (void *adr, SYSTEM_PTR *typ, SYSTEM_ADRINT size, SYSTEM_ADRINT n, void (*P)(void*))
{
SYSTEM_ADRINT *t, off;
SYSTEM_PTR *t; SYSTEM_ADRINT off;
if (typ == 0) return; // not yet initialized
typ++;
while (n > 0) {
t = typ;
off = *t;
while (off >= 0) {P(*(void**)((char*)adr+off)); t++; off = *t;}
off = (SYSTEM_ADRINT)*t;
while (off >= 0) {P(*(void**)((char*)adr+off)); t++; off = (SYSTEM_ADRINT)*t;}
adr = ((char*)adr) + size;
n--;
}
Expand All @@ -206,7 +206,7 @@ void SYSTEM_INIT (void *stktop)
Heap_InitHeap();
}

SYSTEM_PTR SYSTEM_NEWARR(SYSTEM_ADRINT *typ, SYSTEM_ARRLEN elemsz, int elemalgn, int nofdim, int nofdyn, ...)
SYSTEM_PTR SYSTEM_NEWARR (SYSTEM_PTR *typ, SYSTEM_ARRLEN elemsz, INTEGER elemalgn, INTEGER nofdim, INTEGER nofdyn, ...)
{
SYSTEM_ADRINT *x, *p, *ptab;
SYSTEM_ARRLEN nofelems, size, dataoff, n, nptr, nofptrs, i, *pi, off;
Expand All @@ -215,7 +215,7 @@ SYSTEM_PTR SYSTEM_NEWARR(SYSTEM_ADRINT *typ, SYSTEM_ARRLEN elemsz, int elemalgn,
nofelems = 1;
while (nofdim > 0) {
nofelems = nofelems * va_arg(ap, SYSTEM_ARRLEN); nofdim--;
if (nofelems <= 0) __HALT(-20, "SYSTEM.c", 178);
if (nofelems <= 0) __HALT(-20, "SYSTEM.c", 218);
}
va_end(ap);
dataoff = nofdyn * sizeof(SYSTEM_ARRLEN);
Expand All @@ -229,32 +229,32 @@ SYSTEM_PTR SYSTEM_NEWARR(SYSTEM_ADRINT *typ, SYSTEM_ARRLEN elemsz, int elemalgn,
/* element typ does not contain pointers */
x = Heap_NEWBLK(size);
}
else if (typ == (SYSTEM_ADRINT*)POINTER__typ) {
else if (typ == POINTER__typ) {
/* element type is a pointer */
x = Heap_NEWBLK(size + nofelems * sizeof(SYSTEM_ADRINT));
x = Heap_NEWBLK(size + nofelems * sizeof(SYSTEM_PTR));
p = (SYSTEM_ADRINT*)x[-1];
p[-nofelems] = *p; /* build new type desc in situ: 1. copy block size; 2. setup ptr tab; 3. set sentinel; 4. patch tag */
p -= nofelems - 1;
for (n=0; n<nofelems; n++, p++)
*p = dataoff + n*sizeof(SYSTEM_ADRINT);
*p = - (nofelems + 1) * sizeof(SYSTEM_ADRINT); /* sentinel */
x[-1] -= nofelems * sizeof(SYSTEM_ADRINT);
*p = dataoff + n*sizeof(SYSTEM_PTR);
*p = - (nofelems + 1) * sizeof(SYSTEM_PTR); /* sentinel */
x[-1] -= nofelems * sizeof(SYSTEM_PTR);
}
else {
/* element type is a record that contains pointers */
ptab = typ + 1; nofptrs = 0;
ptab = (SYSTEM_ADRINT*)typ + 1; nofptrs = 0;
while (ptab[nofptrs] >= 0) {nofptrs++;} /* number of pointers per element */
nptr = nofelems * nofptrs; /* total number of pointers */
x = Heap_NEWBLK(size + nptr * sizeof(SYSTEM_ADRINT));
x = Heap_NEWBLK(size + nptr * sizeof(SYSTEM_PTR));
p = (SYSTEM_ADRINT*)x[-1];
p[-nptr] = *p; /* build new type desc in situ; 1. copy block size; 2. setup ptr tab; 3. set sentinel; 4. patch tag */
p -= nptr - 1; n = 0; off = dataoff;
while (n < nofelems) {i = 0;
while (i < nofptrs) {*p = off + ptab[i]; p++; i++;}
off += elemsz; n++;
}
*p = - (nptr + 1) * sizeof(SYSTEM_ADRINT); /* sentinel */
x[-1] -= nptr * sizeof(SYSTEM_ADRINT);
*p = - (nptr + 1) * sizeof(SYSTEM_PTR); /* sentinel */
x[-1] -= nptr * sizeof(SYSTEM_PTR);
}
if (nofdyn != 0) {
/* setup len vector for index checks */
Expand Down Expand Up @@ -286,28 +286,28 @@ typedef void (*SystemSignalHandler)(INTEGER); // = Platform_SignalHandler
SystemSignalHandler handler[3] = {0};

// Provide signal handling for Unix based systems
void signalHandler(int s) {
void signalHandler (int s) {
if (s >= 2 && s <= 4) handler[s-2](s);
// (Ignore other signals)
}

void SystemSetHandler(int s, SYSTEM_ADRINT h) {
void SystemSetHandler (int s, SystemSignalHandler h) {
if (s >= 2 && s <= 4) {
int needtosetsystemhandler = handler[s-2] == 0;
handler[s-2] = (SystemSignalHandler)h;
handler[s-2] = h;
if (needtosetsystemhandler) {signal(s, signalHandler);}
}
}

void SystemSetInterruptHandler(SYSTEM_ADRINT h) {
void SystemSetInterruptHandler (SystemSignalHandler h) {
SystemSetHandler(2, h);
}

void SystemSetQuitHandler(SYSTEM_ADRINT h) {
void SystemSetQuitHandler (SystemSignalHandler h) {
SystemSetHandler(3, h);
}

void SystemSetBadInstructionHandler(SYSTEM_ADRINT h) {
void SystemSetBadInstructionHandler (SystemSignalHandler h) {
SystemSetHandler(4, h);
}

Expand Down Expand Up @@ -354,17 +354,17 @@ typedef void (*SystemSignalHandler)(INTEGER); // = Platform_SignalHandler
}
}

void SystemSetInterruptHandler(SYSTEM_ADRINT h) {
void SystemSetInterruptHandler (SystemSignalHandler h) {
EnsureConsoleCtrlHandler();
SystemInterruptHandler = (SystemSignalHandler)h;
SystemInterruptHandler = h;
}

void SystemSetQuitHandler(SYSTEM_ADRINT h) {
void SystemSetQuitHandler (SystemSignalHandler h) {
EnsureConsoleCtrlHandler();
SystemQuitHandler = (SystemSignalHandler)h;
SystemQuitHandler = h;
}

void SystemSetBadInstructionHandler(SYSTEM_ADRINT h) {
void SystemSetBadInstructionHandler (SystemSignalHandler h) {
}

#endif
48 changes: 24 additions & 24 deletions Mod/Lib/SYSTEM.oh
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ typedef int SYSTEM_ARRLEN; // 32 or 64 bits, see also OPM.IndexSize and MaxIndex

#define NIL ((void*)0)
#define __MAXEXT 16
#define POINTER__typ ((SYSTEM_ADRINT*)(1)) // not NIL and not a valid type
#define POINTER__typ ((void**)(1)) // not NIL and not a valid type
#define __INF (*(REAL*)&SYSTEM_INF)
#define __INFS (*(SHORTREAL*)&SYSTEM_INFS)

Expand Down Expand Up @@ -118,9 +118,9 @@ extern void SYSTEM_UNPK (SHORTREAL *x, INTEGER *n);

// Signal handling in SYSTEM.c

extern void SystemSetInterruptHandler (SYSTEM_ADRINT h);
extern void SystemSetQuitHandler (SYSTEM_ADRINT h);
extern void SystemSetBadInstructionHandler(SYSTEM_ADRINT h);
extern void SystemSetInterruptHandler (void (*h)(INTEGER));
extern void SystemSetQuitHandler (void (*h)(INTEGER));
extern void SystemSetBadInstructionHandler (void (*h)(INTEGER));


// Assertions and Halts
Expand Down Expand Up @@ -399,7 +399,7 @@ static inline REAL __MAXFD (REAL x, REAL y) { return x>y?x:y; }

extern void Heap_REGCMD (SYSTEM_PTR m, CHAR *name, INTEGER name__len, void (*cmd)(void));
extern SYSTEM_PTR Heap_REGMOD (CHAR *name, INTEGER name__len, void (*enumPtrs)(void(*)(SYSTEM_PTR)));
extern void Heap_REGTYP (SYSTEM_PTR m, SYSTEM_ADRINT typ);
extern void Heap_REGTYP (SYSTEM_PTR m, SYSTEM_PTR typ);
extern void Heap_INCREF (SYSTEM_PTR m);

#define __DEFMOD static void *m; if (m!=0) {return m;}
Expand Down Expand Up @@ -442,30 +442,30 @@ extern void Heap_FINALL (void);
// Memory allocation

extern SYSTEM_PTR Heap_NEWBLK (SYSTEM_ADRINT size);
extern SYSTEM_PTR Heap_NEWREC (SYSTEM_ADRINT tag);
extern SYSTEM_PTR SYSTEM_NEWARR(SYSTEM_ADRINT*, SYSTEM_ARRLEN, int, int, int, ...);
extern SYSTEM_PTR Heap_NEWREC (SYSTEM_PTR tag);
extern SYSTEM_PTR SYSTEM_NEWARR (SYSTEM_PTR*, SYSTEM_ARRLEN, INTEGER, INTEGER, INTEGER, ...);

#define __SYSNEW(p, len) p = Heap_NEWBLK((SYSTEM_ADRINT)(len))
#define __NEW(p, t) p = Heap_NEWREC((SYSTEM_ADRINT)t##__typ)
#define __NEW(p, t) p = Heap_NEWREC(t##__typ)
#define __NEWARR SYSTEM_NEWARR



/* Type handling */

extern void SYSTEM_INHERIT(SYSTEM_ADRINT *t, SYSTEM_ADRINT *t0);
extern void SYSTEM_ENUMP (void *adr, SYSTEM_ADRINT n, void (*P)(void*));
extern void SYSTEM_ENUMR (void *adr, SYSTEM_ADRINT *typ, SYSTEM_ADRINT size, SYSTEM_ADRINT n, void (*P)(void*));
extern void SYSTEM_INHERIT (SYSTEM_PTR *t, SYSTEM_PTR *t0);
extern void SYSTEM_ENUMP (void *adr, SYSTEM_ADRINT n, void (*P)(void*));
extern void SYSTEM_ENUMR (void *adr, SYSTEM_PTR *typ, SYSTEM_ADRINT size, SYSTEM_ADRINT n, void (*P)(void*));

#define __TDESC(t__desc, m, n) \
static struct t__desc { \
SYSTEM_ADRINT tproc[m]; /* Proc for each ptr field */ \
SYSTEM_ADRINT tag; \
SYSTEM_ADRINT next; /* Module table type list points here */ \
SYSTEM_ADRINT level; \
SYSTEM_ADRINT module; \
SYSTEM_PTR module; \
char name[24]; \
SYSTEM_ADRINT basep[__MAXEXT]; /* List of bases this extends */ \
SYSTEM_PTR basep[__MAXEXT]; /* List of bases this extends */ \
SYSTEM_ADRINT reserved; \
SYSTEM_ADRINT blksz; /* xxx_typ points here */ \
SYSTEM_ADRINT ptr[n+1]; /* Offsets of ptrs up to -ve sentinel */ \
Expand All @@ -479,22 +479,22 @@ extern void SYSTEM_ENUMR (void *adr, SYSTEM_ADRINT *typ, SYSTEM_ADRINT size, SY
#define __ENUMR(adr, typ, size, n, P) SYSTEM_ENUMR(adr, typ, (SYSTEM_ADRINT)(size), (SYSTEM_ADRINT)(n), P)

#define __INITYP(t, t0, level) \
t##__typ = (SYSTEM_ADRINT*)&t##__desc.blksz; \
memcpy(t##__desc.basep, t0##__typ - __BASEOFF, level*sizeof(SYSTEM_ADRINT)); \
t##__desc.basep[level] = (SYSTEM_ADRINT)t##__typ; \
t##__desc.module = (SYSTEM_ADRINT)m; \
if(t##__desc.blksz!=sizeof(struct t)) __HALT(-15, "SYSTEM.oh", 324); \
t##__desc.blksz = (t##__desc.blksz+5*sizeof(SYSTEM_ADRINT)-1)/(4*sizeof(SYSTEM_ADRINT))*(4*sizeof(SYSTEM_ADRINT)); \
Heap_REGTYP(m, (SYSTEM_ADRINT)&t##__desc.next); \
t##__typ = (SYSTEM_PTR*)&t##__desc.blksz; \
memcpy(t##__desc.basep, t0##__typ - __BASEOFF, level*sizeof(SYSTEM_PTR)); \
t##__desc.basep[level] = t##__typ; \
t##__desc.module = (SYSTEM_PTR)m; \
if(t##__desc.blksz!=sizeof(struct t)) __HALT(-15, "SYSTEM.oh", 486); \
t##__desc.blksz = (t##__desc.blksz+5*sizeof(SYSTEM_PTR)-1)/(4*sizeof(SYSTEM_PTR))*(4*sizeof(SYSTEM_PTR)); \
Heap_REGTYP(m, &t##__desc.next); \
SYSTEM_INHERIT(t##__typ, t0##__typ)

#define __IS(tag, typ, level) (*(tag-(__BASEOFF-level))==(SYSTEM_ADRINT)typ##__typ)
#define __TYPEOF(p) (*(((SYSTEM_ADRINT**)(p))-1))
#define __IS(tag, typ, level) ((SYSTEM_PTR)*(tag-(__BASEOFF-level))==typ##__typ)
#define __TYPEOF(p) (*(((SYSTEM_PTR**)(p))-1))
#define __ISP(p, typ, level) __IS(__TYPEOF(p),typ,level)

// Oberon-2 type bound procedures support
#define __INITBP(t, proc, num) *(t##__typ-(__TPROC0OFF+num))=(SYSTEM_ADRINT)proc
#define __SEND(typ, procname, num, funtyp, parlist) ((funtyp)((SYSTEM_ADRINT)*(typ-(__TPROC0OFF+num))))parlist
#define __INITBP(t, proc, num) *(t##__typ-(__TPROC0OFF+num))=proc
#define __SEND(typ, procname, num, funtyp, parlist) ((funtyp)((SYSTEM_PTR)*(typ-(__TPROC0OFF+num))))parlist


#ifndef _WIN32
Expand Down
6 changes: 3 additions & 3 deletions Mod/OfrontOPC.cp
Original file line number Diff line number Diff line change
Expand Up @@ -1116,7 +1116,7 @@
LenList(obj, FALSE, TRUE)
ELSIF (obj^.mode = VarPar) & (obj^.typ^.comp = Record) & (obj^.typ^.sysflag MOD 100H = 0) THEN
EndStat; BegStat;
OPM.WriteString("SYSTEM_ADRINT *"); Ident(obj); OPM.WriteString(TagExt);
OPM.WriteString("void **"); Ident(obj); OPM.WriteString(TagExt);
base := NIL
ELSIF constarr & (vis = 0) THEN (* элементы конст. массива *)
OPM.WriteString(" ="); OPM.WriteLn; Indent(1);
Expand Down Expand Up @@ -1156,7 +1156,7 @@
END;
LenList(obj, TRUE, showParamNames)
ELSIF (obj^.mode = VarPar) & (obj^.typ^.comp = Record) & (obj^.typ^.sysflag MOD 100H = 0) THEN
OPM.WriteString(", SYSTEM_ADRINT *");
OPM.WriteString(", void **");
IF showParamNames THEN Ident(obj); OPM.WriteString(TagExt) END
END;
IF (obj^.link = NIL) OR (obj^.link.mode = TProc) THEN EXIT END ;
Expand Down Expand Up @@ -1262,7 +1262,7 @@
ELSIF dynlib THEN OPM.WriteString(EXPORT)
ELSE OPM.WriteString(Export)
END ;
OPM.WriteString("SYSTEM_ADRINT *"); Andent(typ); OPM.WriteString(DynTypExt);
OPM.WriteString("void **"); Andent(typ); OPM.WriteString(DynTypExt);
EndStat
END ;
n := n^.link
Expand Down
2 changes: 1 addition & 1 deletion Mod/OfrontOPV.cp
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,7 @@
| odd:
OPM.WriteString("__ODD("); expr(l, MinPrec); OPM.Write(CloseParen)
| typfn: (*SYSTEM*)
OPM.WriteString("(SYSTEM_ADRINT)"); TypeOf(l)
OPM.WriteString("(void*)"); TypeOf(l)
| adr: (*SYSTEM*)
IF ~oldc THEN OPM.WriteString("(SYSTEM_ADRINT)") END;
IF l^.class = Ntype THEN TypeOf(l)
Expand Down
Binary file modified Target/BlackBox/Mod/OPC.odc
Binary file not shown.
Binary file modified Target/BlackBox/Mod/OPV.odc
Binary file not shown.
Binary file modified Target/Win32/ofront+.exe
Binary file not shown.

0 comments on commit e6af4de

Please sign in to comment.