Web assembly #6
2 changed files with 19 additions and 45 deletions
|
|
@ -16,17 +16,6 @@ version (Windows)
|
||||||
/*extern(Windows) void* __alloca(size_t size) @nogc nothrow @system;
|
/*extern(Windows) void* __alloca(size_t size) @nogc nothrow @system;
|
||||||
alias alloca = __alloca;*/
|
alias alloca = __alloca;*/
|
||||||
|
|
||||||
private const uint max_alloca = 10000;
|
|
||||||
private char[max_alloca] alloca_array;
|
|
||||||
private uint alloca_pos = 0;
|
|
||||||
void* alloca(size_t length) @nogc nothrow
|
|
||||||
{
|
|
||||||
if(alloca_pos + length > max_alloca)alloca_pos = 0;
|
|
||||||
void* ret = &alloca_array[alloca_pos];
|
|
||||||
alloca_pos += length;
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
extern(Windows) void ___chkstk_ms() @nogc nothrow @system;
|
extern(Windows) void ___chkstk_ms() @nogc nothrow @system;
|
||||||
|
|
||||||
extern(Windows) void __chkstk()
|
extern(Windows) void __chkstk()
|
||||||
|
|
@ -34,7 +23,14 @@ version (Windows)
|
||||||
___chkstk_ms();
|
___chkstk_ms();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
|
else version (Posix)
|
||||||
|
{
|
||||||
|
import core.sys.posix.pthread;
|
||||||
|
import core.sys.posix.stdlib;
|
||||||
|
}
|
||||||
|
|
||||||
|
version(D_betterC)
|
||||||
{
|
{
|
||||||
private const uint max_alloca = 10000;
|
private const uint max_alloca = 10000;
|
||||||
private char[max_alloca] alloca_array;
|
private char[max_alloca] alloca_array;
|
||||||
|
|
@ -47,13 +43,7 @@ version (Windows)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
else public import core.stdc.stdlib : alloca;
|
||||||
else version (Posix)
|
|
||||||
{
|
|
||||||
import core.sys.posix.pthread;
|
|
||||||
import core.sys.posix.stdlib;
|
|
||||||
public import core.stdc.stdlib : alloca;
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct Mallocator
|
static struct Mallocator
|
||||||
{
|
{
|
||||||
|
|
@ -61,7 +51,7 @@ static struct Mallocator
|
||||||
{
|
{
|
||||||
T[] ret = (cast(T*)malloc(T.sizeof * length))[0 .. length];
|
T[] ret = (cast(T*)malloc(T.sizeof * length))[0 .. length];
|
||||||
|
|
||||||
/*static if(__traits(isPOD, T))
|
static if(__traits(isPOD, T))
|
||||||
{
|
{
|
||||||
static immutable T init = T.init;
|
static immutable T init = T.init;
|
||||||
|
|
||||||
|
|
@ -71,21 +61,13 @@ static struct Mallocator
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{*/
|
{
|
||||||
static import std.conv;
|
static import std.conv;
|
||||||
foreach(i;0..ret.length)
|
foreach(i;0..ret.length)
|
||||||
{
|
{
|
||||||
std.conv.emplace(&ret[i]);
|
std.conv.emplace(&ret[i]);
|
||||||
}
|
}
|
||||||
// }
|
}
|
||||||
|
|
||||||
//static if(is(T == struct))std.conv.emplace(ret);
|
|
||||||
//static import std.conv;
|
|
||||||
//emplace
|
|
||||||
/*foreach(i;0..ret.length)
|
|
||||||
{
|
|
||||||
memcpy(ret);
|
|
||||||
}*/
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -94,7 +76,6 @@ static struct Mallocator
|
||||||
T[] ret = (cast(T*)malloc(T.sizeof * length))[0 .. length];
|
T[] ret = (cast(T*)malloc(T.sizeof * length))[0 .. length];
|
||||||
foreach(ref v; ret)v = initializer;
|
foreach(ref v; ret)v = initializer;
|
||||||
return ret;
|
return ret;
|
||||||
//return (cast(T*)ret)[0 .. length];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static T[] expandArray(T)(T[] array, size_t length) nothrow @nogc
|
static T[] expandArray(T)(T[] array, size_t length) nothrow @nogc
|
||||||
|
|
@ -107,17 +88,12 @@ static struct Mallocator
|
||||||
{
|
{
|
||||||
T[] ret = (cast(T*)malloc(T.sizeof * array.length))[0 .. array.length];//Mallocator.makeArray!(T)(array.length);
|
T[] ret = (cast(T*)malloc(T.sizeof * array.length))[0 .. array.length];//Mallocator.makeArray!(T)(array.length);
|
||||||
foreach(i, ref v;ret)v = array[i];
|
foreach(i, ref v;ret)v = array[i];
|
||||||
//ret[0 .. $] = array;
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static T* make(T, Args...)(Args args)
|
static T* make(T, Args...)(Args args)
|
||||||
{
|
{
|
||||||
T* ret = cast(T*)malloc(T.sizeof);
|
T* ret = cast(T*)malloc(T.sizeof);
|
||||||
//*ret = T.init;
|
|
||||||
//static immutable T init = T();
|
|
||||||
//memcpy(ret, &init, T.sizeof);
|
|
||||||
//static if(__traits(hasMember, T, "__ctor"))ret.__ctor(args);
|
|
||||||
static import std.conv;
|
static import std.conv;
|
||||||
static if(__traits(isPOD, T))
|
static if(__traits(isPOD, T))
|
||||||
{
|
{
|
||||||
|
|
@ -125,7 +101,6 @@ static struct Mallocator
|
||||||
memcpy(ret, &init, T.sizeof);
|
memcpy(ret, &init, T.sizeof);
|
||||||
}
|
}
|
||||||
else static if(is(T == struct))std.conv.emplace(ret, args);
|
else static if(is(T == struct))std.conv.emplace(ret, args);
|
||||||
//else std.conv.emplace(ret, args);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -135,7 +110,6 @@ static struct Mallocator
|
||||||
version(Posix)posix_memalign(&ret, alignment, length);//ret = aligned_alloc(alignment, length);
|
version(Posix)posix_memalign(&ret, alignment, length);//ret = aligned_alloc(alignment, length);
|
||||||
else version(Windows)ret = _aligned_malloc(length, alignment);
|
else version(Windows)ret = _aligned_malloc(length, alignment);
|
||||||
else static assert(0, "Unimplemented platform!");
|
else static assert(0, "Unimplemented platform!");
|
||||||
//posix_memalign(&ret, alignment, length);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -512,7 +512,7 @@ extern(C) int main()
|
||||||
printf("TestComp(%u, %u)",test_comp.a,test_comp.b);//write(*test_comp);
|
printf("TestComp(%u, %u)",test_comp.a,test_comp.b);//write(*test_comp);
|
||||||
TestComp2* test_comp2 = entity.getComponent!TestComp2;
|
TestComp2* test_comp2 = entity.getComponent!TestComp2;
|
||||||
if (test_comp2)
|
if (test_comp2)
|
||||||
printf("TestComp2(%u, %u)",test_comp2.a,test_comp2.b);//write(*test_comp2);
|
printf("TestComp2(%u, %u)",test_comp2.b,test_comp2.a);//write(*test_comp2);
|
||||||
TestComp3* test_comp3 = entity.getComponent!TestComp3;
|
TestComp3* test_comp3 = entity.getComponent!TestComp3;
|
||||||
if (test_comp3)
|
if (test_comp3)
|
||||||
printf("TestComp3(%u, %u)",test_comp3.gg,test_comp3.bg);//write(*test_comp3);
|
printf("TestComp3(%u, %u)",test_comp3.gg,test_comp3.bg);//write(*test_comp3);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue