summary refs log tree commit diff stats
path: root/tinyc/win32/lib/crt1.c
diff options
context:
space:
mode:
authorDmitry Atamanov <data-man@users.noreply.github.com>2017-10-28 10:25:56 +0300
committerAndreas Rumpf <rumpf_a@web.de>2017-10-28 09:25:56 +0200
commitd2c7d391c8b69a6a590a2f702ed58bea033f6325 (patch)
treec74a1b46e1166ddb87453ddc49cea84e1baaa5ab /tinyc/win32/lib/crt1.c
parent9c00f6decd4453a4233450a60ccef05b20e9f24a (diff)
downloadNim-d2c7d391c8b69a6a590a2f702ed58bea033f6325.tar.gz
TinyC upgrade (#6593)
Diffstat (limited to 'tinyc/win32/lib/crt1.c')
-rw-r--r--tinyc/win32/lib/crt1.c84
1 files changed, 64 insertions, 20 deletions
diff --git a/tinyc/win32/lib/crt1.c b/tinyc/win32/lib/crt1.c
index 1cf12f294..0e04fc012 100644
--- a/tinyc/win32/lib/crt1.c
+++ b/tinyc/win32/lib/crt1.c
@@ -1,35 +1,79 @@
 // =============================================
 // crt1.c
 
+// _UNICODE for tchar.h, UNICODE for API
+#include <tchar.h>
+
+#include <stdio.h>
 #include <stdlib.h>
 
-#define __UNKNOWN_APP    0
-#define __CONSOLE_APP    1
-#define __GUI_APP        2
-void __set_app_type(int);
-void _controlfp(unsigned a, unsigned b);
+#define _UNKNOWN_APP    0
+#define _CONSOLE_APP    1
+#define _GUI_APP        2
 
-typedef struct
-{
-	int newmode;
-} _startupinfo;
+#define _MCW_PC         0x00030000 // Precision Control
+#define _PC_24          0x00020000 // 24 bits
+#define _PC_53          0x00010000 // 53 bits
+#define _PC_64          0x00000000 // 64 bits
+
+#ifdef _UNICODE
+#define __tgetmainargs __wgetmainargs
+#define _tstart _wstart
+#define _tmain wmain
+#define _runtmain _runwmain
+#else
+#define __tgetmainargs __getmainargs
+#define _tstart _start
+#define _tmain main
+#define _runtmain _runmain
+#endif
 
-void __getmainargs(int *pargc, char ***pargv, char ***penv, int globb, _startupinfo*);
+typedef struct { int newmode; } _startupinfo;
+int __cdecl __tgetmainargs(int *pargc, _TCHAR ***pargv, _TCHAR ***penv, int globb, _startupinfo*);
+void __cdecl __set_app_type(int apptype);
+unsigned int __cdecl _controlfp(unsigned int new_value, unsigned int mask);
+extern int _tmain(int argc, _TCHAR * argv[], _TCHAR * env[]);
 
-int main(int argc, char **argv, char **env);
+/* Allow command-line globbing with "int _dowildcard = 1;" in the user source */
+int _dowildcard;
 
-int _start(void)
+void _tstart(void)
 {
-	int argc; char **argv; char **env; int ret;
-	_startupinfo start_info = {0};
+    __TRY__
+    _startupinfo start_info = {0};
 
-	_controlfp(0x10000, 0x30000);
-	__set_app_type(__CONSOLE_APP);
-	__getmainargs(&argc, &argv, &env, 0, &start_info);
+    // Sets the current application type
+    __set_app_type(_CONSOLE_APP);
 
-	ret = main(argc, argv, env);
-	exit(ret);
+    // Set default FP precision to 53 bits (8-byte double)
+    // _MCW_PC (Precision control) is not supported on ARM
+#if defined __i386__ || defined __x86_64__
+    _controlfp(_PC_53, _MCW_PC);
+#endif
+
+    __tgetmainargs( &__argc, &__targv, &_tenviron, _dowildcard, &start_info);
+    exit(_tmain(__argc, __targv, _tenviron));
 }
 
-// =============================================
+int _runtmain(int argc, /* as tcc passed in */ char **argv)
+{
+#ifdef UNICODE
+    _startupinfo start_info = {0};
+
+    __tgetmainargs(&__argc, &__targv, &_tenviron, _dowildcard, &start_info);
+    /* may be wrong when tcc has received wildcards (*.c) */
+    if (argc < __argc) {
+        __targv += __argc - argc;
+        __argc = argc;
+    }
+#else
+    __argc = argc;
+    __targv = argv;
+#endif
+#if defined __i386__ || defined __x86_64__
+    _controlfp(_PC_53, _MCW_PC);
+#endif
+    return _tmain(__argc, __targv, _tenviron);
+}
 
+// =============================================