Fix c compilation
This commit is contained in:
parent
2a990ed694
commit
6dfee919b4
|
|
@ -12,11 +12,11 @@ const wasmPlugin = ({ production, portable }: WasmLoaderConfig = {}): BunPlugin
|
|||
name: "WASM loader",
|
||||
async setup(build) {
|
||||
build.onLoad({ filter: /\.(c(pp)?|wasm(\.ts)?)$/ }, async (args) => {
|
||||
let wasmPath = path.resolve(import.meta.dir, '..', '..', 'dist', 'tmp.wasm');
|
||||
let wasmPath = path.resolve(import.meta.dir, '..', 'dist', 'tmp.wasm');
|
||||
let jsContent: string = `
|
||||
async function instantiate(url) {
|
||||
const memory = new WebAssembly.Memory({
|
||||
initial: 16,
|
||||
initial: 32,
|
||||
});
|
||||
let data = new DataView(memory.buffer);
|
||||
const { instance } = await WebAssembly.instantiateStreaming(fetch(url), {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define width 512
|
||||
#define height 512
|
||||
|
|
@ -7,15 +8,14 @@ static uint8_t field[width * height];
|
|||
static uint8_t nextField[width * height];
|
||||
static uint8_t pixels[width * height * 4];
|
||||
|
||||
void* malloc(uint32_t n);
|
||||
static uint8_t rand8(void);
|
||||
static int countNeighbours(int x, int y);
|
||||
|
||||
int getWidth(void) { return width; }
|
||||
int getHeight(void) { return height; }
|
||||
uint8_t* getPixels(void) { return pixels; }
|
||||
EXPORT(getWidth) int get_width(void) { return width; }
|
||||
EXPORT(getHeight) int get_height(void) { return height; }
|
||||
EXPORT(getPixels) uint8_t* get_pixels(void) { return pixels; }
|
||||
|
||||
void step(void)
|
||||
EXPORT(step) void step(void)
|
||||
{
|
||||
for (int y = 0; y < height; y++) {
|
||||
for (int x = 0; x < width; x++) {
|
||||
|
|
@ -93,7 +93,7 @@ static uint8_t rand8(void)
|
|||
return x;
|
||||
}
|
||||
|
||||
void initField(uint32_t randomSeed)
|
||||
EXPORT(initField) void init_field(uint32_t randomSeed)
|
||||
{
|
||||
*((uint32_t*)&rand_state[STATE_BYTES - sizeof(uint32_t)]) = randomSeed; // Voodoo
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue