uCBQN/test/ffi/test.bqn

100 lines
7.2 KiB
BQN
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

f@
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 {ab12 cd34} F "ab" "default"
f "lib.so" •FFI "a""getField"">𝕨a""a""a" •Show {ab12 cd34} F "ef" "default"
Section "# print args"
f "lib.so" •FFI """printArgs""i8""i16""i32""u8""u16""u32""f32""f64" •Show F ¯123¯12323¯212312312250500003123456789π÷3
f "lib.so" •FFI "" "noopArgs""i8""i16""i32""u8""u16""u32""f32""f64" •Show F ¯123¯12323¯212312312250500003123456789π÷3
f "lib.so" •FFI """printPtrArgs""*i8""*i16""*i32""*u8""*u16""*u32""*f32""*f64" •Show F ¨¯123¯12323¯212312312250500003123456789π÷3
f "lib.so" •FFI """printPtrArgs""&i8""&i16""&i32""&u8""&u16""&u32""&f32""&f64" •Show F ¨¯123¯12323¯212312312250500003123456789π÷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 1065353216107374182410779361281082130432108422758410863247361088421888109051904010915676161092616192,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 1010101001010011011000010101001000100010001110111111001100100100, 2
f "lib.so" •FFI "","incI32s","&i32:c8", "i32" •Show F "helloworld", 2
f "lib.so" •FFI "","incI32s",">𝕨&i32:c8",">i32" •Show "helloworld" F 2
f "lib.so" •FFI "", "incI32s", "&i32:c8", "i32" •Show F "helloworld", 2
f "lib.so" •FFI "", "incI32s", "&i32:c8", "𝕨i32" •Show 2 F "helloworld"
f "lib.so" •FFI "", "incI32s", "&i32:c8",">𝕨i32" •Show 2 F "helloworld"
f "lib.so" •FFI "", "incI32s", ">&i32:c8",">𝕨i32" •Show 2 F "helloworld"
f "lib.so" •FFI "", "incI32s",">𝕨&i32:c8", ">i32" •Show "helloworld" F 2
f "lib.so" •FFI "", "incI32s", "&i32:c8", "i32" •Show F "helloworld", 2
f "lib.so" •FFI "&","incI32s", "&i32:c8", "i32" •Show F "helloworld", 2
Section "# mutate i32*, i16*, i8*"
f "lib.so" •FFI "","incInts","&i32", "&i16","&i8" •Show F ¨ 102030
f "lib.so" •FFI "","incInts","&i32", "𝕨&i16","&i8" •Show 20 F ¨ 1030
f "lib.so" •FFI "","incInts","&i32",">𝕨&i16","&i8" •Show 20 F ¨ 1030
Section "# u64 tests"
f "lib.so" •FFI "u64", "ident_u64",">u64:i32" •Show F 123412
f "lib.so" •FFI "u64", "ident_u64",">u64" •Show F +´25220
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"
Section "# malloc test"
f "lib.so" •FFI "*:i32""malloc"">u64" •Show (•internal.Info) 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:u16,f64}" s2 "{"s1","s1"}"
f "lib.so" •FFI "i16", "thirdMember", ">"s1 •Show F 200, 2e9, ¯30000, 1234, 3.25
f "lib.so" •FFI s1, "incMembers", ">"s1 •Show F 200, 2e9, ¯30000, 1234, 3.25
f "lib.so" •FFI "&", "incMany", "&"s2, "u64" •Show¨ F 036+3<01+2<200, 2e9, ¯30000, 1234, 3.25, 3
{
calloc @•FFI"*:i32""calloc""u64""u64" mem Calloc 34
f "lib.so" •FFI "i32""arrayRefOp"">&{*:i32,u64}"
{𝕊: sum, arrsz F mem3 •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", ">u64" •Show F 120169
# erroring:
# "local/lib.so" •FFI ""‿"printArgs"‿"i8"‿"i16:c32"‿"i32"‿"u8"‿"u16"‿"u32"‿"f32"‿"f64"
# "local/lib.so" •FFI ""‿"testArgs"‿"i8:c16"‿"i16"‿"i32"‿"u8"‿"u16"‿"u32"‿"f32"‿"f64"
# "local/lib.so" •FFI ""‿"testArgs"‿"i8:c32"‿"i16"‿"i32"‿"u8"‿"u16"‿"u32"‿"f32"‿"f64"
# f ↩ "local/lib.so" •FFI "u64"‿"ident_u64"‿">u64:i32" ⋄ •Show F 1234‿12344444
# f ↩ "local/lib.so" •FFI "u64"‿"ident_u64"‿">u64" ⋄ •Show F +´2⋆53‿20