Mercurial > projects > ddmd
comparison main.d @ 70:6bdecc3f4569
Get rid of win32 bindings
author | korDen |
---|---|
date | Sat, 28 Aug 2010 10:51:32 +0400 |
parents | 544b922227c7 |
children | 7e0d548de9e6 |
comparison
equal
deleted
inserted
replaced
69:c876339731a4 | 70:6bdecc3f4569 |
---|---|
29 import core.stdc.stdlib; | 29 import core.stdc.stdlib; |
30 import core.stdc.limits; | 30 import core.stdc.limits; |
31 | 31 |
32 import core.memory; | 32 import core.memory; |
33 | 33 |
34 import dlib.CrashHandler; | 34 import dbg.CallStackInfo; |
35 import dbg.ui.CrashWindow; | |
36 | 35 |
37 import dmd.Util; | 36 import dmd.Util; |
38 | 37 |
39 enum ExitCode | 38 enum ExitCode |
40 { | 39 { |
41 EXIT_SUCCESS = 0, | 40 EXIT_SUCCESS = 0, |
42 } | 41 } |
43 | 42 |
44 extern (C) extern __gshared bool rt_trapExceptions; | 43 version (Windows) |
45 | 44 { |
46 static this() { | 45 private import core.stdc.wchar_; |
47 rt_trapExceptions = false; | 46 |
47 extern (Windows) alias int function() FARPROC; | |
48 extern (Windows) FARPROC GetProcAddress(void*, in char*); | |
49 extern (Windows) void* LoadLibraryA(in char*); | |
50 extern (Windows) int FreeLibrary(void*); | |
51 extern (Windows) void* LocalFree(void*); | |
52 extern (Windows) wchar_t* GetCommandLineW(); | |
53 extern (Windows) wchar_t** CommandLineToArgvW(wchar_t*, int*); | |
54 extern (Windows) export int WideCharToMultiByte(uint, uint, wchar_t*, int, char*, int, char*, int); | |
55 pragma(lib, "shell32.lib"); // needed for CommandLineToArgvW | |
56 } | |
57 | |
58 shared bool _d_isHalting = false; | |
59 __gshared string[] _d_args = null; | |
60 | |
61 extern (C) void gc_init(); | |
62 extern (C) void gc_term(); | |
63 extern (C) void _minit(); | |
64 extern (C) void _moduleCtor(); | |
65 extern (C) void _moduleDtor(); | |
66 extern (C) bool runModuleUnitTests(); | |
67 extern (C) void thread_joinAll(); | |
68 | |
69 import rt.memory; | |
70 | |
71 extern (C) int main(int argc, char** argv) | |
72 { | |
73 char[][] args; | |
74 int result; | |
75 | |
76 version (OSX) | |
77 { /* OSX does not provide a way to get at the top of the | |
78 * stack, except for the magic value 0xC0000000. | |
79 * But as far as the gc is concerned, argv is at the top | |
80 * of the main thread's stack, so save the address of that. | |
81 */ | |
82 __osx_stack_end = cast(void*)&argv; | |
83 } | |
84 | |
85 version (FreeBSD) version (D_InlineAsm_X86) | |
86 { | |
87 /* | |
88 * FreeBSD/i386 sets the FPU precision mode to 53 bit double. | |
89 * Make it 64 bit extended. | |
90 */ | |
91 ushort fpucw; | |
92 asm | |
93 { | |
94 fstsw fpucw; | |
95 or fpucw, 0b11_00_111111; // 11: use 64 bit extended-precision | |
96 // 111111: mask all FP exceptions | |
97 fldcw fpucw; | |
98 } | |
99 } | |
100 | |
101 version (Posix) | |
102 { | |
103 _STI_monitor_staticctor(); | |
104 _STI_critical_init(); | |
105 } | |
106 | |
107 version (Windows) | |
108 { | |
109 wchar_t* wcbuf = GetCommandLineW(); | |
110 size_t wclen = wcslen(wcbuf); | |
111 int wargc = 0; | |
112 wchar_t** wargs = CommandLineToArgvW(wcbuf, &wargc); | |
113 assert(wargc == argc); | |
114 | |
115 char* cargp = null; | |
116 size_t cargl = WideCharToMultiByte(65001, 0, wcbuf, wclen, null, 0, null, 0); | |
117 | |
118 cargp = cast(char*) alloca(cargl); | |
119 args = ((cast(char[]*) alloca(wargc * (char[]).sizeof)))[0 .. wargc]; | |
120 | |
121 for (size_t i = 0, p = 0; i < wargc; i++) | |
122 { | |
123 int wlen = wcslen(wargs[i]); | |
124 int clen = WideCharToMultiByte(65001, 0, &wargs[i][0], wlen, null, 0, null, 0); | |
125 args[i] = cargp[p .. p+clen]; | |
126 p += clen; assert(p <= cargl); | |
127 WideCharToMultiByte(65001, 0, &wargs[i][0], wlen, &args[i][0], clen, null, 0); | |
128 } | |
129 LocalFree(wargs); | |
130 wargs = null; | |
131 wargc = 0; | |
132 } | |
133 else version (Posix) | |
134 { | |
135 char[]* am = cast(char[]*) malloc(argc * (char[]).sizeof); | |
136 scope(exit) free(am); | |
137 | |
138 for (size_t i = 0; i < argc; i++) | |
139 { | |
140 auto len = strlen(argv[i]); | |
141 am[i] = argv[i][0 .. len]; | |
142 } | |
143 args = am[0 .. argc]; | |
144 } | |
145 _d_args = cast(string[]) args; | |
146 | |
147 void runMain() | |
148 { | |
149 result = main(_d_args); | |
150 } | |
151 | |
152 void runAll() | |
153 { | |
154 gc_init(); | |
155 initStaticDataGC(); | |
156 version (Windows) | |
157 _minit(); | |
158 _moduleCtor(); | |
159 _moduleTlsCtor(); | |
160 if (runModuleUnitTests()) | |
161 runMain(); | |
162 else | |
163 result = EXIT_FAILURE; | |
164 _moduleTlsDtor(); | |
165 thread_joinAll(); | |
166 _d_isHalting = true; | |
167 _moduleDtor(); | |
168 gc_term(); | |
169 } | |
170 | |
171 runAll(); | |
172 | |
173 version (Posix) | |
174 { | |
175 _STD_critical_term(); | |
176 _STD_monitor_staticdtor(); | |
177 } | |
178 return result; | |
48 } | 179 } |
49 | 180 |
50 int main(string[] args) | 181 int main(string[] args) |
51 { | 182 { |
52 GC.disable(); | 183 GC.disable(); |