diff --git a/dub.sdl b/dub.sdl index 8ed5d4e..00b1dfc 100644 --- a/dub.sdl +++ b/dub.sdl @@ -4,3 +4,10 @@ authors "Team Phobos" copyright "Copyright © 2017, Team Phobos" license "BSL-1.0" dependency "mir-core" version=">=0.0.5 <0.3.0" + +configuration "unittest" { +} + +configuration "wasm" { + dflags "-mtriple=wasm32-unknown-unknown-wasm" "-betterC" +} diff --git a/source/stdx/allocator/building_blocks/bitmapped_block.d b/source/stdx/allocator/building_blocks/bitmapped_block.d index 81d8841..b67f55c 100644 --- a/source/stdx/allocator/building_blocks/bitmapped_block.d +++ b/source/stdx/allocator/building_blocks/bitmapped_block.d @@ -57,7 +57,14 @@ struct BitmappedBlock(size_t theBlockSize, uint theAlignment = platformAlignment auto m = cast(ubyte[])(AlignedMallocator.instance.alignedAllocate(1024 * 64, max(theAlignment, cast(uint) size_t.sizeof))); scope(exit) AlignedMallocator.instance.deallocate(m); - testAllocator!(() => BitmappedBlock(m)); + static if (theBlockSize == chooseAtRuntime) + { + testAllocator!(() => BitmappedBlock!(theBlockSize, theAlignment, NullAllocator)(m, 64)); + } + else + { + testAllocator!(() => BitmappedBlock!(theBlockSize, theAlignment, NullAllocator)(m)); + } } static assert(theBlockSize > 0 && theAlignment.isGoodStaticAlignment); static assert(theBlockSize == chooseAtRuntime @@ -81,7 +88,7 @@ struct BitmappedBlock(size_t theBlockSize, uint theAlignment = platformAlignment @property uint blockSize() { return _blockSize; } @property void blockSize(uint s) { - assert(!_control && s % alignment == 0); + assert(_control.allAre0() && s % alignment == 0); _blockSize = s; } private uint _blockSize; @@ -193,6 +200,13 @@ struct BitmappedBlock(size_t theBlockSize, uint theAlignment = platformAlignment assert(_blocks * blockSize >= capacity); } + static if (chooseAtRuntime == theBlockSize) + this(ubyte[] data, uint blockSize) + { + this._blockSize = blockSize; + this(data); + } + /** If $(D ParentAllocator) is not $(D NullAllocator) and defines $(D deallocate), the destructor is defined to deallocate the block held. diff --git a/source/stdx/allocator/building_blocks/region.d b/source/stdx/allocator/building_blocks/region.d index c25ff62..43d6c71 100644 --- a/source/stdx/allocator/building_blocks/region.d +++ b/source/stdx/allocator/building_blocks/region.d @@ -390,6 +390,7 @@ struct InSituRegion(size_t size, size_t minAlign = platformAlignment) else version (MIPS64) enum growDownwards = Yes.growDownwards; else version (SPARC) enum growDownwards = Yes.growDownwards; else version (SystemZ) enum growDownwards = Yes.growDownwards; + else version (WebAssembly) enum growDownwards = Yes.growDownwards; else static assert(0, "Dunno how the stack grows on this architecture."); @disable this(this); diff --git a/source/stdx/allocator/building_blocks/segregator.d b/source/stdx/allocator/building_blocks/segregator.d index 361f3bf..830c7a1 100644 --- a/source/stdx/allocator/building_blocks/segregator.d +++ b/source/stdx/allocator/building_blocks/segregator.d @@ -247,7 +247,7 @@ struct Segregator(size_t threshold, SmallAllocator, LargeAllocator) && __traits(hasMember, LargeAllocator, "empty")) Ternary empty() { - return _small.empty && _large.empty; + return _small.empty & _large.empty; } static if (__traits(hasMember, SmallAllocator, "resolveInternalPointer") diff --git a/source/stdx/allocator/building_blocks/stats_collector.d b/source/stdx/allocator/building_blocks/stats_collector.d index 27f60d2..5eda26f 100644 --- a/source/stdx/allocator/building_blocks/stats_collector.d +++ b/source/stdx/allocator/building_blocks/stats_collector.d @@ -160,7 +160,7 @@ struct StatsCollector(Allocator, ulong flags = Options.all, private: import stdx.allocator.internal : Ternary; - static string define(string type, string[] names...) + enum define = (string type, string[] names...) { string result; foreach (v; names) @@ -169,7 +169,7 @@ private: ~ "public const("~type~") "~v~"() const { return _"~v~"; }" ~ "}"; return result; - } + }; void add(string counter)(sizediff_t n) { diff --git a/source/stdx/allocator/common.d b/source/stdx/allocator/common.d index a0f5663..776e78f 100644 --- a/source/stdx/allocator/common.d +++ b/source/stdx/allocator/common.d @@ -403,7 +403,7 @@ bool alignedReallocate(Allocator)(auto ref Allocator alloc, /** Forwards each of the methods in `funs` (if defined) to `member`. */ -/*package*/ string forwardToMember(string member, string[] funs...) +/*package*/ enum forwardToMember = (string member, string[] funs...) { string result = " import std.traits : Parameters;\n"; foreach (fun; funs) @@ -424,7 +424,7 @@ Forwards each of the methods in `funs` (if defined) to `member`. }\n"; } return result; -} +}; version(unittest) { diff --git a/source/stdx/allocator/gc_allocator.d b/source/stdx/allocator/gc_allocator.d index a607329..eecdf7e 100644 --- a/source/stdx/allocator/gc_allocator.d +++ b/source/stdx/allocator/gc_allocator.d @@ -2,6 +2,14 @@ module stdx.allocator.gc_allocator; import stdx.allocator.common; +version (D_BetterC) { + import stdx.allocator.building_blocks.null_allocator; + alias GCAllocator = NullAllocator; +} else + version = HasDRuntime; + +version (HasDRuntime): + /** D's built-in garbage-collected allocator. */ diff --git a/source/stdx/allocator/mallocator.d b/source/stdx/allocator/mallocator.d index b7ffc2a..1ada069 100644 --- a/source/stdx/allocator/mallocator.d +++ b/source/stdx/allocator/mallocator.d @@ -201,6 +201,9 @@ version (Windows) /** Aligned allocator using OS-specific primitives, under a uniform API. */ +version (WebAssembly) {} else version = HasMemAlign; + +version (HasMemAlign) struct AlignedMallocator { @system unittest { testAllocator!(() => typeof(this).instance); } diff --git a/source/stdx/allocator/package.d b/source/stdx/allocator/package.d index 0cd28a8..7ca7c71 100644 --- a/source/stdx/allocator/package.d +++ b/source/stdx/allocator/package.d @@ -223,6 +223,10 @@ Source: $(PHOBOSSRC std/experimental/_allocator) module stdx.allocator; +version (D_BetterC) {} else version = HasDRuntime; + +version (HasDRuntime): + public import stdx.allocator.common, stdx.allocator.typed; diff --git a/source/stdx/allocator/showcase.d b/source/stdx/allocator/showcase.d index acc0b34..a73bd44 100644 --- a/source/stdx/allocator/showcase.d +++ b/source/stdx/allocator/showcase.d @@ -7,6 +7,10 @@ facilities, or import individual heap building blocks and assemble them. */ module stdx.allocator.showcase; +version (D_BetterC) {} else version = HasDRuntime; + +version (HasDRuntime): + import stdx.allocator.building_blocks.fallback_allocator, stdx.allocator.gc_allocator, stdx.allocator.building_blocks.region;