annotate base/src/java/lang/util.d @ 38:2e09b0e6857a

work on phobosfication
author Frank Benoit <benoit@tionex.de>
date Wed, 25 Mar 2009 11:18:25 +0100
parents 1bf55a6eb092
children 0ecb2b338560
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;
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
11 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
12
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
13 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
14 } else { // Phobos
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
15 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
16 static import std.c.stdlib;
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
17 alias std.c.stdlib.exit exit;
0
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
18 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
19
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
20 version(Tango){
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
21 } else { // Phobos
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
22 }
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
23 version(Tango){
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
24 } else { // Phobos
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
25 }
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
26 version(Tango){
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
27 } else { // Phobos
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
28 }
18
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
29
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
30 interface IDwtLogger {
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
31 void trace( String file, ulong line, String fmt, ... );
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
32 void info( String file, ulong line, String fmt, ... );
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
33 void warn( String file, ulong line, String fmt, ... );
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
34 void error( String file, ulong line, String fmt, ... );
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
35 void fatal( String file, ulong line, String fmt, ... );
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
36 }
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
37
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
38 version(Tango){
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
39 class DwtLogger : IDwtLogger {
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
40 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
41 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
42 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
43 }
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
44 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
45 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
46 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
47 return text;
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 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
50 if( logger.trace ){
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
51 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
52 }
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 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
55 if( logger.info ){
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
56 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
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 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
60 if( logger.warn ){
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
61 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
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 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
65 if( logger.error ){
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
66 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
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 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
70 if( logger.fatal ){
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
71 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
72 }
18
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
73 }
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
74 }
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
75 } else { // Phobos
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
76 class DwtLogger : IDwtLogger {
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
77 private this( String name ){
18
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
78 }
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
79 void trace( String file, ulong line, String fmt, ... ){
18
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
80 }
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
81 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
82 }
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
83 void warn( String file, ulong line, String fmt, ... ){
18
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
84 }
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
85 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
86 }
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
87 void fatal( String file, ulong line, String fmt, ... ){
18
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
88 }
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
89 }
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
90 }
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
91
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
92 private DwtLogger dwtLoggerInstance;
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
93
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
94 IDwtLogger getDwtLogger(){
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
95 if( dwtLoggerInstance is null ){
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
96 synchronized{
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
97 if( dwtLoggerInstance is null ){
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
98 dwtLoggerInstance = new DwtLogger( "dwt" );
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 return dwtLoggerInstance;
0
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
103 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
104
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
105 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
106 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
107 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
108 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
109 exit(1);
0
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
110 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
111
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
112 version(Tango){
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
113 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
114 } else { // Phobos
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
115 class Format{
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
116 static String opCall( String fmt, ... ){
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
117 implMissing(__FILE__,__LINE__);
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
118 return null;
0
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
119 }
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 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
122
38
2e09b0e6857a work on phobosfication
Frank Benoit <benoit@tionex.de>
parents: 27
diff changeset
123 version( D_Version2 ){
2e09b0e6857a work on phobosfication
Frank Benoit <benoit@tionex.de>
parents: 27
diff changeset
124 } else { // D1
2e09b0e6857a work on phobosfication
Frank Benoit <benoit@tionex.de>
parents: 27
diff changeset
125 String16 idup( String16 str ){
2e09b0e6857a work on phobosfication
Frank Benoit <benoit@tionex.de>
parents: 27
diff changeset
126 return str.dup;
2e09b0e6857a work on phobosfication
Frank Benoit <benoit@tionex.de>
parents: 27
diff changeset
127 }
2e09b0e6857a work on phobosfication
Frank Benoit <benoit@tionex.de>
parents: 27
diff changeset
128 String idup( String str ){
2e09b0e6857a work on phobosfication
Frank Benoit <benoit@tionex.de>
parents: 27
diff changeset
129 return str.dup;
2e09b0e6857a work on phobosfication
Frank Benoit <benoit@tionex.de>
parents: 27
diff changeset
130 }
2e09b0e6857a work on phobosfication
Frank Benoit <benoit@tionex.de>
parents: 27
diff changeset
131 }
0
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
132
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
133 private struct GCStats {
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
134 size_t poolsize; // total size of pool
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
135 size_t usedsize; // bytes allocated
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
136 size_t freeblocks; // number of blocks marked FREE
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
137 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
138 size_t pageblocks; // number of blocks marked PAGE
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
139 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
140 private extern(C) GCStats gc_stats();
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 size_t RuntimeTotalMemory(){
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
143 GCStats s = gc_stats();
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
144 return s.poolsize;
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
145 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
146
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
147
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
148 template arraycast(T) {
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
149 T[] arraycast(U) (U[] u) {
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
150 static if (
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
151 (is (T == interface ) && is (U == interface )) ||
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
152 (is (T == class ) && is (U == class ))) {
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
153 return(cast(T[])u);
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 else {
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
156 int l = u.length;
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
157 T[] res;
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
158 res.length = l;
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
159 for (int i = 0; i < l; i++) {
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
160 res[i] = cast(T)u[i];
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 return(res);
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 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
165 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
166
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 bool ArrayEquals(T)( T[] a, T[] b ){
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
169 if( a.length !is b.length ){
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
170 return false;
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
171 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
172 for( int i = 0; i < a.length; i++ ){
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
173 static if( is( T==class) || is(T==interface)){
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
174 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
175 if( a[i] != b[i] ){
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
176 return false;
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
177 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
178 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
179 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
180 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
181 else{
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
182 return false;
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 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
185 else{
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
186 if( a[i] != b[i] ){
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
187 return false;
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 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
191 return true;
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
192 }
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 int arrayIndexOf(T)( T[] arr, T v ){
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
195 int res = -1;
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
196 int idx = 0;
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
197 foreach( p; arr ){
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
198 if( p == v){
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
199 res = idx;
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
200 break;
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
201 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
202 idx++;
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
203 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
204 return res;
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
25
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents: 21
diff changeset
207 T[] arrayIndexRemove(T)(T[] arr, uint n) {
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents: 21
diff changeset
208 if (n is 0)
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents: 21
diff changeset
209 return arr[1..$];
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents: 21
diff changeset
210 if (n > arr.length)
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents: 21
diff changeset
211 return arr;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents: 21
diff changeset
212 if (n is arr.length-1)
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents: 21
diff changeset
213 return arr[0..n-1];
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents: 21
diff changeset
214 // else
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents: 21
diff changeset
215 return arr[0..n] ~ arr[n+1..$];
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents: 21
diff changeset
216 }
0
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
217
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
218 struct ImportData{
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
219 void[] data;
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
220 String name;
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
221
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
222 public static ImportData opCall( void[] data, String name ){
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
223 ImportData res;
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
224 res.data = data;
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
225 res.name = name;
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
226 return res;
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
227 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
228 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
229
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
230 template getImportData(String name ){
38
2e09b0e6857a work on phobosfication
Frank Benoit <benoit@tionex.de>
parents: 27
diff changeset
231 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
232 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
233
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
234