Skip to content

Commit

Permalink
add support for array concatenation
Browse files Browse the repository at this point in the history
  • Loading branch information
Axel Ricard committed Sep 20, 2023
1 parent b3de8c0 commit 7d372b9
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 21 deletions.
8 changes: 4 additions & 4 deletions gen/arrays.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -893,10 +893,10 @@ DSliceValue *DtoCatArrays(const Loc &loc, Type *arrayType, Expression *exp1,
args.push_back(loadArray(exp2,2));
}

/* // file */
/* args.push_back(DtoConstString(loc.filename)); */
/* // line */
/* args.push_back(DtoConstUint(loc.linnum)); */
// line
args.push_back(DtoConstUint(loc.linnum));
// file
args.push_back(DtoConstString(loc.filename));

auto newArray = gIR->CreateCallOrInvoke(fn, args, ".appendedArray");
return getSlice(arrayType, newArray);
Expand Down
8 changes: 4 additions & 4 deletions gen/runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -613,13 +613,13 @@ static void buildRuntimeModule() {
createFwdDecl(LINK::c, voidArrayTy, {"_d_arrayappendcd", "_d_arrayappendwd"},
{voidArrayTy, dcharTy, stringTy, uintTy}, {STCref, 0});

// byte[] _d_arraycatT(const TypeInfo ti, byte[] x, byte[] y, string file, uint line)
// byte[] _d_arraycatT(const TypeInfo ti, byte[] x, byte[] y, uint line, string file)
createFwdDecl(LINK::c, voidArrayTy, {"_d_arraycatT"},
{typeInfoTy, voidArrayTy, voidArrayTy, /*stringTy, uintTy*/}, {STCconst, 0, 0});
{typeInfoTy, voidArrayTy, voidArrayTy, uintTy, stringTy}, {STCconst, 0, 0});

// void[] _d_arraycatnTX(const TypeInfo ti, byte[][] arrs, string file, uint line)
// void[] _d_arraycatnTX(const TypeInfo ti, byte[][] arrs, uint line, string file)
createFwdDecl(LINK::c, voidArrayTy, {"_d_arraycatnTX"},
{typeInfoTy, voidArrayTy->arrayOf(), /*stringTy, uintTy*/}, {STCconst, 0});
{typeInfoTy, voidArrayTy->arrayOf(), uintTy, stringTy}, {STCconst, 0});

// Object _d_newclass(const ClassInfo ci)
createFwdDecl(LINK::c, objectTy, {"_d_newclass"},
Expand Down
4 changes: 2 additions & 2 deletions runtime/druntime/src/core/internal/array/concatenation.d
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
module core.internal.array.concatenation;

/// See $(REF _d_arraycatnTX, rt,lifetime)
private extern (C) void[] _d_arraycatnTX(const TypeInfo ti, scope byte[][] arrs, string file, uint line) pure nothrow;
private extern (C) void[] _d_arraycatnTX(const TypeInfo ti, scope byte[][] arrs, uint line, string file) pure nothrow;

/// Implementation of `_d_arraycatnTX` and `_d_arraycatnTXTrace`
template _d_arraycatnTXImpl(Tarr : ResultArrT[], ResultArrT : T[], T)
Expand All @@ -36,7 +36,7 @@ template _d_arraycatnTXImpl(Tarr : ResultArrT[], ResultArrT : T[], T)
auto ti = typeid(ResultArrT);

byte[][] arrs2 = (cast(byte[]*)arrs.ptr)[0 .. arrs.length];
void[] result = ._d_arraycatnTX(ti, arrs2, "", 0);
void[] result = ._d_arraycatnTX(ti, arrs2, 0, "");
return (cast(T*)result.ptr)[0 .. result.length];
}
else
Expand Down
20 changes: 10 additions & 10 deletions runtime/druntime/src/rt/lifetime.d
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ version (LDC)
*/
extern (C) void* _d_allocmemoryT(TypeInfo ti, string file, uint line) @weak
{
return GC.malloc(ti.tsize(), !(ti.flags() & 1) ? BlkAttr.NO_SCAN : 0, ti,
return GC.malloc(ti.tsize(), !(ti.flags() & 1) ? BlkAttr.NO_SCAN : 0, ti,
DebugInfo.alloc(file, line, ti.tsize(), ti));
}

Expand All @@ -101,7 +101,7 @@ Returns: newly created object
*/
// adapted for LDC
pragma(inline, true)
private extern (D) Object _d_newclass(bool initialize)(const ClassInfo ci,
private extern (D) Object _d_newclass(bool initialize)(const ClassInfo ci,
in string filename = "", int line = 0)
{
import core.stdc.stdlib;
Expand Down Expand Up @@ -507,7 +507,7 @@ private BlkInfo __arrayAlloc(size_t arrsize, ref BlkInfo info, const scope TypeI
return BlkInfo();
}

auto bi = GC.qalloc(padded_size, info.attr, tinext,
auto bi = GC.qalloc(padded_size, info.attr, tinext,
DebugInfo.arrayAlloc(file, line, padded_size, tinext));
__arrayClearPad(bi, arrsize, padsize);
return bi;
Expand Down Expand Up @@ -998,7 +998,7 @@ Params:
length = `.length` of resulting array
Returns: newly allocated array
*/
extern (C) void[] _d_newarrayU(const scope TypeInfo ti, size_t length,
extern (C) void[] _d_newarrayU(const scope TypeInfo ti, size_t length,
string file, uint line) pure nothrow @weak
{
import core.exception : onOutOfMemoryError;
Expand Down Expand Up @@ -1231,7 +1231,7 @@ extern (C) void* _d_newitemU(scope const TypeInfo _ti, string file, uint line) p
if (tiSize)
flags |= BlkAttr.STRUCTFINAL | BlkAttr.FINALIZE;

auto blkInf = GC.qalloc(size, flags, ti,
auto blkInf = GC.qalloc(size, flags, ti,
DebugInfo.alloc(file, line, size, ti));
auto p = blkInf.base;

Expand Down Expand Up @@ -1730,7 +1730,7 @@ do
}

/// ditto
extern (C) void[] _d_arraysetlengthiT(const TypeInfo ti, size_t newlength, void[]* p,
extern (C) void[] _d_arraysetlengthiT(const TypeInfo ti, size_t newlength, void[]* p,
string file, uint line) @weak
in
{
Expand Down Expand Up @@ -2304,7 +2304,7 @@ Params:
Returns:
resulting concatenated array, with `.length` equal to new element length despite `byte` type
*/
extern (C) byte[] _d_arraycatT(const TypeInfo ti, byte[] x, byte[] y) @weak
extern (C) byte[] _d_arraycatT(const TypeInfo ti, byte[] x, byte[] y, uint line, string file) @weak
out (result)
{
auto tinext = unqualify(ti.next);
Expand Down Expand Up @@ -2353,7 +2353,7 @@ do
if (!len)
return null;

auto info = __arrayAlloc(len, ti, tinext, "_d_arraycatT: TODO", 0);
auto info = __arrayAlloc(len, ti, tinext, file, line);
byte* p = cast(byte*)__arrayStart(info);
p[len] = 0; // guessing this is to optimize for null-terminated arrays?
memcpy(p, x.ptr, xlen);
Expand Down Expand Up @@ -2389,7 +2389,7 @@ Params:
Returns:
newly created concatenated array, `.length` equal to the total element length despite `void` type
*/
extern (C) void[] _d_arraycatnTX(const TypeInfo ti, scope byte[][] arrs) @weak
extern (C) void[] _d_arraycatnTX(const TypeInfo ti, scope byte[][] arrs, uint line, string file) @weak
{
import core.stdc.string;

Expand All @@ -2404,7 +2404,7 @@ extern (C) void[] _d_arraycatnTX(const TypeInfo ti, scope byte[][] arrs) @weak
return null;

auto allocsize = length * size;
auto info = __arrayAlloc(allocsize, ti, tinext, "_d_arraycatnTX: TODO", 0);
auto info = __arrayAlloc(allocsize, ti, tinext, file, line);
auto isshared = typeid(ti) is typeid(TypeInfo_Shared);
__setArrayAllocLength(info, allocsize, isshared, tinext);
void *a = __arrayStart (info);
Expand Down
2 changes: 1 addition & 1 deletion runtime/druntime/src/rt/tracegc.d
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ extern (C) void _d_delclass(Object* p);
extern (C) void _d_delinterface(void** p);
extern (C) void _d_delmemory(void* *p);
extern (C) byte[] _d_arraycatT(const TypeInfo ti, byte[] x, byte[] y);
extern (C) void[] _d_arraycatnTX(const TypeInfo ti, scope byte[][] arrs);
extern (C) void[] _d_arraycatnTX(const TypeInfo ti, scope byte[][] arrs, uint l, string f);
extern (C) void* _d_arrayliteralTX(const TypeInfo ti, size_t length);
extern (C) void* _d_assocarrayliteralTX(const TypeInfo_AssociativeArray ti,
void[] keys, void[] vals);
Expand Down

0 comments on commit 7d372b9

Please sign in to comment.