From 218b07a7dbda3484f2570f0a34bb5103d76f2164 Mon Sep 17 00:00:00 2001 From: NikVolf Date: Wed, 26 Jul 2017 21:56:54 +0300 Subject: [PATCH 1/2] add memoryBase global to env module --- src/interpreter/env.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/interpreter/env.rs b/src/interpreter/env.rs index 651fc6c..ce4849c 100644 --- a/src/interpreter/env.rs +++ b/src/interpreter/env.rs @@ -22,6 +22,8 @@ const DEFAULT_TOTAL_MEMORY: u32 = 16 * 1024 * 1024; const DEFAULT_ALLOW_MEMORY_GROWTH: bool = false; /// Default tableBase variable value. const DEFAULT_TABLE_BASE: u32 = 0; +/// Default tableBase variable value. +const DEFAULT_MEMORY_BASE: u32 = 0; /// Defaul table size. const DEFAULT_TABLE_SIZE: u32 = 16; @@ -50,6 +52,8 @@ const INDEX_GLOBAL_ABORT: u32 = 6; const INDEX_GLOBAL_EXIT_STATUS: u32 = 7; /// Index of tableBase global variable. const INDEX_GLOBAL_TABLE_BASE: u32 = 8; +/// Index of memoryBase global. +const INDEX_GLOBAL_MEMORY_BASE: u32 = 9; /// Index of abort function. const INDEX_FUNC_ABORT: u32 = 0; @@ -194,6 +198,8 @@ pub fn env_module(params: EnvParams) -> Result { .with_export(ExportEntry::new("EXITSTATUS".into(), Internal::Global(INDEX_GLOBAL_EXIT_STATUS))) .with_global(GlobalEntry::new(GlobalType::new(ValueType::I32, false), InitExpr::new(vec![Opcode::I32Const(DEFAULT_TABLE_BASE as i32)]))) // TODO: what is this? .with_export(ExportEntry::new("tableBase".into(), Internal::Global(INDEX_GLOBAL_TABLE_BASE))) + .with_global(GlobalEntry::new(GlobalType::new(ValueType::I32, false), InitExpr::new(vec![Opcode::I32Const(DEFAULT_MEMORY_BASE as i32)]))) // TODO: what is this? + .with_export(ExportEntry::new("memoryBaseBase".into(), Internal::Global(INDEX_GLOBAL_MEMORY_BASE))) // functions .function() .signature().build() From cf804da81dc0b24ad084af36be1b447fd4510e97 Mon Sep 17 00:00:00 2001 From: NikVolf Date: Wed, 26 Jul 2017 21:57:31 +0300 Subject: [PATCH 2/2] fix name --- src/interpreter/env.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/interpreter/env.rs b/src/interpreter/env.rs index 8a92365..f07f3d6 100644 --- a/src/interpreter/env.rs +++ b/src/interpreter/env.rs @@ -200,7 +200,7 @@ pub fn env_module(params: EnvParams) -> Result { .with_global(GlobalEntry::new(GlobalType::new(ValueType::I32, false), InitExpr::new(vec![Opcode::I32Const(DEFAULT_TABLE_BASE as i32)]))) // TODO: what is this? .with_export(ExportEntry::new("tableBase".into(), Internal::Global(INDEX_GLOBAL_TABLE_BASE))) .with_global(GlobalEntry::new(GlobalType::new(ValueType::I32, false), InitExpr::new(vec![Opcode::I32Const(DEFAULT_MEMORY_BASE as i32)]))) // TODO: what is this? - .with_export(ExportEntry::new("memoryBaseBase".into(), Internal::Global(INDEX_GLOBAL_MEMORY_BASE))) + .with_export(ExportEntry::new("memoryBase".into(), Internal::Global(INDEX_GLOBAL_MEMORY_BASE))) // functions .function() .signature().build()