Giter Site home page Giter Site logo

Comments (4)

bjfish avatar bjfish commented on May 4, 2024

@lachlansneff I think we are missing Export from the public runtime API, can you confirm?

@hrydgard I modified your example to inspect the global value:

Export::Global(global) => {
   println!("  global: {}, {:?}", name, global);
}

which resulting in the following:

global: SCRATCH_I, Global { desc: GlobalDescriptor { mutable: false, ty: I32 }, value: I32(1053432) }

I suspect this value 1053432 to be an index into the memory, maybe some space setup for statics like this. So, I setup the array to contain some values to confirm this suspicion:

#[no_mangle]
pub static mut SCRATCH_I : [u8; 5] = [1, 2, 3, 4, 5];

and then print this part of the memory:

let i = 1053432;
let memory = instance.context().memory(0);
for b in memory.view::<u8>()[i as usize..(i + 5) as usize].iter() {
    println!("{:?}", b);
}

Results in:

Cell { value: 1 }
Cell { value: 2 }
Cell { value: 3 }
Cell { value: 4 }
Cell { value: 5 }

So, it appears that the SCRATCH_I global contains an index into the memory to the first value in the array.

from wasmer.

hrydgard avatar hrydgard commented on May 4, 2024

Ah, thanks! Good that it's there. Could be clearer in the documentation though...

GlobalDescriptor is even entirely missing from the docs due to a missing /// comment line.

Also it could be nice to add this stuff to the official example :) I'm sure other people will want to do similar things.

from wasmer.

bjfish avatar bjfish commented on May 4, 2024

@hrydgard I've added GlobalDescriptor to runtime with documentation and added Export as well in this PR: #320 Yes, we'll be adding more examples over time.

I'll close this issue as I think it is resolved now. Let us know if you have any more questions, thanks.

from wasmer.

hrydgard avatar hrydgard commented on May 4, 2024

@bjfish I still believe you're missing documentation that you find the address of global arrays in the Value::I32, which I find somewhat unintuitive.

Apart from that, all good!

from wasmer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.