C++26
This commit is contained in:
parent
9ffe98a8c5
commit
5b3afc2287
|
|
@ -167,7 +167,7 @@ const wasmPlugin = ({ production }: WasmLoaderConfig = {}): BunPlugin => {
|
|||
...features,
|
||||
'-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}`;
|
||||
|
||||
if (compileResult.exitCode !== 0) {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
--target=wasm32-wasi
|
||||
--sysroot=dist/wasi/share/wasi-sysroot
|
||||
-std=c++23
|
||||
-std=c++26
|
||||
-fno-exceptions
|
||||
-I
|
||||
build/assets/include
|
||||
|
|
|
|||
|
|
@ -1,12 +1,94 @@
|
|||
#include <cstddef>
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include <format>
|
||||
#include <js.h>
|
||||
#include <stdlib.h>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
|
||||
struct boob {
|
||||
int x;
|
||||
boob(int x_): x(x_) {};
|
||||
operator int() { return rand() + x; }
|
||||
} boob(rand());
|
||||
class bit {
|
||||
private:
|
||||
static constexpr bit nor(const bit& a, const bit& b);
|
||||
|
||||
EXPORT(awoo) auto awoo() -> int {
|
||||
return boob;
|
||||
public:
|
||||
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());
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
import awoo from "./awoo.cpp";
|
||||
|
||||
export default function main() {
|
||||
console.log(awoo, awoo.awoo());
|
||||
console.log(awoo, awoo.play());
|
||||
}
|
||||
Loading…
Reference in New Issue