2019-08-19 00:18:07 +02:00
|
|
|
module main
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
|
|
|
CommonCHeaders = '
|
|
|
|
|
|
|
|
#include <stdio.h> // TODO remove all these includes, define all function signatures and types manually
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <stdarg.h> // for va_list
|
|
|
|
#include <inttypes.h> // int64_t etc
|
|
|
|
#include <string.h> // memcpy
|
|
|
|
|
2019-08-23 22:55:45 +02:00
|
|
|
#ifndef _WIN32
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <locale.h> // tolower
|
2019-08-30 00:05:58 +02:00
|
|
|
#include <sys/time.h>
|
2019-08-30 00:10:29 +02:00
|
|
|
#include <unistd.h> // sleep
|
2019-08-23 22:55:45 +02:00
|
|
|
#endif
|
|
|
|
|
2019-08-24 01:48:40 +02:00
|
|
|
#ifdef __APPLE__
|
2019-08-24 01:53:11 +02:00
|
|
|
#include <libproc.h> // proc_pidpath
|
|
|
|
#include <execinfo.h> // backtrace and backtrace_symbols_fd
|
2019-08-24 01:48:40 +02:00
|
|
|
#endif
|
|
|
|
|
2019-08-27 22:29:13 +02:00
|
|
|
#ifdef __linux__
|
|
|
|
#include <execinfo.h> // backtrace and backtrace_symbols_fd
|
2019-08-28 18:26:18 +02:00
|
|
|
#pragma weak backtrace
|
|
|
|
#pragma weak backtrace_symbols_fd
|
2019-08-27 22:29:13 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __linux__
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/wait.h> // os__wait uses wait on nix
|
|
|
|
#endif
|
|
|
|
|
2019-08-24 01:48:40 +02:00
|
|
|
|
2019-08-19 00:18:07 +02:00
|
|
|
#define EMPTY_STRUCT_DECLARATION
|
|
|
|
#define OPTION_CAST(x) (x)
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
|
#include <windows.h>
|
|
|
|
|
|
|
|
// must be included after <windows.h>
|
|
|
|
#include <shellapi.h>
|
|
|
|
|
|
|
|
#include <io.h> // _waccess
|
|
|
|
#include <fcntl.h> // _O_U8TEXT
|
|
|
|
#include <direct.h> // _wgetcwd
|
|
|
|
//#include <WinSock2.h>
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
// On MSVC these are the same (as long as /volatile:ms is passed)
|
|
|
|
#define _Atomic volatile
|
|
|
|
|
2019-08-23 01:38:18 +02:00
|
|
|
// MSVC cannot parse some things properly
|
2019-08-19 00:18:07 +02:00
|
|
|
#undef EMPTY_STRUCT_DECLARATION
|
2019-09-02 13:21:39 +02:00
|
|
|
#define EMPTY_STRUCT_DECLARATION void *____dummy_variable
|
2019-08-19 00:18:07 +02:00
|
|
|
#undef OPTION_CAST
|
|
|
|
#define OPTION_CAST(x)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void pthread_mutex_lock(HANDLE *m) {
|
|
|
|
WaitForSingleObject(*m, INFINITE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void pthread_mutex_unlock(HANDLE *m) {
|
|
|
|
ReleaseMutex(*m);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#include <pthread.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//================================== TYPEDEFS ================================*/
|
|
|
|
|
|
|
|
typedef int64_t i64;
|
|
|
|
typedef int16_t i16;
|
|
|
|
typedef int8_t i8;
|
|
|
|
typedef uint64_t u64;
|
|
|
|
typedef uint32_t u32;
|
|
|
|
typedef uint16_t u16;
|
2019-09-02 14:02:25 +02:00
|
|
|
typedef uint8_t byte;
|
2019-08-19 00:18:07 +02:00
|
|
|
typedef uint32_t rune;
|
|
|
|
typedef float f32;
|
|
|
|
typedef double f64;
|
|
|
|
typedef unsigned char* byteptr;
|
|
|
|
typedef int* intptr;
|
|
|
|
typedef void* voidptr;
|
|
|
|
typedef struct array array;
|
|
|
|
typedef struct map map;
|
|
|
|
typedef array array_string;
|
|
|
|
typedef array array_int;
|
|
|
|
typedef array array_byte;
|
|
|
|
typedef array array_f32;
|
|
|
|
typedef array array_f64;
|
|
|
|
typedef map map_int;
|
|
|
|
typedef map map_string;
|
|
|
|
#ifndef bool
|
|
|
|
typedef int bool;
|
|
|
|
#define true 1
|
|
|
|
#define false 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//============================== HELPER C MACROS =============================*/
|
|
|
|
|
|
|
|
#define _PUSH(arr, val, tmp, tmp_typ) {tmp_typ tmp = (val); array__push(arr, &tmp);}
|
|
|
|
#define _PUSH_MANY(arr, val, tmp, tmp_typ) {tmp_typ tmp = (val); array__push_many(arr, tmp.data, tmp.len);}
|
|
|
|
#define _IN(typ, val, arr) array_##typ##_contains(arr, val)
|
|
|
|
#define _IN_MAP(val, m) map__exists(m, val)
|
2019-08-26 21:40:07 +02:00
|
|
|
//#define ALLOC_INIT(type, ...) (type *)memdup((type[]){ __VA_ARGS__ }, sizeof(type))
|
2019-08-19 00:18:07 +02:00
|
|
|
|
|
|
|
//================================== GLOBALS =================================*/
|
|
|
|
byteptr g_str_buf;
|
|
|
|
int load_so(byteptr);
|
|
|
|
void reload_so();
|
|
|
|
void init_consts();
|
|
|
|
|
|
|
|
'
|
|
|
|
|
2019-08-20 13:34:29 +02:00
|
|
|
)
|