mirror of
https://github.com/dlang/dmd.git
synced 2025-04-27 21:51:03 +03:00
Add manually ported frontend source files to version control
This commit is contained in:
parent
db9bda359c
commit
ea591ba98e
10 changed files with 3785 additions and 0 deletions
77
.gitignore
vendored
77
.gitignore
vendored
|
@ -3,6 +3,7 @@
|
||||||
src/cdxxx.c
|
src/cdxxx.c
|
||||||
src/debtab.c
|
src/debtab.c
|
||||||
src/dmd
|
src/dmd
|
||||||
|
src/ddmd
|
||||||
src/dmd.conf
|
src/dmd.conf
|
||||||
src/elxxx.c
|
src/elxxx.c
|
||||||
src/fltables.c
|
src/fltables.c
|
||||||
|
@ -26,6 +27,7 @@ src/verstr.h
|
||||||
trace.def
|
trace.def
|
||||||
trace.log
|
trace.log
|
||||||
Makefile
|
Makefile
|
||||||
|
src/magicport/magicport
|
||||||
|
|
||||||
# Visual Studio files
|
# Visual Studio files
|
||||||
*.exe
|
*.exe
|
||||||
|
@ -52,3 +54,78 @@ tags
|
||||||
# OSX
|
# OSX
|
||||||
src/impcnvgen.dSYM/
|
src/impcnvgen.dSYM/
|
||||||
src/optabgen.dSYM/
|
src/optabgen.dSYM/
|
||||||
|
|
||||||
|
# Generated D source
|
||||||
|
src/access.d
|
||||||
|
src/aggregate.d
|
||||||
|
src/aliasthis.d
|
||||||
|
src/apply.d
|
||||||
|
src/argtypes.d
|
||||||
|
src/arrayop.d
|
||||||
|
src/arraytypes.d
|
||||||
|
src/attrib.d
|
||||||
|
src/builtin.d
|
||||||
|
src/canthrow.d
|
||||||
|
src/dcast.d
|
||||||
|
src/dclass.d
|
||||||
|
src/clone.d
|
||||||
|
src/cond.d
|
||||||
|
src/constfold.d
|
||||||
|
src/cppmangle.d
|
||||||
|
src/ctfeexpr.d
|
||||||
|
src/declaration.d
|
||||||
|
src/delegatize.d
|
||||||
|
src/doc.d
|
||||||
|
src/dsymbol.d
|
||||||
|
src/denum.d
|
||||||
|
src/errors.d
|
||||||
|
src/expression.d
|
||||||
|
src/func.d
|
||||||
|
src/hdrgen.d
|
||||||
|
src/id.d
|
||||||
|
src/identifier.d
|
||||||
|
src/imphint.d
|
||||||
|
src/dimport.d
|
||||||
|
src/dinifile.d
|
||||||
|
src/inline.d
|
||||||
|
src/init.d
|
||||||
|
src/dinterpret.d
|
||||||
|
src/json.d
|
||||||
|
src/lexer.d
|
||||||
|
src/link.d
|
||||||
|
src/dmacro.d
|
||||||
|
src/dmangle.d
|
||||||
|
src/mars.d
|
||||||
|
src/dmodule.d
|
||||||
|
src/mtype.d
|
||||||
|
src/nspace.d
|
||||||
|
src/opover.d
|
||||||
|
src/optimize.d
|
||||||
|
src/parse.d
|
||||||
|
src/sapply.d
|
||||||
|
src/dscope.d
|
||||||
|
src/sideeffect.d
|
||||||
|
src/statement.d
|
||||||
|
src/staticassert.d
|
||||||
|
src/dstruct.d
|
||||||
|
src/target.d
|
||||||
|
src/dtemplate.d
|
||||||
|
src/tokens.d
|
||||||
|
src/traits.d
|
||||||
|
src/dunittest.d
|
||||||
|
src/utf.d
|
||||||
|
src/dversion.d
|
||||||
|
src/visitor.d
|
||||||
|
src/lib.d
|
||||||
|
src/nogc.d
|
||||||
|
src/nspace.d
|
||||||
|
src/color.d
|
||||||
|
src/globals.d
|
||||||
|
src/root/aav.d
|
||||||
|
src/root/file.d
|
||||||
|
src/root/filename.d
|
||||||
|
src/root/speller.d
|
||||||
|
src/root/man.d
|
||||||
|
src/root/outbuffer.d
|
||||||
|
src/root/response.d
|
||||||
|
src/root/stringtable.d
|
||||||
|
|
33
src/backend.d
Normal file
33
src/backend.d
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
// Compiler implementation of the D programming language
|
||||||
|
// Copyright (c) 1999-2015 by Digital Mars
|
||||||
|
// All Rights Reserved
|
||||||
|
// written by Walter Bright
|
||||||
|
// http://www.digitalmars.com
|
||||||
|
// Distributed under the Boost Software License, Version 1.0.
|
||||||
|
// http://www.boost.org/LICENSE_1_0.txt
|
||||||
|
|
||||||
|
module ddmd.backend;
|
||||||
|
|
||||||
|
import ddmd.aggregate, ddmd.dmodule, ddmd.dscope, ddmd.expression, ddmd.lib, ddmd.mtype, ddmd.root.file;
|
||||||
|
|
||||||
|
struct Symbol;
|
||||||
|
struct TYPE;
|
||||||
|
alias type = TYPE;
|
||||||
|
struct code;
|
||||||
|
struct block;
|
||||||
|
|
||||||
|
extern extern (C++) void backend_init();
|
||||||
|
extern extern (C++) void backend_term();
|
||||||
|
extern extern (C++) void obj_start(char* srcfile);
|
||||||
|
extern extern (C++) void obj_end(Library library, File* objfile);
|
||||||
|
extern extern (C++) void obj_write_deferred(Library library);
|
||||||
|
|
||||||
|
extern extern (C++) Expression getTypeInfo(Type t, Scope* sc);
|
||||||
|
extern extern (C++) Expression getInternalTypeInfo(Type t, Scope* sc);
|
||||||
|
extern extern (C++) void genObjFile(Module m, bool multiobj);
|
||||||
|
extern extern (C++) void genhelpers(Module m, bool multiobj);
|
||||||
|
|
||||||
|
extern extern (C++) Symbol* toInitializer(AggregateDeclaration sd);
|
||||||
|
extern extern (C++) Symbol* toModuleArray(Module m);
|
||||||
|
extern extern (C++) Symbol* toModuleAssert(Module m);
|
||||||
|
extern extern (C++) Symbol* toModuleUnittest(Module m);
|
110
src/complex.d
Normal file
110
src/complex.d
Normal file
|
@ -0,0 +1,110 @@
|
||||||
|
// Compiler implementation of the D programming language
|
||||||
|
// Copyright (c) 1999-2015 by Digital Mars
|
||||||
|
// All Rights Reserved
|
||||||
|
// written by Walter Bright
|
||||||
|
// http://www.digitalmars.com
|
||||||
|
// Distributed under the Boost Software License, Version 1.0.
|
||||||
|
// http://www.boost.org/LICENSE_1_0.txt
|
||||||
|
|
||||||
|
module ddmd.complex;
|
||||||
|
|
||||||
|
struct complex_t
|
||||||
|
{
|
||||||
|
real re = 0;
|
||||||
|
real im = 0;
|
||||||
|
this(real re)
|
||||||
|
{
|
||||||
|
this.re = re;
|
||||||
|
this.im = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
this(real re, real im)
|
||||||
|
{
|
||||||
|
this.re = re;
|
||||||
|
this.im = im;
|
||||||
|
}
|
||||||
|
|
||||||
|
complex_t opAdd(complex_t y)
|
||||||
|
{
|
||||||
|
complex_t r;
|
||||||
|
r.re = re + y.re;
|
||||||
|
r.im = im + y.im;
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
complex_t opSub(complex_t y)
|
||||||
|
{
|
||||||
|
complex_t r;
|
||||||
|
r.re = re - y.re;
|
||||||
|
r.im = im - y.im;
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
complex_t opNeg()
|
||||||
|
{
|
||||||
|
complex_t r;
|
||||||
|
r.re = -re;
|
||||||
|
r.im = -im;
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
complex_t opMul(complex_t y)
|
||||||
|
{
|
||||||
|
return complex_t(re * y.re - im * y.im, im * y.re + re * y.im);
|
||||||
|
}
|
||||||
|
|
||||||
|
complex_t opMul_r(real x)
|
||||||
|
{
|
||||||
|
return complex_t(x) * this;
|
||||||
|
}
|
||||||
|
|
||||||
|
complex_t opMul(real y)
|
||||||
|
{
|
||||||
|
return this * complex_t(y);
|
||||||
|
}
|
||||||
|
|
||||||
|
complex_t opDiv(real y)
|
||||||
|
{
|
||||||
|
return this / complex_t(y);
|
||||||
|
}
|
||||||
|
|
||||||
|
complex_t opDiv(complex_t y)
|
||||||
|
{
|
||||||
|
real abs_y_re = y.re < 0 ? -y.re : y.re;
|
||||||
|
real abs_y_im = y.im < 0 ? -y.im : y.im;
|
||||||
|
real r, den;
|
||||||
|
|
||||||
|
if (abs_y_re < abs_y_im)
|
||||||
|
{
|
||||||
|
r = y.re / y.im;
|
||||||
|
den = y.im + r * y.re;
|
||||||
|
return complex_t((re * r + im) / den, (im * r - re) / den);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
r = y.im / y.re;
|
||||||
|
den = y.re + r * y.im;
|
||||||
|
return complex_t((re + r * im) / den, (im - r * re) / den);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool opCast(T : bool)()
|
||||||
|
{
|
||||||
|
return re || im;
|
||||||
|
}
|
||||||
|
|
||||||
|
int opEquals(complex_t y)
|
||||||
|
{
|
||||||
|
return re == y.re && im == y.im;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
real creall(complex_t x)
|
||||||
|
{
|
||||||
|
return x.re;
|
||||||
|
}
|
||||||
|
|
||||||
|
real cimagl(complex_t x)
|
||||||
|
{
|
||||||
|
return x.im;
|
||||||
|
}
|
2386
src/entity.d
Normal file
2386
src/entity.d
Normal file
File diff suppressed because it is too large
Load diff
494
src/intrange.d
Normal file
494
src/intrange.d
Normal file
|
@ -0,0 +1,494 @@
|
||||||
|
|
||||||
|
// Compiler implementation of the D programming language
|
||||||
|
// Copyright (c) 1999-2015 by Digital Mars
|
||||||
|
// All Rights Reserved
|
||||||
|
// written by Walter Bright
|
||||||
|
// http://www.digitalmars.com
|
||||||
|
// Distributed under the Boost Software License, Version 1.0.
|
||||||
|
// http://www.boost.org/LICENSE_1_0.txt
|
||||||
|
|
||||||
|
module ddmd.intrange;
|
||||||
|
|
||||||
|
import core.stdc.stdio;
|
||||||
|
|
||||||
|
import ddmd.mtype;
|
||||||
|
import ddmd.expression;
|
||||||
|
import ddmd.globals;
|
||||||
|
|
||||||
|
enum UINT64_MAX = 0xFFFFFFFFFFFFFFFFUL;
|
||||||
|
|
||||||
|
static uinteger_t copySign(uinteger_t x, bool sign)
|
||||||
|
{
|
||||||
|
// return sign ? -x : x;
|
||||||
|
return (x - cast(uinteger_t)sign) ^ -cast(uinteger_t)sign;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct SignExtendedNumber
|
||||||
|
{
|
||||||
|
ulong value;
|
||||||
|
bool negative;
|
||||||
|
static SignExtendedNumber fromInteger(uinteger_t value_)
|
||||||
|
{
|
||||||
|
return SignExtendedNumber(value_, value_ >> 63);
|
||||||
|
}
|
||||||
|
|
||||||
|
static SignExtendedNumber extreme(bool minimum)
|
||||||
|
{
|
||||||
|
return SignExtendedNumber(minimum - 1, minimum);
|
||||||
|
}
|
||||||
|
|
||||||
|
static SignExtendedNumber max()
|
||||||
|
{
|
||||||
|
return SignExtendedNumber(UINT64_MAX, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
static SignExtendedNumber min()
|
||||||
|
{
|
||||||
|
return SignExtendedNumber(0, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isMinimum() const
|
||||||
|
{
|
||||||
|
return negative && value == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool opEquals(const ref SignExtendedNumber a) const
|
||||||
|
{
|
||||||
|
return value == a.value && negative == a.negative;
|
||||||
|
}
|
||||||
|
|
||||||
|
int opCmp(const ref SignExtendedNumber a) const
|
||||||
|
{
|
||||||
|
if (negative != a.negative)
|
||||||
|
{
|
||||||
|
if (negative)
|
||||||
|
return -1;
|
||||||
|
else
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (value < a.value)
|
||||||
|
return -1;
|
||||||
|
else if (value > a.value)
|
||||||
|
return 1;
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
SignExtendedNumber opNeg() const
|
||||||
|
{
|
||||||
|
if (value == 0)
|
||||||
|
return SignExtendedNumber(-cast(ulong)negative);
|
||||||
|
else
|
||||||
|
return SignExtendedNumber(-value, !negative);
|
||||||
|
}
|
||||||
|
|
||||||
|
SignExtendedNumber opAdd(const SignExtendedNumber a) const
|
||||||
|
{
|
||||||
|
uinteger_t sum = value + a.value;
|
||||||
|
bool carry = sum < value && sum < a.value;
|
||||||
|
if (negative != a.negative)
|
||||||
|
return SignExtendedNumber(sum, !carry);
|
||||||
|
else if (negative)
|
||||||
|
return SignExtendedNumber(carry ? sum : 0, true);
|
||||||
|
else
|
||||||
|
return SignExtendedNumber(carry ? UINT64_MAX : sum, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
SignExtendedNumber opSub(const SignExtendedNumber a) const
|
||||||
|
{
|
||||||
|
if (a.isMinimum())
|
||||||
|
return negative ? SignExtendedNumber(value, false) : max();
|
||||||
|
else
|
||||||
|
return this + (-a);
|
||||||
|
}
|
||||||
|
|
||||||
|
SignExtendedNumber opMul(const SignExtendedNumber a) const
|
||||||
|
{
|
||||||
|
// perform *saturated* multiplication, otherwise we may get bogus ranges
|
||||||
|
// like 0x10 * 0x10 == 0x100 == 0.
|
||||||
|
|
||||||
|
/* Special handling for zeros:
|
||||||
|
INT65_MIN * 0 = 0
|
||||||
|
INT65_MIN * + = INT65_MIN
|
||||||
|
INT65_MIN * - = INT65_MAX
|
||||||
|
0 * anything = 0
|
||||||
|
*/
|
||||||
|
if (value == 0)
|
||||||
|
{
|
||||||
|
if (!negative)
|
||||||
|
return this;
|
||||||
|
else if (a.negative)
|
||||||
|
return max();
|
||||||
|
else
|
||||||
|
return a.value == 0 ? a : this;
|
||||||
|
}
|
||||||
|
else if (a.value == 0)
|
||||||
|
return a * this; // don't duplicate the symmetric case.
|
||||||
|
|
||||||
|
SignExtendedNumber rv;
|
||||||
|
// these are != 0 now surely.
|
||||||
|
uinteger_t tAbs = copySign(value, negative);
|
||||||
|
uinteger_t aAbs = copySign(a.value, a.negative);
|
||||||
|
rv.negative = negative != a.negative;
|
||||||
|
if (UINT64_MAX / tAbs < aAbs)
|
||||||
|
rv.value = rv.negative - 1;
|
||||||
|
else
|
||||||
|
rv.value = copySign(tAbs * aAbs, rv.negative);
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
|
SignExtendedNumber opDiv(const SignExtendedNumber a) const
|
||||||
|
{
|
||||||
|
/* special handling for zeros:
|
||||||
|
INT65_MIN / INT65_MIN = 1
|
||||||
|
anything / INT65_MIN = 0
|
||||||
|
+ / 0 = INT65_MAX (eh?)
|
||||||
|
- / 0 = INT65_MIN (eh?)
|
||||||
|
*/
|
||||||
|
if (a.value == 0)
|
||||||
|
{
|
||||||
|
if (a.negative)
|
||||||
|
return SignExtendedNumber(value == 0 && negative);
|
||||||
|
else
|
||||||
|
return extreme(negative);
|
||||||
|
}
|
||||||
|
|
||||||
|
uinteger_t aAbs = copySign(a.value, a.negative);
|
||||||
|
uinteger_t rvVal;
|
||||||
|
|
||||||
|
if (!isMinimum())
|
||||||
|
rvVal = copySign(value, negative) / aAbs;
|
||||||
|
// Special handling for INT65_MIN
|
||||||
|
// if the denominator is not a power of 2, it is same as UINT64_MAX / x.
|
||||||
|
else if (aAbs & (aAbs - 1))
|
||||||
|
rvVal = UINT64_MAX / aAbs;
|
||||||
|
// otherwise, it's the same as reversing the bits of x.
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (aAbs == 1)
|
||||||
|
return extreme(!a.negative);
|
||||||
|
rvVal = 1UL << 63;
|
||||||
|
aAbs >>= 1;
|
||||||
|
if (aAbs & 0xAAAAAAAAAAAAAAAAUL) rvVal >>= 1;
|
||||||
|
if (aAbs & 0xCCCCCCCCCCCCCCCCUL) rvVal >>= 2;
|
||||||
|
if (aAbs & 0xF0F0F0F0F0F0F0F0UL) rvVal >>= 4;
|
||||||
|
if (aAbs & 0xFF00FF00FF00FF00UL) rvVal >>= 8;
|
||||||
|
if (aAbs & 0xFFFF0000FFFF0000UL) rvVal >>= 16;
|
||||||
|
if (aAbs & 0xFFFFFFFF00000000UL) rvVal >>= 32;
|
||||||
|
}
|
||||||
|
bool rvNeg = negative != a.negative;
|
||||||
|
rvVal = copySign(rvVal, rvNeg);
|
||||||
|
|
||||||
|
return SignExtendedNumber(rvVal, rvVal != 0 && rvNeg);
|
||||||
|
}
|
||||||
|
|
||||||
|
SignExtendedNumber opMod(const SignExtendedNumber a) const
|
||||||
|
{
|
||||||
|
if (a.value == 0)
|
||||||
|
return !a.negative ? a : isMinimum() ? SignExtendedNumber(0) : this;
|
||||||
|
|
||||||
|
uinteger_t aAbs = copySign(a.value, a.negative);
|
||||||
|
uinteger_t rvVal;
|
||||||
|
|
||||||
|
// a % b == sgn(a) * abs(a) % abs(b).
|
||||||
|
if (!isMinimum())
|
||||||
|
rvVal = copySign(value, negative) % aAbs;
|
||||||
|
// Special handling for INT65_MIN
|
||||||
|
// if the denominator is not a power of 2, it is same as UINT64_MAX%x + 1.
|
||||||
|
else if (aAbs & (aAbs - 1))
|
||||||
|
rvVal = UINT64_MAX % aAbs + 1;
|
||||||
|
// otherwise, the modulus is trivially zero.
|
||||||
|
else
|
||||||
|
rvVal = 0;
|
||||||
|
|
||||||
|
rvVal = copySign(rvVal, negative);
|
||||||
|
return SignExtendedNumber(rvVal, rvVal != 0 && negative);
|
||||||
|
}
|
||||||
|
|
||||||
|
ref SignExtendedNumber opAddAssign(int a)
|
||||||
|
{
|
||||||
|
assert(a == 1);
|
||||||
|
if (value != UINT64_MAX)
|
||||||
|
++value;
|
||||||
|
else if (negative)
|
||||||
|
{
|
||||||
|
value = 0;
|
||||||
|
negative = false;
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
SignExtendedNumber opShl(const SignExtendedNumber a)
|
||||||
|
{
|
||||||
|
// assume left-shift the shift-amount is always unsigned. Thus negative
|
||||||
|
// shifts will give huge result.
|
||||||
|
if (value == 0)
|
||||||
|
return this;
|
||||||
|
else if (a.negative)
|
||||||
|
return extreme(negative);
|
||||||
|
|
||||||
|
uinteger_t v = copySign(value, negative);
|
||||||
|
|
||||||
|
// compute base-2 log of 'v' to determine the maximum allowed bits to shift.
|
||||||
|
// Ref: http://graphics.stanford.edu/~seander/bithacks.html#IntegerLog
|
||||||
|
|
||||||
|
// Why is this a size_t? Looks like a bug.
|
||||||
|
size_t r, s;
|
||||||
|
|
||||||
|
r = (v > 0xFFFFFFFFUL) << 5; v >>= r;
|
||||||
|
s = (v > 0xFFFFUL ) << 4; v >>= s; r |= s;
|
||||||
|
s = (v > 0xFFUL ) << 3; v >>= s; r |= s;
|
||||||
|
s = (v > 0xFUL ) << 2; v >>= s; r |= s;
|
||||||
|
s = (v > 0x3UL ) << 1; v >>= s; r |= s;
|
||||||
|
r |= (v >> 1);
|
||||||
|
|
||||||
|
uinteger_t allowableShift = 63 - r;
|
||||||
|
if (a.value > allowableShift)
|
||||||
|
return extreme(negative);
|
||||||
|
else
|
||||||
|
return SignExtendedNumber(value << a.value, negative);
|
||||||
|
}
|
||||||
|
|
||||||
|
SignExtendedNumber opShr(const SignExtendedNumber a)
|
||||||
|
{
|
||||||
|
if (a.negative || a.value > 64)
|
||||||
|
return negative ? SignExtendedNumber(-1, true) : SignExtendedNumber(0);
|
||||||
|
else if (isMinimum())
|
||||||
|
return a.value == 0 ? this : SignExtendedNumber(-1UL << (64 - a.value), true);
|
||||||
|
|
||||||
|
uinteger_t x = value ^ -cast(int)negative;
|
||||||
|
x >>= a.value;
|
||||||
|
return SignExtendedNumber(x ^ -cast(int)negative, negative);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct IntRange
|
||||||
|
{
|
||||||
|
SignExtendedNumber imin, imax;
|
||||||
|
|
||||||
|
this(SignExtendedNumber a)
|
||||||
|
{
|
||||||
|
imin = a;
|
||||||
|
imax = a;
|
||||||
|
}
|
||||||
|
|
||||||
|
this(SignExtendedNumber lower, SignExtendedNumber upper)
|
||||||
|
{
|
||||||
|
imin = lower;
|
||||||
|
imax = upper;
|
||||||
|
}
|
||||||
|
|
||||||
|
static IntRange fromType(Type type)
|
||||||
|
{
|
||||||
|
return fromType(type, type.isunsigned());
|
||||||
|
}
|
||||||
|
|
||||||
|
static IntRange fromType(Type type, bool isUnsigned)
|
||||||
|
{
|
||||||
|
if (!type.isintegral())
|
||||||
|
return widest();
|
||||||
|
|
||||||
|
uinteger_t mask = type.sizemask();
|
||||||
|
auto lower = SignExtendedNumber(0);
|
||||||
|
auto upper = SignExtendedNumber(mask);
|
||||||
|
if (type.toBasetype().ty == Tdchar)
|
||||||
|
upper.value = 0x10FFFFUL;
|
||||||
|
else if (!isUnsigned)
|
||||||
|
{
|
||||||
|
lower.value = ~(mask >> 1);
|
||||||
|
lower.negative = true;
|
||||||
|
upper.value = (mask >> 1);
|
||||||
|
}
|
||||||
|
return IntRange(lower, upper);
|
||||||
|
}
|
||||||
|
|
||||||
|
static IntRange fromNumbers2(SignExtendedNumber* numbers)
|
||||||
|
{
|
||||||
|
if (numbers[0] < numbers[1])
|
||||||
|
return IntRange(numbers[0], numbers[1]);
|
||||||
|
else
|
||||||
|
return IntRange(numbers[1], numbers[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
static IntRange fromNumbers4(SignExtendedNumber* numbers)
|
||||||
|
{
|
||||||
|
IntRange ab = fromNumbers2(numbers);
|
||||||
|
IntRange cd = fromNumbers2(numbers + 2);
|
||||||
|
if (cd.imin < ab.imin)
|
||||||
|
ab.imin = cd.imin;
|
||||||
|
if (cd.imax > ab.imax)
|
||||||
|
ab.imax = cd.imax;
|
||||||
|
return ab;
|
||||||
|
}
|
||||||
|
|
||||||
|
static IntRange widest()
|
||||||
|
{
|
||||||
|
return IntRange(SignExtendedNumber.min(), SignExtendedNumber.max());
|
||||||
|
}
|
||||||
|
|
||||||
|
IntRange castSigned(uinteger_t mask)
|
||||||
|
{
|
||||||
|
// .... 0x1e7f ] [0x1e80 .. 0x1f7f] [0x1f80 .. 0x7f] [0x80 .. 0x17f] [0x180 ....
|
||||||
|
//
|
||||||
|
// regular signed type. We use a technique similar to the unsigned version,
|
||||||
|
// but the chunk has to be offset by 1/2 of the range.
|
||||||
|
uinteger_t halfChunkMask = mask >> 1;
|
||||||
|
uinteger_t minHalfChunk = imin.value & ~halfChunkMask;
|
||||||
|
uinteger_t maxHalfChunk = imax.value & ~halfChunkMask;
|
||||||
|
int minHalfChunkNegativity = imin.negative; // 1 = neg, 0 = nonneg, -1 = chunk containing ::max
|
||||||
|
int maxHalfChunkNegativity = imax.negative;
|
||||||
|
if (minHalfChunk & mask)
|
||||||
|
{
|
||||||
|
minHalfChunk += halfChunkMask + 1;
|
||||||
|
if (minHalfChunk == 0)
|
||||||
|
--minHalfChunkNegativity;
|
||||||
|
}
|
||||||
|
if (maxHalfChunk & mask)
|
||||||
|
{
|
||||||
|
maxHalfChunk += halfChunkMask + 1;
|
||||||
|
if (maxHalfChunk == 0)
|
||||||
|
--maxHalfChunkNegativity;
|
||||||
|
}
|
||||||
|
if (minHalfChunk == maxHalfChunk && minHalfChunkNegativity == maxHalfChunkNegativity)
|
||||||
|
{
|
||||||
|
imin.value &= mask;
|
||||||
|
imax.value &= mask;
|
||||||
|
// sign extend if necessary.
|
||||||
|
imin.negative = (imin.value & ~halfChunkMask) != 0;
|
||||||
|
imax.negative = (imax.value & ~halfChunkMask) != 0;
|
||||||
|
halfChunkMask += 1;
|
||||||
|
imin.value = (imin.value ^ halfChunkMask) - halfChunkMask;
|
||||||
|
imax.value = (imax.value ^ halfChunkMask) - halfChunkMask;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
imin = SignExtendedNumber(~halfChunkMask, true);
|
||||||
|
imax = SignExtendedNumber(halfChunkMask, false);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
IntRange castUnsigned(uinteger_t mask)
|
||||||
|
{
|
||||||
|
// .... 0x1eff ] [0x1f00 .. 0x1fff] [0 .. 0xff] [0x100 .. 0x1ff] [0x200 ....
|
||||||
|
//
|
||||||
|
// regular unsigned type. We just need to see if ir steps across the
|
||||||
|
// boundary of validRange. If yes, ir will represent the whole validRange,
|
||||||
|
// otherwise, we just take the modulus.
|
||||||
|
// e.g. [0x105, 0x107] & 0xff == [5, 7]
|
||||||
|
// [0x105, 0x207] & 0xff == [0, 0xff]
|
||||||
|
uinteger_t minChunk = imin.value & ~mask;
|
||||||
|
uinteger_t maxChunk = imax.value & ~mask;
|
||||||
|
if (minChunk == maxChunk && imin.negative == imax.negative)
|
||||||
|
{
|
||||||
|
imin.value &= mask;
|
||||||
|
imax.value &= mask;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
imin.value = 0;
|
||||||
|
imax.value = mask;
|
||||||
|
}
|
||||||
|
imin.negative = imax.negative = false;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
IntRange castDchar()
|
||||||
|
{
|
||||||
|
// special case for dchar. Casting to dchar means "I'll ignore all
|
||||||
|
// invalid characters."
|
||||||
|
castUnsigned(0xFFFFFFFFUL);
|
||||||
|
if (imin.value > 0x10FFFFUL) // ??
|
||||||
|
imin.value = 0x10FFFFUL; // ??
|
||||||
|
if (imax.value > 0x10FFFFUL)
|
||||||
|
imax.value = 0x10FFFFUL;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
IntRange _cast(Type type)
|
||||||
|
{
|
||||||
|
if (!type.isintegral())
|
||||||
|
return this;
|
||||||
|
else if (!type.isunsigned())
|
||||||
|
return castSigned(type.sizemask());
|
||||||
|
else if (type.toBasetype().ty == Tdchar)
|
||||||
|
return castDchar();
|
||||||
|
else
|
||||||
|
return castUnsigned(type.sizemask());
|
||||||
|
}
|
||||||
|
|
||||||
|
IntRange castUnsigned(Type type)
|
||||||
|
{
|
||||||
|
if (!type.isintegral())
|
||||||
|
return castUnsigned(UINT64_MAX);
|
||||||
|
else if (type.toBasetype().ty == Tdchar)
|
||||||
|
return castDchar();
|
||||||
|
else
|
||||||
|
return castUnsigned(type.sizemask());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool contains(IntRange a)
|
||||||
|
{
|
||||||
|
return imin <= a.imin && imax >= a.imax;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool containsZero() const
|
||||||
|
{
|
||||||
|
return (imin.negative && !imax.negative)
|
||||||
|
|| (!imin.negative && imin.value == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
IntRange absNeg() const
|
||||||
|
{
|
||||||
|
if (imax.negative)
|
||||||
|
return this;
|
||||||
|
else if (!imin.negative)
|
||||||
|
return IntRange(-imax, -imin);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SignExtendedNumber imaxAbsNeg = -imax;
|
||||||
|
return IntRange(imaxAbsNeg < imin ? imaxAbsNeg : imin,
|
||||||
|
SignExtendedNumber(0));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
IntRange unionWith(const ref IntRange other) const
|
||||||
|
{
|
||||||
|
return IntRange(imin < other.imin ? imin : other.imin,
|
||||||
|
imax > other.imax ? imax : other.imax);
|
||||||
|
}
|
||||||
|
|
||||||
|
void unionOrAssign(IntRange other, ref bool union_)
|
||||||
|
{
|
||||||
|
if (!union_ || imin > other.imin)
|
||||||
|
imin = other.imin;
|
||||||
|
if (!union_ || imax < other.imax)
|
||||||
|
imax = other.imax;
|
||||||
|
union_ = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
ref const(IntRange) dump(const(char)* funcName, Expression e) const
|
||||||
|
{
|
||||||
|
printf("[(%c)%#018llx, (%c)%#018llx] @ %s ::: %s\n",
|
||||||
|
imin.negative?'-':'+', cast(ulong)imin.value,
|
||||||
|
imax.negative?'-':'+', cast(ulong)imax.value,
|
||||||
|
funcName, e.toChars());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
void splitBySign(ref IntRange negRange, ref bool hasNegRange, ref IntRange nonNegRange, ref bool hasNonNegRange) const
|
||||||
|
{
|
||||||
|
hasNegRange = imin.negative;
|
||||||
|
if (hasNegRange)
|
||||||
|
{
|
||||||
|
negRange.imin = imin;
|
||||||
|
negRange.imax = imax.negative ? imax : SignExtendedNumber(-1, true);
|
||||||
|
}
|
||||||
|
hasNonNegRange = !imax.negative;
|
||||||
|
if (hasNonNegRange)
|
||||||
|
{
|
||||||
|
nonNegRange.imin = imin.negative ? SignExtendedNumber(0) : imin;
|
||||||
|
nonNegRange.imax = imax;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
202
src/root/array.d
Normal file
202
src/root/array.d
Normal file
|
@ -0,0 +1,202 @@
|
||||||
|
// Compiler implementation of the D programming language
|
||||||
|
// Copyright (c) 1999-2015 by Digital Mars
|
||||||
|
// All Rights Reserved
|
||||||
|
// written by Walter Bright
|
||||||
|
// http://www.digitalmars.com
|
||||||
|
// Distributed under the Boost Software License, Version 1.0.
|
||||||
|
// http://www.boost.org/LICENSE_1_0.txt
|
||||||
|
|
||||||
|
module ddmd.root.array;
|
||||||
|
|
||||||
|
import core.stdc.string;
|
||||||
|
|
||||||
|
import ddmd.root.rmem;
|
||||||
|
|
||||||
|
extern (C++) struct Array(T)
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
size_t dim;
|
||||||
|
T* data;
|
||||||
|
|
||||||
|
private:
|
||||||
|
size_t allocdim;
|
||||||
|
enum SMALLARRAYCAP = 1;
|
||||||
|
T[SMALLARRAYCAP] smallarray; // inline storage for small arrays
|
||||||
|
|
||||||
|
public:
|
||||||
|
~this()
|
||||||
|
{
|
||||||
|
if (data != &smallarray[0])
|
||||||
|
mem.xfree(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
char* toChars()
|
||||||
|
{
|
||||||
|
static if (is(typeof(T.init.toChars())))
|
||||||
|
{
|
||||||
|
char** buf = cast(char**)mem.xmalloc(dim * (char*).sizeof);
|
||||||
|
size_t len = 2;
|
||||||
|
for (size_t u = 0; u < dim; u++)
|
||||||
|
{
|
||||||
|
buf[u] = data[u].toChars();
|
||||||
|
len += strlen(buf[u]) + 1;
|
||||||
|
}
|
||||||
|
char* str = cast(char*)mem.xmalloc(len);
|
||||||
|
|
||||||
|
str[0] = '[';
|
||||||
|
char* p = str + 1;
|
||||||
|
for (size_t u = 0; u < dim; u++)
|
||||||
|
{
|
||||||
|
if (u)
|
||||||
|
*p++ = ',';
|
||||||
|
len = strlen(buf[u]);
|
||||||
|
memcpy(p, buf[u], len);
|
||||||
|
p += len;
|
||||||
|
}
|
||||||
|
*p++ = ']';
|
||||||
|
*p = 0;
|
||||||
|
mem.xfree(buf);
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
assert(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void push(T ptr)
|
||||||
|
{
|
||||||
|
reserve(1);
|
||||||
|
data[dim++] = ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void append(typeof(this)* a)
|
||||||
|
{
|
||||||
|
insert(dim, a);
|
||||||
|
}
|
||||||
|
|
||||||
|
void reserve(size_t nentries)
|
||||||
|
{
|
||||||
|
//printf("Array::reserve: dim = %d, allocdim = %d, nentries = %d\n", (int)dim, (int)allocdim, (int)nentries);
|
||||||
|
if (allocdim - dim < nentries)
|
||||||
|
{
|
||||||
|
if (allocdim == 0)
|
||||||
|
{
|
||||||
|
// Not properly initialized, someone memset it to zero
|
||||||
|
if (nentries <= SMALLARRAYCAP)
|
||||||
|
{
|
||||||
|
allocdim = SMALLARRAYCAP;
|
||||||
|
data = SMALLARRAYCAP ? smallarray.ptr : null;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
allocdim = nentries;
|
||||||
|
data = cast(T*)mem.xmalloc(allocdim * (*data).sizeof);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (allocdim == SMALLARRAYCAP)
|
||||||
|
{
|
||||||
|
allocdim = dim + nentries;
|
||||||
|
data = cast(T*)mem.xmalloc(allocdim * (*data).sizeof);
|
||||||
|
memcpy(data, smallarray.ptr, dim * (*data).sizeof);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
allocdim = dim + nentries;
|
||||||
|
data = cast(T*)mem.xrealloc(data, allocdim * (*data).sizeof);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void remove(size_t i)
|
||||||
|
{
|
||||||
|
if (dim - i - 1)
|
||||||
|
memmove(data + i, data + i + 1, (dim - i - 1) * (data[0]).sizeof);
|
||||||
|
dim--;
|
||||||
|
}
|
||||||
|
|
||||||
|
void insert(size_t index, typeof(this)* a)
|
||||||
|
{
|
||||||
|
if (a)
|
||||||
|
{
|
||||||
|
size_t d = a.dim;
|
||||||
|
reserve(d);
|
||||||
|
if (dim != index)
|
||||||
|
memmove(data + index + d, data + index, (dim - index) * (*data).sizeof);
|
||||||
|
memcpy(data + index, a.data, d * (*data).sizeof);
|
||||||
|
dim += d;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void insert(size_t index, T ptr)
|
||||||
|
{
|
||||||
|
reserve(1);
|
||||||
|
memmove(data + index + 1, data + index, (dim - index) * (*data).sizeof);
|
||||||
|
data[index] = ptr;
|
||||||
|
dim++;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setDim(size_t newdim)
|
||||||
|
{
|
||||||
|
if (dim < newdim)
|
||||||
|
{
|
||||||
|
reserve(newdim - dim);
|
||||||
|
}
|
||||||
|
dim = newdim;
|
||||||
|
}
|
||||||
|
|
||||||
|
ref T opIndex(size_t i)
|
||||||
|
{
|
||||||
|
return data[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
T* tdata()
|
||||||
|
{
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
typeof(this)* copy()
|
||||||
|
{
|
||||||
|
auto a = new typeof(this)();
|
||||||
|
a.setDim(dim);
|
||||||
|
memcpy(a.data, data, dim * (void*).sizeof);
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
void shift(T ptr)
|
||||||
|
{
|
||||||
|
reserve(1);
|
||||||
|
memmove(data + 1, data, dim * (*data).sizeof);
|
||||||
|
data[0] = ptr;
|
||||||
|
dim++;
|
||||||
|
}
|
||||||
|
|
||||||
|
void zero()
|
||||||
|
{
|
||||||
|
memset(data, 0, dim * (data[0]).sizeof);
|
||||||
|
}
|
||||||
|
|
||||||
|
T pop()
|
||||||
|
{
|
||||||
|
return data[--dim];
|
||||||
|
}
|
||||||
|
|
||||||
|
int apply(int function(T, void*) fp, void* param)
|
||||||
|
{
|
||||||
|
static if (is(typeof(T.init.apply(fp, null))))
|
||||||
|
{
|
||||||
|
for (size_t i = 0; i < dim; i++)
|
||||||
|
{
|
||||||
|
T e = data[i];
|
||||||
|
if (e)
|
||||||
|
{
|
||||||
|
if (e.apply(fp, param))
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
assert(0);
|
||||||
|
}
|
||||||
|
}
|
35
src/root/longdouble.d
Normal file
35
src/root/longdouble.d
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
// Compiler implementation of the D programming language
|
||||||
|
// Copyright (c) 1999-2015 by Digital Mars
|
||||||
|
// All Rights Reserved
|
||||||
|
// written by Walter Bright
|
||||||
|
// http://www.digitalmars.com
|
||||||
|
// Distributed under the Boost Software License, Version 1.0.
|
||||||
|
// http://www.boost.org/LICENSE_1_0.txt
|
||||||
|
|
||||||
|
module ddmd.root.longdouble;
|
||||||
|
|
||||||
|
import core.stdc.stdio;
|
||||||
|
|
||||||
|
real ldouble(T)(T x)
|
||||||
|
{
|
||||||
|
return cast(real)x;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t ld_sprint(char* str, int fmt, real x)
|
||||||
|
{
|
||||||
|
if ((cast(real)cast(ulong)x) == x)
|
||||||
|
{
|
||||||
|
// ((1.5 -> 1 -> 1.0) == 1.5) is false
|
||||||
|
// ((1.0 -> 1 -> 1.0) == 1.0) is true
|
||||||
|
// see http://en.cppreference.com/w/cpp/io/c/fprintf
|
||||||
|
char sfmt[5] = "%#Lg\0";
|
||||||
|
sfmt[3] = cast(char)fmt;
|
||||||
|
return sprintf(str, sfmt.ptr, x);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
char sfmt[4] = "%Lg\0";
|
||||||
|
sfmt[2] = cast(char)fmt;
|
||||||
|
return sprintf(str, sfmt.ptr, x);
|
||||||
|
}
|
||||||
|
}
|
207
src/root/port.d
Normal file
207
src/root/port.d
Normal file
|
@ -0,0 +1,207 @@
|
||||||
|
// Compiler implementation of the D programming language
|
||||||
|
// Copyright (c) 1999-2015 by Digital Mars
|
||||||
|
// All Rights Reserved
|
||||||
|
// written by Walter Bright
|
||||||
|
// http://www.digitalmars.com
|
||||||
|
// Distributed under the Boost Software License, Version 1.0.
|
||||||
|
// http://www.boost.org/LICENSE_1_0.txt
|
||||||
|
|
||||||
|
module ddmd.root.port;
|
||||||
|
|
||||||
|
import core.stdc.ctype;
|
||||||
|
import core.stdc.string;
|
||||||
|
import core.math;
|
||||||
|
|
||||||
|
version (Windows) __gshared extern (C) extern const(char)* __locale_decpoint;
|
||||||
|
|
||||||
|
extern (C) float strtof(const(char)* p, char** endp);
|
||||||
|
extern (C) double strtod(const(char)* p, char** endp);
|
||||||
|
extern (C) real strtold(const(char)* p, char** endp);
|
||||||
|
|
||||||
|
extern (C++) struct Port
|
||||||
|
{
|
||||||
|
enum nan = double.nan;
|
||||||
|
enum infinity = double.infinity;
|
||||||
|
enum ldbl_max = real.max;
|
||||||
|
enum ldbl_nan = real.nan;
|
||||||
|
enum ldbl_infinity = real.infinity;
|
||||||
|
static __gshared bool yl2x_supported = true;
|
||||||
|
static __gshared bool yl2xp1_supported = true;
|
||||||
|
static __gshared real snan;
|
||||||
|
static this()
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* Use a payload which is different from the machine NaN,
|
||||||
|
* so that uninitialised variables can be
|
||||||
|
* detected even if exceptions are disabled.
|
||||||
|
*/
|
||||||
|
ushort* us = cast(ushort*)&snan;
|
||||||
|
us[0] = 0;
|
||||||
|
us[1] = 0;
|
||||||
|
us[2] = 0;
|
||||||
|
us[3] = 0xA000;
|
||||||
|
us[4] = 0x7FFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool isNan(double r)
|
||||||
|
{
|
||||||
|
return !(r == r);
|
||||||
|
}
|
||||||
|
|
||||||
|
static real sqrt(real x)
|
||||||
|
{
|
||||||
|
return .sqrt(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
static real fmodl(real a, real b)
|
||||||
|
{
|
||||||
|
return a % b;
|
||||||
|
}
|
||||||
|
|
||||||
|
static real fequal(real a, real b)
|
||||||
|
{
|
||||||
|
return memcmp(&a, &b, 10) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int memicmp(const char* s1, const char* s2, size_t n)
|
||||||
|
{
|
||||||
|
int result = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < n; i++)
|
||||||
|
{
|
||||||
|
char c1 = s1[i];
|
||||||
|
char c2 = s2[i];
|
||||||
|
|
||||||
|
result = c1 - c2;
|
||||||
|
if (result)
|
||||||
|
{
|
||||||
|
result = toupper(c1) - toupper(c2);
|
||||||
|
if (result)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
static char* strupr(char* s)
|
||||||
|
{
|
||||||
|
char* t = s;
|
||||||
|
|
||||||
|
while (*s)
|
||||||
|
{
|
||||||
|
*s = cast(char)toupper(*s);
|
||||||
|
s++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int isSignallingNan(double r)
|
||||||
|
{
|
||||||
|
return isNan(r) && !(((cast(ubyte*)&r)[6]) & 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int isSignallingNan(real r)
|
||||||
|
{
|
||||||
|
return isNan(r) && !(((cast(ubyte*)&r)[7]) & 0x40);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int isInfinity(double r)
|
||||||
|
{
|
||||||
|
return r is double.infinity || r is -double.infinity;
|
||||||
|
}
|
||||||
|
|
||||||
|
static float strtof(const(char)* p, char** endp)
|
||||||
|
{
|
||||||
|
version (Windows)
|
||||||
|
{
|
||||||
|
auto save = __locale_decpoint;
|
||||||
|
__locale_decpoint = ".";
|
||||||
|
}
|
||||||
|
auto r = .strtof(p, endp);
|
||||||
|
version (Windows) __locale_decpoint = save;
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
static double strtod(const(char)* p, char** endp)
|
||||||
|
{
|
||||||
|
version (Windows)
|
||||||
|
{
|
||||||
|
auto save = __locale_decpoint;
|
||||||
|
__locale_decpoint = ".";
|
||||||
|
}
|
||||||
|
auto r = .strtod(p, endp);
|
||||||
|
version (Windows) __locale_decpoint = save;
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
static real strtold(const(char)* p, char** endp)
|
||||||
|
{
|
||||||
|
version (Windows)
|
||||||
|
{
|
||||||
|
auto save = __locale_decpoint;
|
||||||
|
__locale_decpoint = ".";
|
||||||
|
}
|
||||||
|
auto r = .strtold(p, endp);
|
||||||
|
version (Windows) __locale_decpoint = save;
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void yl2x_impl(real* x, real* y, real* res)
|
||||||
|
{
|
||||||
|
*res = yl2x(*x, *y);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void yl2xp1_impl(real* x, real* y, real* res)
|
||||||
|
{
|
||||||
|
*res = yl2xp1(*x, *y);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Little endian
|
||||||
|
static void writelongLE(uint value, void* buffer)
|
||||||
|
{
|
||||||
|
auto p = cast(ubyte*)buffer;
|
||||||
|
p[3] = cast(ubyte)(value >> 24);
|
||||||
|
p[2] = cast(ubyte)(value >> 16);
|
||||||
|
p[1] = cast(ubyte)(value >> 8);
|
||||||
|
p[0] = cast(ubyte)(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Little endian
|
||||||
|
static uint readlongLE(void* buffer)
|
||||||
|
{
|
||||||
|
auto p = cast(ubyte*)buffer;
|
||||||
|
return (((((p[3] << 8) | p[2]) << 8) | p[1]) << 8) | p[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Big endian
|
||||||
|
static void writelongBE(uint value, void* buffer)
|
||||||
|
{
|
||||||
|
auto p = cast(ubyte*)buffer;
|
||||||
|
p[0] = cast(ubyte)(value >> 24);
|
||||||
|
p[1] = cast(ubyte)(value >> 16);
|
||||||
|
p[2] = cast(ubyte)(value >> 8);
|
||||||
|
p[3] = cast(ubyte)(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Big endian
|
||||||
|
static uint readlongBE(void* buffer)
|
||||||
|
{
|
||||||
|
auto p = cast(ubyte*)buffer;
|
||||||
|
return (((((p[0] << 8) | p[1]) << 8) | p[2]) << 8) | p[3];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Little endian
|
||||||
|
static uint readwordLE(void* buffer)
|
||||||
|
{
|
||||||
|
auto p = cast(ubyte*)buffer;
|
||||||
|
return (p[1] << 8) | p[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Big endian
|
||||||
|
static uint readwordBE(void* buffer)
|
||||||
|
{
|
||||||
|
auto p = cast(ubyte*)buffer;
|
||||||
|
return (p[0] << 8) | p[1];
|
||||||
|
}
|
||||||
|
}
|
191
src/root/rmem.d
Normal file
191
src/root/rmem.d
Normal file
|
@ -0,0 +1,191 @@
|
||||||
|
// Compiler implementation of the D programming language
|
||||||
|
// Copyright (c) 1999-2015 by Digital Mars
|
||||||
|
// All Rights Reserved
|
||||||
|
// written by Walter Bright
|
||||||
|
// http://www.digitalmars.com
|
||||||
|
// Distributed under the Boost Software License, Version 1.0.
|
||||||
|
// http://www.boost.org/LICENSE_1_0.txt
|
||||||
|
|
||||||
|
module ddmd.root.rmem;
|
||||||
|
|
||||||
|
import core.stdc.string;
|
||||||
|
|
||||||
|
version (GC)
|
||||||
|
{
|
||||||
|
import core.memory : GC;
|
||||||
|
|
||||||
|
extern (C++) struct Mem
|
||||||
|
{
|
||||||
|
char* xstrdup(const char* p)
|
||||||
|
{
|
||||||
|
return p[0 .. strlen(p) + 1].dup.ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void xfree(void* p)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void* xmalloc(size_t n)
|
||||||
|
{
|
||||||
|
return GC.malloc(n);
|
||||||
|
}
|
||||||
|
|
||||||
|
void* xcalloc(size_t size, size_t n)
|
||||||
|
{
|
||||||
|
return GC.calloc(size * n);
|
||||||
|
}
|
||||||
|
|
||||||
|
void* xrealloc(void* p, size_t size)
|
||||||
|
{
|
||||||
|
return GC.realloc(p, size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extern (C++) __gshared Mem mem;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
import core.stdc.stdlib;
|
||||||
|
import core.stdc.stdio;
|
||||||
|
|
||||||
|
extern (C++) struct Mem
|
||||||
|
{
|
||||||
|
char* xstrdup(const char* s)
|
||||||
|
{
|
||||||
|
if (s)
|
||||||
|
{
|
||||||
|
auto p = .strdup(s);
|
||||||
|
if (p)
|
||||||
|
return p;
|
||||||
|
error();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
void xfree(void* p)
|
||||||
|
{
|
||||||
|
if (p)
|
||||||
|
.free(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
void* xmalloc(size_t size)
|
||||||
|
{
|
||||||
|
if (!size)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
auto p = .malloc(size);
|
||||||
|
if (!p)
|
||||||
|
error();
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
void* xcalloc(size_t size, size_t n)
|
||||||
|
{
|
||||||
|
if (!size || !n)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
auto p = .calloc(size, n);
|
||||||
|
if (!p)
|
||||||
|
error();
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
void* xrealloc(void* p, size_t size)
|
||||||
|
{
|
||||||
|
if (!size)
|
||||||
|
{
|
||||||
|
if (p)
|
||||||
|
.free(p);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!p)
|
||||||
|
{
|
||||||
|
p = .malloc(size);
|
||||||
|
if (!p)
|
||||||
|
error();
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
p = .realloc(p, size);
|
||||||
|
if (!p)
|
||||||
|
error();
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
void error()
|
||||||
|
{
|
||||||
|
printf("Error: out of memory\n");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extern (C++) __gshared Mem mem;
|
||||||
|
|
||||||
|
enum CHUNK_SIZE = (256 * 4096 - 64);
|
||||||
|
|
||||||
|
__gshared size_t heapleft = 0;
|
||||||
|
__gshared void* heapp;
|
||||||
|
|
||||||
|
extern (C++) void* allocmemory(size_t m_size)
|
||||||
|
{
|
||||||
|
// 16 byte alignment is better (and sometimes needed) for doubles
|
||||||
|
m_size = (m_size + 15) & ~15;
|
||||||
|
|
||||||
|
// The layout of the code is selected so the most common case is straight through
|
||||||
|
if (m_size <= heapleft)
|
||||||
|
{
|
||||||
|
L1:
|
||||||
|
heapleft -= m_size;
|
||||||
|
auto p = heapp;
|
||||||
|
heapp = cast(void*)(cast(char*)heapp + m_size);
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_size > CHUNK_SIZE)
|
||||||
|
{
|
||||||
|
auto p = malloc(m_size);
|
||||||
|
if (p)
|
||||||
|
{
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
printf("Error: out of memory\n");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
heapleft = CHUNK_SIZE;
|
||||||
|
heapp = malloc(CHUNK_SIZE);
|
||||||
|
if (!heapp)
|
||||||
|
{
|
||||||
|
printf("Error: out of memory\n");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
goto L1;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern (C) void* _d_allocmemory(size_t m_size)
|
||||||
|
{
|
||||||
|
return allocmemory(m_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
extern (C) Object _d_newclass(const ClassInfo ci)
|
||||||
|
{
|
||||||
|
auto p = allocmemory(ci.init.length);
|
||||||
|
(cast(byte*)p)[0 .. ci.init.length] = ci.init[];
|
||||||
|
return cast(Object)p;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern (C) void* _d_newitemT(TypeInfo ti)
|
||||||
|
{
|
||||||
|
auto p = allocmemory(ti.tsize);
|
||||||
|
(cast(ubyte*)p)[0 .. ti.init.length] = 0;
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern (C) void* _d_newitemiT(TypeInfo ti)
|
||||||
|
{
|
||||||
|
auto p = allocmemory(ti.tsize);
|
||||||
|
p[0 .. ti.init.length] = ti.init[];
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
}
|
50
src/root/rootobject.d
Normal file
50
src/root/rootobject.d
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
// Compiler implementation of the D programming language
|
||||||
|
// Copyright (c) 1999-2015 by Digital Mars
|
||||||
|
// All Rights Reserved
|
||||||
|
// written by Walter Bright
|
||||||
|
// http://www.digitalmars.com
|
||||||
|
// Distributed under the Boost Software License, Version 1.0.
|
||||||
|
// http://www.boost.org/LICENSE_1_0.txt
|
||||||
|
|
||||||
|
module ddmd.root.rootobject;
|
||||||
|
|
||||||
|
import core.stdc.stdio;
|
||||||
|
|
||||||
|
import ddmd.root.outbuffer;
|
||||||
|
|
||||||
|
extern (C++) class RootObject
|
||||||
|
{
|
||||||
|
this()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool equals(RootObject o)
|
||||||
|
{
|
||||||
|
return o is this;
|
||||||
|
}
|
||||||
|
|
||||||
|
int compare(RootObject)
|
||||||
|
{
|
||||||
|
assert(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void print()
|
||||||
|
{
|
||||||
|
printf("%s %p\n", toChars(), this);
|
||||||
|
}
|
||||||
|
|
||||||
|
char* toChars()
|
||||||
|
{
|
||||||
|
assert(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void toBuffer(OutBuffer* buf)
|
||||||
|
{
|
||||||
|
assert(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int dyncast()
|
||||||
|
{
|
||||||
|
assert(0);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue