Skip to content

Commit

Permalink
fix #17: fix bitwise not operator
Browse files Browse the repository at this point in the history
  • Loading branch information
hlorenzi committed Nov 18, 2019
1 parent 918c186 commit dee6f48
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "customasm"
version = "0.10.2"
version = "0.10.3"
edition = "2018"
authors = ["Henrique Lorenzi <hlorenzi12@gmail.com>"]

Expand Down
5 changes: 4 additions & 1 deletion src/expr/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,9 +369,12 @@ fn bigint_not(x: BigInt) -> BigInt
{
let mut x_bytes = x.to_signed_bytes_le();

if x.sign() != Sign::Minus
{ x_bytes.push(0); }

for i in 0..x_bytes.len()
{ x_bytes[i] = !x_bytes[i]; }

BigInt::from_signed_bytes_le(&x_bytes)
}

Expand Down
18 changes: 18 additions & 0 deletions src/test/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,24 @@ fn test_ops_bitmanipulation()
test("! 1", Pass(ExpressionValue::Integer(BigInt::from(-2))));
test("!-1", Pass(ExpressionValue::Integer(BigInt::from(0))));

test("!7", Pass(ExpressionValue::Integer(BigInt::from(-8))));
test("!8", Pass(ExpressionValue::Integer(BigInt::from(-9))));
test("!9", Pass(ExpressionValue::Integer(BigInt::from(-10))));
test("!16", Pass(ExpressionValue::Integer(BigInt::from(-17))));
test("!32", Pass(ExpressionValue::Integer(BigInt::from(-33))));
test("!64", Pass(ExpressionValue::Integer(BigInt::from(-65))));
test("!128", Pass(ExpressionValue::Integer(BigInt::from(-129))));
test("!256", Pass(ExpressionValue::Integer(BigInt::from(-257))));

test("!-8", Pass(ExpressionValue::Integer(BigInt::from(7))));
test("!-9", Pass(ExpressionValue::Integer(BigInt::from(8))));
test("!-10", Pass(ExpressionValue::Integer(BigInt::from(9))));
test("!-17", Pass(ExpressionValue::Integer(BigInt::from(16))));
test("!-33", Pass(ExpressionValue::Integer(BigInt::from(32))));
test("!-65", Pass(ExpressionValue::Integer(BigInt::from(64))));
test("!-129", Pass(ExpressionValue::Integer(BigInt::from(128))));
test("!-257", Pass(ExpressionValue::Integer(BigInt::from(256))));

test("0b1100 & 0b1010", Pass(ExpressionValue::Integer(BigInt::from(0b1000))));
test("0b1100 | 0b1010", Pass(ExpressionValue::Integer(BigInt::from(0b1110))));
test("0b1100 ^ 0b1010", Pass(ExpressionValue::Integer(BigInt::from(0b0110))));
Expand Down
Binary file modified web/customasm.gc.wasm
Binary file not shown.

0 comments on commit dee6f48

Please sign in to comment.