1
0
Fork 0
This commit is contained in:
Pabloader 2025-06-19 08:19:53 +00:00
parent 9ffe98a8c5
commit 5b3afc2287
4 changed files with 92 additions and 10 deletions

View File

@ -167,7 +167,7 @@ const wasmPlugin = ({ production }: WasmLoaderConfig = {}): BunPlugin => {
...features, ...features,
'-I', include, '-I', include,
]; ];
const std = args.path.endsWith('.cpp') ? '-std=gnu++23' : '-std=gnu23'; const std = args.path.endsWith('.cpp') ? '-std=gnu++26' : '-std=gnu23';
const compileResult = await $`${cc.cc} -c ${flags} ${std} -o ${objPath} ${args.path}`; const compileResult = await $`${cc.cc} -c ${flags} ${std} -o ${objPath} ${args.path}`;
if (compileResult.exitCode !== 0) { if (compileResult.exitCode !== 0) {

View File

@ -1,6 +1,6 @@
--target=wasm32-wasi --target=wasm32-wasi
--sysroot=dist/wasi/share/wasi-sysroot --sysroot=dist/wasi/share/wasi-sysroot
-std=c++23 -std=c++26
-fno-exceptions -fno-exceptions
-I -I
build/assets/include build/assets/include

View File

@ -1,12 +1,94 @@
#include <cstddef>
#include <cstdlib>
#include <iostream>
#include <format>
#include <js.h> #include <js.h>
#include <stdlib.h> #include <stdlib.h>
#include <string>
#include <string_view>
#include <utility>
struct boob { class bit {
int x; private:
boob(int x_): x(x_) {}; static constexpr bit nor(const bit& a, const bit& b);
operator int() { return rand() + x; }
} boob(rand());
EXPORT(awoo) auto awoo() -> int { public:
return boob; bit() = default;
bit(bool n) : n(n), composition(n ? "1" : "0") {
}
bit(bool n, std::string_view composition) : n(n), composition(composition) {
}
bit(const bit& other) : bit(other.n, other.composition) {
}
constexpr bit operator!() const {
const bit& a = *this;
return nor(a, a);
}
constexpr bit operator|(const bit& b) const {
const bit& a = *this;
return !nor(a, b);
}
constexpr bit operator&(const bit& b) const {
const bit& a = *this;
return nor(!a, !b);
}
constexpr bit operator^(const bit& b) const {
const bit& a = *this;
return (!a & b) | (a & !b);
}
constexpr std::pair<bit, bit> operator+(const bit& b) const {
const bit& a = *this;
return {
a ^ b,
a & b,
};
}
operator bool() const {
return n;
}
friend std::ostream& operator<<(std::ostream& stream, const bit& val) {
return stream << val.composition;
}
friend std::istream& operator>>(std::istream& stream, bit& val) {
return stream >> val.n;
}
private:
bool n = 0;
std::string composition = "";
};
constexpr bit bit::nor(const bit& a, const bit& b) {
bit result{
!(a.n || b.n),
"(" + a.composition + " NOR " + b.composition + ")",
};
return result;
}
uint64_t awoo() {
bit a {1, "a"};
bit b {1, "b"};
auto [sum, carry] = a + b;
std::cout << "sum = " << sum << "\ncarry = " << carry << std::endl;
return sum;
}
EXPORT(play) void play() {
auto awoo = std::format("{2} {1}{0}!\n", 23, "C++", "Hello");
std::puts(awoo.c_str());
} }

View File

@ -1,5 +1,5 @@
import awoo from "./awoo.cpp"; import awoo from "./awoo.cpp";
export default function main() { export default function main() {
console.log(awoo, awoo.awoo()); console.log(awoo, awoo.play());
} }