mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
ffa9646749
This reverts commit d1e7a54f3a
.
174 lines
4.1 KiB
V
174 lines
4.1 KiB
V
module compiler
|
|
|
|
const (
|
|
|
|
CommonCHeaders = '
|
|
|
|
#include <stdio.h> // TODO remove all these includes, define all function signatures and types manually
|
|
#include <stdlib.h>
|
|
|
|
//#include "fns.h"
|
|
#include <signal.h>
|
|
#include <stdarg.h> // for va_list
|
|
#include <inttypes.h> // int64_t etc
|
|
#include <string.h> // memcpy
|
|
|
|
#ifndef _WIN32
|
|
#include <ctype.h>
|
|
#include <locale.h> // tolower
|
|
#include <sys/time.h>
|
|
#include <unistd.h> // sleep
|
|
#else
|
|
#if defined(__MSVCRT_VERSION__) && __MSVCRT_VERSION__ < __MSVCR90_DLL
|
|
#error Please upgrade your MinGW distribution to use msvcr90.dll or later.
|
|
#endif
|
|
#endif
|
|
|
|
#if defined(__CYGWIN__) && !defined(_WIN32)
|
|
#error Cygwin is not supported, please use MinGW or Visual Studio.
|
|
#endif
|
|
|
|
|
|
#ifdef __linux__
|
|
#include <sys/types.h>
|
|
#include <sys/wait.h> // os__wait uses wait on nix
|
|
#endif
|
|
|
|
#ifdef __FreeBSD__
|
|
#include <sys/types.h>
|
|
#include <sys/wait.h> // os__wait uses wait on nix
|
|
#endif
|
|
|
|
#ifdef __DragonFly__
|
|
#include <sys/types.h>
|
|
#include <sys/wait.h> // os__wait uses wait on nix
|
|
#endif
|
|
|
|
#ifdef __OpenBSD__
|
|
#include <sys/types.h>
|
|
#include <sys/resource.h>
|
|
#include <sys/wait.h> // os__wait uses wait on nix
|
|
#endif
|
|
|
|
#define EMPTY_STRUCT_DECLARATION
|
|
#define EMPTY_STRUCT_INITIALIZATION 0
|
|
// 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
|
|
|
|
#ifdef __TINYC__
|
|
#undef EMPTY_STRUCT_INITIALIZATION
|
|
#define EMPTY_STRUCT_INITIALIZATION
|
|
#undef EMPTY_ARRAY_OF_ELEMS
|
|
#define EMPTY_ARRAY_OF_ELEMS(x,n) (x[n])
|
|
#undef TCCSKIP
|
|
#define TCCSKIP(x)
|
|
#endif
|
|
|
|
#define OPTION_CAST(x) (x)
|
|
|
|
#ifdef _WIN32
|
|
#define WINVER 0x0600
|
|
#define _WIN32_WINNT 0x0600
|
|
#define WIN32_LEAN_AND_MEAN
|
|
#define _UNICODE
|
|
#define UNICODE
|
|
#include <windows.h>
|
|
|
|
// must be included after <windows.h>
|
|
#ifndef __TINYC__
|
|
#include <shellapi.h>
|
|
#endif
|
|
|
|
#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
|
|
|
|
// MSVC cannot parse some things properly
|
|
#undef EMPTY_STRUCT_DECLARATION
|
|
#undef OPTION_CAST
|
|
|
|
#define EMPTY_STRUCT_DECLARATION int ____dummy_variable
|
|
#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;
|
|
typedef uint8_t byte;
|
|
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)
|
|
#define DEFAULT_EQUAL(a, b) (a == b)
|
|
#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)
|
|
//================================== GLOBALS =================================*/
|
|
byteptr g_str_buf;
|
|
int load_so(byteptr);
|
|
void reload_so();
|
|
'
|
|
|
|
js_headers = '
|
|
|
|
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() {}
|
|
|
|
'
|
|
)
|