diff --git a/Cargo.toml b/Cargo.toml index 632d42eb..eb4fcc50 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "customasm" -version = "0.10.2" +version = "0.10.3" edition = "2018" authors = ["Henrique Lorenzi "] diff --git a/src/expr/eval.rs b/src/expr/eval.rs index b4edc7db..d80402ab 100644 --- a/src/expr/eval.rs +++ b/src/expr/eval.rs @@ -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) } diff --git a/src/test/expr.rs b/src/test/expr.rs index 76927fcd..a64f75eb 100644 --- a/src/test/expr.rs +++ b/src/test/expr.rs @@ -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)))); diff --git a/web/customasm.gc.wasm b/web/customasm.gc.wasm index c6b5e038..f6b78870 100644 Binary files a/web/customasm.gc.wasm and b/web/customasm.gc.wasm differ