2 * Copyright (C) 2024 Mikulas Patocka
4 * This file is part of Ajla.
6 * Ajla is free software: you can redistribute it and/or modify it under the
7 * terms of the GNU General Public License as published by the Free Software
8 * Foundation, either version 3 of the License, or (at your option) any later
11 * Ajla is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13 * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along with
16 * Ajla. If not, see <https://www.gnu.org/licenses/>.
50 t_structure : ffi_structure;
57 e_get_last_socket_error;
63 fn ffi_unsafe_get_world : world;
65 fn ffi_get_size(ft : ffi_type) : int;
66 fn ffi_get_alignment(ft : ffi_type) : int;
68 fn ffi_create_structure(elements : list(ffi_type)) : (ffi_structure, list(int));
69 fn ffi_get_structure_offset(str : ffi_structure, element : int) : int;
71 fn ffi_poke(w : world, ptr : int, ft : ffi_type, val : int) : world;
72 fn ffi_peek(w : world, ptr : int, ft : ffi_type) : (world, int);
74 fn ffi_poke_array(t : type, w : world, ptr : int, a : list(t)) : world;
75 fn ffi_peek_array(w : world, ptr : int, l : int, ft : ffi_type, t : type) : (world, list(t));
77 fn ffi_handle_to_number(w : world, desc : ffi_destructor, h : handle) : (world, int);
78 fn ffi_number_to_handle(w : world, n : int, sckt : bool) : (world, handle);
80 fn ffi_create_function(filename : bytes, funcname : bytes, err_type : ffi_error, nvarargs : int, rtype : ffi_type, args : list(ffi_type)) : ffi_function;
81 fn ffi_call_function(w : world, func : ffi_function, args : list(int)) : (world, int, int);
83 fn ffi_encode_float(f : real32) : int;
84 fn ffi_encode_double(f : real64) : int;
85 fn ffi_encode_longdouble(f : real80) : int;
86 fn ffi_decode_float(i : int) : real32;
87 fn ffi_decode_double(i : int) : real64;
88 fn ffi_decode_longdouble(i : int) : real80;
90 fn ffi_destructor_new(w : world) : (world, ffi_destructor);
91 fn ffi_destructor_destroy(w : world, fd : ffi_destructor) : world;
92 fn ffi_destructor_allocate(w : world, fd : ffi_destructor, size align : int, zero : bool) : (world, int);
93 fn ffi_destructor_free(w : world, fd : ffi_destructor, ptr : int) : world;
94 fn ffi_destructor_call(w : world, fd : ffi_destructor, func : ffi_function, args : list(int)) : world;
98 type ffi_structure := internal_type;
99 type ffi_function := internal_type;
101 fn ffi_unsafe_get_world : world
103 return unsafe_get_world;
106 fn ffi_get_size(ft : ffi_type) : int
109 pcode IO IO_FFI_Get_Size_Alignment 1 1 1 =r ft 0;
113 fn ffi_get_alignment(ft : ffi_type) : int
116 pcode IO IO_FFI_Get_Size_Alignment 1 1 1 =r ft 1;
120 fn ffi_create_structure(elements : list(ffi_type)) : (ffi_structure, list(int))
122 var r : ffi_structure;
123 var offs : list(int);
124 pcode IO IO_FFI_Create_Structure 2 1 0 =r =offs elements;
128 fn ffi_get_structure_offset(str : ffi_structure, element : int) : int
131 pcode IO IO_FFI_Structure_Offset 1 2 0 =r str element;
135 fn ffi_poke(w : world, ptr : int, ft : ffi_type, val : int) : world
138 pcode IO IO_FFI_Poke 1 4 0 =w2 w ptr ft val;
142 fn ffi_peek(w : world, ptr : int, ft : ffi_type) : (world, int)
146 pcode IO IO_FFI_Peek 2 3 0 =w2 =r w ptr ft;
150 fn ffi_poke_array(t : type, w : world, ptr : int, a : list(t)) : world
153 pcode IO IO_FFI_Poke_Array 1 3 0 =w2 w ptr a;
157 fn ffi_peek_array(w : world, ptr : int, l : int, ft : ffi_type, t : type) : (world, list(t))
161 pcode IO IO_FFI_Peek_Array 2 4 0 =w2 =r w ptr l ft;
165 fn ffi_handle_to_number(w : world, desc : ffi_destructor, h : handle) : (world, int)
169 pcode IO IO_FFI_Handle_To_Number 2 3 0 =w2 =n w desc h;
173 fn ffi_number_to_handle(w : world, n : int, sckt : bool) : (world, handle)
177 pcode IO IO_FFI_Number_To_Handle 2 3 0 =w2 =h w n sckt;
181 fn ffi_create_function(filename : bytes, funcname : bytes, err_type : ffi_error, nvarargs : int, rtype : ffi_type, args : list(ffi_type)) : ffi_function
183 var r : ffi_function;
184 pcode IO IO_FFI_Create_Function 1 6 0 =r filename funcname err_type nvarargs rtype args;
188 fn ffi_call_function(w : world, func : ffi_function, args : list(int)) : (world, int, int)
192 pcode IO IO_FFI_Call_Function 3 3 0 =w2 =r =e w func args;
196 fn ffi_encode_float(f : real32) : int
199 pcode IO IO_FFI_Encode_Real 1 1 0 =r f;
203 fn ffi_encode_double(f : real64) : int
206 pcode IO IO_FFI_Encode_Real 1 1 0 =r f;
210 fn ffi_encode_longdouble(f : real80) : int
213 pcode IO IO_FFI_Encode_Real 1 1 0 =r f;
217 fn ffi_decode_float(i : int) : real32
220 pcode IO IO_FFI_Decode_Real 1 1 0 =r i;
224 fn ffi_decode_double(i : int) : real64
227 pcode IO IO_FFI_Decode_Real 1 1 0 =r i;
231 fn ffi_decode_longdouble(i : int) : real80
234 pcode IO IO_FFI_Decode_Real 1 1 0 =r i;
238 type ffi_destructor := internal_type;
240 fn ffi_destructor_new(w : world) : (world, ffi_destructor)
242 var r : ffi_destructor;
244 pcode IO IO_FFI_Destructor_New 2 1 0 =w2 =r w;
248 fn ffi_destructor_destroy(w : world, fd : ffi_destructor) : world
251 pcode IO IO_Consume_Parameters 1 2 0 =w2 w fd;
255 fn ffi_destructor_allocate(w : world, fd : ffi_destructor, size align : int, zero : bool) : (world, int)
259 pcode IO IO_FFI_Destructor_Allocate 2 5 0 =w2 =r w fd size align zero;
263 fn ffi_destructor_free(w : world, fd : ffi_destructor, ptr : int) : world
266 pcode IO IO_FFI_Destructor_Free 1 3 0 =w2 w fd ptr;
270 fn ffi_destructor_call(w : world, fd : ffi_destructor, func : ffi_function, args : list(int)) : world
273 pcode IO IO_FFI_Destructor_Call 1 4 0 =w2 w fd func args;