2019-10-13 16:37:43 +03:00
|
|
|
module compiler
|
2019-08-19 01:18:07 +03:00
|
|
|
|
|
|
|
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 23:55:45 +03:00
|
|
|
#ifndef _WIN32
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <locale.h> // tolower
|
2019-08-30 01:05:58 +03:00
|
|
|
#include <sys/time.h>
|
2019-08-30 01:10:29 +03:00
|
|
|
#include <unistd.h> // sleep
|
2019-08-23 23:55:45 +03:00
|
|
|
#endif
|
|
|
|
|
2019-09-11 13:31:29 +03:00
|
|
|
|
2019-08-24 02:48:40 +03:00
|
|
|
#ifdef __APPLE__
|
2019-08-24 02:53:11 +03:00
|
|
|
#include <libproc.h> // proc_pidpath
|
2019-10-25 16:06:21 +03:00
|
|
|
#include <execinfo.h> // backtrace and backtrace_symbols_fd
|
2019-08-24 02:48:40 +03:00
|
|
|
#endif
|
|
|
|
|
2019-08-27 23:29:13 +03:00
|
|
|
#ifdef __linux__
|
2019-10-25 12:07:50 +03:00
|
|
|
//#if !defined(__BIONIC__) && !defined(__GNUC_PREREQ)
|
2019-10-25 16:06:21 +03:00
|
|
|
#include <execinfo.h> // backtrace and backtrace_symbols_fd
|
2019-10-25 12:07:50 +03:00
|
|
|
//#endif
|
|
|
|
|
2019-08-28 19:26:18 +03:00
|
|
|
#pragma weak backtrace
|
|
|
|
#pragma weak backtrace_symbols_fd
|
2019-08-27 23:29:13 +03:00
|
|
|
#endif
|
|
|
|
|
2019-09-11 13:31:29 +03:00
|
|
|
|
2019-08-27 23:29:13 +03:00
|
|
|
#ifdef __linux__
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/wait.h> // os__wait uses wait on nix
|
|
|
|
#endif
|
|
|
|
|
2019-10-09 14:28:30 +03:00
|
|
|
#ifdef __FreeBSD__
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/wait.h> // os__wait uses wait on nix
|
|
|
|
#endif
|
|
|
|
|
2019-10-10 20:05:22 +03:00
|
|
|
#ifdef __DragonFly__
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/wait.h> // os__wait uses wait on nix
|
|
|
|
#endif
|
2019-10-20 07:00:01 +03:00
|
|
|
|
|
|
|
#ifdef __OpenBSD__
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/resource.h>
|
|
|
|
#include <sys/wait.h> // os__wait uses wait on nix
|
|
|
|
#endif
|
2019-10-10 20:05:22 +03:00
|
|
|
|
2019-08-19 01:18:07 +03:00
|
|
|
#define EMPTY_STRUCT_DECLARATION
|
2019-09-16 14:44:12 +03:00
|
|
|
#define EMPTY_STRUCT_INITIALIZATION 0
|
2019-10-05 15:46:13 +03:00
|
|
|
// Due to a tcc bug, the length of an array needs to be specified, but GCC crashes if it is...
|
|
|
|
#define EMPTY_ARRAY_OF_ELEMS(x,n) (x[])
|
|
|
|
#define TCCSKIP(x) x
|
|
|
|
|
2019-09-16 14:44:12 +03:00
|
|
|
#ifdef __TINYC__
|
|
|
|
#undef EMPTY_STRUCT_INITIALIZATION
|
2019-09-16 00:41:12 +03:00
|
|
|
#define EMPTY_STRUCT_INITIALIZATION
|
2019-10-05 15:46:13 +03:00
|
|
|
#undef EMPTY_ARRAY_OF_ELEMS
|
|
|
|
#define EMPTY_ARRAY_OF_ELEMS(x,n) (x[n])
|
|
|
|
#undef TCCSKIP
|
|
|
|
#define TCCSKIP(x)
|
2019-09-16 14:44:12 +03:00
|
|
|
#endif
|
|
|
|
|
2019-08-19 01:18:07 +03:00
|
|
|
#define OPTION_CAST(x) (x)
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
2019-09-26 22:54:15 +03:00
|
|
|
#define WINVER 0x0600
|
|
|
|
#define _WIN32_WINNT 0x0600
|
2019-08-19 01:18:07 +03:00
|
|
|
#define WIN32_LEAN_AND_MEAN
|
2019-09-17 14:56:32 +03:00
|
|
|
#define _UNICODE
|
|
|
|
#define UNICODE
|
2019-08-19 01:18:07 +03:00
|
|
|
#include <windows.h>
|
|
|
|
|
|
|
|
// must be included after <windows.h>
|
2019-09-03 16:09:43 +03:00
|
|
|
#ifndef __TINYC__
|
2019-08-19 01:18:07 +03:00
|
|
|
#include <shellapi.h>
|
2019-09-03 16:09:43 +03:00
|
|
|
#endif
|
2019-08-19 01:18:07 +03:00
|
|
|
|
|
|
|
#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 02:38:18 +03:00
|
|
|
// MSVC cannot parse some things properly
|
2019-09-15 15:52:12 +03:00
|
|
|
#undef EMPTY_STRUCT_DECLARATION
|
2019-08-19 01:18:07 +03:00
|
|
|
#undef OPTION_CAST
|
2019-09-16 00:41:12 +03:00
|
|
|
|
|
|
|
#define EMPTY_STRUCT_DECLARATION int ____dummy_variable
|
2019-08-19 01:18:07 +03:00
|
|
|
#define OPTION_CAST(x)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#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 15:02:25 +03:00
|
|
|
typedef uint8_t byte;
|
2019-08-19 01:18:07 +03: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 =============================*/
|
2019-10-10 01:07:00 +03:00
|
|
|
#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);}
|
2019-08-19 01:18:07 +03:00
|
|
|
#define _IN(typ, val, arr) array_##typ##_contains(arr, val)
|
2019-10-10 01:07:00 +03:00
|
|
|
#define _IN_MAP(val, m) map_exists(m, val)
|
2019-09-29 17:39:38 +03:00
|
|
|
#define DEFAULT_EQUAL(a, b) (a == b)
|
2019-10-01 21:21:05 +03:00
|
|
|
#define DEFAULT_NOT_EQUAL(a, b) (a != b)
|
|
|
|
#define DEFAULT_LT(a, b) (a < b)
|
|
|
|
#define DEFAULT_LE(a, b) (a <= b)
|
|
|
|
#define DEFAULT_GT(a, b) (a > b)
|
|
|
|
#define DEFAULT_GE(a, b) (a >= b)
|
2019-08-19 01:18:07 +03:00
|
|
|
//================================== GLOBALS =================================*/
|
|
|
|
byteptr g_str_buf;
|
|
|
|
int load_so(byteptr);
|
|
|
|
void reload_so();
|
|
|
|
'
|
|
|
|
|
2019-09-14 23:48:30 +03:00
|
|
|
js_headers = '
|
|
|
|
|
2019-09-19 00:03:54 +03:00
|
|
|
var array_string = function() {}
|
|
|
|
var array_byte = function() {}
|
|
|
|
var array_int = function() {}
|
|
|
|
var byte = function() {}
|
|
|
|
var double = function() {}
|
|
|
|
var int = function() {}
|
|
|
|
var f64 = function() {}
|
|
|
|
var f32 = function() {}
|
|
|
|
var i64 = function() {}
|
|
|
|
var i32 = function() {}
|
|
|
|
var i16 = function() {}
|
|
|
|
var u64 = function() {}
|
|
|
|
var u32 = function() {}
|
|
|
|
var u16 = function() {}
|
|
|
|
var i8 = function() {}
|
|
|
|
var bool = function() {}
|
|
|
|
var rune = function() {}
|
|
|
|
var map_string = function() {}
|
|
|
|
var map_int = function() {}
|
2019-09-14 23:48:30 +03:00
|
|
|
|
|
|
|
'
|
2019-08-20 14:34:29 +03:00
|
|
|
)
|