diff --git a/random.cwa b/random.cwa index 73c61c5..0127ce6 100644 --- a/random.cwa +++ b/random.cwa @@ -1,19 +1,6 @@ import "env.memory" memory(4); - -global mut randomState: i32 = 37; - -fn random() -> i32 { - let state: i32; - randomState = (state := ( - state := randomState ^ (randomState << 13) - ) ^ (state >> 17) - ) ^ (state << 5); - randomState * 625341585 -} - -fn seed(s: i32) { - randomState = (((s + !(s >> 31)) as i64 * 8445297036689579347i64) >> 31i64) as i32; -} +import "env.random" fn random() -> i32; +import "env.randomSeed" fn seed(i32); export fn tic(time: i32) { let i: i32; diff --git a/src/emit.rs b/src/emit.rs index e7926bb..88aaab8 100644 --- a/src/emit.rs +++ b/src/emit.rs @@ -112,7 +112,9 @@ pub fn emit(script: &ast::Script) -> Vec { } module.section(&functions); - module.section(&global_section); + if !script.global_vars.is_empty() { + module.section(&global_section); + } module.section(&exports); module.section(&code); }