compiler/bootstrap/windows-48/Modules.c
David C W Brown da88496c5f Tidy (#41)
* Deduplicate common constants into OPM and do some source format tidying.

* Fix postpush buildall script to force checkout of updated buildall.

* Show enlistment branch in makefiles

* Support non-printables in string literals and tidy case alignment and constant literals.

* Common code for MIN and MAX of integer types.

* Common code for SInt/Int/LInt in ConstOp parameter preparation.

* Common code for SInt/Int/LInt in Op parameter preparation.

* Refactor SetIntType to work with byte size directly. Prepare to revert my incorrect VAL changes.

* Original meaning of VAL restored. Many library files disabled until use of VAL in 64 bits fixed.

* Make Reals.Mod independent of INTEGER size and add reals tests.

* Implement fraction, IsInfinity and IsNaN in oocLowReal.Mod.

* OPB little simplifications and ShorterSize/LongerSize functions.

* Add test for alignment computability

* Replace alignment constants with calculated alignment.

* typ.size aware OPV.Convert

* Add SYSTEM_INT64 and make tests name independent.

* Remove SYSTEM.H includes (string.h and stdint.h).

* Replace uses of uintptr_t and size_t with SYSTEM_ADDRESS.

* Sad hack to make FreeBSD and OpenBSD happy with memcpy declaration.

* Detect 64 bit on FreeBSD, and size_t defined on OpenBSD.

* %zd not supportd by mingw, cast strnlen return to int.

* Add debug for intermittent failure only on OpenBSD.

* Add textTexts as a confidence test and tidy up a couple of other tests.

* Update binary test process.
2016-08-25 14:41:00 +01:00

171 lines
4.2 KiB
C

/* voc 1.95 [2016/08/23] for gcc LP64 on cygwin xtspkaSfF */
#include "SYSTEM.h"
#include "Console.h"
#include "Heap.h"
typedef
struct Modules_CmdDesc *Modules_Cmd;
typedef
void (*Modules_Command)(void);
typedef
struct Modules_CmdDesc {
Modules_Cmd next;
CHAR name[24];
Modules_Command cmd;
} Modules_CmdDesc;
typedef
struct Modules_ModuleDesc *Modules_Module;
typedef
CHAR Modules_ModuleName[20];
typedef
struct Modules_ModuleDesc {
Modules_Module next;
Modules_ModuleName name;
LONGINT refcnt;
Modules_Cmd cmds;
LONGINT types;
void (*enumPtrs)(void(*)(LONGINT));
LONGINT reserved1, reserved2;
} Modules_ModuleDesc;
export INTEGER Modules_res;
export CHAR Modules_resMsg[256];
export Modules_ModuleName Modules_imported, Modules_importing;
export LONGINT *Modules_ModuleDesc__typ;
export LONGINT *Modules_CmdDesc__typ;
static void Modules_Append (CHAR *a, LONGINT a__len, CHAR *b, LONGINT b__len);
export void Modules_Free (CHAR *name, LONGINT name__len, BOOLEAN all);
export Modules_Command Modules_ThisCommand (Modules_Module mod, CHAR *name, LONGINT name__len);
export Modules_Module Modules_ThisMod (CHAR *name, LONGINT name__len);
#define Modules_modules() (Modules_Module)Heap_modules
#define Modules_setmodules(m) Heap_modules = m
static void Modules_Append (CHAR *a, LONGINT a__len, CHAR *b, LONGINT b__len)
{
INTEGER i, j;
__DUP(b, b__len, CHAR);
i = 0;
while (a[__X(i, a__len)] != 0x00) {
i += 1;
}
j = 0;
while (b[__X(j, b__len)] != 0x00) {
a[__X(i, a__len)] = b[__X(j, b__len)];
i += 1;
j += 1;
}
a[__X(i, a__len)] = 0x00;
__DEL(b);
}
Modules_Module Modules_ThisMod (CHAR *name, LONGINT name__len)
{
Modules_Module _o_result;
Modules_Module m = NIL;
CHAR bodyname[64];
Modules_Command body;
__DUP(name, name__len, CHAR);
m = Modules_modules();
while ((m != NIL && __STRCMP(m->name, name) != 0)) {
m = m->next;
}
if (m != NIL) {
Modules_res = 0;
Modules_resMsg[0] = 0x00;
} else {
Modules_res = 1;
__COPY(name, Modules_importing, ((LONGINT)(20)));
__MOVE(" module \"", Modules_resMsg, 10);
Modules_Append((void*)Modules_resMsg, ((LONGINT)(256)), name, name__len);
Modules_Append((void*)Modules_resMsg, ((LONGINT)(256)), (CHAR*)"\" not found", (LONGINT)12);
}
_o_result = m;
__DEL(name);
return _o_result;
}
Modules_Command Modules_ThisCommand (Modules_Module mod, CHAR *name, LONGINT name__len)
{
Modules_Command _o_result;
Modules_Cmd c = NIL;
__DUP(name, name__len, CHAR);
c = mod->cmds;
while ((c != NIL && __STRCMP(c->name, name) != 0)) {
c = c->next;
}
if (c != NIL) {
Modules_res = 0;
Modules_resMsg[0] = 0x00;
_o_result = c->cmd;
__DEL(name);
return _o_result;
} else {
Modules_res = 2;
__MOVE(" command \"", Modules_resMsg, 11);
__COPY(name, Modules_importing, ((LONGINT)(20)));
Modules_Append((void*)Modules_resMsg, ((LONGINT)(256)), mod->name, ((LONGINT)(20)));
Modules_Append((void*)Modules_resMsg, ((LONGINT)(256)), (CHAR*)".", (LONGINT)2);
Modules_Append((void*)Modules_resMsg, ((LONGINT)(256)), name, name__len);
Modules_Append((void*)Modules_resMsg, ((LONGINT)(256)), (CHAR*)"\" not found", (LONGINT)12);
_o_result = NIL;
__DEL(name);
return _o_result;
}
__RETCHK;
}
void Modules_Free (CHAR *name, LONGINT name__len, BOOLEAN all)
{
Modules_Module m = NIL, p = NIL;
__DUP(name, name__len, CHAR);
m = Modules_modules();
if (all) {
Modules_res = 1;
__MOVE("unloading \"all\" not yet supported", Modules_resMsg, 34);
} else {
while ((m != NIL && __STRCMP(m->name, name) != 0)) {
p = m;
m = m->next;
}
if ((m != NIL && m->refcnt == 0)) {
if (m == Modules_modules()) {
Modules_setmodules(m->next);
} else {
p->next = m->next;
}
Modules_res = 0;
} else {
Modules_res = 1;
if (m == NIL) {
__MOVE("module not found", Modules_resMsg, 17);
} else {
__MOVE("clients of this module exist", Modules_resMsg, 29);
}
}
}
__DEL(name);
}
__TDESC(Modules_ModuleDesc, 1, 2) = {__TDFLDS("ModuleDesc", 48), {0, 28, -12}};
__TDESC(Modules_CmdDesc, 1, 1) = {__TDFLDS("CmdDesc", 32), {0, -8}};
export void *Modules__init(void)
{
__DEFMOD;
__MODULE_IMPORT(Console);
__MODULE_IMPORT(Heap);
__REGMOD("Modules", 0);
__INITYP(Modules_ModuleDesc, Modules_ModuleDesc, 0);
__INITYP(Modules_CmdDesc, Modules_CmdDesc, 0);
/* BEGIN */
__ENDMOD;
}