Skip to content

Commit

Permalink
Update defm_test.exs
Browse files Browse the repository at this point in the history
  • Loading branch information
jackalcooper committed Nov 12, 2024
1 parent 85d01d1 commit 6dc5378
Showing 1 changed file with 4 additions and 19 deletions.
23 changes: 4 additions & 19 deletions test/defm_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ defmodule AddTwoInt do
use Charms, init: false
alias Charms.{Pointer, Term}

defm add_or_error(env, a, b, error) :: Term.t() do
defm add_or_error_with_cond_br(env, a, b, error) :: Term.t() do
ptr_a = Pointer.allocate(i32())
ptr_b = Pointer.allocate(i32())

Expand All @@ -11,7 +11,7 @@ defmodule AddTwoInt do
func.return(error)
end

cond_br enif_get_int64(env, a, ptr_a) != 0 do
cond_br enif_get_int(env, a, ptr_a) != 0 do
cond_br 0 != enif_get_int(env, b, ptr_b) do
a = Pointer.load(i32(), ptr_a)
b = Pointer.load(i32(), ptr_b)
Expand All @@ -26,19 +26,6 @@ defmodule AddTwoInt do
end
end

defm add0(env, a, b) :: Term.t() do
ptr_a = Pointer.allocate(i32())
ptr_b = Pointer.allocate(i32())

if enif_get_int(env, a, ptr_a) <= 0 || enif_get_int(env, b, ptr_b) <= 0 do
enif_make_badarg(env)
else
a = Pointer.load(i32(), ptr_a)
b = Pointer.load(i32(), ptr_b)
enif_make_int(env, a + b)
end
end

defm add(env, a, b) :: Term.t() do
ptr_a = Pointer.allocate(i32())
ptr_b = Pointer.allocate(i32())
Expand Down Expand Up @@ -104,10 +91,8 @@ defmodule DefmTest do
assert String.starts_with?(AddTwoInt.__ir__(), "ML\xefR")
assert AddTwoInt.add(1, 2).(engine) == 3
assert_raise ArgumentError, fn -> AddTwoInt.add(1, "2").(engine) end
assert AddTwoInt.add0(1, 2).(engine) == 3
assert_raise ArgumentError, fn -> AddTwoInt.add0(1, "2").(engine) end
assert AddTwoInt.add_or_error(1, 2, :arg_err).(engine) == 3
assert AddTwoInt.add_or_error(1, "", :arg_err).(engine) == :arg_err
assert AddTwoInt.add_or_error_with_cond_br(1, 2, :arg_err).(engine) == 3
assert AddTwoInt.add_or_error_with_cond_br(1, "", :arg_err).(engine) == :arg_err
assert :ok = Charms.JIT.destroy(:add_int)
end

Expand Down

0 comments on commit 6dc5378

Please sign in to comment.