Created separate tests directory for D1.

This commit is contained in:
David Nadlinger
2012-08-29 11:16:42 +02:00
parent 837ef30fec
commit 1645eff596
27 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,51 @@
# Copied from tango runtime makefile.
# Designed to work with GNU make
# Targets:
# make
# Same as make all
# make lib
# Build the common library
# make doc
# Generate documentation
# make clean
# Delete unneeded files created by build process
LIB_TARGET=libtangobos-partial.a
LIB_MASK=libtangobos-partial.*
CP=cp -f
RM=rm -f
MD=mkdir -p
ADD_CFLAGS=
ADD_DFLAGS=
#CFLAGS=-O3 $(ADD_CFLAGS)
CFLAGS=-g $(ADD_CFLAGS)
#DFLAGS=-release -O3 -inline -w $(ADD_DFLAGS)
DFLAGS=-g -w -noasm $(ADD_DFLAGS)
DC=ldc
targets : lib
all : lib
lib : tangobos.lib
SOURCE= \
std/gc.d \
std/outofmemory.d \
std/IEEE.d \
std/stdarg.d \
# std/asserterror.d \
# std/format.d \
tangobos.lib : $(LIB_TARGET)
$(LIB_TARGET) : $(ALL_OBJS)
$(DC) -lib -of$(LIB_TARGET) $(DFLAGS) $(SOURCE)
clean :
$(RM) $(ALL_OBJS)
find . -name "$(LIB_MASK)" | xargs $(RM)

View File

@@ -0,0 +1,313 @@
// A copy of the object.di from Tango, with std.compat publically included to
// to make sure the Phobos compatibilty aliases are always available (DStress
// depends on Phobos).
module object;
public import std.compat;
/// unsigned integer type of the size of a pointer
alias typeof(int.sizeof) size_t;
/// signed integer type of the size of a pointer
alias typeof(cast(void*)0 - cast(void*)0) ptrdiff_t;
/// type of hashes used in associative arrays
alias size_t hash_t;
/// type returned by equality comparisons
alias int equals_t;
/// root class for all objects in D
class Object
{
void dispose();
/// returns a string representation of the object (for debugging purposes)
char[] toString();
/// returns a hash
hash_t toHash();
/// compares two objects, returns a number ret, such (a op b) is rewritten as (a.opCmp(b) op 0)
/// thus if a>b a.opCmp(b)>0
int opCmp(Object o);
/// returns 0 if this==o
equals_t opEquals(Object o);
interface Monitor
{
void lock();
void unlock();
}
}
/// interface, if COM objects (IUnknown) they might not be casted to Object
struct Interface
{
/// class info of the interface
ClassInfo classinfo;
void*[] vtbl;
/// offset to Interface 'this' from Object 'this'
ptrdiff_t offset;
}
struct PointerMap
{
// Conservative pointer mask (one word, scan it, we don't know if it's
// really a pointer)
size_t[] bits = [1, 1, 0];
size_t size();
bool mustScanWordAt(size_t offset);
bool isPointerAt(size_t offset);
bool canUpdatePointers();
}
struct PointerMapBuilder
{
private size_t[] m_bits = null;
private size_t m_size = 0;
void size(size_t bytes);
void mustScanWordAt(size_t offset);
void inlineAt(size_t offset, PointerMap pm);
PointerMap convertToPointerMap();
}
/// class information
class ClassInfo : Object
{
byte[] init; // class static initializer
char[] name; /// class name
void*[] vtbl; // virtual function pointer table
Interface[] interfaces; /// implemented interfaces
ClassInfo base; /// base class
void* destructor; /// compiler dependent storage of destructor function pointer
void* classInvariant; /// compiler dependent storage of classInvariant function pointer
/// flags
/// 1: IUnknown
/// 2: has no possible pointers into GC memory
/// 4: has offTi[] member
/// 8: has constructors
// 32: has typeinfo
uint flags;
void* deallocator;
OffsetTypeInfo[] offTi; /// offsets of its members (not supported by all compilers)
void* defaultConstructor; /// compiler dependent storage of constructor function pointer
/// TypeInfo information about this class
TypeInfo typeinfo;
version (D_HavePointerMap) {
PointerMap pointermap;
}
/// finds the classinfo of the class with the given name
static ClassInfo find(char[] classname);
/// creates an instance of this class (works only if there is a constructor without arguments)
Object create();
}
/// offset of the different fields (at the moment works only with ldc)
struct OffsetTypeInfo
{
size_t offset;
TypeInfo ti;
}
/// information on a type
class TypeInfo
{
/// returns the hash of the type of this TypeInfo at p
hash_t getHash(void *p);
/// returns 0 if the types of this TypeInfo stored at p1 and p2 are different
equals_t equals(void *p1, void *p2);
/// compares the types of this TypeInfo stored at p1 and p2
int compare(void *p1, void *p2);
/// returns the size of a type with the current TypeInfo
size_t tsize();
/// swaps the two types stored at p1 and p2
void swap(void *p1, void *p2);
/// "next" TypeInfo (for an array its elements, for a pointer what it is pointed to,...)
TypeInfo next();
void[] init();
/// flags, 1: has possible pointers into GC memory
uint flags();
PointerMap pointermap();
/// offsets of the various elements
OffsetTypeInfo[] offTi();
}
class TypeInfo_Typedef : TypeInfo
{
TypeInfo base;
char[] name;
void[] m_init;
}
class TypeInfo_Enum : TypeInfo_Typedef
{
}
class TypeInfo_Pointer : TypeInfo
{
TypeInfo m_next;
}
class TypeInfo_Array : TypeInfo
{
/// typeinfo of the elements, might be null for basic arrays, it is safer to use next()
TypeInfo value;
//ensure derived array TypeInfos use correct method
//if this declaration is forgotten, e.g. TypeInfo_Ai will have a wrong vtbl entry
PointerMap pointermap();
}
class TypeInfo_StaticArray : TypeInfo
{
TypeInfo value;
size_t len;
}
class TypeInfo_AssociativeArray : TypeInfo
{
TypeInfo value;
TypeInfo key;
}
class TypeInfo_Function : TypeInfo
{
TypeInfo next;
}
class TypeInfo_Delegate : TypeInfo
{
TypeInfo next;
}
class TypeInfo_Class : TypeInfo
{
ClassInfo info;
}
class TypeInfo_Interface : TypeInfo
{
ClassInfo info;
}
class TypeInfo_Struct : TypeInfo
{
char[] name;
void[] m_init;
hash_t function() xtoHash;
int function(void*) xopEquals;
int function(void*) xopCmp;
char[] function() xtoString;
uint m_flags;
version (D_HavePointerMap) {
PointerMap m_pointermap;
}
}
class TypeInfo_Tuple : TypeInfo
{
TypeInfo[] elements;
}
/// information about a module (can be used for example to get its unittests)
class ModuleInfo
{
/// name of the module
char[] name;
///
ModuleInfo[] importedModules;
///
ClassInfo[] localClasses;
uint flags;
void function() ctor;
void function() dtor;
/// unit tests of the module
void function() unitTest;
version(GNU){}
else{
void* xgetMembers;
void function() ictor;
}
/// loops on all the modules loaded
static int opApply( int delegate( ref ModuleInfo ) );
}
/// base class for all exceptions/errors
/// it is a good practice to pass line and file to the exception, which can be obtained with
/// __FILE__ and __LINE__, and then passed to the exception constructor
class Exception : Object
{
/// Information about a frame in the stack
struct FrameInfo{
/// line number in the source of the most likely start adress (0 if not available)
long line;
/// number of the stack frame (starting at 0 for the top frame)
ptrdiff_t iframe;
/// offset from baseSymb: within the function, or from the closest symbol
ptrdiff_t offsetSymb;
/// adress of the symbol in this execution
size_t baseSymb;
/// offset within the image (from this you can use better methods to get line number
/// a posteriory)
ptrdiff_t offsetImg;
/// base adress of the image (will be dependent on randomization schemes)
size_t baseImg;
/// adress of the function, or at which the ipc will return
/// (which most likely is the one after the adress where it started)
/// this is the raw adress returned by the backtracing function
size_t address;
/// file (image) of the current adress
char[] file;
/// name of the function, if possible demangled
char[] func;
/// extra information (for example calling arguments)
char[] extra;
/// if the address is exact or it is the return address
bool exactAddress;
/// if this function is an internal functions (for example the backtracing function itself)
/// if true by default the frame is not printed
bool internalFunction;
alias void function(FrameInfo*,void delegate(char[])) FramePrintHandler;
/// the default printing function
static FramePrintHandler defaultFramePrintingFunction;
/// writes out the current frame info
void writeOut(void delegate(char[])sink);
/// clears the frame information stored
void clear();
}
/// trace information has the following interface
interface TraceInfo
{
int opApply( int delegate( ref FrameInfo fInfo) );
void writeOut(void delegate(char[])sink);
}
/// message of the exception
char[] msg;
/// file name
char[] file;
/// line number
size_t line; // long would be better to be consistent
/// trace of where the exception was raised
TraceInfo info;
/// next exception (if an exception made an other exception raise)
Exception next;
/// designated constructor (breakpoint this if you want to catch all explict Exception creations,
/// special exception just allocate and init the structure directly)
this(char[] msg, char[] file, long line, Exception next, TraceInfo info );
this(char[] msg, Exception next=null);
this(char[] msg, char[] file, long line, Exception next = null);
/// returns the message of the exception, should not be used (because it should not allocate,
/// and thus only a small message is returned)
char[] toString();
/// writes out the message of the exception, by default writes toString
/// override this is you have a better message for the exception
void writeOutMsg(void delegate(char[]) sink);
/// writes out the exception message, file, line number, stacktrace (if available) and any
/// subexceptions
void writeOut(void delegate(char[]) sink);
}

View File

@@ -0,0 +1,136 @@
// Written in the D programming language
/*
* Authors:
* Walter Bright, Don Clugston
* Copyright:
* Copyright (c) 2001-2005 by Digital Mars,
* All Rights Reserved,
* www.digitalmars.com
* License:
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* <ul>
* <li> The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* </li>
* <li> Altered source versions must be plainly marked as such, and must not
* be misrepresented as being the original software.
* </li>
* <li> This notice may not be removed or altered from any source
* distribution.
* </li>
* </ul>
*/
/* Cut down version for libtangobos-partial/dstress */
module tango.math.IEEE;
private:
/*
* The following IEEE 'real' formats are currently supported:
* 64 bit Big-endian 'double' (eg PowerPC)
* 128 bit Big-endian 'quadruple' (eg SPARC)
* 64 bit Little-endian 'double' (eg x86-SSE2)
* 80 bit Little-endian, with implied bit 'real80' (eg x87, Itanium).
* 128 bit Little-endian 'quadruple' (not implemented on any known processor!)
*
* Non-IEEE 128 bit Big-endian 'doubledouble' (eg PowerPC) has partial support
*/
version(LittleEndian) {
static assert(real.mant_dig == 53 || real.mant_dig==64
|| real.mant_dig == 113,
"Only 64-bit, 80-bit, and 128-bit reals"
" are supported for LittleEndian CPUs");
} else {
static assert(real.mant_dig == 53 || real.mant_dig==106
|| real.mant_dig == 113,
"Only 64-bit and 128-bit reals are supported for BigEndian CPUs."
" double-double reals have partial support");
}
// Constants used for extracting the components of the representation.
// They supplement the built-in floating point properties.
template floatTraits(T) {
// EXPMASK is a ushort mask to select the exponent portion (without sign)
// POW2MANTDIG = pow(2, real.mant_dig) is the value such that
// (smallest_denormal)*POW2MANTDIG == real.min
// EXPPOS_SHORT is the index of the exponent when represented as a ushort array.
// SIGNPOS_BYTE is the index of the sign when represented as a ubyte array.
static if (T.mant_dig == 24) { // float
const ushort EXPMASK = 0x7F80;
const ushort EXPBIAS = 0x3F00;
const uint EXPMASK_INT = 0x7F80_0000;
const uint MANTISSAMASK_INT = 0x007F_FFFF;
const real POW2MANTDIG = 0x1p+24;
version(LittleEndian) {
const EXPPOS_SHORT = 1;
} else {
const EXPPOS_SHORT = 0;
}
} else static if (T.mant_dig == 53) { // double, or real==double
const ushort EXPMASK = 0x7FF0;
const ushort EXPBIAS = 0x3FE0;
const uint EXPMASK_INT = 0x7FF0_0000;
const uint MANTISSAMASK_INT = 0x000F_FFFF; // for the MSB only
const real POW2MANTDIG = 0x1p+53;
version(LittleEndian) {
const EXPPOS_SHORT = 3;
const SIGNPOS_BYTE = 7;
} else {
const EXPPOS_SHORT = 0;
const SIGNPOS_BYTE = 0;
}
} else static if (T.mant_dig == 64) { // real80
const ushort EXPMASK = 0x7FFF;
const ushort EXPBIAS = 0x3FFE;
const real POW2MANTDIG = 0x1p+63;
version(LittleEndian) {
const EXPPOS_SHORT = 4;
const SIGNPOS_BYTE = 9;
} else {
const EXPPOS_SHORT = 0;
const SIGNPOS_BYTE = 0;
}
} else static if (real.mant_dig == 113){ // quadruple
const ushort EXPMASK = 0x7FFF;
const real POW2MANTDIG = 0x1p+113;
version(LittleEndian) {
const EXPPOS_SHORT = 7;
const SIGNPOS_BYTE = 15;
} else {
const EXPPOS_SHORT = 0;
const SIGNPOS_BYTE = 0;
}
} else static if (real.mant_dig == 106) { // doubledouble
const ushort EXPMASK = 0x7FF0;
const real POW2MANTDIG = 0x1p+53; // doubledouble denormals are strange
// and the exponent byte is not unique
version(LittleEndian) {
const EXPPOS_SHORT = 7; // [3] is also an exp short
const SIGNPOS_BYTE = 15;
} else {
const EXPPOS_SHORT = 0; // [4] is also an exp short
const SIGNPOS_BYTE = 0;
}
}
}
public:
/*********************************
* Return 1 if sign bit of e is set, 0 if not.
*/
int signbit(real x)
{
return ((cast(ubyte *)&x)[floatTraits!(real).SIGNPOS_BYTE] & 0x80) != 0;
}

View File

@@ -0,0 +1,10 @@
module std.compat;
extern (C) int printf(char *, ...);
alias char[] string;
alias wchar[] wstring;
alias dchar[] dstring;
alias Exception Error;
alias bool bit;

View File

@@ -0,0 +1,250 @@
/*
* Copyright (C) 1999-2006 by Digital Mars, www.digitalmars.com
* Written by Walter Bright
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* o The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* o Altered source versions must be plainly marked as such, and must not
* be misrepresented as being the original software.
* o This notice may not be removed or altered from any source
* distribution.
*/
/**
* The garbage collector normally works behind the scenes without needing any
* specific interaction. These functions are for advanced applications that
* benefit from tuning the operation of the collector.
* Macros:
* WIKI=Phobos/StdGc
*/
module std.gc;
import tango.core.Memory;
/**
* Add p to list of roots. Roots are references to memory allocated by the
collector that are maintained in memory outside the collector pool. The garbage
collector will by default look for roots in the stacks of each thread, the
registers, and the default static data segment. If roots are held elsewhere,
use addRoot() or addRange() to tell the collector not to free the memory it
points to.
*/
void addRoot(void *p) // add p to list of roots
{
GC.addRoot(p);
}
/**
* Remove p from list of roots.
*/
void removeRoot(void *p) // remove p from list of roots
{
GC.removeRoot(p);
}
/**
* Add range to scan for roots.
*/
void addRange(void *pbot, void *ptop) // add range to scan for roots
{
GC.addRange(pbot, ptop-pbot);
}
/**
* Remove range.
*/
void removeRange(void *pbot) // remove range
{
GC.removeRange(pbot);
}
/**
* Mark a gc allocated block of memory as possibly containing pointers.
*/
void hasPointers(void* p)
{
GC.clrAttr(p, GC.BlkAttr.NO_SCAN);
}
/**
* Mark a gc allocated block of memory as definitely NOT containing pointers.
*/
void hasNoPointers(void* p)
{
GC.setAttr(p, GC.BlkAttr.NO_SCAN);
}
/**
* Mark a gc allocated block of memory pointed to by p as being populated with
* an array of TypeInfo ti (as many as will fit).
*/
//void setTypeInfo(TypeInfo ti, void* p);
/**
* Allocate nbytes of uninitialized data.
* The allocated memory will be scanned for pointers during
* a gc collection cycle, unless
* it is followed by a call to hasNoPointers().
*/
void[] malloc(size_t nbytes)
{
void* p = GC.malloc(nbytes);
if (p is null)
return null;
else
return p[0..nbytes];
}
/**
* Resize allocated memory block pointed to by p to be at least nbytes long.
* It will try to resize the memory block in place.
* If nbytes is 0, the memory block is free'd.
* If p is null, the memory block is allocated using malloc.
* The returned array may not be at the same location as the original
* memory block.
* The allocated memory will be scanned for pointers during
* a gc collection cycle, unless
* it is followed by a call to hasNoPointers().
*/
void[] realloc(void* p, size_t nbytes)
{
p = GC.realloc(p, nbytes);
if (p is null)
return null;
else
return p[0..nbytes];
}
/**
* Attempt to enlarge the memory block pointed to by p
* by at least minbytes beyond its current capacity,
* up to a maximum of maxbytes.
* Returns:
* 0 if could not extend p,
* total size of entire memory block if successful.
*/
size_t extend(void* p, size_t minbytes, size_t maxbytes)
{
return GC.extend(p, maxbytes, minbytes);
}
/**
* Returns capacity (size of the memory block) that p
* points to the beginning of.
* If p does not point into the gc memory pool, or does
* not point to the beginning of an allocated memory block,
* 0 is returned.
*/
size_t capacity(void* p)
{
return GC.sizeOf(p);
}
/**
* Set gc behavior to match that of 1.0.
*/
void setV1_0()
{
}
/***********************************
* Run a full garbage collection cycle.
*
* The collector normally runs synchronously with a storage allocation request
(i.e. it never happens when in code that does not allocate memory). In some
circumstances, for example when a particular task is finished, it is convenient
to explicitly run the collector and free up all memory used by that task. It
can also be helpful to run a collection before starting a new task that would
be annoying if it ran a collection in the middle of that task. Explicitly
running a collection can also be done in a separate very low priority thread,
so that if the program is idly waiting for input, memory can be cleaned up.
*/
void fullCollect()
{
GC.collect();
}
/***********************************
* Run a generational garbage collection cycle.
* Takes less time than a fullcollect(), but isn't
* as effective.
*/
void genCollect()
{
GC.collect();
}
//void genCollectNoStack();
/**
* Minimizes physical memory usage
*/
void minimize()
{
GC.collect();
}
/***************************************
* disable() temporarily disables garbage collection cycle, enable()
* then reenables them.
*
* This is used for brief time critical sections of code, so the amount of time
* it will take is predictable.
* If the collector runs out of memory while it is disabled, it will throw an
* std.outofmemory.OutOfMemoryException.
* The disable() function calls can be nested, but must be
* matched with corresponding enable() calls.
* By default collections are enabled.
*/
void disable()
{
GC.disable();
}
/**
* ditto
*/
void enable()
{
GC.enable();
}
//void getStats(out GCStats stats);
/***************************************
* Get handle to the collector.
*/
//void* getGCHandle();
/***************************************
* Set handle to the collector.
*/
//void setGCHandle(void* p);
//void endGCHandle();
/*
extern (C)
{
void gc_init();
void gc_term();
}
*/

View File

@@ -0,0 +1,11 @@
module std.outofmemory;
import std.compat;
public import tango.core.Exception;
extern (C) void _d_OutOfMemory()
{
throw cast(OutOfMemoryException)
cast(void *)
OutOfMemoryException.classinfo.init;
}

View File

@@ -0,0 +1,30 @@
/*
* Placed in public domain.
* Written by Hauke Duden and Walter Bright
*/
/* This is for use with variable argument lists with extern(D) linkage. */
module std.stdarg;
version(LDC)
{
public import ldc.vararg;
}
else
{
alias void* va_list;
template va_arg(T)
{
T va_arg(inout va_list _argptr)
{
T arg = *cast(T*)_argptr;
_argptr = _argptr + ((T.sizeof + int.sizeof - 1) & ~(int.sizeof - 1));
return arg;
}
}
}