3 funcs needed for some mwcc compilers (#22)

* 3 funcs needed for some mwcc compilers

* some PR feedback

* lots more via pair programming with Simon

* cleanup, add test dir as an include dir for tests

* bugfix
This commit is contained in:
Ethan Roseman
2022-09-24 23:59:30 +09:00
committed by GitHub
parent ffe30a626b
commit 6de4e9a163
8 changed files with 210 additions and 43 deletions

View File

@@ -1,9 +1,10 @@
#include "common.h"
#include "files.h"
#include "handles.h"
#include <algorithm>
#include <map>
namespace files {
static FILE *handleFps[0x10000];
static void *stdinHandle;
static void *stdoutHandle;
@@ -68,28 +69,19 @@ namespace files {
}
FILE *fpFromHandle(void *handle, bool pop) {
uintptr_t index = (uintptr_t)handle;
if (index > 0 && index < 0x10000) {
FILE *ret = handleFps[index];
if (pop)
handleFps[index] = 0;
return ret;
}
if (pop)
handles::Data data = handles::dataFromHandle(handle, pop);
if (data.type == handles::TYPE_FILE) {
return (FILE*)data.ptr;
} else if (data.type == handles::TYPE_UNUSED && pop) {
return 0;
printf("Invalid file handle %p\n", handle);
assert(0);
} else {
printf("Invalid file handle %p\n", handle);
assert(0);
}
}
void *allocFpHandle(FILE *fp) {
for (int i = 1; i < 0x10000; i++) {
if (!handleFps[i]) {
handleFps[i] = fp;
return (void*)i;
}
}
printf("Out of file handles\n");
assert(0);
return handles::allocDataHandle(handles::Data{handles::TYPE_FILE, fp, 0});
}
void *getStdHandle(uint32_t nStdHandle) {