annotate base/src/java/lang/util.d @ 113:fb3aa8075988

D2 support for the linux port.
author Jacob Carlborg <doob@me.com>
date Wed, 06 Apr 2011 21:57:23 +0200
parents 9f4c18c268b2
children 536e43f63c81
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
1 module java.lang.util;
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
2
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
3 public import java.lang.wrappers;
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
4 public import java.lang.String;
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
5 public import java.lang.interfaces;
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
6
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
7 version(Tango){
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
8 static import tango.text.convert.Format;
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
9 static import tango.core.Exception;
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
10 static import tango.util.log.Log;
74
8939451abc39 Configure std logging
Frank Benoit <benoit@tionex.de>
parents: 44
diff changeset
11 static import tango.util.log.Config;
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
12 static import tango.stdc.stdlib;
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
13
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
14 alias tango.stdc.stdlib.exit exit;
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
15 } else { // Phobos
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
16 static import core.exception;
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
17 static import std.c.stdlib;
44
ed96ea2a2764 First swt win snippets are buiding with d2+phobos
Frank Benoit <benoit@tionex.de>
parents: 39
diff changeset
18 static import std.stdio;
112
9f4c18c268b2 Update to compile and execute with dmd 2.052.
kntroh
parents: 74
diff changeset
19 static import std.array;
9f4c18c268b2 Update to compile and execute with dmd 2.052.
kntroh
parents: 74
diff changeset
20 static import std.format;
9f4c18c268b2 Update to compile and execute with dmd 2.052.
kntroh
parents: 74
diff changeset
21 static import std.exception;
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
22 alias std.c.stdlib.exit exit;
0
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
23 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
24
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
25 version(Tango){
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
26 } else { // Phobos
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
27 }
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
28 version(Tango){
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
29 } else { // Phobos
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
30 }
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
31 version(Tango){
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
32 } else { // Phobos
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
33 }
18
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
34
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
35 interface IDwtLogger {
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
36 void trace( String file, ulong line, String fmt, ... );
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
37 void info( String file, ulong line, String fmt, ... );
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
38 void warn( String file, ulong line, String fmt, ... );
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
39 void error( String file, ulong line, String fmt, ... );
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
40 void fatal( String file, ulong line, String fmt, ... );
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
41 }
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
42
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
43 version(Tango){
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
44 class DwtLogger : IDwtLogger {
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
45 tango.util.log.Log.Logger logger;
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
46 private this( char[] name ){
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
47 logger = tango.util.log.Log.Log.lookup( name );
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
48 }
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
49 private char[] format( String file, ulong line, String fmt, TypeInfo[] types, void* argptr ){
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
50 auto msg = Format.convert( types, argptr, fmt );
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
51 auto text = Format( "{} {}: {}", file, line, msg );
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
52 return text;
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
53 }
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
54 void trace( String file, ulong line, String fmt, ... ){
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
55 if( logger.trace ){
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
56 logger.trace( format( file, line, fmt, _arguments, _argptr ));
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
57 }
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
58 }
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
59 void info( String file, ulong line, String fmt, ... ){
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
60 if( logger.info ){
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
61 logger.info( format( file, line, fmt, _arguments, _argptr ));
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
62 }
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
63 }
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
64 void warn( String file, ulong line, String fmt, ... ){
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
65 if( logger.warn ){
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
66 logger.warn( format( file, line, fmt, _arguments, _argptr ));
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
67 }
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
68 }
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
69 void error( String file, ulong line, String fmt, ... ){
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
70 if( logger.error ){
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
71 logger.error( format( file, line, fmt, _arguments, _argptr ));
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
72 }
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
73 }
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
74 void fatal( String file, ulong line, String fmt, ... ){
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
75 if( logger.fatal ){
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
76 logger.fatal( format( file, line, fmt, _arguments, _argptr ));
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
77 }
18
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
78 }
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
79 }
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
80 } else { // Phobos
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
81 class DwtLogger : IDwtLogger {
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
82 private this( String name ){
18
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
83 }
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
84 void trace( String file, ulong line, String fmt, ... ){
44
ed96ea2a2764 First swt win snippets are buiding with d2+phobos
Frank Benoit <benoit@tionex.de>
parents: 39
diff changeset
85 std.stdio.writefln( "TRC %s %d: %s", file, line, fmt );
18
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
86 }
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
87 void info( String file, ulong line, String fmt, ... ){
44
ed96ea2a2764 First swt win snippets are buiding with d2+phobos
Frank Benoit <benoit@tionex.de>
parents: 39
diff changeset
88 std.stdio.writefln( "INF %s %d: %s", file, line, fmt );
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
89 }
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
90 void warn( String file, ulong line, String fmt, ... ){
44
ed96ea2a2764 First swt win snippets are buiding with d2+phobos
Frank Benoit <benoit@tionex.de>
parents: 39
diff changeset
91 std.stdio.writefln( "WRN %s %d: %s", file, line, fmt );
18
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
92 }
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
93 void error( String file, ulong line, String fmt, ... ){
44
ed96ea2a2764 First swt win snippets are buiding with d2+phobos
Frank Benoit <benoit@tionex.de>
parents: 39
diff changeset
94 std.stdio.writefln( "ERR %s %d: %s", file, line, fmt );
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
95 }
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
96 void fatal( String file, ulong line, String fmt, ... ){
44
ed96ea2a2764 First swt win snippets are buiding with d2+phobos
Frank Benoit <benoit@tionex.de>
parents: 39
diff changeset
97 std.stdio.writefln( "FAT %s %d: %s", file, line, fmt );
18
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
98 }
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
99 }
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
100 }
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
101
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
102 private DwtLogger dwtLoggerInstance;
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
103
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
104 IDwtLogger getDwtLogger(){
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
105 if( dwtLoggerInstance is null ){
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
106 synchronized{
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
107 if( dwtLoggerInstance is null ){
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
108 dwtLoggerInstance = new DwtLogger( "dwt" );
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
109 }
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
110 }
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
111 }
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
112 return dwtLoggerInstance;
0
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
113 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
114
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
115 void implMissing( String file, uint line ){
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
116 getDwtLogger().fatal( file, line, "implementation missing in file {} line {}", file, line );
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
117 getDwtLogger().fatal( file, line, "Please create a bug report at http://www.dsource.org/projects/dwt" );
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
118 getDwtLogger().fatal( file, line, "exiting ..." );
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
119 exit(1);
0
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
120 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
121
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
122 version(Tango){
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
123 public alias tango.text.convert.Format.Format Format;
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
124 } else { // Phobos
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
125 class Format{
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
126 static String opCall( String fmt, ... ){
112
9f4c18c268b2 Update to compile and execute with dmd 2.052.
kntroh
parents: 74
diff changeset
127 fmt = std.array.replace(fmt, "%", "%%");
9f4c18c268b2 Update to compile and execute with dmd 2.052.
kntroh
parents: 74
diff changeset
128 fmt = std.array.replace(fmt, "{}", "%s");
9f4c18c268b2 Update to compile and execute with dmd 2.052.
kntroh
parents: 74
diff changeset
129 char[] buf;
9f4c18c268b2 Update to compile and execute with dmd 2.052.
kntroh
parents: 74
diff changeset
130 void putc(dchar c) {
9f4c18c268b2 Update to compile and execute with dmd 2.052.
kntroh
parents: 74
diff changeset
131 if (c <= 0x7F) {
9f4c18c268b2 Update to compile and execute with dmd 2.052.
kntroh
parents: 74
diff changeset
132 buf ~= cast(char)c;
9f4c18c268b2 Update to compile and execute with dmd 2.052.
kntroh
parents: 74
diff changeset
133 } else {
9f4c18c268b2 Update to compile and execute with dmd 2.052.
kntroh
parents: 74
diff changeset
134 char[4] buf2;
9f4c18c268b2 Update to compile and execute with dmd 2.052.
kntroh
parents: 74
diff changeset
135 buf ~= std.utf.toUTF8(buf2, c);
9f4c18c268b2 Update to compile and execute with dmd 2.052.
kntroh
parents: 74
diff changeset
136 }
9f4c18c268b2 Update to compile and execute with dmd 2.052.
kntroh
parents: 74
diff changeset
137 }
9f4c18c268b2 Update to compile and execute with dmd 2.052.
kntroh
parents: 74
diff changeset
138 std.format.doFormat(&putc, _arguments, _argptr);
9f4c18c268b2 Update to compile and execute with dmd 2.052.
kntroh
parents: 74
diff changeset
139 return std.exception.assumeUnique(buf);
0
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
140 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
141 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
142 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
143
38
2e09b0e6857a work on phobosfication
Frank Benoit <benoit@tionex.de>
parents: 27
diff changeset
144 version( D_Version2 ){
112
9f4c18c268b2 Update to compile and execute with dmd 2.052.
kntroh
parents: 74
diff changeset
145 mixin("immutable(T)[] _idup(T)( T[] str ){ return str.idup; }");
38
2e09b0e6857a work on phobosfication
Frank Benoit <benoit@tionex.de>
parents: 27
diff changeset
146 } else { // D1
39
0ecb2b338560 further work on phobosification
Frank Benoit <benoit@tionex.de>
parents: 38
diff changeset
147 String16 _idup( String16 str ){
38
2e09b0e6857a work on phobosfication
Frank Benoit <benoit@tionex.de>
parents: 27
diff changeset
148 return str.dup;
2e09b0e6857a work on phobosfication
Frank Benoit <benoit@tionex.de>
parents: 27
diff changeset
149 }
39
0ecb2b338560 further work on phobosification
Frank Benoit <benoit@tionex.de>
parents: 38
diff changeset
150 String _idup( String str ){
38
2e09b0e6857a work on phobosfication
Frank Benoit <benoit@tionex.de>
parents: 27
diff changeset
151 return str.dup;
2e09b0e6857a work on phobosfication
Frank Benoit <benoit@tionex.de>
parents: 27
diff changeset
152 }
2e09b0e6857a work on phobosfication
Frank Benoit <benoit@tionex.de>
parents: 27
diff changeset
153 }
0
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
154
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
155 private struct GCStats {
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
156 size_t poolsize; // total size of pool
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
157 size_t usedsize; // bytes allocated
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
158 size_t freeblocks; // number of blocks marked FREE
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
159 size_t freelistsize; // total of memory on free lists
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
160 size_t pageblocks; // number of blocks marked PAGE
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
161 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
162 private extern(C) GCStats gc_stats();
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
163
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
164 size_t RuntimeTotalMemory(){
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
165 GCStats s = gc_stats();
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
166 return s.poolsize;
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
167 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
168
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
169
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
170 template arraycast(T) {
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
171 T[] arraycast(U) (U[] u) {
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
172 static if (
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
173 (is (T == interface ) && is (U == interface )) ||
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
174 (is (T == class ) && is (U == class ))) {
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
175 return(cast(T[])u);
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
176 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
177 else {
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
178 int l = u.length;
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
179 T[] res;
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
180 res.length = l;
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
181 for (int i = 0; i < l; i++) {
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
182 res[i] = cast(T)u[i];
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
183 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
184 return(res);
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
185 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
186 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
187 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
188
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
189
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
190 bool ArrayEquals(T)( T[] a, T[] b ){
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
191 if( a.length !is b.length ){
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
192 return false;
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
193 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
194 for( int i = 0; i < a.length; i++ ){
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
195 static if( is( T==class) || is(T==interface)){
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
196 if( a[i] !is null && b[i] !is null ){
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
197 if( a[i] != b[i] ){
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
198 return false;
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
199 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
200 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
201 else if( a[i] is null && b[i] is null ){
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
202 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
203 else{
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
204 return false;
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
205 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
206 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
207 else{
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
208 if( a[i] != b[i] ){
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
209 return false;
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
210 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
211 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
212 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
213 return true;
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
214 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
215
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
216 int arrayIndexOf(T)( T[] arr, T v ){
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
217 int res = -1;
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
218 int idx = 0;
113
fb3aa8075988 D2 support for the linux port.
Jacob Carlborg <doob@me.com>
parents: 112
diff changeset
219
fb3aa8075988 D2 support for the linux port.
Jacob Carlborg <doob@me.com>
parents: 112
diff changeset
220
fb3aa8075988 D2 support for the linux port.
Jacob Carlborg <doob@me.com>
parents: 112
diff changeset
221 static if (is(T == interface))
fb3aa8075988 D2 support for the linux port.
Jacob Carlborg <doob@me.com>
parents: 112
diff changeset
222 {
fb3aa8075988 D2 support for the linux port.
Jacob Carlborg <doob@me.com>
parents: 112
diff changeset
223 Object[] array = cast(Object[]) arr;
fb3aa8075988 D2 support for the linux port.
Jacob Carlborg <doob@me.com>
parents: 112
diff changeset
224 Object value = cast(Object) v;
fb3aa8075988 D2 support for the linux port.
Jacob Carlborg <doob@me.com>
parents: 112
diff changeset
225 }
fb3aa8075988 D2 support for the linux port.
Jacob Carlborg <doob@me.com>
parents: 112
diff changeset
226
fb3aa8075988 D2 support for the linux port.
Jacob Carlborg <doob@me.com>
parents: 112
diff changeset
227 else
fb3aa8075988 D2 support for the linux port.
Jacob Carlborg <doob@me.com>
parents: 112
diff changeset
228 {
fb3aa8075988 D2 support for the linux port.
Jacob Carlborg <doob@me.com>
parents: 112
diff changeset
229 auto array = arr;
fb3aa8075988 D2 support for the linux port.
Jacob Carlborg <doob@me.com>
parents: 112
diff changeset
230 auto value = v;
fb3aa8075988 D2 support for the linux port.
Jacob Carlborg <doob@me.com>
parents: 112
diff changeset
231 }
fb3aa8075988 D2 support for the linux port.
Jacob Carlborg <doob@me.com>
parents: 112
diff changeset
232
fb3aa8075988 D2 support for the linux port.
Jacob Carlborg <doob@me.com>
parents: 112
diff changeset
233 foreach( p; array ){
fb3aa8075988 D2 support for the linux port.
Jacob Carlborg <doob@me.com>
parents: 112
diff changeset
234 if( p == value){
0
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
235 res = idx;
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
236 break;
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
237 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
238 idx++;
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
239 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
240 return res;
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
241 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
242
25
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents: 21
diff changeset
243 T[] arrayIndexRemove(T)(T[] arr, uint n) {
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents: 21
diff changeset
244 if (n is 0)
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents: 21
diff changeset
245 return arr[1..$];
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents: 21
diff changeset
246 if (n > arr.length)
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents: 21
diff changeset
247 return arr;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents: 21
diff changeset
248 if (n is arr.length-1)
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents: 21
diff changeset
249 return arr[0..n-1];
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents: 21
diff changeset
250 // else
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents: 21
diff changeset
251 return arr[0..n] ~ arr[n+1..$];
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents: 21
diff changeset
252 }
0
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
253
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
254 struct ImportData{
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
255 void[] data;
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
256 String name;
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
257
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
258 public static ImportData opCall( void[] data, String name ){
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
259 ImportData res;
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
260 res.data = data;
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
261 res.name = name;
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
262 return res;
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
263 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
264 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
265
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
266 template getImportData(String name ){
38
2e09b0e6857a work on phobosfication
Frank Benoit <benoit@tionex.de>
parents: 27
diff changeset
267 const ImportData getImportData = ImportData( cast(void[]) import(name), name );
0
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
268 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
269
113
fb3aa8075988 D2 support for the linux port.
Jacob Carlborg <doob@me.com>
parents: 112
diff changeset
270 template gshared (String content)
fb3aa8075988 D2 support for the linux port.
Jacob Carlborg <doob@me.com>
parents: 112
diff changeset
271 {
fb3aa8075988 D2 support for the linux port.
Jacob Carlborg <doob@me.com>
parents: 112
diff changeset
272 version (D_Version2)
fb3aa8075988 D2 support for the linux port.
Jacob Carlborg <doob@me.com>
parents: 112
diff changeset
273 const gshared = "__gshared: " ~ content;
fb3aa8075988 D2 support for the linux port.
Jacob Carlborg <doob@me.com>
parents: 112
diff changeset
274
fb3aa8075988 D2 support for the linux port.
Jacob Carlborg <doob@me.com>
parents: 112
diff changeset
275 else
fb3aa8075988 D2 support for the linux port.
Jacob Carlborg <doob@me.com>
parents: 112
diff changeset
276 const gshared = content;
fb3aa8075988 D2 support for the linux port.
Jacob Carlborg <doob@me.com>
parents: 112
diff changeset
277 }