Skip to content

In assemblyscript,Is there a way to check the type of a value in wasm which has been loaded by assemblyscript, example:i32? #888

Closed
@chooaya

Description

@chooaya

image
-1
In the capture image,main.ts is a assemblyscript

assembly/main.ts (assemblyscript)

declare function sayHello(): void;

sayHello()

export function add(x: i32, y: i32): i32 {
  return x + y;
}

export function getTypeOf():string {
  let x:i32 = 12;
  return typeof x;
}
export function teste(): string {
  let x = "ZZZZZZZZZZZZ"
  return x;
}

but the code

export function getTypeOf():string {
  let x:i32 = 12;
  return typeof x;
}

src/main.js

(async()=>{
  let buffer = await fetch("../out/main.wasm");
  let arrayBuffer = await buffer.arrayBuffer();
  let lib = instantiateBuffer(arrayBuffer,{
    main: {
      sayHello() {
        console.log("Hello from WebAssembly!");
      }
    },
    env: {
      abort(_msg, _file, line, column) {
        console.error("abort called at main.ts:" + line + ":" + column);
      }
    },
  });
  document.getElementById("container").textContent = "Result: " + lib.add(19, 23) 
   + " Type:" + lib.__getString(lib.getTypeOf()) 
   + " teste:" + lib.__getString(lib.teste()) ;
})();

lib.getTypeOf() return a ptr of a string,so I use lib.__getString(ptr) to convert ptr to string.but a value is "number",not the "i32"

### Issue: The Expected value of This Function is "i32",but actuality the result is "number"

image
I added a assemblyscript loader by download from 「 https://raw.githubusercontent.com/AssemblyScript/assemblyscript/master/lib/loader/index.js 」,and rename the to loader.js and put the file to folder src.

### In assemblyscript,we have i32 A 32-bit signed integer,if we load this wasm ,so we can check the type of i32?If cannot check i32 by assemblyscript,is there another way to check the value of wasm ?
wasm-project201910070050.zip

PS:
This days ,I found the https://github.com/AssemblyScript/assemblyscript/tree/master/lib/parse
,but I don`t know the detail about the parse,is this parse can check type the type of i32?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions