forked from dzaima/CBQN
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.bqn
More file actions
161 lines (129 loc) · 11 KB
/
test.bqn
File metadata and controls
161 lines (129 loc) · 11 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
f←@
sizet ← "u64"
Section ← {•Out 𝕩∾˜@+10}
f ↩ "lib.so" •FFI ""‿"do_nothing" ⋄ •Show F ⟨⟩
Section "# ""a"""
f ↩ "lib.so" •FFI "i32"‿"getType"‿">a" ⋄ •Show F¨ ⟨⟨⟩, 1, '𝕩', +, ¨, ∘, {⇐}⟩
f ↩ "lib.so" •FFI "a"‿"timesTen"‿"a" ⋄ •Show F ⟨↕10⟩
f ↩ "lib.so" •FFI "a"‿"readAtoms"‿"a"‿"a" ⋄ •Show F ⟨÷5 ⋄ '𝕨'⟩
f ↩ "lib.so" •FFI "a"‿"readTyped"‿">a" ⋄ •Show F (10×↕7) + (4⥊<↕10)∾3⥊<@+↕10
f ↩ "lib.so" •FFI "a"‿"getShape"‿">a" ⋄ •Show F¨ {0⥊˜⌽⍟𝕩↕𝕩}¨ ↕5
f ↩ "lib.so" •FFI "a"‿"evalBQN"‿">a" ⋄ •Show F "↕5"
f ↩ "lib.so" •FFI "a"‿"makeArrays" ⋄ •Out∘•Repr¨ F ⟨⟩
f ↩ "lib.so" •FFI "a"‿"makeThree"‿">a" ⋄ •Show F "foo"
f ↩ "lib.so" •FFI "i32"‿"directAccess"‿">a" ⋄ •Show F "Ai32"•internal.Variation ↕10
bind ← "lib.so" •FFI "a"‿"bindAdd"‿">a" ⋄ g ← Bind 4 ⋄ •Show G 123
Section "# namespaces"
f ↩ "lib.so" •FFI "a"‿"getField"‿">𝕨a"‿"a"‿"a" ⋄ •Show {ab⇐1‿2 ⋄ cd⇐3‿4} F ⟨"ab" ⋄ "default"⟩
f ↩ "lib.so" •FFI "a"‿"getField"‿">𝕨a"‿"a"‿"a" ⋄ •Show {ab⇐1‿2 ⋄ cd⇐3‿4} F ⟨"ef" ⋄ "default"⟩
f ↩ "lib.so" •FFI "a"‿"getField"‿"𝕨a"‿"𝕨a"‿"𝕨a" ⋄ •Show ⟨{ab⇐1‿2 ⋄ cd⇐3‿4} ⋄ "ef" ⋄ "default"⟩ F ⟨⟩
Section "# print args"
f ↩ "lib.so" •FFI ""‿"printArgs"‿"i8"‿"i16"‿"i32"‿"u8"‿"u16"‿"u32"‿"f32"‿"f64" ⋄ •Show F ¯123‿¯12323‿¯212312312‿250‿50000‿3123456789‿π∾÷3
f ↩ "lib.so" •FFI ""‿ "noopArgs"‿"i8"‿"i16"‿"i32"‿"u8"‿"u16"‿"u32"‿"f32"‿"f64" ⋄ •Show F ¯123‿¯12323‿¯212312312‿250‿50000‿3123456789‿π∾÷3
f ↩ "lib.so" •FFI ""‿"printPtrArgs"‿"*i8"‿"*i16"‿"*i32"‿"*u8"‿"*u16"‿"*u32"‿"*f32"‿"*f64" ⋄ •Show F ⥊¨¯123‿¯12323‿¯212312312‿250‿50000‿3123456789‿π∾÷3
f ↩ "lib.so" •FFI ""‿"printPtrArgs"‿"&i8"‿"&i16"‿"&i32"‿"&u8"‿"&u16"‿"&u32"‿"&f32"‿"&f64" ⋄ •Show F ⥊¨¯123‿¯12323‿¯212312312‿250‿50000‿3123456789‿π∾÷3
f ↩ "lib.so" •FFI "f32"‿"printU64s"‿"u64:c8"‿"*u64:c8" ⋄ •Show F ⟨"hellowor", "aaaaaaaa12345678texttext"⟩
f ↩ "lib.so" •FFI "f32"‿"printU64s"‿"u64:u1"‿"*u64:u1" ⋄ •Show F ⟨64↑∾×∘↕¨↕12, 192↑∾×∘↕¨↕21⟩
! 3 ≡ •Type "lib.so" •FFI ""‿"printArgs"‿"i8"‿"i16:c8"‿"i32"‿"u8"‿"u16"‿"u32"‿"f32"‿"f64"
! 3 ≡ •Type "lib.so" •FFI ""‿"printArgs"‿"i8"‿"i16:c16"‿"i32"‿"u8"‿"u16"‿"u32"‿"f32"‿"f64"
! 3 ≡ •Type "lib.so" •FFI ""‿"printArgs"‿"i8:c8"‿"i16"‿"i32"‿"u8"‿"u16"‿"u32"‿"f32"‿"f64"
Section "# read pointers"
f ↩ "lib.so" •FFI "i32"‿"multiplyI32Ptrs"‿"*i32"‿"*i32"‿"i32" ⋄ •Show F ⟨↕10 ⋄ •Show ⌽↕10 ⋄ •Show 10⟩
f ↩ "lib.so" •FFI "f32"‿"sumF32Arr"‿"*f32:i32"‿"i32" ⋄ •Show F ⟨1065353216‿1073741824‿1077936128‿1082130432‿1084227584‿1086324736‿1088421888‿1090519040‿1091567616‿1092616192,10⟩
Section "# mutate i32*"
f ↩ "lib.so" •FFI ⟨"","incI32s","&u32", "i32"⟩ ⋄ •Show F ⟨1e8×20+↕10 ⋄ 10⟩
f ↩ "lib.so" •FFI ⟨"","incI32s","&i32:u1", "i32"⟩ ⋄ •Show ⊑F ⟨1‿0‿1‿0‿1‿0‿1‿0‿0‿1‿0‿1‿0‿0‿1‿1‿0‿1‿1‿0‿0‿0‿0‿1‿0‿1‿0‿1‿0‿0‿1‿0‿0‿0‿1‿0‿0‿0‿1‿0‿0‿0‿1‿1‿1‿0‿1‿1‿1‿1‿1‿1‿0‿0‿1‿1‿0‿0‿1‿0‿0‿1‿0‿0, 2⟩
f ↩ "lib.so" •FFI ⟨"","incI32s","&i32:c8", "i32"⟩ ⋄ •Show ⊑F ⟨"hello, world", 2⟩
f ↩ "lib.so" •FFI ⟨"","incI32s",">𝕨&i32:c8",">i32"⟩ ⋄ •Show ⊑ "hello, world" F 2
f ↩ "lib.so" •FFI ⟨"", "incI32s", "&i32:c8", "i32"⟩ ⋄ •Show ⊑F ⟨"hello, world", 2⟩
f ↩ "lib.so" •FFI ⟨"", "incI32s", "&i32:c8", "𝕨i32"⟩ ⋄ •Show ⊑ ⟨2⟩ F ⟨"hello, world"⟩
f ↩ "lib.so" •FFI ⟨"", "incI32s", "&i32:c8",">𝕨i32"⟩ ⋄ •Show ⊑ 2 F ⟨"hello, world"⟩
f ↩ "lib.so" •FFI ⟨"", "incI32s", ">&i32:c8",">𝕨i32"⟩ ⋄ •Show ⊑ 2 F "hello, world"
f ↩ "lib.so" •FFI ⟨"", "incI32s",">𝕨&i32:c8", ">i32"⟩ ⋄ •Show ⊑ "hello, world" F 2
f ↩ "lib.so" •FFI ⟨"", "incI32s", "&i32:c8", "i32"⟩ ⋄ •Show F ⟨"hello, world", 2⟩
f ↩ "lib.so" •FFI ⟨"&","incI32s", "&i32:c8", "i32"⟩ ⋄ •Show F ⟨"hello, world", 2⟩
Section "# mutate i32*, i16*, i8*"
f ↩ "lib.so" •FFI ⟨"","incInts","&i32", "&i16","&i8"⟩ ⋄ •Show F ⥊¨ 10‿20‿30
f ↩ "lib.so" •FFI ⟨"","incInts","&i32", "𝕨&i16","&i8"⟩ ⋄ •Show ⟨⥊20⟩ F ⥊¨ 10‿30
f ↩ "lib.so" •FFI ⟨"","incInts","&i32",">𝕨&i16","&i8"⟩ ⋄ •Show ⟨20⟩ F ⥊¨ 10‿30
Section "# mutate all element types"
f ↩ "lib.so" •FFI ⟨"","incNativeElements"⟩∾ "&"⊸∾¨ "f32"‿"f64"∾˜ ⥊"i"‿"u" ∾⌜ "8"‿"16"‿"32" ⋄ •Show F 1‿2⊸⥊¨ 0.5⊸+⌾(¯2⊸↑) 10+↕8
f ↩ "lib.so" •FFI ⟨"","incNativeElements"⟩∾ "&"⊸∾¨ "f32"‿"f64"∾˜ ⥊"i"‿"u" ∾⌜ "8"‿"16"‿"32" ⋄ •Show F 8⥊< 1‿2⥊0
f ↩ "lib.so" •FFI ⟨"","incNativeElements"⟩∾ "&"⊸∾¨ "f32"‿"f64"∾˜ ⥊"i"‿"u" ∾⌜ "8"‿"16"‿"32" ⋄ •Show F 1‿2⊸⥊¨ ¯100‿¯30000‿¯2e9‿200‿60000‿4e9 ∾ 1e38‿1e300
f ↩ "lib.so" •FFI ⟨"","incInt64","&u64:i16","&i64:i16"⟩ ⋄ •Show F 2⥊< 2‿4⥊¯1‿¯1‿6‿0
Section "# u64 & i64 tests"
f ↩ "lib.so" •FFI ⟨"u64", "ident_u64",">u64:i32"⟩ ⋄ •Show F 1234‿12
f ↩ "lib.so" •FFI ⟨"u64", "ident_u64",">u64" ⟩ ⋄ •Show F +´2⋆52‿20
f ↩ "lib.so" •FFI ⟨"u64", "ident_u64",">u64" ⟩ ⋄ •Show F ¯1+2⋆53
f ↩ "lib.so" •FFI ⟨"u64:i32","ident_u64",">u64" ⟩ ⋄ •Show F 123456789123456
f ↩ "lib.so" •FFI ⟨"u64:u1", "ident_u64",">u64:c8" ⟩ ⋄ •Show F "hellowor"
f ↩ "lib.so" •FFI ⟨"i64:u1", "ident_i64",">i64:c8" ⟩ ⋄ •Show F "hellowor"
f ↩ "lib.so" •FFI ⟨"i64", "ident_i64",">i64"⟩ ⋄ •Show F ¯1+2⋆53
f ↩ "lib.so" •FFI ⟨"i64", "ident_i64",">i64"⟩ ⋄ •Show F - ¯1+2⋆53
Section "# malloc test"
f ↩ "lib.so" •FFI "*:i32"‿"malloc"‿">u64" ⋄ •Show (•internal.Type⋈≠) malloc ← F 123
f ↩ "lib.so" •FFI ""‿"free"‿">*:i32" ⋄ F malloc
Section "# pick item"
f ↩ "lib.so" •FFI "*:i8"‿"pick_ptr"‿">**:i8"‿">𝕨i32" ⋄ •Show @+0 F "helloworfoobarba"-@
f ↩ "lib.so" •FFI "*:c8"‿"pick_ptr"‿">**:c8"‿">𝕨i32" ⋄ •Show 0 F "helloworfoobarba"
f ↩ "lib.so" •FFI ⟨"u64:i8","pick_u64",">*u64:i8",">𝕨i32"⟩ ⋄ •Show @+2 F "000000001234560011122100abacabad"-@
f ↩ "lib.so" •FFI ⟨"u64:i8","pick_u64",">*u64:i8",">𝕨i32"⟩ ⋄ •Show @+3 F "000000001234560011122100abacabad"-@
f ↩ "lib.so" •FFI ⟨"u64", "pick_u64",">*u64:i8",">𝕨i32"⟩ ⋄ •Show 1 F "000000001234560011122100"-'0'
Section "# structs"
s1 ← "{u8,i32,i16,u64:i16,f64}" ⋄ s2 ← ∾"{"‿s1‿","‿s1‿"}"
f ↩ "lib.so" •FFI ⟨"i16", "thirdMember", ">"∾s1⟩ ⋄ •Show F ⟨200, 2e9, ¯30000, 1‿2‿3‿4, 3.25⟩
f ↩ "lib.so" •FFI ⟨s1, "incMembers", ">"∾s1⟩ ⋄ •Show F ⟨200, 2e9, ¯30000, 1‿2‿3‿4, 3.25⟩
f ↩ "lib.so" •FFI ⟨"&", "incMany", "&"∾s2, "u64"⟩ ⋄ •Show¨ F ⟨0‿3‿6+3⥊<0‿1+2⥊<⟨200, 2e9, ¯30000, 1‿2‿3‿4, 3.25⟩, 3⟩
{
calloc ← @•FFI"*:i32"‿"calloc"‿sizet‿sizet ⋄ mem ← Calloc 3‿4
f ← "lib.so" •FFI "i32"‿"arrayRefOp"‿">&{*:i32,u64}"
{𝕊: ⟨sum, ⟨arr‿sz⟩⟩ ← F ⟨mem‿3⟩ ⋄ •Show sum ∾ arr-mem}¨ ↕2
}
Section "# self-ffi"
•term.Flush@
f ↩ @ •FFI ⟨"i32", "putchar", ">i32"⟩ ⋄ F¨ 10∾˜"text"-@
•term.Flush@
f ↩ @ •FFI ⟨"a", "bqn_makeChar", ">u32"⟩ ⋄ •Show F 120169
Section "# array types"
f ↩ "lib.so"•FFI"i32"‿"arrarg"‿">[3]i32" ⋄ •Show F ⟨1,2,3⟩
f ↩ "lib.so"•FFI"i32"‿"ptrToArr"‿">*[2]i32" ⋄ •Show F ⟨0‿0, 0‿0, 0‿0, 10‿20, 3‿4⟩
as1 ← "{[1]i32}"
f ↩ "lib.so"•FFI ⟨"i32", "arrstruct1", as1, "*"∾as1⟩ ⋄ •Show F ⟨⋈⋈10, ⟨⋈⋈20⟩⟩
as2 ← "{[1]i32,[2]"∾as1∾",[3]f64}"
f ↩ "lib.so"•FFI ⟨as2, "arrstruct2", as2, "*"∾as2⟩ ⋄ •Out •Repr F ⟨⟨⟨4⟩ ⋄ ⋈∘⋈¨1‿2 ⋄ 1.2‿2.3‿3.4⟩, ⟨⟨⟨5⟩ ⋄ ⋈∘⋈¨10‿20 ⋄ 5.1‿6.1‿7.1⟩⟩⟩
f ↩ "lib.so"•FFI ⟨"&", "arrstruct2Inc", ">&"∾as2⟩ ⋄ •Out •Repr F (⊢⋈50⊸+) ⟨⟨10⟩ ⋄ ⋈∘⋈¨11‿12 ⋄ 13‿14‿15⟩
f ↩ "lib.so"•FFI "&"‿"manyargs"‿"{f32,*i8,[5]i8}"‿"*[7]i8"‿"[4]i8"‿"&i8" ⋄ •Show F ⟨⟨31, 10+↕10, 5+↕5⟩, ⟨14+↕7, 21+↕7⟩, 40+↕4, 100+↕13⟩ # ⟨100, 31, 10,19, 5,9 ⋄ 14,20, 21,27, 40,43, 112⟩
f ↩ "lib.so"•FFI ""‿"manyargs"‿"{f32,*i8,[5]i8}"‿"*[7]i8"‿"[4]i8"‿"&i8" ⋄ •Show F ⟨⟨31, 10+↕10, 5+↕5⟩, ⟨14+↕7, 21+↕7⟩, 40+↕4, 100+↕13⟩
Section "# nested"
{
f ← "lib.so"•FFI "i32"‿"callWithinMutated"‿"a"‿"&i32"
g ← @ •FFI "*:i8"‿"memcpy"‿"&i8"‿"*i8"‿sizet
Fn ← {
! 𝕩≡fn
•Show 1⊑G ⟨5⥊0, 3+↕5, 4⟩
"hello"
}
•Show F ⟨fn, ↕10⟩
}
Section "# Struct of pointers"
{
malloc ← "lib.so" •FFI ⟨"*u8", "malloc", ">"∾sizet⟩
p ← Malloc 100
sop ← "{*,*i32,[2]*}"
f ← "lib.so"•FFI ⟨sop, "operateOnStructOfPtrs", sop, "[2]"∾sop⟩
•Show {(𝕩.Cast "u8").Sub p}⚇0 F {(p.Add 𝕩).Cast ""}⚇0 ⟨1,2,3‿4⟩⊸+⚇0 ⟨10, 20‿30⟩
f ↩ "lib.so" •FFI "&"‿"updatePointerWithinPointer"‿">&{i32,*}"
•Show {x‿y: x ⋈ (y.Cast "u8").Sub p}¨ F {⟨𝕩×1000, p.Add 𝕩×100⟩}¨ ↕5
f ↩ "lib.so" •FFI "&"‿"updatePointerWithinPointer"‿">&{i32,*u8}"
•Show {x‿y: x ⋈ y.Sub p}¨ F {⟨𝕩×1000, (p.Add 𝕩×100).Cast ""⟩}¨ ↕5
}
# erroring:
# "lib.so" •FFI ""‿"printArgs"‿"i8"‿"i16:c32"‿"i32"‿"u8"‿"u16"‿"u32"‿"f32"‿"f64"
# "lib.so" •FFI ""‿"testArgs"‿"i8:c16"‿"i16"‿"i32"‿"u8"‿"u16"‿"u32"‿"f32"‿"f64"
# "lib.so" •FFI ""‿"testArgs"‿"i8:c32"‿"i16"‿"i32"‿"u8"‿"u16"‿"u32"‿"f32"‿"f64"
# f ↩ "lib.so" •FFI "u64"‿"ident_u64"‿">u64:i32" ⋄ •Show F 1234‿12344444
# f ↩ "lib.so" •FFI "u64"‿"ident_u64"‿">u64" ⋄ •Show F +´2⋆53‿20
# f ↩ "lib.so"•FFI"i32"‿"arrarg"‿">[3]i32" ⋄ •Show F ⟨1,2⟩
# f ↩ "lib.so"•FFI ⟨as2, "arrstruct2", as2, "*"∾as2⟩ ⋄ •Show F ⟨⟨⟨4⟩ ⋄ ⋈∘⋈¨1‿2 ⋄ 1.2‿2.3‿3.4‿4⟩, ⟨⟨⟨5⟩ ⋄ ⋈∘⋈¨10‿20 ⋄ 5.1‿6.1‿7.1⟩⟩⟩
# f ↩ "lib.so"•FFI ⟨as2, "arrstruct2", as2, "*"∾as2⟩ ⋄ •Show F ⟨⟨⟨4⟩ ⋄ ⋈∘⋈¨1‿2 ⋄ 1.2‿2.3‿3.4⟩, ⟨⟨⟨5⟩ ⋄ ⋈∘⋈¨10‿20 ⋄ 5.1‿6.1‿7.1‿5⟩⟩⟩
# f ↩ "lib.so"•FFI ⟨as2, "arrstruct2", as2, "*"∾as2⟩ ⋄ •Show F ⟨⟨⟨4⟩ ⋄ ⋈∘⋈¨1‿2 ⋄ 1.2‿2.3‿3.4⟩, ⟨⟨⟨5⟩ ⋄ ⋈∘⋈¨10‿20 ⋄ 5.1‿6.1‿7.1,5⟩⟩⟩