RoyalIcing / Orb

Write WebAssembly with Elixir
https://useorb.dev
BSD 3-Clause "New" or "Revised" License
174 stars 1 forks source link

Calling to_wat after an error seems to break #18

Closed superchris closed 4 months ago

superchris commented 4 months ago

In an iex session, calling to_wat after an error seems to break somehow

iex(3)> Orb.to_wat HelloOrb 
"(module $HelloOrb\n  (func $add (export \"add\") (param $x i32) (param $y i32) (result i32)\n    (i32.add (local.get $x) (local.get $y))\n  )\n)\n"
iex(4)> Orb.to_wat TemperatureConverter
** (Orb.TypeCheckError) Instruction i32.sub expected type i32, found f32 via Orb.F32.
    (orb 0.0.33) lib/orb/instruction.ex:300: Orb.Instruction.types_must_match!/3
    (orb 0.0.33) lib/orb/instruction.ex:215: Orb.Instruction.type_check_operand!/4
    (orb 0.0.33) lib/orb/instruction.ex:175: anonymous fn/4 in Orb.Instruction.type_check_operands!/3
    (elixir 1.15.7) lib/enum.ex:4789: Enum.with_index_list/3
    (orb 0.0.33) lib/orb/instruction.ex:25: Orb.Instruction.new/3
    (codebeam_2024 0.1.0) lib/temperature_converter.ex:9: TemperatureConverter."__wasm_body__ (overridable 3)"/1
    (codebeam_2024 0.1.0) lib/temperature_converter.ex:12: TemperatureConverter."__wasm_body__ (overridable 4)"/1
    (codebeam_2024 0.1.0) lib/temperature_converter.ex:16: TemperatureConverter.__wasm_body__/1
iex(4)> Orb.to_wat HelloOrb 
** (RuntimeError) Must not nest Orb.Constants scopes.
    (orb 0.0.33) lib/orb/constants.ex:11: Orb.Constants.__begin/1
    (orb 0.0.33) lib/orb/compiler.ex:12: Orb.Compiler.run/2
    (codebeam_2024 0.1.0) lib/hello_orb.ex:1: HelloOrb.__wasm_module__/0
    (orb 0.0.33) lib/orb.ex:961: Orb.to_wat/1
RoyalIcing commented 4 months ago

Aha! I know exceptions are seen as evil in Erlang but I probably need to add some recovery code in an after to unset the Process dictionary key.