Address build errors on llvm-mingw to build bqn.exe with no SH, FFI, or repl support

This commit is contained in:
actalley 2023-01-05 20:31:11 -06:00
parent fef8cfaef0
commit 815de4fd97
No known key found for this signature in database
GPG Key ID: E432DD92DE787775
11 changed files with 109 additions and 3 deletions

2
.gitignore vendored
View File

@ -5,6 +5,8 @@
*.wasm *.wasm
*.cwasm *.cwasm
libcbqn.so libcbqn.so
*.exe
*.dll
# build system things # build system things
/build/obj/ /build/obj/

View File

@ -9,7 +9,11 @@
#include "../nfns.h" #include "../nfns.h"
#include <unistd.h> #include <unistd.h>
#include <poll.h> #if !defined(_WIN32) && !defined(_WIN64)
#include <poll.h>
#else
#include "../windows/getline.c"
#endif
#include <errno.h> #include <errno.h>
static bool eqStr(B w, u32* x) { static bool eqStr(B w, u32* x) {

View File

@ -899,7 +899,11 @@ int main(int argc, char* argv[]) {
} }
char* ln = NULL; char* ln = NULL;
size_t gl = 0; size_t gl = 0;
i64 read = getline(&ln, &gl, stdin); #if defined(_WIN32) || defined(_WIN64)
i64 read = 0;
#else
i64 read = getline(&ln, &gl, stdin);
#endif
if (read<=0 || ln[0]==0) { if(!silentREPL) putchar('\n'); break; } if (read<=0 || ln[0]==0) { if(!silentREPL) putchar('\n'); break; }
if (ln[read-1]==10) ln[--read] = 0; if (ln[read-1]==10) ln[--read] = 0;
cbqn_runLine(ln, read); cbqn_runLine(ln, read);

View File

@ -6,6 +6,10 @@
#include <unistd.h> #include <unistd.h>
#include <errno.h> #include <errno.h>
#if defined(_WIN32) || defined(_WIN64)
#include "../windows/realpath.c"
#endif
FILE* file_open(B path, char* desc, char* mode) { // doesn't consume FILE* file_open(B path, char* desc, char* mode) { // doesn't consume
char* p = toCStr(path); char* p = toCStr(path);
@ -318,7 +322,11 @@ void mmap_init() { }
bool dir_create(B path) { bool dir_create(B path) {
char* p = toCStr(path); char* p = toCStr(path);
bool r = mkdir(p, S_IRWXU) == 0; #if defined(_WIN32) || defined(_WIN64)
bool r = 1;
#else
bool r = mkdir(p, S_IRWXU) == 0;
#endif
freeCStr(p); freeCStr(p);
return r; return r;
} }

View File

@ -6,6 +6,10 @@
#include "utils/interrupt.h" #include "utils/interrupt.h"
#include <unistd.h> #include <unistd.h>
#if defined(_WIN32) || defined(_WIN64)
#include "windows/sysconf.c"
#endif
#ifndef UNWIND_COMPILER // whether to hide stackframes of the compiler in compiling errors #ifndef UNWIND_COMPILER // whether to hide stackframes of the compiler in compiling errors
#define UNWIND_COMPILER 1 #define UNWIND_COMPILER 1
#endif #endif

41
src/windows/getline.c Normal file
View File

@ -0,0 +1,41 @@
#include "getline.h"
ssize_t getline (char **lptr, size_t *n, FILE *fp) {
wchar_t buf[MAX_LINE_LENGTH/3] = {0};
DWORD bytes;
DWORD chars, read_chars;
int convertResult;
char *m;
bytes = MAX_LINE_LENGTH;
chars = bytes/3;
HANDLE hIn = GetStdHandle(STD_INPUT_HANDLE);
if (!ReadConsoleW(hIn, &buf, chars, &read_chars, NULL)) {
fprintf(stderr, "Failed to read console input: %d", GetLastError());
goto error;
}
convertResult = WideCharToMultiByte(CP_ACP, 0, buf, -1, NULL, 0, NULL, NULL);
if (convertResult == 0) {
fprintf(stderr, "Failed to get MultiByte length: %d", GetLastError());
goto error;
}
m = *lptr = (char*) calloc(convertResult, sizeof(char));
if (WideCharToMultiByte(CP_ACP, 0, buf, -1, m, convertResult, NULL, NULL) == 0 ) {
fprintf(stderr, "Failed to convert wide characters: %d", GetLastError());
free(m);
goto error;
}
return convertResult;
error:
CloseHandle(hIn);
return -1;
}

11
src/windows/getline.h Normal file
View File

@ -0,0 +1,11 @@
#ifndef GETLINE_H
#define GETLINE_H
#include <windows.h>
#include <stdio.h>
#define MAX_LINE_LENGTH 8192
//ssize_t processinput (char **lptr, size_t *n, FILE *hIn);
#endif /* GETLINE_H */

9
src/windows/realpath.c Normal file
View File

@ -0,0 +1,9 @@
#include "realpath.h"
char* realpath (const char *__restrict path, char *__restrict resolved_path) {
unsigned long len=strlen(path)+1;
void* r = malloc(len);
memcpy(r, path, len);
return r;
}

9
src/windows/realpath.h Normal file
View File

@ -0,0 +1,9 @@
#ifndef REALPATH_H
#define REALPATH_H
#define S_ISLNK(m) (0)
#define S_ISSOCK(m) (0)
char* realpath (const char *__restrict path, char *__restrict resolved_path);
#endif /* REALPATH_H */

6
src/windows/sysconf.c Normal file
View File

@ -0,0 +1,6 @@
#include "sysconf.h"
long int sysconf (int in) {
return 1L;
}

8
src/windows/sysconf.h Normal file
View File

@ -0,0 +1,8 @@
#ifndef SYSCONF_H
#define SYSCONF_H
#define _SC_PAGESIZE 8
long int sysconf (int in);
#endif /* SYSCONF_H */