Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AssemblyScript conflicts #43

Closed
Dudeplayz opened this issue May 3, 2020 · 8 comments
Closed

AssemblyScript conflicts #43

Dudeplayz opened this issue May 3, 2020 · 8 comments

Comments

@Dudeplayz
Copy link
Contributor

This issue collects conflicts of the current code base and AssemblyScript. See #35 and the research project.

Found problems:

  1. Data types must be specified explicitly
  2. AssemblyScript has a restricted data type set
    • The current types file can be adapted to keep JS compatibility
  3. Interfaces are currently not supported. Breaks e.g. ICPU and CPU. (further research required)
  4. Declaring variables as constructor parameters brings up memory access errors because the instantiation works differently. E.g. CPU with progMem, which has to be declared outside the constructor and the following instantiations have to be done in the constructor body:
    constructor(progMem: Uint16Array, private sramBytes: u64 = 8192) {
        this.progMem = progMem;
        this.progBytes = Uint8Array.wrap(this.progMem.buffer);
        this.pc22Bits = this.progBytes.length > 0x20000;
        this.reset();
    }

(The research is still ongoing.)

@MaxGraey
Copy link

MaxGraey commented May 3, 2020

  1. Some basic interfaces should be allowed in assemblyscript@nightly with recent PR
  2. this is known issue

@MaxGraey
Copy link

MaxGraey commented May 9, 2020

  1. fixed

@urish
Copy link
Contributor

urish commented May 9, 2020

Thank @MaxGraey for your help here :-) It's really appreciated!

@Dudeplayz
Copy link
Contributor Author

@MaxGraey There is still an error if a class variable is based on a constructor variable:

RuntimeError: memory access out of bounds
    at ~lib/arraybuffer/ArrayBuffer#get:byteLength (wasm-function[26]:0xfd6)
    at ~lib/typedarray/Uint8Array.wrap (wasm-function[31]:0x11c5)
    at ~lib/typedarray/Uint8Array.wrap@varargs (wasm-function[32]:0x12a6)
    at assembly/cpu/cpu/CPU#constructor (wasm-function[35]:0x1345)

I had to change this:

readonly progBytes : Uint8Array = Uint8Array.wrap(this.progMem.buffer);
constructor(public progMem: Uint16Array, private sramBytes: u64 = 8192) {
    this.reset();
}

To that:

readonly progBytes : Uint8Array;
constructor(public progMem: Uint16Array, private sramBytes: u64 = 8192) {
    this.progBytes = Uint8Array.wrap(this.progMem.buffer);
    this.reset();
}

@MaxGraey
Copy link

Could you create minimal example on WebAssembly Studio?

@Dudeplayz
Copy link
Contributor Author

@MaxGraey

  1. Some basic interfaces should be allowed in assemblyscript@nightly with recent PR
  2. this is known issue

Is the mentioned PR already in 0.12.3? I tried to use the CPU Interface again, but it doesn't work with the error, that the variables are declared twice with the same name.

@MaxGraey
Copy link

Without code I can't tell what's wrong. Plz open issue with minimal reproducible example

@Dudeplayz
Copy link
Contributor Author

Yes, I will open an issue.

@urish urish closed this as completed Apr 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants