Skip to content

Commit

Permalink
v0.9.77
Browse files Browse the repository at this point in the history
  • Loading branch information
elect86 committed Apr 14, 2023
1 parent c32a865 commit a3c1fda
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 25 deletions.
45 changes: 21 additions & 24 deletions buildSrc/src/main/kotlin/kool/pointers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -97,25 +97,25 @@ fun pointers(target: File) {
@JvmName("invokeULong")
inline infix operator fun $PtrType.invoke(index: ULong): $Type = get(index)
@JvmName("plus${Type}Int")
inline infix operator fun $PtrType.plus(offset: Int): $PtrType = Ptr(address + offset.toULong())
inline infix operator fun $PtrType.plus(offset: Int): $PtrType = plus(offset.toULong())
@JvmName("plus${Type}UInt")
inline infix operator fun $PtrType.plus(offset: UInt): $PtrType = Ptr(address + offset.toULong())
inline infix operator fun $PtrType.plus(offset: UInt): $PtrType = plus(offset.toULong())
@JvmName("plus${Type}Long")
inline infix operator fun $PtrType.plus(offset: Long): $PtrType = Ptr(address + offset.toULong())
inline infix operator fun $PtrType.plus(offset: Long): $PtrType = plus(offset.toULong())
@JvmName("plus${Type}ULong")
inline infix operator fun $PtrType.plus(offset: ULong): $PtrType = Ptr(address + offset)
inline infix operator fun $PtrType.plus(offset: ULong): $PtrType = Ptr(address + offset * $Type.BYTES.toULong())
@JvmName("minus${Type}Int")
inline infix operator fun $PtrType.minus(offset: Int): $PtrType = Ptr(address - offset.toULong())
inline infix operator fun $PtrType.minus(offset: Int): $PtrType = minus(offset.toULong())
@JvmName("minus${Type}UInt")
inline infix operator fun $PtrType.minus(offset: UInt): $PtrType = Ptr(address - offset.toULong())
inline infix operator fun $PtrType.minus(offset: UInt): $PtrType = minus(offset.toULong())
@JvmName("minus${Type}Long")
inline infix operator fun $PtrType.minus(offset: Long): $PtrType = Ptr(address - offset.toULong())
inline infix operator fun $PtrType.minus(offset: Long): $PtrType = minus(offset.toULong())
@JvmName("minus${Type}ULong")
inline infix operator fun $PtrType.minus(offset: ULong): $PtrType = Ptr(address - offset)
inline infix operator fun $PtrType.minus(offset: ULong): $PtrType = Ptr(address - offset * $Type.BYTES.toULong())
@JvmName("inc$Type")
inline operator fun $PtrType.inc(): $PtrType = Ptr(address + $Type.BYTES.toUInt())
inline operator fun $PtrType.inc(): $PtrType = plus(1)
@JvmName("dec$Type")
inline operator fun $PtrType.dec(): $PtrType = Ptr(address - $Type.BYTES.toUInt())"""
inline operator fun $PtrType.dec(): $PtrType = minus(1)"""
else
+"""
inline infix operator fun $PtrType.get(index: Int): $Type = get(index.toULong())
Expand All @@ -129,33 +129,30 @@ fun pointers(target: File) {
inline operator fun $PtrType.invoke(): $Type = get(0uL)
inline infix operator fun $PtrType.invoke(index: ULong): $Type = get(index)
@JvmName("plus${Type}Int")
inline infix operator fun $PtrType.plus(offset: Int): $PtrType = Ptr(address + offset.toULong())
inline infix operator fun $PtrType.plus(offset: Int): $PtrType = plus(offset.toULong())
@JvmName("plus${Type}UInt")
inline infix operator fun $PtrType.plus(offset: UInt): $PtrType = Ptr(address + offset.toULong())
inline infix operator fun $PtrType.plus(offset: UInt): $PtrType = plus(offset.toULong())
@JvmName("plus${Type}Long")
inline infix operator fun $PtrType.plus(offset: Long): $PtrType = Ptr(address + offset.toULong())
inline infix operator fun $PtrType.plus(offset: Long): $PtrType = plus(offset.toULong())
@JvmName("plus${Type}ULong")
inline infix operator fun $PtrType.plus(offset: ULong): $PtrType = Ptr(address + offset)
inline infix operator fun $PtrType.plus(offset: ULong): $PtrType = Ptr(address + offset * $Type.BYTES.toULong())
@JvmName("minus${Type}Int")
inline infix operator fun $PtrType.minus(offset: Int): $PtrType = Ptr(address - offset.toULong())
inline infix operator fun $PtrType.minus(offset: Int): $PtrType = minus(offset.toULong())
@JvmName("minus${Type}UInt")
inline infix operator fun $PtrType.minus(offset: UInt): $PtrType = Ptr(address - offset.toULong())
inline infix operator fun $PtrType.minus(offset: UInt): $PtrType = minus(offset.toULong())
@JvmName("minus${Type}Long")
inline infix operator fun $PtrType.minus(offset: Long): $PtrType = Ptr(address - offset.toULong())
inline infix operator fun $PtrType.minus(offset: Long): $PtrType = minus(offset.toULong())
@JvmName("minus${Type}ULong")
inline infix operator fun $PtrType.minus(offset: ULong): $PtrType = Ptr(address - offset)
inline infix operator fun $PtrType.minus(offset: ULong): $PtrType = Ptr(address - offset * $Type.BYTES.toUInt())
@JvmName("inc$Type")
inline operator fun $PtrType.inc(): $PtrType = Ptr(address + $Type.BYTES.toUInt())
inline operator fun $PtrType.inc(): $PtrType = plus(1)
@JvmName("dec$Type")
inline operator fun $PtrType.dec(): $PtrType = Ptr(address - $Type.BYTES.toUInt())"""
inline operator fun $PtrType.dec(): $PtrType = minus(1)"""
+"""
inline operator fun $PtrType.set(index: Int, $type: $Type) = set(index.toULong(), $type)
inline operator fun $PtrType.set(index: UInt, $type: $Type) = set(index.toULong(), $type)
inline operator fun $PtrType.set(index: Long, $type: $Type) = set(index.toULong(), $type)
inline operator fun $PtrType.set(index: ULong, $type: $Type) = unsafe.set(adr + index$maybeTimes, $type$maybeToS)
// inline operator fun plus(pByte: BytePtr): BytePtr = BytePtr(adr + pByte.adr)
"""
inline operator fun $PtrType.set(index: ULong, $type: $Type) = unsafe.set(adr + index$maybeTimes, $type$maybeToS)"""
}

if (Type == "Pointer") {
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pluginManagement {

gradle.rootProject {
group = "kotlin.graphics"
version = "0.9.76"
version = "0.9.77"
}

//includeBuild("../build-logic")
33 changes: 33 additions & 0 deletions src/test/kotlin/kool/PointersTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import kotlin.test.Test
class PointersTest {

val count = 100
val lastIndex = count - 1
val range = 0..99
@Test
fun testByte() = stack {
Expand All @@ -13,6 +14,10 @@ class PointersTest {
p[i] = i.toByte()
for (i in range)
assert(p[i] == i.toByte())
for (i in range)
assert((p + i)[0] == i.toByte())
for (i in range)
assert((p + lastIndex - i)[0] == (lastIndex - i).toByte())
for (i in range)
assert(p++[0] == i.toByte())
p--
Expand All @@ -26,6 +31,10 @@ class PointersTest {
p[i] = i.toShort()
for (i in range)
assert(p[i] == i.toShort())
for (i in range)
assert((p + i)[0] == i.toShort())
for (i in range)
assert((p + lastIndex - i)[0] == (lastIndex - i).toShort())
for (i in range)
assert(p++[0] == i.toShort())
p--
Expand All @@ -39,6 +48,10 @@ class PointersTest {
p[i] = i
for (i in range)
assert(p[i] == i)
for (i in range)
assert((p + i)[0] == i)
for (i in range)
assert((p + lastIndex - i)[0] == lastIndex - i)
for (i in range)
assert(p++[0] == i)
p--
Expand All @@ -52,6 +65,10 @@ class PointersTest {
p[i] = i.toLong()
for (i in range)
assert(p[i] == i.toLong())
for (i in range)
assert((p + i)[0] == i.toLong())
for (i in range)
assert((p + lastIndex - i)[0] == (lastIndex - i).toLong())
for (i in range)
assert(p++[0] == i.toLong())
p--
Expand All @@ -65,6 +82,10 @@ class PointersTest {
p[i] = i.toUByte()
for (i in range)
assert(p[i] == i.toUByte())
for (i in range)
assert((p + i)[0] == i.toUByte())
for (i in range)
assert((p + lastIndex - i)[0] == (lastIndex - i).toUByte())
for (i in range)
assert(p++[0] == i.toUByte())
p--
Expand All @@ -78,6 +99,10 @@ class PointersTest {
p[i] = i.toUShort()
for (i in range)
assert(p[i] == i.toUShort())
for (i in range)
assert((p + i)[0] == i.toUShort())
for (i in range)
assert((p + lastIndex - i)[0] == (lastIndex - i).toUShort())
for (i in range)
assert(p++[0] == i.toUShort())
p--
Expand All @@ -91,6 +116,10 @@ class PointersTest {
p[i] = i.toUInt()
for (i in range)
assert(p[i] == i.toUInt())
for (i in range)
assert((p + i)[0] == i.toUInt())
for (i in range)
assert((p + lastIndex - i)[0] == (lastIndex - i).toUInt())
for (i in range)
assert(p++[0] == i.toUInt())
p--
Expand All @@ -104,6 +133,10 @@ class PointersTest {
p[i] = i.toULong()
for (i in range)
assert(p[i] == i.toULong())
for (i in range)
assert((p + i)[0] == i.toULong())
for (i in range)
assert((p + lastIndex - i)[0] == (lastIndex - i).toULong())
for (i in range)
assert(p++[0] == i.toULong())
p--
Expand Down

0 comments on commit a3c1fda

Please sign in to comment.