diff --git a/build/assets/include/cassert b/build/assets/include/cassert new file mode 100644 index 0000000..cad9086 --- /dev/null +++ b/build/assets/include/cassert @@ -0,0 +1 @@ +#define assert(x) ((void)(x)) diff --git a/build/assets/include/cfloat b/build/assets/include/cfloat new file mode 100644 index 0000000..2478ef2 --- /dev/null +++ b/build/assets/include/cfloat @@ -0,0 +1 @@ +#include \ No newline at end of file diff --git a/build/assets/include/climits b/build/assets/include/climits new file mode 100644 index 0000000..990e9b5 --- /dev/null +++ b/build/assets/include/climits @@ -0,0 +1 @@ +#include \ No newline at end of file diff --git a/build/assets/include/cmath b/build/assets/include/cmath new file mode 100644 index 0000000..4140673 --- /dev/null +++ b/build/assets/include/cmath @@ -0,0 +1 @@ +#include \ No newline at end of file diff --git a/build/assets/include/cstddef b/build/assets/include/cstddef new file mode 100644 index 0000000..1fa32ca --- /dev/null +++ b/build/assets/include/cstddef @@ -0,0 +1,6 @@ +#include + +namespace std { + using nullptr_t = decltype(nullptr); + using size_t = ::size_t; +} \ No newline at end of file diff --git a/build/assets/include/cstdint b/build/assets/include/cstdint new file mode 100644 index 0000000..2aadec1 --- /dev/null +++ b/build/assets/include/cstdint @@ -0,0 +1,12 @@ +#include +namespace std { + using uint8_t = ::uint8_t; + using int8_t = ::int8_t; + using uint16_t = ::uint16_t; + using int16_t = ::int16_t; + using uint32_t = ::uint32_t; + using int32_t = ::int32_t; + using uint64_t = ::uint64_t; + using int64_t = ::int64_t; + using uintptr_t = ::uintptr_t; +} \ No newline at end of file diff --git a/build/assets/include/limits b/build/assets/include/limits new file mode 100644 index 0000000..da9b153 --- /dev/null +++ b/build/assets/include/limits @@ -0,0 +1,12 @@ +#pragma once + +#include + +namespace std { + template + struct numeric_limits { + static constexpr bool is_iec559 = std::is_floating_point::value; + static constexpr bool is_integer = std::is_integral::value; + static constexpr bool is_signed = std::is_signed::value; + }; +} \ No newline at end of file diff --git a/build/assets/include/linalg.hpp b/build/assets/include/linalg.hpp index b5d9848..b900320 100644 --- a/build/assets/include/linalg.hpp +++ b/build/assets/include/linalg.hpp @@ -49,9 +49,10 @@ #ifndef LINALG_H #define LINALG_H -#include -#include -#include +#include +#include +#include +#include namespace linalg { diff --git a/build/assets/include/math.h b/build/assets/include/math.h index 5e7c8d0..21e8de7 100644 --- a/build/assets/include/math.h +++ b/build/assets/include/math.h @@ -1,7 +1,6 @@ #pragma once #include -#include #define M_PI 3.14159265359 #define M_PI_2 1.57079632679 @@ -21,12 +20,13 @@ static inline bool isinf(double x) { return !isnan(x) && isnan(x - x); } -#define IMPORT_UNARY(fn) IMPORT(Math_##fn) double fn(double); -#define IMPORT_BINARY(fn) IMPORT(Math_##fn) double fn(double, double); +#define IMPORT_UNARY(fn) __attribute__((import_module("Math"), import_name(#fn))) double fn(double); +#define IMPORT_BINARY(fn) __attribute__((import_module("Math"), import_name(#fn))) double fn(double, double); IMPORT_UNARY(floor) IMPORT_UNARY(ceil) IMPORT_UNARY(round) +IMPORT_UNARY(trunc) IMPORT_UNARY(exp) IMPORT_UNARY(log) IMPORT_UNARY(log10) diff --git a/build/assets/include/math.hpp b/build/assets/include/math.hpp index db1f273..68b9281 100644 --- a/build/assets/include/math.hpp +++ b/build/assets/include/math.hpp @@ -3,9 +3,17 @@ #include #include +#ifdef abs #undef abs +#endif + +#ifdef max #undef max +#endif + +#ifdef min #undef min +#endif namespace std { template T max(T a, T b) { @@ -23,6 +31,11 @@ template T abs(T a) { typename std::enable_if::value, T>::type \ fn(T a) { return static_cast(::fn(static_cast(a))); } +#define UNARY_BOOL(fn) \ + template \ + typename std::enable_if::value, bool>::type \ + fn(T a) { return ::fn(static_cast(a)); } + #define BINARY(fn) \ template \ typename std::enable_if::value, T>::type \ @@ -30,6 +43,8 @@ template T abs(T a) { UNARY(floor) UNARY(ceil) +UNARY(round) +UNARY(trunc) UNARY(exp) UNARY(log) UNARY(log10) @@ -43,13 +58,15 @@ UNARY(atan) UNARY(sinh) UNARY(cosh) UNARY(tanh) -UNARY(round) +UNARY_BOOL(isnan) +UNARY_BOOL(isinf) BINARY(fmod) BINARY(pow) BINARY(atan2) #undef UNARY +#undef UNARY_BOOL #undef BINARY } // namespace std diff --git a/build/assets/include/type_traits b/build/assets/include/type_traits new file mode 100644 index 0000000..ad6afba --- /dev/null +++ b/build/assets/include/type_traits @@ -0,0 +1 @@ +#include \ No newline at end of file diff --git a/build/assets/include/type_traits.hpp b/build/assets/include/type_traits.hpp index d11b241..0c2a792 100644 --- a/build/assets/include/type_traits.hpp +++ b/build/assets/include/type_traits.hpp @@ -59,7 +59,6 @@ namespace std { static_assert(false, "declval not allowed in an evaluated context"); } - using nullptr_t = decltype(nullptr); template struct conditional { using type = T; }; @@ -111,9 +110,21 @@ namespace std { std::is_integral::value || std::is_floating_point::value> {}; + namespace detail + { + template::value> + struct is_signed : std::integral_constant {}; + + template + struct is_signed : std::false_type {}; + } + + template + struct is_signed : detail::is_signed::type {}; + template struct is_void : std::is_same::type> {}; - + namespace detail { template diff --git a/build/wasmPlugin.ts b/build/wasmPlugin.ts index 1c24ff2..f36bf63 100644 --- a/build/wasmPlugin.ts +++ b/build/wasmPlugin.ts @@ -27,6 +27,7 @@ const wasmPlugin = ({ production, portable }: WasmLoaderConfig = {}): BunPlugin return decoder.decode(memory.buffer.slice(start, end)); }; let buf = ''; + Math.fmod = (x, y) => x % y; const { instance } = await WebAssembly.instantiateStreaming(fetch(url), { env: { memory, @@ -65,27 +66,8 @@ const wasmPlugin = ({ production, portable }: WasmLoaderConfig = {}): BunPlugin data = new DataView(memory.buffer); } }, - Math_round(x) { return Math.round(x); }, - Math_floor(x) { return Math.floor(x); }, - Math_ceil(x) { return Math.ceil(x); }, - Math_exp(x) { return Math.exp(x); }, - Math_log(x) { return Math.log(x); }, - Math_log10(x) { return Math.log10(x); }, - Math_sqrt(x) { return Math.sqrt(x); }, - Math_sin(x) { return Math.sin(x); }, - Math_cos(x) { return Math.cos(x); }, - Math_tan(x) { return Math.tan(x); }, - Math_asin(x) { return Math.asin(x); }, - Math_acos(x) { return Math.acos(x); }, - Math_atan(x) { return Math.atan(x); }, - Math_sinh(x) { return Math.sinh(x); }, - Math_cosh(x) { return Math.cosh(x); }, - Math_tanh(x) { return Math.tanh(x); }, - - Math_fmod(x, y) { return x % y; }, - Math_pow(x, y) { return Math.pow(x, y); }, - Math_atan2(x, y) { return Math.atan2(x, y); }, - } + }, + Math: Math, }); return { diff --git a/src/games/playground/awoo.cpp b/src/games/playground/awoo.cpp index 1bbcb4c..31c0c5d 100644 --- a/src/games/playground/awoo.cpp +++ b/src/games/playground/awoo.cpp @@ -1,13 +1,11 @@ +#include #include using namespace linalg::aliases; -int awoo(auto arg) { - return arg() + 69; -} +EXPORT(main) auto init() { + double2 dir = {0, -1}; + double2 rot = linalg::rot(3.14 / 2, dir); -EXPORT(main) auto init(int arg) { - auto fn = [arg] () { return arg; }; - - return awoo(fn) + arg; + return linalg::angle(rot, {0, 1}); } \ No newline at end of file