From d8626454bc7e0f247a43caba2c7bd80d654e6d29 Mon Sep 17 00:00:00 2001 From: NikVolf Date: Wed, 12 Apr 2017 18:44:03 +0300 Subject: [PATCH] fix call update --- gas/src/main.rs | 18 ++++++++++++++---- runner/build.sh | 9 +++++---- samples/hello_world.c | 3 --- 3 files changed, 19 insertions(+), 11 deletions(-) delete mode 100644 samples/hello_world.c diff --git a/gas/src/main.rs b/gas/src/main.rs index f451242..22a6149 100644 --- a/gas/src/main.rs +++ b/gas/src/main.rs @@ -34,12 +34,10 @@ fn main() { let import_sig = mbuilder.push_signature( builder::signature() .param().i32() - .param().i32() - .return_type().i32() .build_sig() ); - let gas_func = mbuilder.push_import( + let mut gas_func = mbuilder.push_import( builder::import() .module("env") .field("gas") @@ -47,8 +45,20 @@ fn main() { .build() ); - // Updating calling addresses (all calls to function index >= `gas_func` should be incremented) + // back to plain module let mut module = mbuilder.build(); + + // calculate actual function index of the imported definition + // (substract all imports that are NOT functions) + + for import_entry in module.import_section().expect("Builder should have insert the import section").entries() { + match *import_entry.external() { + elements::External::Function(_) => {}, + _ => { gas_func -= 1; } + } + } + + // Updating calling addresses (all calls to function index >= `gas_func` should be incremented) for section in module.sections_mut() { match section { &mut elements::Section::Code(ref mut code_section) => { diff --git a/runner/build.sh b/runner/build.sh index 1a685a4..532c533 100755 --- a/runner/build.sh +++ b/runner/build.sh @@ -14,9 +14,10 @@ else emcc $file -Os -s WASM=1 -s SIDE_MODULE=1 -o out/contract.wasm fi -if [ ! -f ./../gas/target/release/gas ] && [ ! -f ./../gas/target/release/gas.exe ] then +if [ ! -f ./../gas/target/release/gas ] && [ ! -f ./../gas/target/release/gas.exe ] +then echo "No gas utility, compile it in /gas folder with" - echo "cargo build --release" + echo "cargo build --release" +else + ./../gas/target/release/gas ./out/contract.wasm ./out/contract.wasm fi - -./../gas/target/release/gas ./out/contract.wasm ./out/contract.wasm \ No newline at end of file diff --git a/samples/hello_world.c b/samples/hello_world.c deleted file mode 100644 index 7c99106..0000000 --- a/samples/hello_world.c +++ /dev/null @@ -1,3 +0,0 @@ -int call(int x) { - return 2 * x; -} \ No newline at end of file