Skip to content

Commit c2897a8

Browse files
committed
Fix #25, Implemented array types in structs
Functions that accepted structs containing arrays just ignored the array lengths and accepted a single struct instead. Obviously, these functions were broken. Now fixed! I also made WriteF4 and similar return their input pointer.
1 parent 7a3167b commit c2897a8

File tree

1 file changed

+69
-10
lines changed

1 file changed

+69
-10
lines changed

non-link/setup.apln.hide

Lines changed: 69 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ intVecRefPushGen←{
129129
pop ,← ⊂intVecRefPopGen ⍬
130130
push ,← ⊂intVecRefPushGen⍬
131131
atomTypes,←⊂'=I4'
132+
typeByteSize,←8
132133

133134
runAfterFuncDone ← 0/⊂id
134135

@@ -150,6 +151,7 @@ intVecPushGen←{
150151
pop ,← ¯1↑pop ⍝ Adding a filler function. It won't be used since popping an input-only type can't happen.
151152
push ,← ⊂intVecPushGen⍬
152153
atomTypes,←⊂'<I4'
154+
typeByteSize,←8
153155

154156
⍝ ---------------- ⍝
155157
⍝ Stack operations ⍝
@@ -170,8 +172,8 @@ Pop ← {
170172

171173
NameOfStruct ← {
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
}
176178
remPtrInfo ← {⍵/⍨~ (~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+
194199
BytesEachArg ← ⌈/ 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

197252
PopStructGen←{
198253
name←NameOfStruct ⍵
@@ -226,9 +281,10 @@ PushStructGen ← {
226281
}(name cleaned)
227282
⎕OR'O'
228283
}
229-
284+
atomTypes ,← 1↓¨⊃¨structs
230285
pop ,← PopStructGen E._Each_(0/⊂id)⊢ structs
231286
push,← PushStructGen E._Each_(0/⊂id)⊢ structs
287+
typeByteSize,← structByteSizes
232288
⍝ -------------------------------- ⍝
233289

234290
⍝ --------------------------- ⍝
@@ -244,14 +300,14 @@ equalPtrPushGen←{
244300
}
245301
pop ,← equalPtrPopGen E._Each_(0/⊂id)⊢ pop
246302
push,← equalPtrPushGen E._Each_(0/⊂id)⊢ push
303+
typeByteSize,← 8⍨¨atomTypes
247304
atomTypes,←'=',¨atomTypes
248305
⍝ --------------------------- ⍝
249306

250307

251308
⍝ --------------------------- ⍝
252309
⍝ Handling signed string type ⍝
253310
⍝ --------------------------- ⍝
254-
atomTypes ,←⊂ str ← '=0C1'
255311
StringPopGen←{
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
278336
pop ,←⊂ StringPopGen ⍬
279337
push,←⊂ 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

Comments
 (0)