 |
Changeset 24
- Timestamp:
- 06/01/06 22:35:25
(3 years ago)
- Author:
- sean
- Message:
Merged in latest Ares changes.
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r16 |
r24 |
|
| 35 | 35 | * This module is the first attempt at developing function interface guidelines |
|---|
| 36 | 36 | * for Ares. All functions will likely be templates and will be designed with |
|---|
| 37 | | * implicit tempalte instantiation and template overloading as required features. |
|---|
| | 37 | * implicit template instantiation and template overloading as required features. |
|---|
| 38 | 38 | * The goal here is to provide a useful set of string routines for everyday use |
|---|
| 39 | 39 | * and to use this experience for developing more generalized algorithms later on. |
|---|
| r16 |
r24 |
|
| 41 | 41 | private |
|---|
| 42 | 42 | { |
|---|
| 43 | | import tango.stdc.stdio; |
|---|
| 44 | | import tango.stdc.stdlib; |
|---|
| | 43 | import tango.stdc.stddef; |
|---|
| 45 | 44 | } |
|---|
| 46 | 45 | |
|---|
| … | … | |
| 191 | 190 | * line = The line number on which this error occurred. |
|---|
| 192 | 191 | */ |
|---|
| 193 | | extern (C) void onAssertError( char[] file, uint line ) |
|---|
| 194 | | { |
|---|
| 195 | | if( !assertHandler ) |
|---|
| 196 | | throw new AssertException( file, line ); |
|---|
| 197 | | assertHandler( file, line ); |
|---|
| 198 | | } |
|---|
| | 192 | extern (C) void onAssertError( char[] file, uint line ); |
|---|
| 199 | 193 | |
|---|
| 200 | 194 | |
|---|
| … | … | |
| 211 | 205 | * Default behavior is to return true. |
|---|
| 212 | 206 | */ |
|---|
| 213 | | extern (C) bool onCollectResource( Object obj ) |
|---|
| 214 | | { |
|---|
| 215 | | if( !collectHandler ) |
|---|
| 216 | | return true; |
|---|
| 217 | | return collectHandler( obj ); |
|---|
| 218 | | } |
|---|
| | 207 | extern (C) bool onCollectResource( Object obj ); |
|---|
| 219 | 208 | |
|---|
| 220 | 209 | |
|---|
| … | … | |
| 235 | 224 | * ArrayBoundsException. |
|---|
| 236 | 225 | */ |
|---|
| 237 | | extern (C) void onArrayBoundsError( char[] file, size_t line ) |
|---|
| 238 | | { |
|---|
| 239 | | throw new ArrayBoundsException( file, line ); |
|---|
| 240 | | } |
|---|
| | 226 | extern (C) void onArrayBoundsError( char[] file, size_t line ); |
|---|
| 241 | 227 | |
|---|
| 242 | 228 | |
|---|
| … | … | |
| 250 | 236 | * FinalizeException. |
|---|
| 251 | 237 | */ |
|---|
| 252 | | extern (C) void onFinalizeError( ClassInfo info, Exception ex ) |
|---|
| 253 | | { |
|---|
| 254 | | throw new FinalizeException( info, ex ); |
|---|
| 255 | | } |
|---|
| | 238 | extern (C) void onFinalizeError( ClassInfo info, Exception ex ); |
|---|
| 256 | 239 | |
|---|
| 257 | 240 | |
|---|
| … | … | |
| 263 | 246 | * OutOfMemoryException. |
|---|
| 264 | 247 | */ |
|---|
| 265 | | extern (C) void onOutOfMemoryError() |
|---|
| 266 | | { |
|---|
| 267 | | // NOTE: Since an out of memory condition exists, no allocation must occur |
|---|
| 268 | | // while generating this object. |
|---|
| 269 | | throw cast(OutOfMemoryException) cast(void*) OutOfMemoryException.classinfo.init; |
|---|
| 270 | | } |
|---|
| | 248 | extern (C) void onOutOfMemoryError(); |
|---|
| 271 | 249 | |
|---|
| 272 | 250 | |
|---|
| … | … | |
| 281 | 259 | * SwitchException. |
|---|
| 282 | 260 | */ |
|---|
| 283 | | extern (C) void onSwitchError( char[] file, size_t line ) |
|---|
| 284 | | { |
|---|
| 285 | | throw new SwitchException( file, line ); |
|---|
| 286 | | } |
|---|
| | 261 | extern (C) void onSwitchError( char[] file, size_t line ); |
|---|
| 287 | 262 | |
|---|
| 288 | 263 | |
|---|
| … | … | |
| 297 | 272 | * UnicodeException. |
|---|
| 298 | 273 | */ |
|---|
| 299 | | extern (C) void onUnicodeError( char[] msg, size_t idx ) |
|---|
| 300 | | { |
|---|
| 301 | | throw new UnicodeException( msg, idx ); |
|---|
| 302 | | } |
|---|
| | 274 | extern (C) void onUnicodeError( char[] msg, size_t idx ); |
|---|
| r16 |
r24 |
|
| 1 | | // Copyright (c) 1999-2003 by Digital Mars |
|---|
| 2 | | // All Rights Reserved |
|---|
| 3 | | // written by Walter Bright |
|---|
| 4 | | // www.digitalmars.com |
|---|
| 5 | | // |
|---|
| 6 | | // Documentation written by Sean Kelly <sean@f4.ca> |
|---|
| 7 | | |
|---|
| 8 | 1 | /** |
|---|
| 9 | | * This module contains functions that the compiler is intended to replace |
|---|
| 10 | | * with optimized assembler code at compile-time. While the instructions |
|---|
| 11 | | * provided are based on instructions outlined in the IA-32 spec, it should |
|---|
| 12 | | * be easy to emulate such functionality on other architectures, provided |
|---|
| 13 | | * there is no directly equivalent function available. |
|---|
| | 2 | * These functions are built-in intrinsics to the compiler. |
|---|
| | 3 | * |
|---|
| | 4 | * Intrinsic functions are functions built in to the compiler, usually to take |
|---|
| | 5 | * advantage of specific CPU features that are inefficient to handle via |
|---|
| | 6 | * external functions. The compiler's optimizer and code generator are fully |
|---|
| | 7 | * integrated in with intrinsic functions, bringing to bear their full power on |
|---|
| | 8 | * them. This can result in some surprising speedups. |
|---|
| | 9 | * |
|---|
| | 10 | * Authors: Walter Bright |
|---|
| | 11 | * Copyright: Public Domain |
|---|
| | 12 | * License: See about.d |
|---|
| 14 | 13 | */ |
|---|
| 15 | 14 | module tango.core.intrinsic; |
|---|
| … | … | |
| 17 | 16 | |
|---|
| 18 | 17 | /** |
|---|
| 19 | | * |
|---|
| | 18 | * Scans the bits in v starting with bit 0, looking |
|---|
| | 19 | * for the first set bit. |
|---|
| | 20 | * Returns: |
|---|
| | 21 | * The bit number of the first bit set. |
|---|
| | 22 | * The return value is undefined if v is zero. |
|---|
| 20 | 23 | */ |
|---|
| 21 | 24 | int bsf( uint v ); |
|---|
| … | … | |
| 23 | 26 | |
|---|
| 24 | 27 | /** |
|---|
| | 28 | * Scans the bits in v from the most significant bit |
|---|
| | 29 | * to the least significant bit, looking |
|---|
| | 30 | * for the first set bit. |
|---|
| | 31 | * Returns: |
|---|
| | 32 | * The bit number of the first bit set. |
|---|
| | 33 | * The return value is undefined if v is zero. |
|---|
| | 34 | * Example: |
|---|
| | 35 | * --- |
|---|
| | 36 | * import std.intrinsic; |
|---|
| 25 | 37 | * |
|---|
| | 38 | * int main() |
|---|
| | 39 | * { |
|---|
| | 40 | * uint v; |
|---|
| | 41 | * int x; |
|---|
| | 42 | * |
|---|
| | 43 | * v = 0x21; |
|---|
| | 44 | * x = bsf(v); |
|---|
| | 45 | * printf("bsf(x%x) = %d\n", v, x); |
|---|
| | 46 | * x = bsr(v); |
|---|
| | 47 | * printf("bsr(x%x) = %d\n", v, x); |
|---|
| | 48 | * return 0; |
|---|
| | 49 | * } |
|---|
| | 50 | * --- |
|---|
| | 51 | * Output: |
|---|
| | 52 | * bsf(x21) = 0<br> |
|---|
| | 53 | * bsr(x21) = 5 |
|---|
| 26 | 54 | */ |
|---|
| 27 | 55 | int bsr( uint v ); |
|---|
| … | … | |
| 29 | 57 | |
|---|
| 30 | 58 | /** |
|---|
| 31 | | * |
|---|
| | 59 | * Tests the bit. |
|---|
| 32 | 60 | */ |
|---|
| 33 | 61 | int bt( uint* p, uint bitnum ); |
|---|
| … | … | |
| 35 | 63 | |
|---|
| 36 | 64 | /** |
|---|
| 37 | | * |
|---|
| | 65 | * Tests and complements the bit. |
|---|
| 38 | 66 | */ |
|---|
| 39 | 67 | int btc( uint* p, uint bitnum ); |
|---|
| … | … | |
| 41 | 69 | |
|---|
| 42 | 70 | /** |
|---|
| 43 | | * |
|---|
| | 71 | * Tests and resets (sets to 0) the bit. |
|---|
| 44 | 72 | */ |
|---|
| 45 | 73 | int btr( uint* p, uint bitnum ); |
|---|
| … | … | |
| 47 | 75 | |
|---|
| 48 | 76 | /** |
|---|
| | 77 | * Tests and sets the bit. |
|---|
| | 78 | * Params: |
|---|
| | 79 | * p = a non-NULL pointer to an array of uints. |
|---|
| | 80 | * index = a bit number, starting with bit 0 of p[0], |
|---|
| | 81 | * and progressing. It addresses bits like the expression: |
|---|
| | 82 | --- |
|---|
| | 83 | p[index / (uint.sizeof*8)] & (1 << (index & ((uint.sizeof*8) - 1))) |
|---|
| | 84 | --- |
|---|
| | 85 | * Returns: |
|---|
| | 86 | * A non-zero value if the bit was set, and a zero |
|---|
| | 87 | * if it was clear. |
|---|
| 49 | 88 | * |
|---|
| | 89 | * Example: |
|---|
| | 90 | * --- |
|---|
| | 91 | import std.intrinsic; |
|---|
| | 92 | |
|---|
| | 93 | int main() |
|---|
| | 94 | { |
|---|
| | 95 | uint array[2]; |
|---|
| | 96 | |
|---|
| | 97 | array[0] = 2; |
|---|
| | 98 | array[1] = 0x100; |
|---|
| | 99 | |
|---|
| | 100 | printf("btc(array, 35) = %d\n", <b>btc</b>(array, 35)); |
|---|
| | 101 | printf("array = [0]:x%x, [1]:x%x\n", array[0], array[1]); |
|---|
| | 102 | |
|---|
| | 103 | printf("btc(array, 35) = %d\n", <b>btc</b>(array, 35)); |
|---|
| | 104 | printf("array = [0]:x%x, [1]:x%x\n", array[0], array[1]); |
|---|
| | 105 | |
|---|
| | 106 | printf("bts(array, 35) = %d\n", <b>bts</b>(array, 35)); |
|---|
| | 107 | printf("array = [0]:x%x, [1]:x%x\n", array[0], array[1]); |
|---|
| | 108 | |
|---|
| | 109 | printf("btr(array, 35) = %d\n", <b>btr</b>(array, 35)); |
|---|
| | 110 | printf("array = [0]:x%x, [1]:x%x\n", array[0], array[1]); |
|---|
| | 111 | |
|---|
| | 112 | printf("bt(array, 1) = %d\n", <b>bt</b>(array, 1)); |
|---|
| | 113 | printf("array = [0]:x%x, [1]:x%x\n", array[0], array[1]); |
|---|
| | 114 | |
|---|
| | 115 | return 0; |
|---|
| | 116 | } |
|---|
| | 117 | * --- |
|---|
| | 118 | * Output: |
|---|
| | 119 | <pre> |
|---|
| | 120 | btc(array, 35) = 0 |
|---|
| | 121 | array = [0]:x2, [1]:x108 |
|---|
| | 122 | btc(array, 35) = -1 |
|---|
| | 123 | array = [0]:x2, [1]:x100 |
|---|
| | 124 | bts(array, 35) = 0 |
|---|
| | 125 | array = [0]:x2, [1]:x108 |
|---|
| | 126 | btr(array, 35) = -1 |
|---|
| | 127 | array = [0]:x2, [1]:x100 |
|---|
| | 128 | bt(array, 1) = -1 |
|---|
| | 129 | array = [0]:x2, [1]:x100 |
|---|
| | 130 | </pre> |
|---|
| 50 | 131 | */ |
|---|
| 51 | 132 | int bts( uint* p, uint bitnum ); |
|---|
| … | … | |
| 53 | 134 | |
|---|
| 54 | 135 | /** |
|---|
| 55 | | * |
|---|
| | 136 | * Swaps bytes in a 4 byte uint end-to-end, i.e. byte 0 becomes |
|---|
| | 137 | * byte 3, byte 1 becomes byte 2, byte 2 becomes byte 1, byte 3 |
|---|
| | 138 | * becomes byte 0. |
|---|
| 56 | 139 | */ |
|---|
| 57 | 140 | uint bswap( uint v ); |
|---|
| … | … | |
| 59 | 142 | |
|---|
| 60 | 143 | /** |
|---|
| 61 | | * |
|---|
| | 144 | * Reads I/O port at port_address. |
|---|
| 62 | 145 | */ |
|---|
| 63 | | ubyte inp( uint ); |
|---|
| | 146 | ubyte inp(uint port_address); |
|---|
| 64 | 147 | |
|---|
| 65 | 148 | |
|---|
| 66 | 149 | /** |
|---|
| 67 | | * |
|---|
| | 150 | * ditto |
|---|
| 68 | 151 | */ |
|---|
| 69 | | ushort inpw( uint ); |
|---|
| 70 | | |
|---|
| | 152 | ushort inpw(uint port_address); |
|---|
| 71 | 153 | |
|---|
| 72 | 154 | |
|---|
| 73 | 155 | /** |
|---|
| 74 | | * |
|---|
| | 156 | * ditto |
|---|
| 75 | 157 | */ |
|---|
| 76 | | uint inpl( uint ); |
|---|
| | 158 | uint inpl(uint port_address); |
|---|
| 77 | 159 | |
|---|
| 78 | 160 | |
|---|
| 79 | 161 | /** |
|---|
| 80 | | * |
|---|
| | 162 | * Writes and returns value to I/O port at port_address. |
|---|
| 81 | 163 | */ |
|---|
| 82 | | ubyte outp( uint, ubyte ); |
|---|
| | 164 | ubyte outp(uint port_address, ubyte value); |
|---|
| 83 | 165 | |
|---|
| 84 | 166 | |
|---|
| 85 | 167 | /** |
|---|
| 86 | | * |
|---|
| | 168 | * ditto |
|---|
| 87 | 169 | */ |
|---|
| 88 | | ushort outpw( uint, ushort ); |
|---|
| | 170 | ushort outpw(uint port_address, ushort value); |
|---|
| 89 | 171 | |
|---|
| 90 | 172 | |
|---|
| 91 | 173 | /** |
|---|
| 92 | | * |
|---|
| | 174 | * ditto |
|---|
| 93 | 175 | */ |
|---|
| 94 | | uint outpl( uint, uint ); |
|---|
| | 176 | uint outpl(uint port_address, uint value); |
|---|
| r16 |
r24 |
|
| 173 | 173 | * otherwise expected to later reclaim the memory block if it is unused. |
|---|
| 174 | 174 | * If allocation fails, this function will call onOutOfMemory which is |
|---|
| 175 | | * expected to throw an OutOfMemoryException. |
|---|
| | 175 | * expected to throw an OutOfMemoryException. If p references memory not |
|---|
| | 176 | * originally allocated by this garbage collector, or if it points to the |
|---|
| | 177 | * interior of a memory block, no action will be taken. |
|---|
| 176 | 178 | * |
|---|
| 177 | 179 | * Params: |
|---|
| … | … | |
| 197 | 199 | * occurs. If p references memory not originally allocated by this |
|---|
| 198 | 200 | * garbage collector, or if it points to the interior of a memory block, |
|---|
| 199 | | * the result is undefined. |
|---|
| | 201 | * no action will be taken. |
|---|
| 200 | 202 | * |
|---|
| 201 | 203 | * Params: |
|---|
| r16 |
r24 |
|
| 74 | 74 | is( T == class ) || |
|---|
| 75 | 75 | is( T == interface ) || |
|---|
| 76 | | is( T == function ) || isFunctionType!( T ) || |
|---|
| | 76 | isFunctionPointerType!( T ) || |
|---|
| 77 | 77 | is( T == delegate ); |
|---|
| 78 | 78 | } |
|---|
| … | … | |
| 84 | 84 | template isCallableType( T ) |
|---|
| 85 | 85 | { |
|---|
| 86 | | const bool isCallableType = is( T == function ) || isFunctionType!( T ) || |
|---|
| | 86 | const bool isCallableType = is( T == function ) || isFunctionPointerType!( T ) || |
|---|
| 87 | 87 | is( T == delegate ) || |
|---|
| 88 | 88 | is( typeof(T.opCall) == function ); |
|---|
| … | … | |
| 91 | 91 | |
|---|
| 92 | 92 | // |
|---|
| 93 | | // NOTE: This template is a hack to replace is(T==function) since it's broken. |
|---|
| | 93 | // NOTE: This template is a hack to use in place of "is(T==function)" since |
|---|
| | 94 | // it actually detects a function alias, not a function pointer. |
|---|
| 94 | 95 | // |
|---|
| 95 | | private template isFunctionType( T ) |
|---|
| | 96 | private template isFunctionPointerType( T ) |
|---|
| 96 | 97 | { |
|---|
| 97 | | const bool isFunctionType = mangleString!(T).length > 2 && |
|---|
| 98 | | mangleString!(T)[0] == 'P' && |
|---|
| 99 | | mangleString!(T)[1] == 'F'; |
|---|
| | 98 | const bool isFunctionPointerType = T.mangleof.length > 2 && |
|---|
| | 99 | T.mangleof[0] == 'P' && |
|---|
| | 100 | T.mangleof[1] == 'F'; |
|---|
| 100 | 101 | } |
|---|
| 101 | | |
|---|
| 102 | | |
|---|
| 103 | | // |
|---|
| 104 | | // NOTE: Yet another workaround for a compiler bug. |
|---|
| 105 | | // |
|---|
| 106 | | private template mangleString( T ) |
|---|
| 107 | | { |
|---|
| 108 | | const char[] mangleString = T.mangleof; |
|---|
| 109 | | } |
|---|
| r16 |
r24 |
|
| 34 | 34 | |
|---|
| 35 | 35 | History: Initial version; Oct 2004 |
|---|
| 36 | | History: Moved to tango.convert; Nov 2005 |
|---|
| | 36 | History: Moved to mango.convert; Nov 2005 |
|---|
| 37 | 37 | |
|---|
| 38 | 38 | Authors: Kris |
|---|
| r16 |
r24 |
|
| 8 | 8 | /** |
|---|
| 9 | 9 | * The vararg module is intended to facilitate vararg manipulation in D. |
|---|
| 10 | | * It should be interface compatible with the C module of the same name, |
|---|
| 11 | | * and the two modules may share a common implementation if possible |
|---|
| 12 | | * (as is done here). |
|---|
| | 10 | * It should be interface compatible with the C module "stdarg," and the |
|---|
| | 11 | * two modules may share a common implementation if possible (as is done |
|---|
| | 12 | * here). |
|---|
| 13 | 13 | */ |
|---|
| 14 | 14 | module tango.core.vararg; |
|---|
Download in other formats:
|
 |