X-Git-Url: https://git.llucax.com/software/druntime.git/blobdiff_plain/471a1a23753606871f4d85eb951f615e5310792e..ee7c028ebdd89ffc05410551c6e4812187049279:/src/compiler/dmd/dmain2.d diff --git a/src/compiler/dmd/dmain2.d b/src/compiler/dmd/dmain2.d index 8c22052..15c46d2 100644 --- a/src/compiler/dmd/dmain2.d +++ b/src/compiler/dmd/dmain2.d @@ -12,19 +12,24 @@ module rt.dmain2; private { + import memory; import util.console; - import stdc.stddef; - import stdc.stdlib; - import stdc.string; + import core.stdc.stddef; + import core.stdc.stdlib; + import core.stdc.string; } -version( Windows ) +version (Windows) { + extern (Windows) alias int function() FARPROC; + extern (Windows) FARPROC GetProcAddress(void*, in char*); + extern (Windows) void* LoadLibraryA(in char*); + extern (Windows) int FreeLibrary(void*); extern (Windows) void* LocalFree(void*); extern (Windows) wchar_t* GetCommandLineW(); extern (Windows) wchar_t** CommandLineToArgvW(wchar_t*, int*); extern (Windows) export int WideCharToMultiByte(uint, uint, wchar_t*, int, char*, int, char*, int); - pragma(lib, "shell32.lib"); // needed for CommandLineToArgvW + pragma(lib, "shell32.lib"); // needed for CommandLineToArgvW } extern (C) void _STI_monitor_staticctor(); @@ -38,49 +43,104 @@ extern (C) void _moduleCtor(); extern (C) void _moduleDtor(); extern (C) void thread_joinAll(); +/*********************************** + * These are a temporary means of providing a GC hook for DLL use. They may be + * replaced with some other similar functionality later. + */ +extern (C) +{ + void* gc_getProxy(); + void gc_setProxy(void* p); + void gc_clrProxy(); + + alias void* function() gcGetFn; + alias void function(void*) gcSetFn; + alias void function() gcClrFn; +} + +extern (C) void* rt_loadLibrary(in char[] name) +{ + version (Windows) + { + char[260] temp = void; + temp[0 .. name.length] = name[]; + temp[name.length] = cast(char) 0; + void* ptr = LoadLibraryA(temp.ptr); + if (ptr is null) + return ptr; + gcSetFn gcSet = cast(gcSetFn) GetProcAddress(ptr, "gc_setProxy"); + if (gcSet !is null) + gcSet(gc_getProxy()); + return ptr; + + } + else version (linux) + { + throw new Exception("rt_loadLibrary not yet implemented on linux."); + } +} + +extern (C) bool rt_unloadLibrary(void* ptr) +{ + version (Windows) + { + gcClrFn gcClr = cast(gcClrFn) GetProcAddress(ptr, "gc_clrProxy"); + if (gcClr !is null) + gcClr(); + return FreeLibrary(ptr) != 0; + } + else version (linux) + { + throw new Exception("rt_unloadLibrary not yet implemented on linux."); + } +} + /*********************************** * These functions must be defined for any D program linked * against this library. */ -extern (C) void onAssertError( string file, size_t line ); -extern (C) void onAssertErrorMsg( string file, size_t line, string msg ); -extern (C) void onArrayBoundsError( string file, size_t line ); -extern (C) void onSwitchError( string file, size_t line ); +extern (C) void onAssertError(string file, size_t line); +extern (C) void onAssertErrorMsg(string file, size_t line, string msg); +extern (C) void onRangeError(string file, size_t line); +extern (C) void onHiddenFuncError(Object o); +extern (C) void onSwitchError(string file, size_t line); extern (C) bool runModuleUnitTests(); // this function is called from the utf module -//extern (C) void onUnicodeError( string msg, size_t idx ); +//extern (C) void onUnicodeError(string msg, size_t idx); /*********************************** * These are internal callbacks for various language errors. */ -extern (C) void _d_assert( string file, uint line ) +extern (C) void _d_assert(string file, uint line) { - onAssertError( file, line ); + onAssertError(file, line); } -extern (C) static void _d_assert_msg( string msg, string file, uint line ) +extern (C) static void _d_assert_msg(string msg, string file, uint line) { - onAssertErrorMsg( file, line, msg ); + onAssertErrorMsg(file, line, msg); } -extern (C) void _d_array_bounds( string file, uint line ) +extern (C) void _d_array_bounds(string file, uint line) { - onArrayBoundsError( file, line ); + onRangeError(file, line); } -extern (C) void _d_switch_error( string file, uint line ) +extern (C) void _d_switch_error(string file, uint line) { - onSwitchError( file, line ); + onSwitchError(file, line); } -/+ extern (C) void _d_hidden_func() { - // TODO: Figure out what to do with this routine - // it's in exception.d for the moment + Object o; + asm + { + mov o, EAX; + } + onHiddenFuncError(o); } -+/ bool _d_isHalting = false; @@ -100,24 +160,25 @@ void _d_criticalInit() } } -alias void delegate( Exception ) ExceptionHandler; +alias void delegate(Throwable) ExceptionHandler; -extern (C) bool rt_init( ExceptionHandler dg = null ) +extern (C) bool rt_init(ExceptionHandler dg = null) { _d_criticalInit(); try { gc_init(); + initStaticDataGC(); version (Windows) _minit(); _moduleCtor(); return true; } - catch( Exception e ) + catch (Throwable e) { - if( dg ) - dg( e ); + if (dg) + dg(e); } catch { @@ -136,7 +197,7 @@ void _d_criticalTerm() } } -extern (C) bool rt_term( ExceptionHandler dg = null ) +extern (C) bool rt_term(ExceptionHandler dg = null) { try { @@ -146,10 +207,10 @@ extern (C) bool rt_term( ExceptionHandler dg = null ) gc_term(); return true; } - catch( Exception e ) + catch (Throwable e) { - if( dg ) - dg( e ); + if (dg) + dg(e); } catch { @@ -200,7 +261,7 @@ extern (C) int main(int argc, char **argv) for (size_t i = 0, p = 0; i < wargc; i++) { - int wlen = wcslen( wargs[i] ); + int wlen = wcslen(wargs[i]); int clen = WideCharToMultiByte(65001, 0, &wargs[i][0], wlen, null, 0, null, 0); args[i] = cargp[p .. p+clen]; p += clen; assert(p <= cargl); @@ -225,7 +286,7 @@ extern (C) int main(int argc, char **argv) bool trapExceptions = rt_trapExceptions; - void tryExec(void delegate() dg) + void tryExec(scope void delegate() dg) { if (trapExceptions) @@ -234,19 +295,19 @@ extern (C) int main(int argc, char **argv) { dg(); } - catch (Exception e) + catch (Throwable e) { while (e) { if (e.file) { - // fprintf(stderr, "%.*s(%u): %.*s\n", e.file, e.line, e.msg); - console (e.classinfo.name)("@")(e.file)("(")(e.line)("): ")(e.msg)("\n"); + // fprintf(stderr, "%.*s(%u): %.*s\n", e.file, e.line, e.msg); + console (e.classinfo.name)("@")(e.file)("(")(e.line)("): ")(e.msg)("\n"); } else { - // fprintf(stderr, "%.*s\n", e.toString()); - console (e.classinfo.name)(": ")(e.toString)("\n"); + // fprintf(stderr, "%.*s\n", e.toString()); + console (e.toString)("\n"); } if (e.info) { @@ -290,6 +351,7 @@ extern (C) int main(int argc, char **argv) void runAll() { gc_init(); + initStaticDataGC(); version (Windows) _minit(); _moduleCtor();