@@ -129,6 +129,7 @@ intVecRefPushGen←{
129129pop ,← ⊂intVecRefPopGen ⍬
130130push ,← ⊂intVecRefPushGen⍬
131131atomTypes,←⊂'=I4'
132+ typeByteSize,←8
132133
133134runAfterFuncDone ← 0/⊂id
134135
@@ -150,6 +151,7 @@ intVecPushGen←{
150151pop ,← ¯1↑pop ⍝ Adding a filler function. It won't be used since popping an input-only type can't happen.
151152push ,← ⊂intVecPushGen⍬
152153atomTypes,←⊂'<I4'
154+ typeByteSize,←8
153155
154156⍝ ---------------- ⍝
155157⍝ Stack operations ⍝
@@ -170,8 +172,8 @@ Pop ← {
170172
171173NameOfStruct ← {
172174 2>|≡⍵:⍵
173- _← 'NameCheck applied to a non-atomic pointer type, this should be impossible.' Assert ∧/'<=>'≢¨⊂⊃⍵
174- ,'⋄'∘,⍣¯1⊃ ⍵
175+ _← 'INTERNAL: NameCheck applied to a non-atomic pointer type, this should be impossible.' Assert ∧/'<=>'≢¨⊂⊃⍵
176+ ,'⋄'∘,⍣¯1⊢(⊃⍵),⍵/⍨⌽∧\⌽0=≡¨ ⍵
175177}
176178remPtrInfo ← {⍵/⍨~ (~atomTypes∊⍨⊂⍵)∧ ∧\'<=>'∊⍨⍵}
177179
@@ -184,15 +186,68 @@ structs ← ∪{(('⋄'≡⊃⍤⊃)¨⍵)/⍵}##.{⍎⍵._Each_(0/⊂,⊂'')⎕
184186
185187⎕NA 'I4 ',pathToBinary,'|GetStructNameLength I4'
186188⎕NA pathToBinary,'|GetStructName =C1[] I4 I4'
187- structNames ← {l←GetStructNameLength⍵ ⋄ GetStructName ((l⍴'')l ⍵)}E._Each_(0/⊂'')⊢ ¯1+⍳StructCount
188-
189- ('Not all structs were found in the .so/dll/dylib library binary:',⊃,/' ',¨(~r)/NameOfStruct¨structs) Assert ∧/r←structNames∊⍨NameOfStruct¨structs
189+ structNamesAll ← {l←GetStructNameLength⍵ ⋄ GetStructName ((l⍴'')l ⍵)}E._Each_(0/⊂'')⊢ ⎕IO-⍨⍳StructCount
190+ ('Not all structs were found in the .so/dll/dylib library binary:',⊃,/' ',¨(~r)/NameOfStruct¨structs) Assert ∧/r←structNamesAll∊⍨NameOfStruct¨structs
191+ rrr←structNamesAll⍳NameOfStruct¨structs
192+ ⎕EX 'structNamesAll' 'r'
190193
191194⎕NA 'I4 ',pathToBinary,'|GetStructSize I4'
192195'tempAlloc' ⎕NA 'P ',pathToBinary,'|MemAlloc U4'
193196'tempFree' ⎕NA pathToBinary,'|MemFree P'
197+ structByteSizes←(GetStructSize¨⎕IO-⍨⍳StructCount)[rrr]
198+
194199BytesEachArg ← ⌈/ GetStructSize¨ ⎕IO-⍨⍳≢structs
195- atomTypes ,← 1↓¨⊃¨structs
200+ ⎕EX 'rrr'
201+
202+ ∇r←FormatArrType (t l)
203+ r←t,'[',(⍕l),']'
204+ ∇
205+ PopArrGen←{
206+ (t l)←⍵
207+
208+ O←(t l){ ⍝ pop value
209+ (t l)←⍺⍺
210+ Popper←⊃pop[atomTypes⍳⊂t]
211+ typeLen ← typeByteSize[atomTypes⍳⊂t]
212+ eachValueInResultPtr ← (Pop⍬) MovePtr⍤,E._Each_⍬⊢ typeLen×⎕IO-⍨⍳l
213+ resultPtrs←Push E._Each_⍬⍳l
214+ _←resultPtrs({MemCpy⍺⍵typeLen}E._Each_⍬)eachValueInResultPtr
215+ ⌽{Popper∘⊢⍬}E._Each_⍬⌽resultPtrs
216+ }
217+ ⎕OR 'O'
218+ }
219+ PushArrGen←{
220+ (t l)←⍵
221+
222+ O←(t l){ ⍝ push value
223+ (t l)←⍺⍺
224+ l≢≢⍵:0 Assert⍨'Wrong list length given for ',t,'[',(⍕l),'], (',(⍕l),'≢≢⍵)'
225+ Pusher←⊃push[atomTypes⍳⊂t]
226+ typeLen ← typeByteSize[atomTypes⍳⊂t]
227+ ptr←Push⍬
228+ _←{Pusher∘⊢⍵}E._Each_⍬⊢⌽⍵
229+ _←(Pop E._Each_⍬⍳l) ({MemCpy (⍵⍺typeLen)}E._Each_⍬) (MovePtr ptr,⊢)E._Each_⍬⊢typeLen×⎕IO-⍨⍳l
230+ ⍝_←{_←{⎕←⍵}¨'this '∘,¨⍵⋄⍵≡⍥(⊂100÷⍨(⌊.5∘+)⍤×∘100)⊢⎕←ptr ReadF4 16×l}⍣('Matrix'≡t)⊢⍵
231+ ptr
232+ }
233+
234+ ⎕OR'O'
235+ }
236+ ⍝ TODO: Possible improvement: Automatically read the loaded structs and create these ArrTypes
237+ arrTypes ← ⍬
238+ arrTypes ,←⊂ 'F4' 4 ⋄ typeByteSize ,← 4×4
239+ arrTypes ,←⊂ 'F4' 2 ⋄ typeByteSize ,← 4×2
240+ arrTypes ,←⊂ 'Matrix' 2 ⋄ typeByteSize ,← (4×4)×4
241+ arrTypes ,←⊂ 'U1' 32 ⋄ typeByteSize ,← 1×32
242+ arrTypes ,←⊂ 'I4' 4 ⋄ typeByteSize ,← 4×4
243+ arrTypes ,←⊂ 'Vector2'2 ⋄ typeByteSize ,← 8×2
244+ arrTypes ,←⊂ 'F4' 3 ⋄ typeByteSize ,← 4×3
245+ arrTypes ,←⊂ 'F4' 16 ⋄ typeByteSize ,← 4×16
246+ arrTypes ,←⊂ 'U4' 4 ⋄ typeByteSize ,← 4×4
247+
248+ atomTypes,←FormatArrType¨arrTypes
249+ pop ,← PopArrGen E._Each_(0/⊂id)⊢ arrTypes
250+ push,← PushArrGen E._Each_(0/⊂id)⊢ arrTypes
196251
197252PopStructGen←{
198253 name←NameOfStruct ⍵
@@ -226,9 +281,10 @@ PushStructGen ← {
226281 }(name cleaned)
227282 ⎕OR'O'
228283}
229-
284+ atomTypes ,← 1↓¨⊃¨structs
230285pop ,← PopStructGen E._Each_(0/⊂id)⊢ structs
231286push,← PushStructGen E._Each_(0/⊂id)⊢ structs
287+ typeByteSize,← structByteSizes
232288⍝ -------------------------------- ⍝
233289
234290⍝ --------------------------- ⍝
@@ -244,14 +300,14 @@ equalPtrPushGen←{
244300}
245301pop ,← equalPtrPopGen E._Each_(0/⊂id)⊢ pop
246302push,← equalPtrPushGen E._Each_(0/⊂id)⊢ push
303+ typeByteSize,← 8⍨¨atomTypes
247304atomTypes,←'=',¨atomTypes
248305⍝ --------------------------- ⍝
249306
250307
251308⍝ --------------------------- ⍝
252309⍝ Handling signed string type ⍝
253310⍝ --------------------------- ⍝
254- atomTypes ,←⊂ str ← '=0C1'
255311StringPopGen←{
256312 _←'A'⎕NA pathToBinary,'|strcpy2 >0T1[] P'
257313 O←(⊃pop[atomTypes⍳⊂,'P']){
@@ -275,6 +331,8 @@ StringPushGen←{
275331 }M
276332 ⎕OR 'push'
277333}
334+ atomTypes ,←⊂ str ← '=0C1'
335+ typeByteSize,← 8
278336pop ,←⊂ StringPopGen ⍬
279337push,←⊂ StringPushGen ⍬
280338⍝ --------------------------- ⍝
@@ -329,12 +387,13 @@ _←'MemCpyF4' ⎕NA pathToBinary,'|memcpy2 P <F4[] U8'
329387_←'MemCpyI4' ⎕NA pathToBinary,'|memcpy2 P <I4[] U8'
330388_←'MemCpyI4Out'⎕NA pathToBinary,'|memcpy2 =I4[] P U8'
331389_←'MemCpyF4Out'⎕NA pathToBinary,'|memcpy2 =F4[] P U8'
390+ _←'MemCpy' ⎕NA pathToBinary,'|memcpy2 P P U8'
332391_←'MovePtr'⎕NA'P ',pathToBinary,'|MovePtr P I4'
333392
334- ∇ptr WriteF4 floats
393+ ∇ptr←ptr WriteF4 floats
335394 MemCpyF4 {⍺⍺ ⍵} (ptr floats (4×≢floats))
336395∇
337- ∇ptr WriteI4 ints
396+ ∇ptr←ptr WriteI4 ints
338397 MemCpyI4 {⍺⍺ ⍵} (ptr ints (4×≢ints))
339398∇
340399∇r←ptr ReadI4 amount
0 commit comments