Skip to content

Commit

Permalink
CLeanups to sqNamedPrims.c and sqCogStackAlignment.h
Browse files Browse the repository at this point in the history
  • Loading branch information
eliotmiranda committed Jun 13, 2020
1 parent 07161bc commit cedc9cd
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 39 deletions.
36 changes: 23 additions & 13 deletions platforms/Cross/vm/sqCogStackAlignment.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
# define STACK_ALIGN_BYTES 4
# define STACK_FP_ALIGNMENT 0
# endif
# if _MSC_VER
# define STACK_SP_ALIGNMENT 4
# endif
#endif

#if defined(__arm64__) || defined(__aarch64__) || defined(ARM64)
Expand Down Expand Up @@ -115,19 +118,7 @@
# else /* !(__i386__ || __arm__ || __x86_64__) */
# error define code for your processor here
# endif
# if !defined(getfp)
# define getfp() ceGetFP() /* provided by Cogit */
# endif
# if !defined(getsp)
# define getsp() ceGetSP() /* provided by Cogit */
# endif
# define STACK_ALIGN_MASK (STACK_ALIGN_BYTES-1)
# define assertCStackWellAligned() do { \
extern sqInt cFramePointerInUse; \
if (cFramePointerInUse) \
assert((getfp() & STACK_ALIGN_MASK) == STACK_FP_ALIGNMENT); \
assert((getsp() & STACK_ALIGN_MASK) == 0); \
} while (0)

#else /* defined(STACK_ALIGN_BYTES) */
# if defined(powerpc) || defined(__powerpc__) || defined(_POWER) || defined(__POWERPC__) || defined(__PPC__)
# define STACK_ALIGN_BYTES 16
Expand All @@ -140,3 +131,22 @@
# endif
# define assertCStackWellAligned() 0
#endif /* defined(STACK_ALIGN_BYTES) */

#if !defined(getfp)
# define getfp() ceGetFP() /* provided by Cogit */
#endif
#if !defined(getsp)
# define getsp() ceGetSP() /* provided by Cogit */
#endif
#define STACK_ALIGN_MASK (STACK_ALIGN_BYTES-1)
#if !defined(STACK_SP_ALIGNMENT)
# define STACK_SP_ALIGNMENT 0
#endif
#if !defined(assertCStackWellAligned)
# define assertCStackWellAligned() do { \
extern sqInt cFramePointerInUse; \
if (cFramePointerInUse) \
assert((getfp() & STACK_ALIGN_MASK) == STACK_FP_ALIGNMENT); \
assert((getsp() & STACK_ALIGN_MASK) == STACK_SP_ALIGNMENT); \
} while (0)
#endif
42 changes: 16 additions & 26 deletions platforms/Cross/vm/sqNamedPrims.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,11 @@ struct VirtualMachine *sqGetInterpreterProxy(void);
static void *
findLoadedModule(char *pluginName)
{
ModuleEntry *module;
ModuleEntry *module = firstModule;
if (!pluginName || !pluginName[0])
return squeakModule;
module = firstModule;
while (module) {
if (strcmp(module->name, pluginName) == 0)
if (!strcmp(module->name, pluginName))
return module;
module = module->next;
}
Expand Down Expand Up @@ -140,21 +139,19 @@ findInternalFunctionIn(char *functionName, char *pluginName
#endif
)
{
char *function, *plugin;
sqInt listIndex, index;
sqExport *exports;

DPRINTF(("Looking (internally) for %s in %s ... ", functionName, (pluginName ? pluginName : "<intrinsic>")));

/* canonicalize functionName and pluginName to be NULL if not specified */
if (functionName && !functionName[0]) functionName = NULL;
if (pluginName && !pluginName[0]) pluginName = NULL;
for (listIndex=0;; listIndex++) {
exports = pluginExports[listIndex];
sqExport *exports = pluginExports[listIndex];
if (!exports) break;
for (index=0;; index++) {
plugin = exports[index].pluginName;
function = exports[index].primitiveName;
char *plugin = exports[index].pluginName;
char *function = exports[index].primitiveName;
/* canonicalize plugin and function to be NULL if not specified */
if (plugin && !plugin[0]) plugin = NULL;
if (function && !function[0]) function = NULL;
Expand Down Expand Up @@ -307,10 +304,9 @@ findAndLoadModule(char *pluginName, sqInt ffiLoad)
/* NOT ffiLoad */
if (!handle) {
/* might be internal, so go looking for setInterpreter() */
if (findInternalFunctionIn("setInterpreter", pluginName NADA))
handle = squeakModule->handle;
else
if (!findInternalFunctionIn("setInterpreter", pluginName NADA))
return NULL; /* PluginName_setInterpreter() not found */
handle = squeakModule->handle;
}
module = addToModuleList(pluginName, handle, ffiLoad);
if (!callInitializersIn(module)) {
Expand Down Expand Up @@ -593,17 +589,15 @@ char *
ioListBuiltinModule(sqInt moduleIndex)
{
sqInt index, listIndex;
char *function, *plugin;
sqExport *exports;

for (listIndex=0;; listIndex++) {
exports = pluginExports[listIndex];
sqExport * exports = pluginExports[listIndex];
if (!exports) break;
for (index=0;; index++) {
plugin = exports[index].pluginName;
function = exports[index].primitiveName;
char *plugin = exports[index].pluginName;
char *function = exports[index].primitiveName;
if (!function && !plugin) break; /* no more plugins */
if (strcmp(function,"setInterpreter") == 0) {
if (!strcmp(function,"setInterpreter")) {
/* new module */
if (--moduleIndex == 0) {
char *moduleName;
Expand All @@ -630,24 +624,20 @@ ioListLoadedModule(sqInt moduleIndex)
ModuleEntry *entry = firstModule;

if (moduleIndex < 1)
return (char*)NULL;
return NULL;
while (entry && index < moduleIndex) {
entry = entry->next;
index = index + 1;
}
if ( entry ) {
char *moduleName;
void * init0;

init0 = findFunctionIn("getModuleName", entry);
if (entry) {
void *init0 = findFunctionIn("getModuleName", entry);
if (init0) {
/* Check the compiled name of the module */
moduleName = ((char* (*) (void))init0)();
char *moduleName = ((char* (*) (void))init0)();
if (moduleName)
return moduleName;
}
return entry->name;
}
else
return (char*)NULL;
return NULL;
}

0 comments on commit cedc9cd

Please sign in to comment.