comparison main.d @ 34:544b922227c7

update to work with dmd 2.048
author korDen
date Sat, 21 Aug 2010 05:46:08 +0400
parents 3f834bed4f13
children 6bdecc3f4569
comparison
equal deleted inserted replaced
33:e0a36abe1184 34:544b922227c7
18 import dmd.String; 18 import dmd.String;
19 import dmd.backend.glue; 19 import dmd.backend.glue;
20 20
21 import std.stdarg; 21 import std.stdarg;
22 import std.string : toStringz; 22 import std.string : toStringz;
23 import std.contracts; 23 import std.exception;
24 24
25 import core.stdc.string; 25 import core.stdc.string;
26 import core.stdc.stdio; 26 import core.stdc.stdio;
27 import core.stdc.ctype; 27 import core.stdc.ctype;
28 import core.stdc.errno; 28 import core.stdc.errno;
34 import dlib.CrashHandler; 34 import dlib.CrashHandler;
35 import dbg.ui.CrashWindow; 35 import dbg.ui.CrashWindow;
36 36
37 import dmd.Util; 37 import dmd.Util;
38 38
39 bool loop = true;
40
41 enum ExitCode 39 enum ExitCode
42 { 40 {
43 EXIT_SUCCESS = 0, 41 EXIT_SUCCESS = 0,
44 } 42 }
45 43
46 version (Windows) 44 extern (C) extern __gshared bool rt_trapExceptions;
47 { 45
48 private import core.stdc.wchar_; 46 static this() {
49 } 47 rt_trapExceptions = false;
50
51 extern (C) void gc_init();
52 extern (C) void gc_term();
53 extern (C) void _minit();
54 extern (C) void _moduleCtor();
55 extern (C) void _moduleDtor();
56 extern (C) void thread_joinAll();
57
58 shared bool _d_isHalting = false;
59
60 version (Windows)
61 {
62 import win32.windows;
63
64 /* Link to druntimes main() */
65
66 extern (C) int main(int argc, char **argv)
67 {
68 char[][] args;
69 int result;
70
71 version (OSX)
72 { /* OSX does not provide a way to get at the top of the
73 * stack, except for the magic value 0xC0000000.
74 * But as far as the gc is concerned, argv is at the top
75 * of the main thread's stack, so save the address of that.
76 */
77 __osx_stack_end = cast(void*)&argv;
78 }
79
80 version (Posix)
81 {
82 _STI_monitor_staticctor();
83 _STI_critical_init();
84 }
85
86 version (Windows)
87 {
88 wchar_t* wcbuf = GetCommandLineW();
89 size_t wclen = wcslen(wcbuf);
90 int wargc = 0;
91 wchar_t** wargs = CommandLineToArgvW(wcbuf, &wargc);
92 assert(wargc == argc);
93
94 char* cargp = null;
95 size_t cargl = WideCharToMultiByte(65001, 0, wcbuf, wclen, null, 0, null, null);
96
97 cargp = cast(char*) alloca(cargl);
98 args = ((cast(char[]*) alloca(wargc * (char[]).sizeof)))[0 .. wargc];
99
100 for (size_t i = 0, p = 0; i < wargc; i++)
101 {
102 int wlen = wcslen(wargs[i]);
103 int clen = WideCharToMultiByte(65001, 0, &wargs[i][0], wlen, null, 0, null, null);
104 args[i] = cargp[p .. p+clen];
105 p += clen; assert(p <= cargl);
106 WideCharToMultiByte(65001, 0, &wargs[i][0], wlen, &args[i][0], clen, null, null);
107 }
108 LocalFree(cast(HANDLE)wargs);
109 wargs = null;
110 wargc = 0;
111 }
112 else version (Posix)
113 {
114 char[]* am = cast(char[]*) malloc(argc * (char[]).sizeof);
115 scope(exit) free(am);
116
117 for (size_t i = 0; i < argc; i++)
118 {
119 auto len = strlen(argv[i]);
120 am[i] = argv[i][0 .. len];
121 }
122 args = am[0 .. argc];
123 }
124
125 gc_init();
126 version (Windows)
127 _minit();
128 _moduleCtor();
129
130 GC.disable();
131 CrashHandlerInit();
132
133 result = main(cast(string[])args);
134
135 thread_joinAll();
136 _d_isHalting = true;
137 _moduleDtor();
138 gc_term();
139
140 version (Posix)
141 {
142 _STD_critical_term();
143 _STD_monitor_staticdtor();
144 }
145
146 return result;
147 }
148 } 48 }
149 49
150 int main(string[] args) 50 int main(string[] args)
151 { 51 {
152 GC.disable(); 52 GC.disable();
53 CrashHandlerInit();
54
153 Array files = new Array(); 55 Array files = new Array();
154 Array libmodules = new Array(); 56 Array libmodules = new Array();
155 Module m; 57 Module m;
156 int status = ExitCode.EXIT_SUCCESS; 58 int status = ExitCode.EXIT_SUCCESS;
157 int argcstart = args.length; 59 int argcstart = args.length;