Step one of trying to clean up the macro namespace

This commit is contained in:
K. Lange 2024-01-08 09:29:52 +09:00
parent a5f5c30157
commit 0a9a3c7129
21 changed files with 126 additions and 126 deletions

View File

@ -1299,7 +1299,7 @@ static void module_sweep(KrkInstance * inst) {
#ifndef KRK_STATIC_ONLY #ifndef KRK_STATIC_ONLY
struct KrkModule * module = (struct KrkModule*)inst; struct KrkModule * module = (struct KrkModule*)inst;
if (module->libHandle) { if (module->libHandle) {
dlClose(module->libHandle); krk_dlClose(module->libHandle);
} }
#endif #endif
} }

View File

@ -21,8 +21,8 @@ static void addLine(KrkChunk * chunk, size_t line) {
if (chunk->linesCount && chunk->lines[chunk->linesCount-1].line == line) return; if (chunk->linesCount && chunk->lines[chunk->linesCount-1].line == line) return;
if (chunk->linesCapacity < chunk->linesCount + 1) { if (chunk->linesCapacity < chunk->linesCount + 1) {
int old = chunk->linesCapacity; int old = chunk->linesCapacity;
chunk->linesCapacity = GROW_CAPACITY(old); chunk->linesCapacity = KRK_GROW_CAPACITY(old);
chunk->lines = GROW_ARRAY(KrkLineMap, chunk->lines, old, chunk->linesCapacity); chunk->lines = KRK_GROW_ARRAY(KrkLineMap, chunk->lines, old, chunk->linesCapacity);
} }
chunk->lines[chunk->linesCount] = (KrkLineMap){chunk->count, line}; chunk->lines[chunk->linesCount] = (KrkLineMap){chunk->count, line};
chunk->linesCount++; chunk->linesCount++;
@ -31,8 +31,8 @@ static void addLine(KrkChunk * chunk, size_t line) {
void krk_writeChunk(KrkChunk * chunk, uint8_t byte, size_t line) { void krk_writeChunk(KrkChunk * chunk, uint8_t byte, size_t line) {
if (chunk->capacity < chunk->count + 1) { if (chunk->capacity < chunk->count + 1) {
int old = chunk->capacity; int old = chunk->capacity;
chunk->capacity = GROW_CAPACITY(old); chunk->capacity = KRK_GROW_CAPACITY(old);
chunk->code = GROW_ARRAY(uint8_t, chunk->code, old, chunk->capacity); chunk->code = KRK_GROW_ARRAY(uint8_t, chunk->code, old, chunk->capacity);
} }
chunk->code[chunk->count] = byte; chunk->code[chunk->count] = byte;
@ -41,8 +41,8 @@ void krk_writeChunk(KrkChunk * chunk, uint8_t byte, size_t line) {
} }
void krk_freeChunk(KrkChunk * chunk) { void krk_freeChunk(KrkChunk * chunk) {
FREE_ARRAY(uint8_t, chunk->code, chunk->capacity); KRK_FREE_ARRAY(uint8_t, chunk->code, chunk->capacity);
FREE_ARRAY(KrkLineMap, chunk->lines, chunk->linesCapacity); KRK_FREE_ARRAY(KrkLineMap, chunk->lines, chunk->linesCapacity);
krk_freeValueArray(&chunk->constants); krk_freeValueArray(&chunk->constants);
krk_initChunk(chunk); krk_initChunk(chunk);
} }

View File

@ -362,7 +362,7 @@ static void initCompiler(struct GlobalState * state, Compiler * compiler, Functi
compiler->codeobject = krk_newCodeObject(); compiler->codeobject = krk_newCodeObject();
compiler->localCount = 0; compiler->localCount = 0;
compiler->localsSpace = 8; compiler->localsSpace = 8;
compiler->locals = GROW_ARRAY(Local,NULL,0,8); compiler->locals = KRK_GROW_ARRAY(Local,NULL,0,8);
compiler->upvaluesSpace = 0; compiler->upvaluesSpace = 0;
compiler->upvalues = NULL; compiler->upvalues = NULL;
compiler->breakCount = 0; compiler->breakCount = 0;
@ -576,7 +576,7 @@ static KrkCodeObject * endCompiler(struct GlobalState * state) {
function->localNames[i].deathday = currentChunk()->count; function->localNames[i].deathday = currentChunk()->count;
} }
} }
function->localNames = GROW_ARRAY(KrkLocalEntry, function->localNames, function->localNames = KRK_GROW_ARRAY(KrkLocalEntry, function->localNames,
state->current->localNameCapacity, function->localNameCount); /* Shorten this down for runtime */ state->current->localNameCapacity, function->localNameCount); /* Shorten this down for runtime */
if (state->current->continueCount) { state->parser.previous = state->current->continues[0].token; error("continue without loop"); } if (state->current->continueCount) { state->parser.previous = state->current->continues[0].token; error("continue without loop"); }
@ -584,14 +584,14 @@ static KrkCodeObject * endCompiler(struct GlobalState * state) {
emitReturn(state); emitReturn(state);
/* Reduce the size of dynamic arrays to their fixed sizes. */ /* Reduce the size of dynamic arrays to their fixed sizes. */
function->chunk.lines = GROW_ARRAY(KrkLineMap, function->chunk.lines, function->chunk.lines = KRK_GROW_ARRAY(KrkLineMap, function->chunk.lines,
function->chunk.linesCapacity, function->chunk.linesCount); function->chunk.linesCapacity, function->chunk.linesCount);
function->chunk.linesCapacity = function->chunk.linesCount; function->chunk.linesCapacity = function->chunk.linesCount;
function->chunk.code = GROW_ARRAY(uint8_t, function->chunk.code, function->chunk.code = KRK_GROW_ARRAY(uint8_t, function->chunk.code,
function->chunk.capacity, function->chunk.count); function->chunk.capacity, function->chunk.count);
function->chunk.capacity = function->chunk.count; function->chunk.capacity = function->chunk.count;
function->expressions = GROW_ARRAY(KrkExpressionsMap, function->expressions, function->expressions = KRK_GROW_ARRAY(KrkExpressionsMap, function->expressions,
function->expressionsCapacity, function->expressionsCount); function->expressionsCapacity, function->expressionsCount);
function->expressionsCapacity = function->expressionsCount; function->expressionsCapacity = function->expressionsCount;
@ -648,10 +648,10 @@ static KrkCodeObject * endCompiler(struct GlobalState * state) {
} }
static void freeCompiler(Compiler * compiler) { static void freeCompiler(Compiler * compiler) {
FREE_ARRAY(Local,compiler->locals, compiler->localsSpace); KRK_FREE_ARRAY(Local,compiler->locals, compiler->localsSpace);
FREE_ARRAY(Upvalue,compiler->upvalues, compiler->upvaluesSpace); KRK_FREE_ARRAY(Upvalue,compiler->upvalues, compiler->upvaluesSpace);
FREE_ARRAY(struct LoopExit,compiler->breaks, compiler->breakSpace); KRK_FREE_ARRAY(struct LoopExit,compiler->breaks, compiler->breakSpace);
FREE_ARRAY(struct LoopExit,compiler->continues, compiler->continueSpace); KRK_FREE_ARRAY(struct LoopExit,compiler->continues, compiler->continueSpace);
while (compiler->properties) { while (compiler->properties) {
void * tmp = compiler->properties; void * tmp = compiler->properties;
@ -714,8 +714,8 @@ static ssize_t resolveLocal(struct GlobalState * state, Compiler * compiler, Krk
static size_t renameLocal(struct GlobalState * state, size_t ind, KrkToken name) { static size_t renameLocal(struct GlobalState * state, size_t ind, KrkToken name) {
if (state->current->codeobject->localNameCount + 1 > state->current->localNameCapacity) { if (state->current->codeobject->localNameCount + 1 > state->current->localNameCapacity) {
size_t old = state->current->localNameCapacity; size_t old = state->current->localNameCapacity;
state->current->localNameCapacity = GROW_CAPACITY(old); state->current->localNameCapacity = KRK_GROW_CAPACITY(old);
state->current->codeobject->localNames = GROW_ARRAY(KrkLocalEntry, state->current->codeobject->localNames, old, state->current->localNameCapacity); state->current->codeobject->localNames = KRK_GROW_ARRAY(KrkLocalEntry, state->current->codeobject->localNames, old, state->current->localNameCapacity);
} }
state->current->codeobject->localNames[state->current->codeobject->localNameCount].id = ind; state->current->codeobject->localNames[state->current->codeobject->localNameCount].id = ind;
state->current->codeobject->localNames[state->current->codeobject->localNameCount].birthday = currentChunk()->count; state->current->codeobject->localNames[state->current->codeobject->localNameCount].birthday = currentChunk()->count;
@ -727,8 +727,8 @@ static size_t renameLocal(struct GlobalState * state, size_t ind, KrkToken name)
static size_t addLocal(struct GlobalState * state, KrkToken name) { static size_t addLocal(struct GlobalState * state, KrkToken name) {
if (state->current->localCount + 1 > state->current->localsSpace) { if (state->current->localCount + 1 > state->current->localsSpace) {
size_t old = state->current->localsSpace; size_t old = state->current->localsSpace;
state->current->localsSpace = GROW_CAPACITY(old); state->current->localsSpace = KRK_GROW_CAPACITY(old);
state->current->locals = GROW_ARRAY(Local,state->current->locals,old,state->current->localsSpace); state->current->locals = KRK_GROW_ARRAY(Local,state->current->locals,old,state->current->localsSpace);
} }
size_t out = state->current->localCount; size_t out = state->current->localCount;
Local * local = &state->current->locals[state->current->localCount++]; Local * local = &state->current->locals[state->current->localCount++];
@ -1115,13 +1115,13 @@ static void attributeUnpack(struct GlobalState * state, int exprType) {
startEatingWhitespace(); startEatingWhitespace();
size_t argCount = 0; size_t argCount = 0;
size_t argSpace = 1; size_t argSpace = 1;
ssize_t * args = GROW_ARRAY(ssize_t,NULL,0,1); ssize_t * args = KRK_GROW_ARRAY(ssize_t,NULL,0,1);
do { do {
if (argSpace < argCount + 1) { if (argSpace < argCount + 1) {
size_t old = argSpace; size_t old = argSpace;
argSpace = GROW_CAPACITY(old); argSpace = KRK_GROW_CAPACITY(old);
args = GROW_ARRAY(ssize_t,args,old,argSpace); args = KRK_GROW_ARRAY(ssize_t,args,old,argSpace);
} }
consume(TOKEN_IDENTIFIER, "Expected attribute name"); consume(TOKEN_IDENTIFIER, "Expected attribute name");
size_t ind = identifierConstant(state, &state->parser.previous); size_t ind = identifierConstant(state, &state->parser.previous);
@ -1173,7 +1173,7 @@ static void attributeUnpack(struct GlobalState * state, int exprType) {
} }
_dotDone: _dotDone:
FREE_ARRAY(ssize_t,args,argSpace); KRK_FREE_ARRAY(ssize_t,args,argSpace);
return; return;
} }
@ -1253,13 +1253,13 @@ static void typeHintLocal(struct GlobalState * state) {
static void letDeclaration(struct GlobalState * state) { static void letDeclaration(struct GlobalState * state) {
size_t argCount = 0; size_t argCount = 0;
size_t argSpace = 1; size_t argSpace = 1;
ssize_t * args = GROW_ARRAY(ssize_t,NULL,0,1); ssize_t * args = KRK_GROW_ARRAY(ssize_t,NULL,0,1);
do { do {
if (argSpace < argCount + 1) { if (argSpace < argCount + 1) {
size_t old = argSpace; size_t old = argSpace;
argSpace = GROW_CAPACITY(old); argSpace = KRK_GROW_CAPACITY(old);
args = GROW_ARRAY(ssize_t,args,old,argSpace); args = KRK_GROW_ARRAY(ssize_t,args,old,argSpace);
} }
ssize_t ind = parseVariable(state, "Expected variable name."); ssize_t ind = parseVariable(state, "Expected variable name.");
if (state->parser.hadError) goto _letDone; if (state->parser.hadError) goto _letDone;
@ -1319,7 +1319,7 @@ static void letDeclaration(struct GlobalState * state) {
} }
_letDone: _letDone:
FREE_ARRAY(ssize_t,args,argSpace); KRK_FREE_ARRAY(ssize_t,args,argSpace);
return; return;
} }
@ -2142,8 +2142,8 @@ static void patchBreaks(struct GlobalState * state, int loopStart) {
static void breakStatement(struct GlobalState * state) { static void breakStatement(struct GlobalState * state) {
if (state->current->breakSpace < state->current->breakCount + 1) { if (state->current->breakSpace < state->current->breakCount + 1) {
size_t old = state->current->breakSpace; size_t old = state->current->breakSpace;
state->current->breakSpace = GROW_CAPACITY(old); state->current->breakSpace = KRK_GROW_CAPACITY(old);
state->current->breaks = GROW_ARRAY(struct LoopExit,state->current->breaks,old,state->current->breakSpace); state->current->breaks = KRK_GROW_ARRAY(struct LoopExit,state->current->breaks,old,state->current->breakSpace);
} }
if (state->current->loopLocalCount != state->current->localCount) { if (state->current->loopLocalCount != state->current->localCount) {
@ -2156,8 +2156,8 @@ static void breakStatement(struct GlobalState * state) {
static void continueStatement(struct GlobalState * state) { static void continueStatement(struct GlobalState * state) {
if (state->current->continueSpace < state->current->continueCount + 1) { if (state->current->continueSpace < state->current->continueCount + 1) {
size_t old = state->current->continueSpace; size_t old = state->current->continueSpace;
state->current->continueSpace = GROW_CAPACITY(old); state->current->continueSpace = KRK_GROW_CAPACITY(old);
state->current->continues = GROW_ARRAY(struct LoopExit,state->current->continues,old,state->current->continueSpace); state->current->continues = KRK_GROW_ARRAY(struct LoopExit,state->current->continues,old,state->current->continueSpace);
} }
if (state->current->loopLocalCount != state->current->localCount) { if (state->current->loopLocalCount != state->current->localCount) {
@ -3054,8 +3054,8 @@ static size_t addUpvalue(struct GlobalState * state, Compiler * compiler, ssize_
} }
if (upvalueCount + 1 > compiler->upvaluesSpace) { if (upvalueCount + 1 > compiler->upvaluesSpace) {
size_t old = compiler->upvaluesSpace; size_t old = compiler->upvaluesSpace;
compiler->upvaluesSpace = GROW_CAPACITY(old); compiler->upvaluesSpace = KRK_GROW_CAPACITY(old);
compiler->upvalues = GROW_ARRAY(Upvalue,compiler->upvalues,old,compiler->upvaluesSpace); compiler->upvalues = KRK_GROW_ARRAY(Upvalue,compiler->upvalues,old,compiler->upvaluesSpace);
} }
compiler->upvalues[upvalueCount].isLocal = isLocal; compiler->upvalues[upvalueCount].isLocal = isLocal;
compiler->upvalues[upvalueCount].index = index; compiler->upvalues[upvalueCount].index = index;

View File

@ -649,8 +649,8 @@ void krk_debug_addExpression(KrkCodeObject * codeobject, uint8_t start, uint8_t
if (codeobject->expressionsCapacity < codeobject->expressionsCount + 1) { if (codeobject->expressionsCapacity < codeobject->expressionsCount + 1) {
size_t old = codeobject->expressionsCapacity; size_t old = codeobject->expressionsCapacity;
codeobject->expressionsCapacity = GROW_CAPACITY(old); codeobject->expressionsCapacity = KRK_GROW_CAPACITY(old);
codeobject->expressions = GROW_ARRAY(KrkExpressionsMap, codeobject->expressions, old, codeobject->expressionsCapacity); codeobject->expressions = KRK_GROW_ARRAY(KrkExpressionsMap, codeobject->expressions, old, codeobject->expressionsCapacity);
} }
codeobject->expressions[codeobject->expressionsCount] = (KrkExpressionsMap){offset,start,midStart,midEnd,end}; codeobject->expressions[codeobject->expressionsCount] = (KrkExpressionsMap){offset,start,midStart,midEnd,end};

View File

@ -1016,7 +1016,7 @@ _finishArgs:
while (!exitRepl) { while (!exitRepl) {
size_t lineCapacity = 8; size_t lineCapacity = 8;
size_t lineCount = 0; size_t lineCount = 0;
char ** lines = ALLOCATE(char *, lineCapacity); char ** lines = KRK_ALLOCATE(char *, lineCapacity);
size_t totalData = 0; size_t totalData = 0;
int valid = 1; int valid = 1;
char * allData = NULL; char * allData = NULL;
@ -1102,8 +1102,8 @@ _finishArgs:
if (lineCapacity < lineCount + 1) { if (lineCapacity < lineCount + 1) {
/* If we need more space, grow as needed... */ /* If we need more space, grow as needed... */
size_t old = lineCapacity; size_t old = lineCapacity;
lineCapacity = GROW_CAPACITY(old); lineCapacity = KRK_GROW_CAPACITY(old);
lines = GROW_ARRAY(char *,lines,old,lineCapacity); lines = KRK_GROW_ARRAY(char *,lines,old,lineCapacity);
} }
int i = lineCount++; int i = lineCount++;
@ -1172,7 +1172,7 @@ _finishArgs:
#endif #endif
free(lines[i]); free(lines[i]);
} }
FREE_ARRAY(char *, lines, lineCapacity); KRK_FREE_ARRAY(char *, lines, lineCapacity);
if (valid) { if (valid) {
KrkValue result = krk_interpret(allData, "<stdin>"); KrkValue result = krk_interpret(allData, "<stdin>");

View File

@ -11,24 +11,24 @@
typedef int64_t krk_integer_type; typedef int64_t krk_integer_type;
#ifndef _WIN32 #ifndef _WIN32
# define PATH_SEP "/" # define KRK_PATH_SEP "/"
# ifndef KRK_STATIC_ONLY # ifndef KRK_STATIC_ONLY
# include <dlfcn.h> # include <dlfcn.h>
# define dlRefType void * # define krk_dlRefType void *
# define dlSymType void * # define krk_dlSymType void *
# define dlOpen(fileName) dlopen(fileName, RTLD_NOW) # define krk_dlOpen(fileName) dlopen(fileName, RTLD_NOW)
# define dlSym(dlRef, handlerName) dlsym(dlRef,handlerName) # define krk_dlSym(dlRef, handlerName) dlsym(dlRef,handlerName)
# define dlClose(dlRef) dlclose(dlRef) # define krk_dlClose(dlRef) dlclose(dlRef)
# endif # endif
#else #else
# include <windows.h> # include <windows.h>
# define PATH_SEP "\\" # define KRK_PATH_SEP "\\"
# ifndef KRK_STATIC_ONLY # ifndef KRK_STATIC_ONLY
# define dlRefType HINSTANCE # define krk_dlRefType HINSTANCE
# define dlSymType FARPROC # define krk_dlSymType FARPROC
# define dlOpen(fileName) LoadLibraryA(fileName) # define krk_dlOpen(fileName) LoadLibraryA(fileName)
# define dlSym(dlRef, handlerName) GetProcAddress(dlRef, handlerName) # define krk_dlSym(dlRef, handlerName) GetProcAddress(dlRef, handlerName)
# define dlClose(dlRef) # define krk_dlClose(dlRef)
# endif # endif
#endif #endif

View File

@ -7,13 +7,10 @@
#include "object.h" #include "object.h"
#include "table.h" #include "table.h"
#define GROW_CAPACITY(c) ((c) < 8 ? 8 : (c) * 2) #define KRK_GROW_CAPACITY(c) ((c) < 8 ? 8 : (c) * 2)
#define GROW_ARRAY(t,p,o,n) (t*)krk_reallocate(p,sizeof(t)*o,sizeof(t)*n) #define KRK_GROW_ARRAY(t,p,o,n) (t*)krk_reallocate(p,sizeof(t)*o,sizeof(t)*n)
#define KRK_FREE_ARRAY(t,a,c) krk_reallocate(a,sizeof(t) * c, 0)
#define FREE_ARRAY(t,a,c) krk_reallocate(a,sizeof(t) * c, 0) #define KRK_ALLOCATE(type, count) (type*)krk_reallocate(NULL,0,sizeof(type)*(count))
#define FREE(t,p) krk_reallocate(p,sizeof(t),0)
#define ALLOCATE(type, count) (type*)krk_reallocate(NULL,0,sizeof(type)*(count))
/** /**
* @brief Resize an allocated heap object. * @brief Resize an allocated heap object.

View File

@ -375,7 +375,7 @@ struct DictValues {
struct KrkModule { struct KrkModule {
KrkInstance inst; KrkInstance inst;
#ifndef KRK_STATIC_ONLY #ifndef KRK_STATIC_ONLY
dlRefType libHandle; krk_dlRefType libHandle;
#endif #endif
}; };

View File

@ -12,7 +12,6 @@
#include <stdlib.h> #include <stdlib.h>
#include "kuroko.h" #include "kuroko.h"
#include "value.h" #include "value.h"
#include "threads.h"
/** /**
* @brief One (key,value) pair in a table. * @brief One (key,value) pair in a table.

View File

@ -224,9 +224,9 @@ typedef struct KrkVM {
#define KRK_GLOBAL_NO_DEFAULT_MODULES (1 << 14) #define KRK_GLOBAL_NO_DEFAULT_MODULES (1 << 14)
#ifndef KRK_DISABLE_THREADS #ifndef KRK_DISABLE_THREADS
# define threadLocal __thread # define krk_threadLocal __thread
#else #else
# define threadLocal # define krk_threadLocal
#endif #endif
/** /**
@ -247,7 +247,7 @@ inline KrkThreadState * _macos_currentThread(void) {
#elif !defined(KRK_DISABLE_THREADS) && ((defined(_WIN32) && !defined(KRKINLIB)) || defined(KRK_MEDIOCRE_TLS)) #elif !defined(KRK_DISABLE_THREADS) && ((defined(_WIN32) && !defined(KRKINLIB)) || defined(KRK_MEDIOCRE_TLS))
#define krk_currentThread (*krk_getCurrentThread()) #define krk_currentThread (*krk_getCurrentThread())
#else #else
extern threadLocal KrkThreadState krk_currentThread; extern krk_threadLocal KrkThreadState krk_currentThread;
#endif #endif
/** /**

View File

@ -7,6 +7,8 @@
#include "private.h" #include "private.h"
#define FREE_OBJECT(t,p) krk_reallocate(p,sizeof(t),0)
#if defined(KRK_EXTENSIVE_MEMORY_DEBUGGING) #if defined(KRK_EXTENSIVE_MEMORY_DEBUGGING)
/** /**
* Extensive Memory Debugging * Extensive Memory Debugging
@ -18,7 +20,7 @@
* the sizes of objects by both using the appropriate macros and by * the sizes of objects by both using the appropriate macros and by
* ensuring the right sizes are passed to those macros. This is a very * ensuring the right sizes are passed to those macros. This is a very
* easy thing to get wrong - allocate with @c malloc but free with the * easy thing to get wrong - allocate with @c malloc but free with the
* @c FREE_ARRAY macros, for example, and the memory tracking now has * @c KRK_FREE_ARRAY macros, for example, and the memory tracking now has
* a net negative, which may lead to underflowing. Use the right macros, * a net negative, which may lead to underflowing. Use the right macros,
* but mix up sizes between allocation and deallocation, and we may have * but mix up sizes between allocation and deallocation, and we may have
* a "leak" of bytes and garbage collection may happen more often than * a "leak" of bytes and garbage collection may happen more often than
@ -202,9 +204,9 @@ static void freeObject(KrkObj * object) {
switch (object->type) { switch (object->type) {
case KRK_OBJ_STRING: { case KRK_OBJ_STRING: {
KrkString * string = (KrkString*)object; KrkString * string = (KrkString*)object;
FREE_ARRAY(char, string->chars, string->length + 1); KRK_FREE_ARRAY(char, string->chars, string->length + 1);
if (string->codes && string->codes != string->chars) free(string->codes); if (string->codes && string->codes != string->chars) free(string->codes);
FREE(KrkString, object); FREE_OBJECT(KrkString, object);
break; break;
} }
case KRK_OBJ_CODEOBJECT: { case KRK_OBJ_CODEOBJECT: {
@ -212,25 +214,25 @@ static void freeObject(KrkObj * object) {
krk_freeChunk(&function->chunk); krk_freeChunk(&function->chunk);
krk_freeValueArray(&function->positionalArgNames); krk_freeValueArray(&function->positionalArgNames);
krk_freeValueArray(&function->keywordArgNames); krk_freeValueArray(&function->keywordArgNames);
FREE_ARRAY(KrkLocalEntry, function->localNames, function->localNameCount); KRK_FREE_ARRAY(KrkLocalEntry, function->localNames, function->localNameCount);
FREE_ARRAY(KrkExpressionsMap, function->expressions, function->expressionsCapacity); KRK_FREE_ARRAY(KrkExpressionsMap, function->expressions, function->expressionsCapacity);
function->localNameCount = 0; function->localNameCount = 0;
FREE(KrkCodeObject, object); FREE_OBJECT(KrkCodeObject, object);
break; break;
} }
case KRK_OBJ_NATIVE: { case KRK_OBJ_NATIVE: {
FREE(KrkNative, object); FREE_OBJECT(KrkNative, object);
break; break;
} }
case KRK_OBJ_CLOSURE: { case KRK_OBJ_CLOSURE: {
KrkClosure * closure = (KrkClosure*)object; KrkClosure * closure = (KrkClosure*)object;
FREE_ARRAY(KrkUpvalue*,closure->upvalues,closure->upvalueCount); KRK_FREE_ARRAY(KrkUpvalue*,closure->upvalues,closure->upvalueCount);
krk_freeTable(&closure->fields); krk_freeTable(&closure->fields);
FREE(KrkClosure, object); FREE_OBJECT(KrkClosure, object);
break; break;
} }
case KRK_OBJ_UPVALUE: { case KRK_OBJ_UPVALUE: {
FREE(KrkUpvalue, object); FREE_OBJECT(KrkUpvalue, object);
break; break;
} }
case KRK_OBJ_CLASS: { case KRK_OBJ_CLASS: {
@ -240,7 +242,7 @@ static void freeObject(KrkObj * object) {
if (_class->base) { if (_class->base) {
krk_tableDeleteExact(&_class->base->subclasses, OBJECT_VAL(object)); krk_tableDeleteExact(&_class->base->subclasses, OBJECT_VAL(object));
} }
FREE(KrkClass, object); FREE_OBJECT(KrkClass, object);
break; break;
} }
case KRK_OBJ_INSTANCE: { case KRK_OBJ_INSTANCE: {
@ -253,18 +255,18 @@ static void freeObject(KrkObj * object) {
break; break;
} }
case KRK_OBJ_BOUND_METHOD: case KRK_OBJ_BOUND_METHOD:
FREE(KrkBoundMethod, object); FREE_OBJECT(KrkBoundMethod, object);
break; break;
case KRK_OBJ_TUPLE: { case KRK_OBJ_TUPLE: {
KrkTuple * tuple = (KrkTuple*)object; KrkTuple * tuple = (KrkTuple*)object;
krk_freeValueArray(&tuple->values); krk_freeValueArray(&tuple->values);
FREE(KrkTuple, object); FREE_OBJECT(KrkTuple, object);
break; break;
} }
case KRK_OBJ_BYTES: { case KRK_OBJ_BYTES: {
KrkBytes * bytes = (KrkBytes*)object; KrkBytes * bytes = (KrkBytes*)object;
FREE_ARRAY(uint8_t, bytes->bytes, bytes->length); KRK_FREE_ARRAY(uint8_t, bytes->bytes, bytes->length);
FREE(KrkBytes, bytes); FREE_OBJECT(KrkBytes, bytes);
break; break;
} }
} }
@ -320,7 +322,7 @@ void krk_markObject(KrkObj * object) {
object->flags |= KRK_OBJ_FLAGS_IS_MARKED; object->flags |= KRK_OBJ_FLAGS_IS_MARKED;
if (vm.grayCapacity < vm.grayCount + 1) { if (vm.grayCapacity < vm.grayCount + 1) {
vm.grayCapacity = GROW_CAPACITY(vm.grayCapacity); vm.grayCapacity = KRK_GROW_CAPACITY(vm.grayCapacity);
vm.grayStack = realloc(vm.grayStack, sizeof(KrkObj*) * vm.grayCapacity); vm.grayStack = realloc(vm.grayStack, sizeof(KrkObj*) * vm.grayCapacity);
if (!vm.grayStack) exit(1); if (!vm.grayStack) exit(1);
} }

View File

@ -34,7 +34,7 @@ KrkValue krk_list_of(int argc, const KrkValue argv[], int hasKw) {
if (argc) { if (argc) {
AS_LIST(outList)->capacity = argc; AS_LIST(outList)->capacity = argc;
AS_LIST(outList)->values = GROW_ARRAY(KrkValue, AS_LIST(outList)->values, 0, argc); AS_LIST(outList)->values = KRK_GROW_ARRAY(KrkValue, AS_LIST(outList)->values, 0, argc);
memcpy(AS_LIST(outList)->values, argv, sizeof(KrkValue) * argc); memcpy(AS_LIST(outList)->values, argv, sizeof(KrkValue) * argc);
AS_LIST(outList)->count = argc; AS_LIST(outList)->count = argc;
} }
@ -162,8 +162,8 @@ static int _list_extend_callback(void * context, const KrkValue * values, size_t
KrkValueArray * positionals = context; KrkValueArray * positionals = context;
if (positionals->count + count > positionals->capacity) { if (positionals->count + count > positionals->capacity) {
size_t old = positionals->capacity; size_t old = positionals->capacity;
positionals->capacity = (count == 1) ? GROW_CAPACITY(old) : (positionals->count + count); positionals->capacity = (count == 1) ? KRK_GROW_CAPACITY(old) : (positionals->count + count);
positionals->values = GROW_ARRAY(KrkValue, positionals->values, old, positionals->capacity); positionals->values = KRK_GROW_ARRAY(KrkValue, positionals->values, old, positionals->capacity);
} }
for (size_t i = 0; i < count; ++i) { for (size_t i = 0; i < count; ++i) {

View File

@ -56,7 +56,7 @@ KRK_Method(str,__add__) {
bl = them->length; bl = them->length;
size_t length = al + bl; size_t length = al + bl;
char * chars = ALLOCATE(char, length + 1); char * chars = KRK_ALLOCATE(char, length + 1);
memcpy(chars, a, al); memcpy(chars, a, al);
memcpy(chars + al, b, bl); memcpy(chars + al, b, bl);
chars[length] = '\0'; chars[length] = '\0';
@ -1080,8 +1080,8 @@ _corrupt:
void krk_pushStringBuilder(struct StringBuilder * sb, char c) { void krk_pushStringBuilder(struct StringBuilder * sb, char c) {
if (sb->capacity < sb->length + 1) { if (sb->capacity < sb->length + 1) {
size_t old = sb->capacity; size_t old = sb->capacity;
sb->capacity = GROW_CAPACITY(old); sb->capacity = KRK_GROW_CAPACITY(old);
sb->bytes = GROW_ARRAY(char, sb->bytes, old, sb->capacity); sb->bytes = KRK_GROW_ARRAY(char, sb->bytes, old, sb->capacity);
} }
sb->bytes[sb->length++] = c; sb->bytes[sb->length++] = c;
} }
@ -1091,9 +1091,9 @@ void krk_pushStringBuilderStr(struct StringBuilder * sb, const char *str, size_t
size_t prevcap = sb->capacity; size_t prevcap = sb->capacity;
while (sb->capacity < sb->length + len) { while (sb->capacity < sb->length + len) {
size_t old = sb->capacity; size_t old = sb->capacity;
sb->capacity = GROW_CAPACITY(old); sb->capacity = KRK_GROW_CAPACITY(old);
} }
sb->bytes = GROW_ARRAY(char, sb->bytes, prevcap, sb->capacity); sb->bytes = KRK_GROW_ARRAY(char, sb->bytes, prevcap, sb->capacity);
} }
for (size_t i = 0; i < len; ++i) { for (size_t i = 0; i < len; ++i) {
sb->bytes[sb->length++] = *(str++); sb->bytes[sb->length++] = *(str++);
@ -1101,7 +1101,7 @@ void krk_pushStringBuilderStr(struct StringBuilder * sb, const char *str, size_t
} }
static void _freeStringBuilder(struct StringBuilder * sb) { static void _freeStringBuilder(struct StringBuilder * sb) {
FREE_ARRAY(char,sb->bytes, sb->capacity); KRK_FREE_ARRAY(char,sb->bytes, sb->capacity);
sb->bytes = NULL; sb->bytes = NULL;
sb->length = 0; sb->length = 0;
sb->capacity = 0; sb->capacity = 0;

View File

@ -13,8 +13,8 @@ static int _tuple_init_callback(void * context, const KrkValue * values, size_t
KrkValueArray * positionals = context; KrkValueArray * positionals = context;
if (positionals->count + count > positionals->capacity) { if (positionals->count + count > positionals->capacity) {
size_t old = positionals->capacity; size_t old = positionals->capacity;
positionals->capacity = (count == 1) ? GROW_CAPACITY(old) : (positionals->count + count); positionals->capacity = (count == 1) ? KRK_GROW_CAPACITY(old) : (positionals->count + count);
positionals->values = GROW_ARRAY(KrkValue, positionals->values, old, positionals->capacity); positionals->values = KRK_GROW_ARRAY(KrkValue, positionals->values, old, positionals->capacity);
} }
for (size_t i = 0; i < count; ++i) { for (size_t i = 0; i < count; ++i) {

View File

@ -7,6 +7,7 @@
#include <kuroko/value.h> #include <kuroko/value.h>
#include <kuroko/vm.h> #include <kuroko/vm.h>
#include <kuroko/table.h> #include <kuroko/table.h>
#include <kuroko/threads.h>
#include "private.h" #include "private.h"
@ -207,7 +208,7 @@ KrkString * krk_takeString(char * chars, size_t length) {
_obtain_lock(_stringLock); _obtain_lock(_stringLock);
KrkString * interned = krk_tableFindString(&vm.strings, chars, length, hash); KrkString * interned = krk_tableFindString(&vm.strings, chars, length, hash);
if (interned != NULL) { if (interned != NULL) {
free(chars); /* This string isn't owned by us yet, so free, not FREE_ARRAY */ free(chars); /* This string isn't owned by us yet, so free, not KRK_FREE_ARRAY */
_release_lock(_stringLock); _release_lock(_stringLock);
return interned; return interned;
} }
@ -226,7 +227,7 @@ KrkString * krk_copyString(const char * chars, size_t length) {
_release_lock(_stringLock); _release_lock(_stringLock);
return interned; return interned;
} }
char * heapChars = ALLOCATE(char, length + 1); char * heapChars = KRK_ALLOCATE(char, length + 1);
memcpy(heapChars, chars ? chars : "", length); memcpy(heapChars, chars ? chars : "", length);
heapChars[length] = '\0'; heapChars[length] = '\0';
KrkString * result = allocateString(heapChars, length, hash); KrkString * result = allocateString(heapChars, length, hash);
@ -239,7 +240,7 @@ KrkString * krk_takeStringVetted(char * chars, size_t length, size_t codesLength
_obtain_lock(_stringLock); _obtain_lock(_stringLock);
KrkString * interned = krk_tableFindString(&vm.strings, chars, length, hash); KrkString * interned = krk_tableFindString(&vm.strings, chars, length, hash);
if (interned != NULL) { if (interned != NULL) {
FREE_ARRAY(char, chars, length + 1); KRK_FREE_ARRAY(char, chars, length + 1);
_release_lock(_stringLock); _release_lock(_stringLock);
return interned; return interned;
} }
@ -284,7 +285,7 @@ KrkNative * krk_newNative(NativeFn function, const char * name, int type) {
} }
KrkClosure * krk_newClosure(KrkCodeObject * function, KrkValue globals) { KrkClosure * krk_newClosure(KrkCodeObject * function, KrkValue globals) {
KrkUpvalue ** upvalues = ALLOCATE(KrkUpvalue*, function->upvalueCount); KrkUpvalue ** upvalues = KRK_ALLOCATE(KrkUpvalue*, function->upvalueCount);
for (size_t i = 0; i < function->upvalueCount; ++i) { for (size_t i = 0; i < function->upvalueCount; ++i) {
upvalues[i] = NULL; upvalues[i] = NULL;
} }
@ -355,7 +356,7 @@ KrkTuple * krk_newTuple(size_t length) {
krk_initValueArray(&tuple->values); krk_initValueArray(&tuple->values);
krk_push(OBJECT_VAL(tuple)); krk_push(OBJECT_VAL(tuple));
tuple->values.capacity = length; tuple->values.capacity = length;
tuple->values.values = GROW_ARRAY(KrkValue,NULL,0,length); tuple->values.values = KRK_GROW_ARRAY(KrkValue,NULL,0,length);
krk_pop(); krk_pop();
return tuple; return tuple;
} }
@ -365,7 +366,7 @@ KrkBytes * krk_newBytes(size_t length, uint8_t * source) {
bytes->length = length; bytes->length = length;
bytes->bytes = NULL; bytes->bytes = NULL;
krk_push(OBJECT_VAL(bytes)); krk_push(OBJECT_VAL(bytes));
bytes->bytes = ALLOCATE(uint8_t, length); bytes->bytes = KRK_ALLOCATE(uint8_t, length);
bytes->obj.hash = -1; bytes->obj.hash = -1;
if (source) { if (source) {
memcpy(bytes->bytes, source, length); memcpy(bytes->bytes, source, length);

View File

@ -272,7 +272,7 @@ void krk_module_init_kuroko(void) {
KRK_DOC(BIND_FUNC(vm.system,get_recursion_depth), KRK_DOC(BIND_FUNC(vm.system,get_recursion_depth),
"Examine the maximum recursion depth of the current thread."); "Examine the maximum recursion depth of the current thread.");
krk_attachNamedObject(&vm.system->fields, "module", (KrkObj*)vm.baseClasses->moduleClass); krk_attachNamedObject(&vm.system->fields, "module", (KrkObj*)vm.baseClasses->moduleClass);
krk_attachNamedObject(&vm.system->fields, "path_sep", (KrkObj*)S(PATH_SEP)); krk_attachNamedObject(&vm.system->fields, "path_sep", (KrkObj*)S(KRK_PATH_SEP));
KrkValue module_paths = krk_list_of(0,NULL,0); KrkValue module_paths = krk_list_of(0,NULL,0);
krk_attachNamedValue(&vm.system->fields, "module_paths", module_paths); krk_attachNamedValue(&vm.system->fields, "module_paths", module_paths);
krk_writeValueArray(AS_LIST(module_paths), OBJECT_VAL(S("./"))); krk_writeValueArray(AS_LIST(module_paths), OBJECT_VAL(S("./")));

View File

@ -18,7 +18,7 @@ void krk_initTable(KrkTable * table) {
} }
void krk_freeTable(KrkTable * table) { void krk_freeTable(KrkTable * table) {
FREE_ARRAY(KrkTableEntry, table->entries, table->capacity); KRK_FREE_ARRAY(KrkTableEntry, table->entries, table->capacity);
krk_initTable(table); krk_initTable(table);
} }
@ -121,7 +121,7 @@ void krk_tableAdjustCapacity(KrkTable * table, size_t capacity) {
capacity = (1UL << powerOfTwoCapacity); capacity = (1UL << powerOfTwoCapacity);
} }
KrkTableEntry * entries = ALLOCATE(KrkTableEntry, capacity); KrkTableEntry * entries = KRK_ALLOCATE(KrkTableEntry, capacity);
for (size_t i = 0; i < capacity; ++i) { for (size_t i = 0; i < capacity; ++i) {
entries[i].key = KWARGS_VAL(0); entries[i].key = KWARGS_VAL(0);
entries[i].value = KWARGS_VAL(0); entries[i].value = KWARGS_VAL(0);
@ -137,14 +137,14 @@ void krk_tableAdjustCapacity(KrkTable * table, size_t capacity) {
table->count++; table->count++;
} }
FREE_ARRAY(KrkTableEntry, table->entries, table->capacity); KRK_FREE_ARRAY(KrkTableEntry, table->entries, table->capacity);
table->entries = entries; table->entries = entries;
table->capacity = capacity; table->capacity = capacity;
} }
int krk_tableSet(KrkTable * table, KrkValue key, KrkValue value) { int krk_tableSet(KrkTable * table, KrkValue key, KrkValue value) {
if (table->count + 1 > table->capacity * TABLE_MAX_LOAD) { if (table->count + 1 > table->capacity * TABLE_MAX_LOAD) {
size_t capacity = GROW_CAPACITY(table->capacity); size_t capacity = KRK_GROW_CAPACITY(table->capacity);
krk_tableAdjustCapacity(table, capacity); krk_tableAdjustCapacity(table, capacity);
} }
KrkTableEntry * entry = krk_findEntry(table->entries, table->capacity, key); KrkTableEntry * entry = krk_findEntry(table->entries, table->capacity, key);

View File

@ -4,6 +4,7 @@
#ifndef KRK_DISABLE_THREADS #ifndef KRK_DISABLE_THREADS
#include <kuroko/util.h> #include <kuroko/util.h>
#include <kuroko/threads.h>
#include <unistd.h> #include <unistd.h>
#include <pthread.h> #include <pthread.h>
@ -106,7 +107,7 @@ static void * _startthread(void * _threadObj) {
} }
_release_lock(_threadLock); _release_lock(_threadLock);
FREE_ARRAY(size_t, krk_currentThread.stack, krk_currentThread.stackSize); KRK_FREE_ARRAY(size_t, krk_currentThread.stack, krk_currentThread.stackSize);
free(krk_currentThread.frames); free(krk_currentThread.frames);
return NULL; return NULL;

View File

@ -17,8 +17,8 @@ void krk_initValueArray(KrkValueArray * array) {
void krk_writeValueArray(KrkValueArray * array, KrkValue value) { void krk_writeValueArray(KrkValueArray * array, KrkValue value) {
if (array->capacity < array->count + 1) { if (array->capacity < array->count + 1) {
int old = array->capacity; int old = array->capacity;
array->capacity = GROW_CAPACITY(old); array->capacity = KRK_GROW_CAPACITY(old);
array->values = GROW_ARRAY(KrkValue, array->values, old, array->capacity); array->values = KRK_GROW_ARRAY(KrkValue, array->values, old, array->capacity);
} }
array->values[array->count] = value; array->values[array->count] = value;
@ -26,7 +26,7 @@ void krk_writeValueArray(KrkValueArray * array, KrkValue value) {
} }
void krk_freeValueArray(KrkValueArray * array) { void krk_freeValueArray(KrkValueArray * array) {
FREE_ARRAY(KrkValue, array->values, array->capacity); KRK_FREE_ARRAY(KrkValue, array->values, array->capacity);
krk_initValueArray(array); krk_initValueArray(array);
} }

View File

@ -133,14 +133,14 @@ void krk_resetStack(void) {
void krk_growStack(void) { void krk_growStack(void) {
size_t old = krk_currentThread.stackSize; size_t old = krk_currentThread.stackSize;
size_t old_offset = krk_currentThread.stackTop - krk_currentThread.stack; size_t old_offset = krk_currentThread.stackTop - krk_currentThread.stack;
size_t newsize = GROW_CAPACITY(old); size_t newsize = KRK_GROW_CAPACITY(old);
if (krk_currentThread.flags & KRK_THREAD_DEFER_STACK_FREE) { if (krk_currentThread.flags & KRK_THREAD_DEFER_STACK_FREE) {
KrkValue * newStack = GROW_ARRAY(KrkValue, NULL, 0, newsize); KrkValue * newStack = KRK_GROW_ARRAY(KrkValue, NULL, 0, newsize);
memcpy(newStack, krk_currentThread.stack, sizeof(KrkValue) * old); memcpy(newStack, krk_currentThread.stack, sizeof(KrkValue) * old);
krk_currentThread.stack = newStack; krk_currentThread.stack = newStack;
krk_currentThread.flags &= ~(KRK_THREAD_DEFER_STACK_FREE); krk_currentThread.flags &= ~(KRK_THREAD_DEFER_STACK_FREE);
} else { } else {
krk_currentThread.stack = GROW_ARRAY(KrkValue, krk_currentThread.stack, old, newsize); krk_currentThread.stack = KRK_GROW_ARRAY(KrkValue, krk_currentThread.stack, old, newsize);
} }
krk_currentThread.stackSize = newsize; krk_currentThread.stackSize = newsize;
krk_currentThread.stackTop = krk_currentThread.stack + old_offset; krk_currentThread.stackTop = krk_currentThread.stack + old_offset;
@ -368,8 +368,8 @@ static int _unpack_args(void * context, const KrkValue * values, size_t count) {
KrkValueArray * positionals = context; KrkValueArray * positionals = context;
if (positionals->count + count > positionals->capacity) { if (positionals->count + count > positionals->capacity) {
size_t old = positionals->capacity; size_t old = positionals->capacity;
positionals->capacity = (count == 1) ? GROW_CAPACITY(old) : (positionals->count + count); positionals->capacity = (count == 1) ? KRK_GROW_CAPACITY(old) : (positionals->count + count);
positionals->values = GROW_ARRAY(KrkValue, positionals->values, old, positionals->capacity); positionals->values = KRK_GROW_ARRAY(KrkValue, positionals->values, old, positionals->capacity);
} }
for (size_t i = 0; i < count; ++i) { for (size_t i = 0; i < count; ++i) {
@ -654,7 +654,7 @@ inline KrkValue krk_callNativeOnStack(size_t argCount, const KrkValue *stackArgs
KrkValue result = native(argCount, stackArgs, hasKw); KrkValue result = native(argCount, stackArgs, hasKw);
if (unlikely(krk_currentThread.stack != stackBefore)) { if (unlikely(krk_currentThread.stack != stackBefore)) {
FREE_ARRAY(KrkValue, stackBefore, sizeBefore); KRK_FREE_ARRAY(KrkValue, stackBefore, sizeBefore);
} }
krk_currentThread.flags &= ~(KRK_THREAD_DEFER_STACK_FREE); krk_currentThread.flags &= ~(KRK_THREAD_DEFER_STACK_FREE);
@ -1004,11 +1004,11 @@ void krk_freeVM(void) {
while (krk_currentThread.next) { while (krk_currentThread.next) {
KrkThreadState * thread = krk_currentThread.next; KrkThreadState * thread = krk_currentThread.next;
krk_currentThread.next = thread->next; krk_currentThread.next = thread->next;
FREE_ARRAY(size_t, thread->stack, thread->stackSize); KRK_FREE_ARRAY(size_t, thread->stack, thread->stackSize);
free(thread->frames); free(thread->frames);
} }
FREE_ARRAY(size_t, krk_currentThread.stack, krk_currentThread.stackSize); KRK_FREE_ARRAY(size_t, krk_currentThread.stack, krk_currentThread.stackSize);
memset(&krk_vm,0,sizeof(krk_vm)); memset(&krk_vm,0,sizeof(krk_vm));
free(krk_currentThread.frames); free(krk_currentThread.frames);
memset(&krk_currentThread,0,sizeof(KrkThreadState)); memset(&krk_currentThread,0,sizeof(KrkThreadState));
@ -1233,7 +1233,7 @@ int krk_loadModule(KrkString * path, KrkValue * moduleOut, KrkString * runAs, Kr
/* Try .../path/__init__.krk */ /* Try .../path/__init__.krk */
krk_push(OBJECT_VAL(path)); krk_push(OBJECT_VAL(path));
krk_addObjects(); krk_addObjects();
krk_push(OBJECT_VAL(S(PATH_SEP "__init__.krk"))); krk_push(OBJECT_VAL(S(KRK_PATH_SEP "__init__.krk")));
krk_addObjects(); krk_addObjects();
fileName = AS_CSTRING(krk_peek(0)); fileName = AS_CSTRING(krk_peek(0));
if (stat(fileName,&statbuf) == 0) { if (stat(fileName,&statbuf) == 0) {
@ -1243,7 +1243,7 @@ int krk_loadModule(KrkString * path, KrkValue * moduleOut, KrkString * runAs, Kr
/* Convert back to .-formatted */ /* Convert back to .-formatted */
krk_push(krk_valueGetAttribute(OBJECT_VAL(path), "replace")); krk_push(krk_valueGetAttribute(OBJECT_VAL(path), "replace"));
krk_push(OBJECT_VAL(S(PATH_SEP))); krk_push(OBJECT_VAL(S(KRK_PATH_SEP)));
krk_push(OBJECT_VAL(S("."))); krk_push(OBJECT_VAL(S(".")));
krk_push(krk_callStack(2)); krk_push(krk_callStack(2));
KrkValue packageName = krk_peek(0); KrkValue packageName = krk_peek(0);
@ -1337,7 +1337,7 @@ int krk_loadModule(KrkString * path, KrkValue * moduleOut, KrkString * runAs, Kr
#ifndef KRK_STATIC_ONLY #ifndef KRK_STATIC_ONLY
_sharedObject: (void)0; _sharedObject: (void)0;
dlRefType dlRef = dlOpen(fileName); krk_dlRefType dlRef = krk_dlOpen(fileName);
if (!dlRef) { if (!dlRef) {
*moduleOut = NONE_VAL(); *moduleOut = NONE_VAL();
krk_runtimeError(vm.exceptions->importError, krk_runtimeError(vm.exceptions->importError,
@ -1357,11 +1357,11 @@ int krk_loadModule(KrkString * path, KrkValue * moduleOut, KrkString * runAs, Kr
char * handlerName = AS_CSTRING(krk_peek(0)); char * handlerName = AS_CSTRING(krk_peek(0));
KrkValue (*moduleOnLoad)(KrkString * name); KrkValue (*moduleOnLoad)(KrkString * name);
dlSymType out = dlSym(dlRef, handlerName); krk_dlSymType out = krk_dlSym(dlRef, handlerName);
memcpy(&moduleOnLoad,&out,sizeof(out)); memcpy(&moduleOnLoad,&out,sizeof(out));
if (!moduleOnLoad) { if (!moduleOnLoad) {
dlClose(dlRef); krk_dlClose(dlRef);
*moduleOut = NONE_VAL(); *moduleOut = NONE_VAL();
krk_runtimeError(vm.exceptions->importError, krk_runtimeError(vm.exceptions->importError,
"Failed to run module initialization method '%s' from shared object '%s'", "Failed to run module initialization method '%s' from shared object '%s'",
@ -1373,7 +1373,7 @@ int krk_loadModule(KrkString * path, KrkValue * moduleOut, KrkString * runAs, Kr
*moduleOut = moduleOnLoad(runAs); *moduleOut = moduleOnLoad(runAs);
if (!krk_isInstanceOf(*moduleOut, vm.baseClasses->moduleClass)) { if (!krk_isInstanceOf(*moduleOut, vm.baseClasses->moduleClass)) {
dlClose(dlRef); krk_dlClose(dlRef);
krk_runtimeError(vm.exceptions->importError, krk_runtimeError(vm.exceptions->importError,
"Failed to load module '%S' from '%s'", runAs, fileName); "Failed to load module '%S' from '%s'", runAs, fileName);
return 0; return 0;
@ -1403,7 +1403,7 @@ int krk_loadModule(KrkString * path, KrkValue * moduleOut, KrkString * runAs, Kr
if (runAs == S("__main__")) { if (runAs == S("__main__")) {
/* Then let's use 'path' instead, and replace all the /'s with .'s... */ /* Then let's use 'path' instead, and replace all the /'s with .'s... */
krk_push(krk_valueGetAttribute(OBJECT_VAL(path), "replace")); krk_push(krk_valueGetAttribute(OBJECT_VAL(path), "replace"));
krk_push(OBJECT_VAL(S(PATH_SEP))); krk_push(OBJECT_VAL(S(KRK_PATH_SEP)));
krk_push(OBJECT_VAL(S("."))); krk_push(OBJECT_VAL(S(".")));
krk_push(krk_callStack(2)); krk_push(krk_callStack(2));
} else { } else {
@ -1597,7 +1597,7 @@ int krk_importModule(KrkString * name, KrkString * runAs) {
krk_currentThread.stack[argBase-1] = krk_pop(); krk_currentThread.stack[argBase-1] = krk_pop();
/* Now concatenate forward slash... */ /* Now concatenate forward slash... */
krk_push(krk_currentThread.stack[argBase+1]); /* Slash path */ krk_push(krk_currentThread.stack[argBase+1]); /* Slash path */
krk_push(OBJECT_VAL(S(PATH_SEP))); krk_push(OBJECT_VAL(S(KRK_PATH_SEP)));
krk_addObjects(); krk_addObjects();
krk_currentThread.stack[argBase+1] = krk_pop(); krk_currentThread.stack[argBase+1] = krk_pop();
/* And now for the dot... */ /* And now for the dot... */

View File

@ -15,7 +15,7 @@ static int runSimpleRepl(void) {
while (!exitRepl) { while (!exitRepl) {
size_t lineCapacity = 8; size_t lineCapacity = 8;
size_t lineCount = 0; size_t lineCount = 0;
char ** lines = ALLOCATE(char *, lineCapacity); char ** lines = KRK_ALLOCATE(char *, lineCapacity);
size_t totalData = 0; size_t totalData = 0;
int valid = 1; int valid = 1;
char * allData = NULL; char * allData = NULL;
@ -80,8 +80,8 @@ static int runSimpleRepl(void) {
if (lineCapacity < lineCount + 1) { if (lineCapacity < lineCount + 1) {
/* If we need more space, grow as needed... */ /* If we need more space, grow as needed... */
size_t old = lineCapacity; size_t old = lineCapacity;
lineCapacity = GROW_CAPACITY(old); lineCapacity = KRK_GROW_CAPACITY(old);
lines = GROW_ARRAY(char *,lines,old,lineCapacity); lines = KRK_GROW_ARRAY(char *,lines,old,lineCapacity);
} }
int i = lineCount++; int i = lineCount++;
@ -149,7 +149,7 @@ static int runSimpleRepl(void) {
#endif #endif
free(lines[i]); free(lines[i]);
} }
FREE_ARRAY(char *, lines, lineCapacity); KRK_FREE_ARRAY(char *, lines, lineCapacity);
if (valid) { if (valid) {
KrkValue result = krk_interpret(allData, "<stdin>"); KrkValue result = krk_interpret(allData, "<stdin>");
if (!IS_NONE(result)) { if (!IS_NONE(result)) {