add platform module providing implementation of random functions

This commit is contained in:
2021-11-08 23:16:17 +01:00
parent 35ff01d7a8
commit 3be4e7b101
5 changed files with 38 additions and 1 deletions

View File

@@ -1,4 +1,7 @@
all: loader.wasm
all: loader.wasm platform.wasm
loader.wasm: loader.cwa
curlywas loader.cwa
platform.wasm: platform.cwa
curlywas platform.cwa

16
platform/platform.cwa Normal file
View File

@@ -0,0 +1,16 @@
import "env.memory" memory(4);
global mut randomState: i32 = 37;
export fn random() -> i32 {
let state: i32;
randomState = (state := (
state := randomState ^ (randomState << 13)
) ^ (state >> 17)
) ^ (state << 5);
randomState * 625341585
}
export fn randomSeed(s: i32) {
randomState = (((s + !(s >> 31)) as i64 * 8445297036689579347i64) >> 31i64) as i32;
}