diff --git a/bin/environment.c b/bin/environment.c index f1aec03c..0ea844be 100644 --- a/bin/environment.c +++ b/bin/environment.c @@ -8,6 +8,12 @@ #include #endif +#if (defined(__MSYS__)) || (defined(__MINGW32__)) || (defined(_WIN32)) +#include +#else +extern char **environ; +#endif + /* Add environment key/value pair to tree T */ static void addVar(const char *e, lMap *t){ int endOfKey, endOfString; @@ -18,31 +24,26 @@ static void addVar(const char *e, lMap *t){ lMapSet(t, lValKeywordS(sym), v); } -#if (defined(__MSYS__)) || (defined(__MINGW32__)) || (defined(_WIN32)) -#include - -/* Windows specific - add Environment args to `environment/variables` */ +/* Add Environment args to `environment/variables` */ void lRedefineEnvironment(lClosure *c){ - lTree *t = NULL; + lMap *t = lMapAllocRaw(); + + #if (defined(__MSYS__)) || (defined(__MINGW32__)) || (defined(_WIN32)) + /* Windows */ LPCH env = GetEnvironmentStrings(); while(*env){ addVar(env,t); while(*env++){} } - lDefineClosureSym(c,lSymS("System/Environment"), lValMap(t)); -} - -#else -extern char **environ; -/* Add Environment args to `environment/variables` */ -void lRedefineEnvironment(lClosure *c){ - lMap *t = lMapAllocRaw(); - #ifdef __wasi__ + #elif defined(__wasi__) + /* Wasm */ addVar("PATH=",t); // Necessary so that tests don't fail - #endif + #else + /* Most other system, mainly *nix Systems */ for(int i=0;environ[i];i++){ addVar(environ[i], t); } + #endif + lDefineClosureSym(c,lSymS("System/Environment"), lValMap(t)); } -#endif diff --git a/lib/imageReader.c b/lib/imageReader.c index 57c8a933..9738a657 100644 --- a/lib/imageReader.c +++ b/lib/imageReader.c @@ -18,24 +18,20 @@ static lVal readVal(readImageMap *map, const lImage *img, i32 off, bool staticIm static void *readMapGet(readImageMap *map, i32 key){ lVal v = lMapRef(map->map, lValInt(key)); if(v.type == ltInt){ - return (void *)v.vInt; + return (void *)(intptr_t)v.vInt; } else { return NULL; } } static void readMapSet(readImageMap *map, i32 key, void *val){ - lMapSet(map->map, lValInt(key), lValInt((u64)val)); + lMapSet(map->map, lValInt(key), lValInt((intptr_t)val)); } -static inline i32 readI8(const lImage *img, i32 off){ +static i32 readI8(const lImage *img, i32 off){ return img->data[off ]; } -static inline i32 readI16(const lImage *img, i32 off){ - return img->data[off ] | (img->data[off+1]<<8); -} - static i32 readI24(const lImage *img, i32 off){ return img->data[off ] | (img->data[off+1]<<8) | (img->data[off+2]<<16); }