Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions effekt/shared/src/main/scala/effekt/core/vm/Builtin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ lazy val integers: Builtins = Map(
builtin("effekt::bitwiseXor(Int, Int)") {
case As.Int(x) :: As.Int(y) :: Nil => Value.Int(x ^ y)
},
builtin("effekt::bitwiseNot(Int)") {
case As.Int(x) :: Nil => Value.Int(~x)
},

// Comparison
// ----------
Expand Down
1 change: 1 addition & 0 deletions examples/stdlib/acme.effekt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module acme
import args
import array
import bench
import binstream
import buffer
import bytearray
import char
Expand Down
20 changes: 20 additions & 0 deletions examples/stdlib/binstream.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Binstream
✓ literal hex 10
✓ literal hex ff
✓ literal char a
✓ literal string ba
✓ int back-and-forth (17)
✓ int back-and-forth (17), explicit BE
✓ int back-and-forth (17), explicit LE
✓ byte 00101010
✓ to bits and back LE bitorder
✓ to bits and back BE bitorder
✓ append 0 means *2
✓ pow agrees with double one
✓ LE 2s-complement
✓ BE 2s-complement

14 pass
0 fail
14 tests total

49 changes: 49 additions & 0 deletions examples/stdlib/binstream.effekt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import binstream
import stream
import test

def main() = {
suite("Binstream", false){
test("literal hex 10"){ assert(x"10${()}", 16) }
test("literal hex ff"){ assert(x"ff${()}", 255) }
test("literal char a"){ assert(x"${'a'}", x"61${()}") }
test("literal string ba"){ assert(x"${"ba"}", x"62${()}" * 256 + x"61${()}") }
test("int back-and-forth (17)"){ assert(x"${17}", 17)}
test("int back-and-forth (17), explicit BE"){ assert(x"${17.BE}", 17) }
test("int back-and-forth (17), explicit LE"){ assert(x"${17.LE}", 17 * 256 * 256 * 256) }
test("byte 00101010"){
with on[MissingValue].assertNotThrown
assert(first[Byte]{groupBytesBE{ bit"00101010${()}" }}.toInt, 42)
}
test("to bits and back LE bitorder"){
with on[MissingValue].assertNotThrown
[42.toByte, 12.toByte, 113.toByte, 0.toByte, 255.toByte].foreach{ v =>
assert(first[Byte]{ groupBytesLE{ bitsLE(v) } }, v)
}
}
test("to bits and back BE bitorder"){
with on[MissingValue].assertNotThrown
[42.toByte, 12.toByte, 113.toByte, 0.toByte, 255.toByte].foreach{ v =>
assert(first[Byte]{ groupBytesBE{ bitsBE(v) } }, v)
}
}
test("append 0 means *2"){
with on[MissingValue].assertNotThrown
[42.toByte, 12.toByte, 127.toByte].foreach{ v =>
assert(nth[Byte](1){ groupBytesBE{ repeat(7){ do emit(B0()) }; bitsBE(v); do emit(B0()) } }, (v.toInt * 2).toByte)
}
}
test("pow agrees with double one"){
assert(pow(2,5), pow(2.0,5).toInt)
}
test("LE 2s-complement"){
with on[MissingValue].assertNotThrown
assert(first[Byte]{ groupBytesLE{ twoscomplementLE{ bitsLE(6.toByte) } } }, 250.toByte)
}
test("BE 2s-complement"){
with on[MissingValue].assertNotThrown
assert(first[Byte]{ groupBytesBE{ bit"${-6.Signed.BE.OfWidth(8)}" } }, 250.toByte)
}
}
()
}
17 changes: 17 additions & 0 deletions examples/stdlib/test/exceptions.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Test test suite on Exceptions
✓ Test test assertNotThrown pass
✕ Test test assertNotThrown fail
Unexpected Exception
✕ Test test assertThrown fail
Expected Exception, but exited normally
✓ Test test assertThrows pass
✓ Test test assertNoThrow pass
✕ Test test assertNoThrow fail
Unexpected Exception
✕ Test test assertThrows fail
Expected Exception, but exited normally
✓ Test test assertThrows pass

4 pass
4 fail
8 tests total
44 changes: 44 additions & 0 deletions examples/stdlib/test/exceptions.effekt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import test

def main() = {
// Don't print out times in CI.
suite("Test test suite on Exceptions", false) {
// on[E] variant
// -------------
test("Test test assertNotThrown pass") {
with on[MissingValue].assertNotThrown
assert(Some(12).value, 12)
}
test("Test test assertNotThrown fail") {
with on[MissingValue].assertNotThrown
assert(None().value, 12)
}
test("Test test assertThrown fail") {
with on[MissingValue].assertThrown
assert(Some(12).value, 12)
}
test("Test test assertThrows pass") {
with on[MissingValue].assertThrown[MissingValue]
assert(None().value, 12)
}
// direct variant
// --------------
test("Test test assertNoThrow pass") {
with assertNoThrow[MissingValue]
assert(Some(12).value, 12)
}
test("Test test assertNoThrow fail") {
with assertNoThrow[MissingValue]
assert(None().value, 12)
}
test("Test test assertThrows fail") {
with assertThrows[MissingValue]
assert(Some(12).value, 12)
}
test("Test test assertThrows pass") {
with assertThrows[MissingValue]
assert(None().value, 12)
}
};
()
}
Loading