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

What about ffi with AssemblyScript? #1

Open
MaxGraey opened this issue Apr 12, 2018 · 3 comments
Open

What about ffi with AssemblyScript? #1

MaxGraey opened this issue Apr 12, 2018 · 3 comments

Comments

@MaxGraey
Copy link

MaxGraey commented Apr 12, 2018

Hi DeMille. You did a great stuff with integration C/C++ and rust. What do you think add also dcode's AssemblyScript?

@DeMille
Copy link
Owner

DeMille commented Apr 17, 2018

AssemblyScript looks pretty sweet! I just started playing around with it and I think support could be added pretty easily. I just pushed a branch to work on it.

The main issues I've noticed are strings and arrays, which have to be done differently than c/rust. I added an option field in the Wrapper class for assemblyscript to change that behavior. Classes seem work fine if you just treat them like a C struct.

You can check out the changes I made: https://webassembly.studio/?f=tc114km3bvh

I haven't really dived too deep into it, are there other language features I'm missing?

@MaxGraey
Copy link
Author

MaxGraey commented Apr 17, 2018

Cool! Are you try Array instead ArrayBuffer? AssemblyScript support global arrays:

const globArray: i32[] = [1, 2, 3];

export function getFirstElement(): i32 {
   return globArray[i];
}

as well as alloc in heap arrays:

export function createArray(len: i32): f32[] {
   var arr = new Array<f32>(1);
   arr.push(1.0);
   arr.push(NaN);
   return arr;
}

@DeMille
Copy link
Owner

DeMille commented Apr 19, 2018

That might make more sense. I did the arraybuffers because those seem like they're the most basic element ('normal' arrays are backed by them).

I didn't realize arrays are typed in AssemblyScript though! That's basically an arraybuffer with some extra methods here. I think that should be an easy change. I'll try that.

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

2 participants