alexdovzhanyn / AlchemyVM

WebAssembly Virtual Machine Built In Elixir
MIT License
188 stars 5 forks source link

Parse current_memory instruction #31

Open fermuch opened 5 years ago

fermuch commented 5 years ago

Trying the language poetry, I found WaspVM doesn't currently parse current_memory, which is not mentioned at the specification but seems to be valid on firefox, chrome and nodejs. Related issue on the spec: https://github.com/WebAssembly/design/issues/904

Minimal poetry code which uses current_memory

export_memory "memory"

export "init" init
  return true

WAT file


Traceback of the error

[error][ ] Task #PID<0.1283.0> started from #PID<0.1206.0> terminating
** (RuntimeError) Couldn't parse instruction for current_memory
    (wasp_vm) lib/decoding/instruction_parser.ex:193: WaspVM.Decoder.InstructionParser.parse_instruction/2
    (wasp_vm) lib/decoding/code_section_parser.ex:70: WaspVM.Decoder.CodeSectionParser.parse_bytecode/2
    (wasp_vm) lib/decoding/code_section_parser.ex:36: WaspVM.Decoder.CodeSectionParser.parse_bodies/2
    (wasp_vm) lib/decoding/code_section_parser.ex:12: WaspVM.Decoder.CodeSectionParser.parse/1
    (elixir) lib/task/supervised.ex:90: Task.Supervised.invoke_mfa/2
    (elixir) lib/task/supervised.ex:35: Task.Supervised.reply/5
    (stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3
Function: &:erlang.apply/2
    Args: [#Function<0.26794313/1 in WaspVM.Decoder.parallel_decode/1>, [{10, <<109, 23, 1, 2, 127, 16, 46, 2, 64, 65, 5, 33, 0, 12, 0, 65, 1, 33, 1, 11, 32, 0, 16, 47, 11, 8, 0, 32, 0, 16, 52, 16, 99, 11, 8, 0, 32, 0, 16, 54, 16, 99, 11, 8, 0, ...>>}]]
** (EXIT from #PID<0.1206.0>) shell process exited with reason: an exception was raised:
    ** (RuntimeError) Couldn't parse instruction for current_memory
        (wasp_vm) lib/decoding/instruction_parser.ex:193: WaspVM.Decoder.InstructionParser.parse_instruction/2
        (wasp_vm) lib/decoding/code_section_parser.ex:70: WaspVM.Decoder.CodeSectionParser.parse_bytecode/2
        (wasp_vm) lib/decoding/code_section_parser.ex:36: WaspVM.Decoder.CodeSectionParser.parse_bodies/2
        (wasp_vm) lib/decoding/code_section_parser.ex:12: WaspVM.Decoder.CodeSectionParser.parse/1
        (elixir) lib/task/supervised.ex:90: Task.Supervised.invoke_mfa/2
        (elixir) lib/task/supervised.ex:35: Task.Supervised.reply/5
        (stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3
fantypants commented 5 years ago

Looks like it's a missing OPCode, i'll dig through the .wat and then see where its hanging.

fermuch commented 5 years ago

This might be unrelated, but:

On opcodes.ex there is declared current_memory and grow_memory, but on instruction_parser.ex they are called memory_size and memory_grow

alexdovzhanyn commented 5 years ago

@fermuch @fantypants That is exactly the issue. They should be called current_memory and grow_memory in both locations, respectively.

fantypants commented 5 years ago

I was 98% certain we had one or the other, i think along our PR's its noted somewhere, I believe we changed it somewhere along the road.

Not too worry, I'll get it patched up right away