Skip to content

A Wasm parser and interpreter written in Kotlin.

License

Notifications You must be signed in to change notification settings

Marco4413/kwasm

Repository files navigation

kwasm

A Wasm parser and interpreter written in Kotlin.

I'd also like to specify that I'm using this project to learn Kotlin. So things may not be written in the best way possible.

References

https://webassembly.github.io/spec/core/index.html
https://webassembly.github.io/spec/core/binary/index.html
https://webassembly.github.io/spec/core/exec/index.html
https://en.wikipedia.org/wiki/LEB128

https://github.com/WebAssembly/wabt
https://webassembly.github.io/wabt/demo/wat2wasm
https://webassembly.github.io/wabt/demo/wasm2wat

What can this do right now?

This project is now able to parse basic Wasm and run it. Elements, Tables and 'partially' Globals are not yet supported.

I plan on adding support for Wat parsing (or a custom language) in the future.

Here's a rough list of the supported features:

  • Binary Format (read/write)
    • Values
    • Types
      • Value Types
      • Function Types
      • Limits
      • Memory Types
      • Table Types
      • Global Types
    • Instructions
      • Control (75%)
      • Reference
      • Parametric (33%)
      • Variable
        • Local
        • Global (50%)
      • Table
      • Memory (~10%)
      • Numeric
        • I32 (20%)
        • I64
        • F32
        • F64
      • Vector
    • Modules
      • Magic
      • Version
      • Sections
        • Custom
        • Type
        • Import
          • Function
          • Table
          • Memory
          • Global
        • Function
        • Table
        • Memory
        • Global
        • Export
        • Start
        • Element
        • Code
        • Data
        • Data Count
  • Validation Who needs validation?
  • Execution
    • Runtime Structures
      • Values
        • Number
        • Vector
        • Reference
      • Store
        • Functions
        • Tables
        • Memories
        • Globals
        • Elements
        • Data
      • Instances
        • Module
          • Types
          • Functions
          • Tables
          • Memories
          • Globals (only from Imports)
          • Elements
          • Data
          • Exports
        • Function
        • Table
        • Memory
        • Global
        • Element
        • Data
        • Export
      • External Values
        • Function
        • Table
        • Memory
        • Global
      • Stack
      • Label

These categories were taken from https://webassembly.github.io/spec/core/index.html

I'd need some Wasm examples which use the features that are not yet implemented to undestand exactly how they work and test them.

Examples

Usage examples can be found in the test Kotlin module.