@@ -12,14 +12,9 @@ import modules.DescriptorModule
12
12
import fr .hammons .slinc .modules .TransitionModule
13
13
import fr .hammons .slinc .modules .ReadWriteModule
14
14
15
- class StructI (using DescriptorModule , TransitionModule , ReadWriteModule ):
16
- /** Summons up Descriptors for the members of Product A
17
- *
18
- * @tparam A
19
- * The product type to summon a list of descriptors for
20
- * @return
21
- * List[TypeDescriptor]
22
- */
15
+ trait Struct [A <: Product ] extends DescriptorOf [A ], MethodCompatible [A ]
16
+
17
+ object Struct :
23
18
private inline def memberDescriptors [A ](using
24
19
m : Mirror .ProductOf [A ]
25
20
): List [TypeDescriptor ] =
@@ -83,43 +78,40 @@ class StructI(using DescriptorModule, TransitionModule, ReadWriteModule):
83
78
inline EmptyTuple match
84
79
case a : A => a
85
80
86
- trait Struct [A <: Product ] extends DescriptorOf [A ], MethodCompatible [A ]
87
-
88
- object Struct :
89
- inline def derived [A <: Product ](using
90
- m : Mirror .ProductOf [A ],
91
- ct : ClassTag [A ]
92
- ) = new Struct [A ]:
93
- val descriptor : StructDescriptor = StructDescriptor (
94
- memberDescriptors[A ].view
95
- .zip(memberNames[A ])
96
- .map(StructMemberDescriptor .apply)
97
- .toList,
98
- ct.runtimeClass,
99
- m.fromProduct(_)
100
- )
81
+ inline def derived [A <: Product ](using
82
+ m : Mirror .ProductOf [A ],
83
+ ct : ClassTag [A ]
84
+ )(using DescriptorModule , ReadWriteModule , TransitionModule ) = new Struct [A ]:
85
+ val descriptor : StructDescriptor = StructDescriptor (
86
+ memberDescriptors[A ].view
87
+ .zip(memberNames[A ])
88
+ .map(StructMemberDescriptor .apply)
89
+ .toList,
90
+ ct.runtimeClass,
91
+ m.fromProduct(_)
92
+ )
101
93
102
- private val offsetsArray = descriptor.offsets
94
+ private val offsetsArray = descriptor.offsets
103
95
104
- summon[ReadWriteModule ].registerWriter[A ]((m, b, a) =>
105
- writeGen(offsetsArray.map(_ + b), a, m)
106
- )(using this )
96
+ summon[ReadWriteModule ].registerWriter[A ]((m, b, a) =>
97
+ writeGen(offsetsArray.map(_ + b), a, m)
98
+ )(using this )
107
99
108
- summon[ReadWriteModule ].registerReader((m, b) =>
109
- readGen(offsetsArray.map(_ + b), m)
110
- )(using this )
100
+ summon[ReadWriteModule ].registerReader((m, b) =>
101
+ readGen(offsetsArray.map(_ + b), m)
102
+ )(using this )
111
103
112
- summon[TransitionModule ].registerMethodArgumentTransition[A ](
113
- this .descriptor,
114
- Allocator ?=> in(_)
115
- )
116
- summon[TransitionModule ]
117
- .registerMethodReturnTransition[A ](this .descriptor, out)
118
- final def in (a : A )(using alloc : Allocator ): Object =
119
- val mem = alloc.allocate(this .descriptor, 1 )
120
- summon[ReadWriteModule ].write(mem, Bytes (0 ), a)(using this )
121
- summon[TransitionModule ].methodArgument(mem).asInstanceOf [Object ]
104
+ summon[TransitionModule ].registerMethodArgumentTransition[A ](
105
+ this .descriptor,
106
+ Allocator ?=> in(_)
107
+ )
108
+ summon[TransitionModule ]
109
+ .registerMethodReturnTransition[A ](this .descriptor, out)
110
+ final def in (a : A )(using alloc : Allocator ): Object =
111
+ val mem = alloc.allocate(this .descriptor, 1 )
112
+ summon[ReadWriteModule ].write(mem, Bytes (0 ), a)(using this )
113
+ summon[TransitionModule ].methodArgument(mem).asInstanceOf [Object ]
122
114
123
- final def out (a : Object ): A =
124
- val mem = summon[TransitionModule ].memReturn(a)
125
- summon[ReadWriteModule ].read[A ](mem, Bytes (0 ))(using this )
115
+ final def out (a : Object ): A =
116
+ val mem = summon[TransitionModule ].memReturn(a)
117
+ summon[ReadWriteModule ].read[A ](mem, Bytes (0 ))(using this )
0 commit comments