-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetupMacro.bqn
48 lines (44 loc) · 1.46 KB
/
setupMacro.bqn
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# Makes an importer that improves the ffi function creation syntax
MakeImporter ⇐ {debug𝕊pathToBin: # Debug is useful for Segmentation Faults
NestedStructToStr ← {
1≥≡𝕩?𝕩;
lists‿atoms ← ×∘≡¨⊸(/ ⋈ ¬⊸/)𝕩
atoms∾'{'∾'}'«∾','∾¨𝕊¨lists
}
NestedStructToStrRet ← {
1≥≡𝕩?𝕩;
lists‿atoms ← ×∘≡¨⊸(/ ⋈ ¬⊸/)𝕩
atoms∾'{'∾'}'«∾','∾¨𝕊¨"*"⍟("*i8:c8"⊸≡∨"*u8:c8"⊸≡)¨lists
}
{𝕨 funcName _𝕣 inpTypes: outType←𝕨⊣⟨⟩
a←'>'⊸∾⌾⊑⍟(1=≠) NestedStructToStr¨𝕩
HandleError ← {
•Out "DEBUG TYPE INFO:"
•Out •Fmt 𝕩
•Out "END OF DEBUG TYPE INFO; BEGINING WITH FULL ERROR:"
•term.Flush@
𝕨•FFI𝕩
}
func ← pathToBin •FFI⎊HandleError ⟨ NestedStructToStrRet outType⋄funcName⟩∾a
m ← str⊸≡¨a
IfDebug ← {•term.Flush@⊣•Out funcName ⋄ 𝕏⊣•term.Flush∘@⊣•Out∘funcName}
IfDebug⍟debug {𝕏∾⟜@}⍟(a≡⋈'>'∾str) {𝕏∾⟜@¨⌾(m⊸/)}⍟(∨´m) func
}
}
# predefined C types
bool ⇐ "i8"
c ⇐ "i8"
i ⇐ "i32"
f ⇐ "f32"
u ⇐ "u32"
i8 ⇐ "i8"
u8 ⇐ "u8"
str ⇐ "*i8:c8"
uStr ⇐ "*u8:c8"
ptr ⇐ "*"
pathToBinary ⇐ ⊑•args
r ⇐ 0 MakeImporter pathToBinary
##################################
# End of setup for easy ffi. #
# Begining of autogenerated ffi. #
##################################