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

[WIP] feat(examples): AssemblyScript implementation of median algorithm #4

Draft
wants to merge 18 commits into
base: main
Choose a base branch
from

Conversation

jdvlio
Copy link
Contributor

@jdvlio jdvlio commented Feb 10, 2022

TODO

  • Use the JSONEncoder class for encoding JSON. Currently, this is done manually via raw strings.
  • Explicitly (in writing): how do we interface with the allocator and pass in memory buffers?

Build instructions

  • The actual source code is the index file in the assembly subdirectory of the Node project directory i.e. examples/as-median. Change to this directory before proceeding
  • Install assemblyscript and other dependencies:
    npm update
    
  • In order to compile the source, simply run the command
    make build
    
    which, via npm, builds the AssemblyScript (AS) project.

Additional information

  • Further detail regarding the build process and toolchain can be found here
  • Documentation related to memory operations in AS can be found here
  • This blog article was used as a reference point. The AssemblyScript segment starts just past halfway through the article.

@jdvlio jdvlio changed the title feat(examples): AssemblyScript implementation of median algorithm [WIP] feat(examples): AssemblyScript implementation of median algorithm Feb 10, 2022
examples/as-median/package-lock.json Outdated Show resolved Hide resolved
examples/as-median/assembly/index.ts Outdated Show resolved Hide resolved
examples/as-median/assembly/index.ts Outdated Show resolved Hide resolved
@jdvlio jdvlio requested a review from PiDelport February 28, 2022 12:04
Copy link

@PiDelport PiDelport left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we include a write-up of how this interfaces with the allocator, to actually get buffers into and out of the AssemblyScript code?

Can this branch also update the Rust host do an example call, to pass the data in and out?

}

let median = calc_median(len, sample);
let out = '{ median: ${median} }';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be using JSONEncoder, like here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will make a to-do for that in the PR description

jdvlio added 3 commits March 7, 2022 20:02
We now properly use the JSONEncoder from `assemblyscript-json`.  The
output buffer (and its length) is now returned as a mutable pointer.
Note that an `ArrayBuffer` must have an i32 as its length, by
definition.
@jdvlio jdvlio requested a review from PiDelport March 11, 2022 16:17
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

Successfully merging this pull request may close these issues.

2 participants