Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 1 addition & 3 deletions build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ object core
with PublishableModule
with FacadeGenerationModule
with BenchmarksModule {

def javacOptions =
super.javacOptions() ++ Seq("--release", "17")

Expand All @@ -62,8 +61,7 @@ object core
"-project", "slinc"
)
}



def pomSettings = pomTemplate("slinc-core")

def specializationArity = 4
Expand Down
3 changes: 0 additions & 3 deletions core/src/fr/hammons/slinc/Address.scala

This file was deleted.

4 changes: 4 additions & 0 deletions core/src/fr/hammons/slinc/LibraryI.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ object LibraryI:
descriptor: FunctionDescriptor
): MethodHandle

def getDowncall(
descriptor: FunctionDescriptor
): MethodHandle

def getLocalLookup(name: String): Lookup
def getLibraryPathLookup(name: String): Lookup
def getStandardLibLookup: Lookup
Expand Down
12 changes: 8 additions & 4 deletions core/src/fr/hammons/slinc/MethodHandleTools.scala
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,15 @@ object MethodHandleTools:
calculateMethodHandleImplementation[L]('platformSpecific, 'addresses)
}

inline def wrappedMH[A](methodHandle: MethodHandle) = ${
wrappedMHImpl[A]('methodHandle)
inline def wrappedMH[A](mem: Mem, methodHandle: MethodHandle) = ${
wrappedMHImpl[A]('mem, 'methodHandle)
}

// todo: get rid of this once bug https://github.com/lampepfl/dotty/issues/16863 is fixed
@nowarn("msg=unused implicit parameter")
@nowarn("msg=unused local definition")
private def wrappedMHImpl[A](
mem: Expr[Mem],
methodHandleExpr: Expr[MethodHandle]
)(using Quotes, Type[A]) =
import quotes.reflect.*
Expand All @@ -176,7 +177,7 @@ object MethodHandleTools:

val paramNames = LazyList.iterate("a")(a => a ++ a)

Lambda(
val expr = Lambda(
Symbol.spliceOwner,
MethodType(paramNames.take(inputTypes.size).toList)(
_ => inputTypes,
Expand All @@ -187,7 +188,8 @@ object MethodHandleTools:
case '[r] =>
val invokeExpr = invokeArguments[r](
methodHandleExpr,
params.map(_.asExpr)
'{ $mem.asBase } +:
params.map(_.asExpr)
)
val invokeResultExpr = '{
val invokeResult = $invokeExpr
Expand All @@ -197,3 +199,5 @@ object MethodHandleTools:
invokeResultExpr.asTerm
.changeOwner(meth)
).asExprOf[A]

expr
37 changes: 26 additions & 11 deletions core/src/fr/hammons/slinc/Ptr.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,30 @@ package fr.hammons.slinc

import scala.reflect.ClassTag
import fr.hammons.slinc.modules.DescriptorModule
import fr.hammons.slinc.modules.ReadWriteModule

import scala.compiletime.summonFrom

class Ptr[A](private[slinc] val mem: Mem, private[slinc] val offset: Bytes):
def `unary_!`(using receive: Receive[A]): A = receive.from(mem, offset)
inline def `unary_!`(using rwm: ReadWriteModule): A = summonFrom {
case descO: DescriptorOf[A] => rwm.read(mem, offset)
case f: Fn[A, ?, ?] =>
rwm.readFn(
mem,
FunctionDescriptor.fromFunction[A],
mh => MethodHandleTools.wrappedMH[A](_, mh)
)
}

def asArray(size: Int)(using DescriptorOf[A], DescriptorModule)(using
r: ReceiveBulk[A]
) =
r.from(mem.resize(DescriptorOf[A].size * size), offset, size)
r: ReadWriteModule
): IArray[A] =
IArray.unsafeFromArray(
r.readArray(mem.resize(DescriptorOf[A].size * size), offset, size)
)

def `unary_!_=`(value: A)(using send: Send[A]) = send.to(mem, offset, value)
def `unary_!_=`(value: A)(using rwM: ReadWriteModule)(using DescriptorOf[A]) =
rwM.write(mem, offset, value)
def apply(bytes: Bytes): Ptr[A] = Ptr[A](mem, offset + bytes)
def apply(index: Int)(using DescriptorOf[A], DescriptorModule): Ptr[A] =
Ptr[A](mem, offset + (DescriptorOf[A].size * index))
Expand All @@ -23,7 +38,7 @@ object Ptr:
extension (p: Ptr[Byte])
def copyIntoString(
maxSize: Int
)(using DescriptorOf[Byte], DescriptorModule) =
)(using DescriptorOf[Byte], DescriptorModule, ReadWriteModule) =
var i = 0
val resizedPtr = p.resize(Bytes(maxSize))
while (i < maxSize && !resizedPtr(i) != 0) do i += 1
Expand All @@ -39,21 +54,21 @@ object Ptr:

def copy[A](
a: Array[A]
)(using alloc: Allocator, descriptor: DescriptorOf[A], send: Send[Array[A]]) =
)(using alloc: Allocator, descriptor: DescriptorOf[A], rwm: ReadWriteModule) =
val mem = alloc.allocate(DescriptorOf[A], a.size)
send.to(mem, Bytes(0), a)
rwm.writeArray(mem, Bytes(0), a)
Ptr[A](mem, Bytes(0))

def copy[A](using alloc: Allocator)(
a: A
)(using send: Send[A], descriptor: DescriptorOf[A]) =
)(using rwm: ReadWriteModule, descriptor: DescriptorOf[A]) =
val mem = alloc.allocate(DescriptorOf[A], 1)
send.to(mem, Bytes(0), a)
rwm.write(mem, Bytes(0), a)
Ptr[A](mem, Bytes(0))

def copy(
string: String
)(using Allocator, DescriptorOf[Byte], Send[Array[Byte]]): Ptr[Byte] = copy(
)(using Allocator, DescriptorOf[Byte], ReadWriteModule): Ptr[Byte] = copy(
string.getBytes("ASCII").nn :+ 0.toByte
)

Expand Down
186 changes: 0 additions & 186 deletions core/src/fr/hammons/slinc/Receive.scala

This file was deleted.

24 changes: 0 additions & 24 deletions core/src/fr/hammons/slinc/ReceiveBulk.scala

This file was deleted.

2 changes: 0 additions & 2 deletions core/src/fr/hammons/slinc/Scope.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package fr.hammons.slinc

import scala.annotation.experimental

sealed trait Scope:
def apply[A](fn: Allocator ?=> A): A

Expand Down
Loading