some clean up (something broke!)
This commit is contained in:
parent
b0c0120fc4
commit
f98e6cc07f
@ -56,6 +56,8 @@ extern(C)
|
||||
}
|
||||
*/
|
||||
|
||||
@nogc:
|
||||
|
||||
version(WebAssembly)
|
||||
{
|
||||
|
||||
|
||||
@ -18,22 +18,22 @@
|
||||
#endif
|
||||
|
||||
#if !defined(NO_STBI) && !defined(BUILD_WASM)
|
||||
# include "external/stb/stb_image.h"
|
||||
# include "external/stb/stb_image_write.h"
|
||||
# include "../external/stb/stb_image.h"
|
||||
# include "../external/stb/stb_image_write.h"
|
||||
#endif
|
||||
|
||||
#ifdef BUILD_WASM
|
||||
# include "external/tinyalloc/tinyalloc.c"
|
||||
# include "../external/tinyalloc/tinyalloc.c"
|
||||
#endif
|
||||
|
||||
#ifndef NO_STBI
|
||||
# include "external/stb/stb_truetype.h"
|
||||
# include "../external/stb/stb_truetype.h"
|
||||
#endif
|
||||
|
||||
#ifdef DLIB_INCLUDE_VULKAN
|
||||
# include "../VulkanRenderer/vulkan_includes.c"
|
||||
# include "../../VulkanRenderer/vulkan_includes.c"
|
||||
#endif
|
||||
|
||||
#ifndef BUILD_WASM
|
||||
# include "external/cgltf/cgltf.h"
|
||||
# include "../external/cgltf/cgltf.h"
|
||||
#endif
|
||||
|
||||
@ -47,7 +47,7 @@ struct stbtt_fontinfo
|
||||
stbtt__buf fdselect;
|
||||
}
|
||||
|
||||
extern(C):
|
||||
@nogc extern(C):
|
||||
|
||||
// stb_truetype
|
||||
|
||||
|
||||
@ -461,7 +461,7 @@ struct Vector(T, int N)
|
||||
return this;
|
||||
}
|
||||
|
||||
ref Vector opAssign(U)(U u) if(isStaticArray!(U) && U.length == N && isAssignable!(T, typeof(*U.init.ptr)))
|
||||
ref Vector opAssign(U)(U u) if(isArray!(U) && U.length == N)
|
||||
{
|
||||
static foreach(i; 0 .. N)
|
||||
{
|
||||
@ -470,9 +470,12 @@ struct Vector(T, int N)
|
||||
return this;
|
||||
}
|
||||
|
||||
ref Vector opAssign(U)(U u) if(is(U : Vector))
|
||||
ref Vector opAssign(U)(U u) if(isInstanceOf!(Vector, U))
|
||||
{
|
||||
v[] = u.v[];
|
||||
static foreach(i; 0 .. N)
|
||||
{
|
||||
v[i] = cast(T)u.v[i];
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@ -10,30 +10,7 @@ public import dlib.assets;
|
||||
public import dlib.externdecl;
|
||||
|
||||
version(WebAssembly)
|
||||
{
|
||||
version(unittest)
|
||||
{
|
||||
extern(C) void _start()
|
||||
{
|
||||
import wasm;
|
||||
import std.format;
|
||||
|
||||
char[512] buffer;
|
||||
u32[5] arr = [3, 55, 123, 528, 3943];
|
||||
string str = Str(sformat(buffer, "Nigger %s pppp %s", "faggot", arr));
|
||||
|
||||
Console(str, true);
|
||||
|
||||
static foreach(test_fn; __traits(getUnitTests, __traits(parent, _start)))
|
||||
{
|
||||
test_fn();
|
||||
}
|
||||
|
||||
|
||||
Console("success", true);
|
||||
}
|
||||
}
|
||||
}
|
||||
{}
|
||||
else
|
||||
{
|
||||
public import dlibincludes;
|
||||
|
||||
@ -1972,10 +1972,10 @@ version(DLIB_TEST) unittest
|
||||
|
||||
u8[] data_valid, data_test;
|
||||
|
||||
File f = File("platform.d", "rb");
|
||||
File f = File("dlib/platform.d", "rb");
|
||||
|
||||
data_valid = f.rawRead(new u8[f.size()]);
|
||||
data_test = LoadFile(&arena, "platform.d");
|
||||
data_test = LoadFile(&arena, "dlib/platform.d");
|
||||
|
||||
assert(data_valid == data_test);
|
||||
}
|
||||
|
||||
45
dlib/util.d
45
dlib/util.d
@ -7,12 +7,13 @@ import std.traits : isIntegral, hasMember, isArray;
|
||||
|
||||
import core.stdc.string;
|
||||
|
||||
import std.format : sformat;
|
||||
import std.stdio : writeln, writef, writefln;
|
||||
|
||||
//import std.traits;
|
||||
|
||||
static if(NativeTarget)
|
||||
{
|
||||
import std.format : sformat;
|
||||
import std.stdio : writeln, writef, writefln;
|
||||
import dlib.platform;
|
||||
}
|
||||
|
||||
@ -77,6 +78,8 @@ CastArr(T, U)(U[] input_array)
|
||||
return output_array;
|
||||
}
|
||||
|
||||
// TODO: remove exceptions here
|
||||
|
||||
void
|
||||
Logf(string prefix = "INFO ", Args...)(string fmt, Args args)
|
||||
{
|
||||
@ -92,6 +95,11 @@ Logf(string prefix = "INFO ", Args...)(string fmt, Args args)
|
||||
assert(false, "Incompatible format type");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
writef("[%s]: ", prefix);
|
||||
writefln(fmt, args);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
@ -109,6 +117,11 @@ Logif(Args...)(string fmt, Args args, string func = __FUNCTION__)
|
||||
assert(false, "Incompatible format type");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
writef("FN: [%s] ", func);
|
||||
Logf(fmt, args);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
@ -132,44 +145,46 @@ Debugf(Args...)(string fmt, Args args)
|
||||
string
|
||||
Scratchf(Args...)(string fmt, Args args)
|
||||
{
|
||||
static if(NativeTarget)
|
||||
{
|
||||
assert(g_scratch.init);
|
||||
char[] buf = ScratchAlloc!(char)(fmt.length < 16 ? 32 : 128);
|
||||
return Str(sformat(buf, fmt, args));
|
||||
}
|
||||
else static assert(false, NO_IMPL);
|
||||
}
|
||||
|
||||
void
|
||||
Log(string str)
|
||||
{
|
||||
static if(NativeTarget) writeln(str);
|
||||
writeln(str);
|
||||
}
|
||||
|
||||
void
|
||||
Log(char* str)
|
||||
{
|
||||
static if(NativeTarget) writeln(str);
|
||||
writeln(str[0 .. cast(usize)(strlen(str))]);
|
||||
}
|
||||
|
||||
@nogc usize
|
||||
@nogc pure @safe
|
||||
{
|
||||
|
||||
usize
|
||||
KB(usize v)
|
||||
{
|
||||
return v * 1024;
|
||||
};
|
||||
}
|
||||
|
||||
@nogc usize
|
||||
usize
|
||||
MB(usize v)
|
||||
{
|
||||
return KB(v) * 1024;
|
||||
};
|
||||
}
|
||||
|
||||
@nogc usize
|
||||
usize
|
||||
GB(usize v)
|
||||
{
|
||||
return MB(v) * 1024;
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
u32
|
||||
StrCharCount(T)(T str, u8 ch) if(is(T: string) || is(T: u8[]) || is(T: char[]))
|
||||
@ -1339,11 +1354,11 @@ version(DLIB_TEST) unittest
|
||||
arr = CastArr!(u8)(char_arr);
|
||||
}
|
||||
|
||||
static if(NativeTarget)
|
||||
{
|
||||
ResetScratch(MB(4));
|
||||
string str = Scratchf("%s testing %s", 55, "testing");
|
||||
assert(str == "55 testing testing");
|
||||
Logf(str);
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
6
test.sh
6
test.sh
@ -5,18 +5,18 @@ name="Test_Runner"
|
||||
shared_src="dlib/package.d dlib/platform.d dlib/fonts.d dlib/aliases.d dlib/math.d dlib/util.d dlib/alloc.d dlib/assets.d dlib/externdecl.d"
|
||||
|
||||
if [ "$1" == "wasm" ]; then
|
||||
flags="-c -vgc -mtriple=wasm32-unknown-unknown-wasm -fvisibility=public -dllimport=all --unittest --Xcc=-DBUILD_WASM -Iwasm/runtime -L--no-entry -i=core -i=std -i=. -g --real-precision=double --of=build/dlibmain.wasm --d-version=inline_concat -verrors=90"
|
||||
flags="-c -vgc -mtriple=wasm32-unknown-unknown-wasm -d-version=DLIB_TEST -fvisibility=public -dllimport=all --unittest --Xcc=-DBUILD_WASM -Iwasm/runtime -L--no-entry -i=core -i=std -i=. --real-precision=double --of=build/dlibmain.wasm --d-version=inline_concat -verrors=90"
|
||||
wasm_src="wasm/runtime/object.d"
|
||||
|
||||
/bin/bash ./build.sh build wasm
|
||||
|
||||
ldc2 $flags $shared_src $wasm_src
|
||||
|
||||
wasm-ld build/dlibmain.wasm build/dlibincludes.wasm --error-limit=0 --export-memory -obuild/dlib.wasm
|
||||
wasm-ld build/dlibmain.wasm build/dlibincludes.wasm --export=RunTests --error-limit=0 --export-memory -obuild/dlib.wasm
|
||||
|
||||
cp build/dlib.wasm wasm/dlib.wasm
|
||||
else
|
||||
flags="-P-I/usr/include/freetype2 -L-lfreetype --main --unittest -g --of=$name"
|
||||
flags="-P-I/usr/include/freetype2 -Idlib -L-lfreetype --main --unittest -g --of=$name"
|
||||
|
||||
/bin/bash ./build.sh build
|
||||
|
||||
|
||||
BIN
wasm/dlib.wasm
BIN
wasm/dlib.wasm
Binary file not shown.
Binary file not shown.
@ -212,7 +212,7 @@ extern(C) void _d_arraybounds_index(string file, uint line, size_t index, size_t
|
||||
|
||||
// }
|
||||
|
||||
extern(C) void _d_assert(string file, uint line) @trusted @nogc pure
|
||||
extern(C) void _d_assert(string file, uint line) @trusted @nogc
|
||||
{
|
||||
Abort("Assertion failure");
|
||||
}
|
||||
@ -222,12 +222,12 @@ void _d_assertp(immutable(char)* file, uint line)
|
||||
Abort("Assertion failure");
|
||||
}
|
||||
|
||||
extern(C) void _d_assert_msg(string msg, string file, uint line) @trusted @nogc pure
|
||||
extern(C) void _d_assert_msg(string msg, string file, uint line) @trusted @nogc
|
||||
{
|
||||
Abort("Assertion failure with msg");
|
||||
}
|
||||
|
||||
void __switch_error(string file, size_t line) @trusted @nogc pure
|
||||
void __switch_error(string file, size_t line) @trusted @nogc
|
||||
{
|
||||
_d_assert_msg("final switch error", file, line);
|
||||
}
|
||||
|
||||
@ -2,21 +2,49 @@ module std.stdio;
|
||||
|
||||
import dlib.util;
|
||||
import std.traits;
|
||||
import wasm;
|
||||
import std.format;
|
||||
|
||||
void
|
||||
writefln(alias fmt, A...)(A args) if(isSomeString!(typeof(fmt)))
|
||||
{
|
||||
static foreach(i; 0 .. A.length)
|
||||
{
|
||||
{
|
||||
static if()
|
||||
}
|
||||
}
|
||||
.writefln(Str(fmt), args);
|
||||
}
|
||||
|
||||
void
|
||||
writefln(Char, A...)(in Char[] fmt, A args)
|
||||
{
|
||||
writefln(Str(fmt), args);
|
||||
char[1024] buffer;
|
||||
|
||||
string result = Str(sformat(buffer, fmt, args));
|
||||
|
||||
Console(result, true);
|
||||
}
|
||||
|
||||
void
|
||||
writef(alias fmt, A...)(A args) if(isSomeString!(typeof(fmt)))
|
||||
{
|
||||
.writef(Str(fmt), args);
|
||||
}
|
||||
|
||||
void
|
||||
writef(Char, A...)(in Char[] fmt, A args)
|
||||
{
|
||||
char[1024] buffer;
|
||||
|
||||
string result = Str(sformat(buffer, fmt, args));
|
||||
|
||||
Console(result, false);
|
||||
}
|
||||
|
||||
void
|
||||
write(T...)(T args) if(T.length == 1 && isSomeString!(T[0]))
|
||||
{
|
||||
Console(Str(args[0]), false);
|
||||
}
|
||||
|
||||
void
|
||||
writeln(T...)(T args) if(T.length == 1 && isSomeString!(T[0]))
|
||||
{
|
||||
Console(Str(args[0]), true);
|
||||
}
|
||||
|
||||
@ -32,11 +32,14 @@ enum SprintfType : size_t
|
||||
CharArray,
|
||||
}
|
||||
|
||||
extern extern(C) @nogc pure @llvmAttr("wasm-import-module", "env"):
|
||||
extern extern(C) @nogc @llvmAttr("wasm-import-module", "env"):
|
||||
|
||||
@llvmAttr("wasm-import-name", "Console") void
|
||||
Console(string str, bool write_line);
|
||||
|
||||
@llvmAttr("wasm-import-name", "Console2") void
|
||||
Console2(size_t length, const(void)* ptr, bool write_line);
|
||||
|
||||
@llvmAttr("wasm-import-name", "Abort") void
|
||||
Abort(string message);
|
||||
|
||||
@ -49,3 +52,28 @@ SprintfLoadArray(size_t length, const(void)* ptr, SprintfType type);
|
||||
@llvmAttr("wasm-import-name", "SprintfEnd") size_t
|
||||
SprintfEnd(char[] buffer, string format);
|
||||
|
||||
export void
|
||||
_start()
|
||||
{
|
||||
import dlib.alloc;
|
||||
import dlib.util;
|
||||
|
||||
ResetScratch(MB(2));
|
||||
}
|
||||
|
||||
version(DLIB_TEST)
|
||||
{
|
||||
|
||||
export void
|
||||
RunTests()
|
||||
{
|
||||
Console("azZ", true);
|
||||
static foreach(test_fn; __traits(getUnitTests, __traits(parent, _start)))
|
||||
{
|
||||
Console("Running test", true);
|
||||
test_fn();
|
||||
}
|
||||
Console("Tests succeeded", true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
15
wasm/wasm.js
15
wasm/wasm.js
@ -253,6 +253,19 @@ class WasmManager
|
||||
Console(string_length, string_ptr, write_line)
|
||||
{
|
||||
manager.stdout_string += manager.LoadString(string_length, string_ptr);
|
||||
const arr = manager.LoadArray(Uint8Array, string_length, string_ptr);
|
||||
|
||||
if(write_line || manager.stdout_string.includes("\n"))
|
||||
{
|
||||
console.log(manager.stdout_string);
|
||||
manager.stdout_string = "";
|
||||
}
|
||||
},
|
||||
Console2(string_length, string_ptr, write_line)
|
||||
{
|
||||
manager.stdout_string += manager.LoadString(string_length, string_ptr);
|
||||
const arr = manager.LoadArray(Uint8Array, string_length, string_ptr);
|
||||
|
||||
if(write_line || manager.stdout_string.includes("\n"))
|
||||
{
|
||||
console.log(manager.stdout_string);
|
||||
@ -281,5 +294,7 @@ async function StartWasm(path)
|
||||
|
||||
exports?._start();
|
||||
|
||||
exports?.RunTests();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user