assemblyscript icon indicating copy to clipboard operation
assemblyscript copied to clipboard

Add memoryData option to import a file as static memory

Open dcodeIO opened this issue 5 years ago • 1 comments

An implementation of the suggestion in https://github.com/AssemblyScript/assemblyscript/issues/1367, loading a file specified via --memoryData into static memory at memoryBase.

Open questions:

  • Do we need constants like ASC_MEMORY_DATA_OFFSET and ASC_MEMORY_DATA_LENGTH to obtain the exact range or is expecting it at ASC_MEMORY_BASE with a known length enough?
  • Currently does not attempt to align the loaded data, but places it right at memoryBase. If --memoryBase is omitted, it starts at 0, otherwise exactly at --memoryBase putting alignment under the user's control.
  • Should we change related constants like ASC_MEMORY_BASE and ASC_LOW_MEMORY_LIMIT to usize (is i32 currently)? Would be a breaking change, so might make sense to do this later.
  • Doesn't play well with asconfig merging, in that exactly one memory segment can be imported somewhere, but not multiple from different configs. Given how low level this is I guess this is fine? A mechanism for multiple data files would be more complicated to use, since a user would have to keep track somehow. cc @jtenner
  • [x] I've read the contributing guidelines

dcodeIO avatar Jul 01 '20 16:07 dcodeIO

So I've been doing this kind of behavior in Node scripts for a few projects of mine. Normally for multiple files though.

I was thinking of maybe doing a PR on the compiler for something like https://github.com/rollup/rollup-plugin-url or https://github.com/parcel-bundler/parcel/issues/1080#issuecomment-557240449 , where you can import a static file using an ES6 import as memory.data :smile:

Also, @tschneidereit mentioned to me that it may also be a good idea to take a look at: import assertions ( and the companion proposal for JSON modules ) . As we could then define our own behavior per type :smile:

Though, I think this would maybe require some discussion. As I could imagine some assets would want special handlers (like JSON), and others may want to just be binary blobs (Like Images). And we'd probably want to allow people to decide how to handle it :thinking:

(Edit: It was mentioned the file extension wouldn't matter if we assert: blob, cause then we are assuming it's a byte array, which would be perfect :smile: )

torch2424 avatar Nov 24 '20 01:11 torch2424

This PR has been automatically marked as stale because it has not had recent activity. It will be closed in one week if no further activity occurs. Thank you for your contributions!

github-actions[bot] avatar Dec 09 '23 23:12 github-actions[bot]

This PR has been automatically closed due to lack of recent activity, but feel free to reopen it as long as you merge in the main branch afterwards.

github-actions[bot] avatar Dec 17 '23 23:12 github-actions[bot]