libwren_sys/
lib.rs

1#![allow(non_upper_case_globals)]
2#![allow(non_camel_case_types)]
3#![allow(non_snake_case)]
4#![allow(dead_code)]
5
6use paste::paste;
7
8// ===================== WREN_H ===================== //
9type WrenReallocateFn = Option<unsafe extern "C" fn(memory: *mut libc::c_void, newSize: usize, userData: *mut libc::c_void) -> *mut libc::c_void>;
10type WrenForeignMethodFn = Option<unsafe extern "C" fn(vm: *mut WrenVM)>;
11type WrenFinalizerFn = Option<unsafe extern "C" fn(data: *mut libc::c_void)>;
12type WrenResolveModuleFn = Option<unsafe extern "C" fn(vm: *mut WrenVM, importer: *const std::os::raw::c_char, name: *const std::os::raw::c_char) -> *const std::os::raw::c_char>;
13type WrenLoadModuleCompleteFn = Option<unsafe extern "C" fn(vm: *mut WrenVM, name: *const std::os::raw::c_char, result: WrenLoadModuleResult)>;
14
15#[repr(C)]
16struct WrenLoadModuleResult {
17    source: *const std::os::raw::c_char,
18    onComplete: WrenLoadModuleCompleteFn,
19    userData: *mut libc::c_void
20}
21
22type WrenLoadModuleFn = Option<unsafe extern "C" fn(vm: *mut WrenVM, name: *const std::os::raw::c_char) -> WrenLoadModuleResult>;
23type WrenBindForeignMethodFn = Option<unsafe extern "C" fn(vm: *mut WrenVM, module: *const std::os::raw::c_char, className: *const std::os::raw::c_char, isStatic: bool, signature: *const std::os::raw::c_char) -> WrenForeignMethodFn>;
24type WrenWriteFn = Option<unsafe extern "C" fn(vm: *mut WrenVM, text: *const std::os::raw::c_char)>;
25
26#[repr(C)]
27enum WrenErrorType {
28    WREN_ERROR_COMPILE,
29    WREN_ERROR_RUNTIME,
30    WREN_ERROR_STACK_TRACE
31}
32
33type WrenErrorFn = Option<unsafe extern "C" fn(vm: *mut WrenVM, r#type: WrenErrorType, module: *const std::os::raw::c_char, line: std::os::raw::c_int, message: *const std::os::raw::c_char)>;
34
35#[repr(C)]
36struct WrenForeignClassMethods {
37    allocate: WrenForeignMethodFn,
38    finalize: WrenFinalizerFn
39}
40
41type WrenBindForeignClassFn = Option<unsafe extern "C" fn(vm: *mut WrenVM, module: *const std::os::raw::c_char, className: *const std::os::raw::c_char) -> WrenForeignClassMethods>;
42
43#[repr(C)]
44struct WrenConfiguration {
45    reallocateFn: WrenReallocateFn,
46    resolveModuleFn: WrenResolveModuleFn,
47    loadModuleFn: WrenLoadModuleFn,
48    bindForeignMethodFn: WrenBindForeignMethodFn,
49    bindForeignClassFn: WrenBindForeignClassFn,
50    writeFn: WrenWriteFn,
51    errorFn: WrenErrorFn,
52    initialHeapSize: usize,
53    minHeapSize: usize,
54    heapGrowthPercent: std::os::raw::c_int,
55    userData: *mut libc::c_void
56}
57
58#[repr(C)]
59#[derive(Debug)]
60enum WrenInterpretResult {
61    WREN_RESULT_SUCCESS,
62    WREN_RESULT_COMPILE_ERROR,
63    WREN_RESULT_RUNTIME_ERROR
64}
65
66#[repr(C)]
67enum WrenType {
68    WREN_TYPE_BOOL,
69    WREN_TYPE_NUM,
70    WREN_TYPE_FOREIGN,
71    WREN_TYPE_LIST,
72    WREN_TYPE_MAP,
73    WREN_TYPE_NULL,
74    WREN_TYPE_STRING,
75    WREN_TYPE_UNKNOWN
76}
77
78#[link(name = "wren")]
79extern "C" {
80    fn wrenInitConfiguration(configuration: *mut WrenConfiguration);
81    fn wrenNewVM(configuration: *mut WrenConfiguration) -> *mut WrenVM;
82    fn wrenFreeVM(vm: *mut WrenVM);
83    fn wrenCollectGarbage(vm: *mut WrenVM);
84    fn wrenInterpret(vm: *mut WrenVM, module: *const std::os::raw::c_char, source: *const std::os::raw::c_char) -> WrenInterpretResult;
85    fn wrenMakeCallHandle(vm: *mut WrenVM, signature: *const std::os::raw::c_char) -> *mut WrenHandle;
86    fn wrenCall(vm: *mut WrenVM, method: *mut WrenHandle) -> WrenInterpretResult;
87    fn wrenReleaseHandle(vm: *mut WrenVM, handle: *mut WrenHandle);
88    fn wrenGetSlotCount(vm: *mut WrenVM) -> std::os::raw::c_int;
89    fn wrenEnsureSlots(vm: *mut WrenVM, numSlots: std::os::raw::c_int);
90    fn wrenGetSlotType(vm: *mut WrenVM, slot: std::os::raw::c_int) -> WrenType;
91    fn wrenGetSlotBool(vm: *mut WrenVM, slot: std::os::raw::c_int) -> bool;
92    fn wrenGetSlotBytes(vm: *mut WrenVM, slot: std::os::raw::c_int, length: *mut std::os::raw::c_int) -> *const std::os::raw::c_char;
93    fn wrenGetSlotDouble(vm: *mut WrenVM, slot: std::os::raw::c_int) -> std::os::raw::c_double;
94    fn wrenGetSlotForeign(vm: *mut WrenVM, slot: std::os::raw::c_int) -> *mut libc::c_void;
95    fn wrenGetSlotString(vm: *mut WrenVM, slot: std::os::raw::c_int) -> *const std::os::raw::c_char;
96    fn wrenGetSlotHandle(vm: *mut WrenVM, slot: std::os::raw::c_int) -> *mut WrenHandle;
97    fn wrenSetSlotBool(vm: *mut WrenVM, slot: std::os::raw::c_int, value: bool);
98    fn wrenSetSlotBytes(vm: *mut WrenVM, slot: std::os::raw::c_int, bytes: *const std::os::raw::c_char, length: usize);
99    fn wrenSetSlotDouble(vm: *mut WrenVM, slot: std::os::raw::c_int, value: std::os::raw::c_double);
100    fn wrenSetSlotNewForeign(vm: *mut WrenVM, slot: std::os::raw::c_int, classSlot: std::os::raw::c_int, size: usize) -> *mut libc::c_void;
101    fn wrenSetSlotNewList(vm: *mut WrenVM, slot: std::os::raw::c_int);
102    fn wrenSetSlotNewMap(vm: *mut WrenVM, slot: std::os::raw::c_int);
103    fn wrenSetSlotNull(vm: *mut WrenVM, slot: std::os::raw::c_int);
104    fn wrenSetSlotString(vm: *mut WrenVM, slot: std::os::raw::c_int, text: *const std::os::raw::c_char);
105    fn wrenSetSlotHandle(vm: *mut WrenVM, slot: std::os::raw::c_int, handle: *mut WrenHandle);
106    fn wrenGetListCount(vm: *mut WrenVM, slot: std::os::raw::c_int) -> std::os::raw::c_int;
107    fn wrenGetListElement(vm: *mut WrenVM, listSlot: std::os::raw::c_int, index: std::os::raw::c_int, elementSlot: std::os::raw::c_int);
108    fn wrenSetListElement(vm: *mut WrenVM, listSlot: std::os::raw::c_int, index: std::os::raw::c_int, elementSlot: std::os::raw::c_int);
109    fn wrenInsertInList(vm: *mut WrenVM, listSlot: std::os::raw::c_int, index: std::os::raw::c_int, elementSlot: std::os::raw::c_int);
110    fn wrenGetMapCount(vm: *mut WrenVM, slot: std::os::raw::c_int) -> std::os::raw::c_int;
111    fn wrenGetMapContainsKey(vm: *mut WrenVM, mapSlot: std::os::raw::c_int, keySlot: std::os::raw::c_int) -> bool;
112    fn wrenGetMapValue(vm: *mut WrenVM, mapSlot: std::os::raw::c_int, keySlot: std::os::raw::c_int, valueSlot: std::os::raw::c_int);
113    fn wrenSetMapValue(vm: *mut WrenVM, mapSlot: std::os::raw::c_int, keySlot: std::os::raw::c_int, valueSlot: std::os::raw::c_int);
114    fn wrenRemoveMapValue(vm: *mut WrenVM, mapSlot: std::os::raw::c_int, keySlot: std::os::raw::c_int, removedValueSlot: std::os::raw::c_int);
115    fn wrenGetVariable(vm: *mut WrenVM, module: *const std::os::raw::c_char, name: *const std::os::raw::c_char, slot: std::os::raw::c_int);
116    fn wrenHasVariable(vm: *mut WrenVM, module: *const std::os::raw::c_char, name: *const std::os::raw::c_char) -> bool;
117    fn wrenHasModule(vm: *mut WrenVM, module: *const std::os::raw::c_char) -> bool;
118    fn wrenAbortFiber(vm: *mut WrenVM, slot: std::os::raw::c_int);
119    fn wrenGetUserData(vm: *mut WrenVM) -> *mut libc::c_void;
120    fn wrenSetUserData(vm: *mut WrenVM, userData: *mut libc::c_void);
121}
122// ===================== END_WREN_H ===================== //
123
124// ===================== WREN_UTILS ===================== //
125macro_rules! declare_buffer {
126    ($name:ident, $type:ty) => {
127        paste! {
128            #[repr(C)]
129            struct [<$name Buffer>] {
130                data: *mut $type,
131                count: std::os::raw::c_int,
132                capacity: std::os::raw::c_int
133            }
134
135            #[link(name = "wren")]
136            extern "C" {
137                fn [<wren $name BufferInit>](buffer: *mut [<$name Buffer>]);
138                fn [<wren $name BufferClear>](vm: *mut WrenVM, buffer: *mut [<$name Buffer>]);
139                fn [<wren $name BufferFill>](vm: *mut WrenVM, buffer: *mut [<$name Buffer>], data: $type, count: std::os::raw::c_int);
140                fn [<wren $name BufferWrite>](vm: *mut WrenVM, buffer: *mut [<$name Buffer>], data: $type);
141            }
142        }
143    };
144}
145
146declare_buffer!(Byte, u8);
147declare_buffer!(Int, std::os::raw::c_int);
148declare_buffer!(String, *mut ObjString);
149
150type SymbolTable = StringBuffer;
151
152#[link(name = "wren")]
153extern "C" {
154    fn wrenSymbolTableInit(symbols: *mut SymbolTable);
155    fn wrenSymbolTableClear(vm: *mut WrenVM, symbols: *mut SymbolTable);
156    fn wrenSymbolTableAdd(vm: *mut WrenVM, symbols: *mut SymbolTable, name: *const std::os::raw::c_char, length: usize) -> std::os::raw::c_int;
157    fn wrenSymbolTableEnsure(vm: *mut WrenVM, symbols: *mut SymbolTable, name: *const std::os::raw::c_char, length: usize) -> std::os::raw::c_int;
158    fn wrenSymbolTableFind(symbols: *const SymbolTable, name: *const std::os::raw::c_char, length: usize) -> std::os::raw::c_int;
159    fn wrenBlackenSymbolTable(vm: *mut WrenVM, symbolTable: *mut SymbolTable);
160    fn wrenUtf8EncodeNumBytes(value: std::os::raw::c_int) -> std::os::raw::c_int;
161    fn wrenUtf8Encode(value: std::os::raw::c_int, bytes: *mut u8) -> std::os::raw::c_int;
162    fn wrenUtf8Decode(bytes: *const std::os::raw::c_char, length: u32) -> std::os::raw::c_int;
163    fn wrenUtf8DecodeNumBytes(byte: u8) -> std::os::raw::c_int;
164    fn wrenPowerOf2Ceil(n: std::os::raw::c_int) -> std::os::raw::c_int;
165    fn wrenValidateIndex(count: u32, value: i64) -> u32;
166}
167// ===================== END_WREN_UTILS ===================== //
168
169// ===================== WREN_MATH ===================== //
170#[link(name = "wren")]
171extern "C" {
172    fn wrenDoubleFromBits(bits: u64) -> std::os::raw::c_double;
173    fn wrenDoubleToBits(num: std::os::raw::c_double) -> u64;
174}
175// ===================== END_WREN_MATH ===================== //
176
177// ===================== WREN_VALUE ===================== //
178#[repr(C)]
179enum ObjType {
180    OBJ_CLASS,
181    OBJ_CLOSURE,
182    OBJ_FIBER,
183    OBJ_FN,
184    OBJ_FOREIGN,
185    OBJ_INSTANCE,
186    OBJ_LIST,
187    OBJ_MAP,
188    OBJ_MODULE,
189    OBJ_RANGE,
190    OBJ_STRING,
191    OBJ_UPVALUE
192}
193
194#[repr(C)]
195struct Obj {
196    r#type: ObjType,
197    isDark: bool,
198    classObj: *mut ObjClass,
199    next: *mut Obj
200}
201
202type Value = u64;
203
204declare_buffer!(Value, Value);
205
206#[repr(C)]
207struct ObjString {
208    obj: Obj,
209    length: u32,
210    hash: u32,
211    value: *mut std::os::raw::c_char
212}
213
214#[repr(C)]
215struct ObjUpvalue {
216    obj: Obj,
217    value: *mut Value,
218    closed: Value,
219    next: *mut ObjUpvalue
220}
221
222type Primitive = extern "C" fn(vm: *mut WrenVM, args: *mut Value) -> bool;
223
224#[repr(C)]
225struct FnDebug {
226    name: *mut std::os::raw::c_char,
227    sourceLines: IntBuffer 
228}
229
230#[repr(C)]
231struct ObjModule {
232    obj: Obj,
233    variables: ValueBuffer,
234    variablesNames: SymbolTable,
235    name: *mut ObjString
236}
237
238#[repr(C)]
239struct ObjFn {
240    obj: Obj,
241    code: ByteBuffer,
242    constants: ValueBuffer,
243    module: *mut ObjModule,
244    maxSlots: std::os::raw::c_int,
245    numUpvalues: std::os::raw::c_int,
246    arity: std::os::raw::c_int,
247    debug: *mut FnDebug
248}
249
250#[repr(C)]
251struct ObjClosure {
252    obj: Obj,
253    r#fn: *mut ObjFn,
254    upvalues: *mut *mut ObjUpvalue
255}
256
257#[repr(C)]
258struct CallFrame {
259    ip: u8,
260    closure: *mut ObjClosure,
261    stackStart: *mut Value
262}
263
264#[repr(C)]
265enum FiberState {
266    FIBER_TRY,
267    FIBER_ROOT,
268    FIBER_OTHER
269}
270
271#[repr(C)]
272struct ObjFiber {
273    obj: Obj,
274    stack: *mut Value,
275    stackTop: *mut Value,
276    stackCapacity: std::os::raw::c_int,
277    frames: *mut CallFrame,
278    numFrames: std::os::raw::c_int,
279    frameCapacity: std::os::raw::c_int,
280    openUpvalues: *mut ObjUpvalue,
281    caller: *mut ObjFiber,
282    error: Value,
283    state: FiberState
284}
285
286#[repr(C)]
287enum MethodType {
288    METHOD_PRIMITIVE,
289    METHOD_FUNCTION_CALL,
290    METHOD_FOREIGN,
291    METHOD_BLOCK,    
292    METHOD_NONE
293}
294
295#[repr(C)]
296union MethodContents {
297    primitive: Primitive,
298    foreign: WrenForeignMethodFn,
299    closure: *mut ObjClosure
300}
301
302#[repr(C)]
303struct Method {
304    r#type: MethodType,
305    r#as: MethodContents
306}
307
308declare_buffer!(Method, Method);
309
310#[repr(C)]
311struct ObjClass {
312    obj: Obj,
313    superclass: *mut ObjClass,
314    numFields: std::os::raw::c_int,
315    methods: MethodBuffer,
316    name: *mut ObjString
317}
318
319#[repr(C)]
320struct ObjForeign {
321    obj: Obj,
322    data: *mut u8
323}
324
325#[repr(C)]
326struct ObjInstance {
327    obj: Obj,
328    fields: *mut Value
329}
330
331#[repr(C)]
332struct ObjList {
333    obj: Obj,
334    elements: ValueBuffer
335}
336
337#[repr(C)]
338struct MapEntry {
339    key: Value,
340    value: Value
341}
342
343#[repr(C)]
344struct ObjMap {
345    obj: Obj,
346    capacity: u32,
347    count: u32,
348    entries: *mut MapEntry
349}
350
351#[repr(C)]
352struct ObjRange {
353    obj: Obj,
354    from: std::os::raw::c_double,
355    to: std::os::raw::c_double,
356    isInclusive: bool
357}
358
359#[link(name = "wren")]
360extern "C" {
361    fn wrenNewSingleClass(vm: *mut WrenVM, numFields: std::os::raw::c_int, name: *mut ObjString) -> *mut ObjClass;
362    fn wrenBindSuperclass(vm: *mut WrenVM, subclass: *mut ObjClass, superclass: *mut ObjClass);
363    fn wrenNewClass(vm: *mut WrenVM, suuperclass: *mut ObjClass, numFields: std::os::raw::c_int, name: *mut ObjString) -> *mut ObjClass;
364    fn wrenBindMethod(vm: *mut WrenVM, classObject: *mut ObjClass, symbol: std::os::raw::c_int, method: Method);
365    fn wrenNewClosure(vm: *mut WrenVM, r#fn: *mut ObjFn) -> *mut ObjClosure;
366    fn wrenNewFiber(vm: *mut WrenVM, closure: *mut ObjClosure) -> *mut ObjFiber;
367    fn wrenAppendCallFrame(vm: *mut WrenVM, fiber: *mut ObjFiber, closure: *mut ObjClosure, stackStart: *mut Value);
368    fn wrenEnsureStack(vm: *mut WrenVM, fiber: *mut ObjFiber, needed: std::os::raw::c_int);
369    fn wrenHasError(fiber: *const ObjFiber) -> bool;
370    fn wrenNewForeign(vm: *mut WrenVM, classObj: *mut ObjClass, size: usize) -> *mut ObjForeign;
371    fn wrenNewFunction(vm: *mut WrenVM, module: *mut ObjModule, maxSlots: std::os::raw::c_int) -> *mut ObjFn;
372    fn wrenFunctionBindName(vm: *mut WrenVM, r#fn: *mut ObjFn, name: *const std::os::raw::c_char, length: std::os::raw::c_int);
373    fn wrenNewInstance(vm: *mut WrenVM, classObj: *mut ObjClass) -> Value;
374    fn wrenNewList(vm: *mut WrenVM, numElements: u32) -> *mut ObjList;
375    fn wrenListInsert(vm: *mut WrenVM, list: *mut ObjList, value: Value, index: u32);
376    fn wrenListRemoveAt(vm: *mut WrenVM, list: *mut ObjList, index: u32) -> Value;
377    fn wrenListIndexOf(vm: *mut WrenVM, list: *mut ObjList, value: Value) -> std::os::raw::c_int;
378    fn wrenNewMap(vm: *mut WrenVM) -> *mut ObjMap;
379    fn wrenMapGet(map: *mut ObjMap, key: Value) -> Value;
380    fn wrenMapSet(vm: *mut WrenVM, map: *mut ObjMap, key: Value, value: Value);
381    fn wrenMapClear(vm: *mut WrenVM, map: *mut ObjMap);
382    fn wrenMapRemoveKey(vm: *mut WrenVM, map: *mut ObjMap, key: Value) -> Value;
383    fn wrenNewModule(vm: *mut WrenVM, name: *mut ObjString) -> *mut ObjModule;
384    fn wrenNewRange(vm: *mut WrenVM, from: std::os::raw::c_double, to: std::os::raw::c_double, isInclusive: bool) -> Value;
385    fn wrenNeString(vm: *mut WrenVM, text: *const std::os::raw::c_char) -> Value;
386    fn wrenNewStringLength(vm: *mut WrenVM, text: *const std::os::raw::c_char, length: usize) -> Value;
387    fn wrenNewStringFromRange(vm: *mut WrenVM, source: *mut ObjString, start: std::os::raw::c_int, count: u32, step: std::os::raw::c_int) -> Value;
388    fn wrenNumToString(vm: *mut WrenVM, value: std::os::raw::c_double) -> Value;
389    fn wrenStringFormat(vm: *mut WrenVM, format: *const std::os::raw::c_char, ...) -> Value;
390    fn wrenStringFromCodePoint(vm: *mut WrenVM, value: std::os::raw::c_int) -> Value;
391    fn wrenStringFromByte(vm: *mut WrenVM, value: u8) -> Value;
392    fn wrenStringCodePointAt(vm: *mut WrenVM, string: *mut ObjString, index: u32) -> Value;
393    fn wrenStringFind(haystack: *mut ObjString, needle: *mut ObjString, startIndex: u32) -> u32;
394    fn wrenStringEqualsCString(a: *const ObjString, b: *const std::os::raw::c_char, length: usize) -> bool;
395    fn wrenNewUpvalue(vm: *mut WrenVM, value: *mut Value) -> *mut ObjUpvalue;
396    fn wrenGrayObj(vm: *mut WrenVM, obj: *mut Obj);
397    fn wrenGrayValue(vm: *mut WrenVM, value: Value);
398    fn wrenGrayBuffer(vm: *mut WrenVM, buffer: *mut ValueBuffer);
399    fn wrenBlackenObjects(vm: *mut WrenVM);
400    fn wrenFreeObj(vm: *mut WrenVM, obj: *mut Obj);
401    fn wrenGetClass(vm: *mut WrenVM, value: Value) -> *mut ObjClass;
402    fn wrenValuesSame(a: Value, b: Value);
403    fn wrenValuesEqual(a: Value, b: Value) -> bool;
404    fn wrenIsBool(value: Value) -> bool;
405    fn wrenIsObjType(value: Value, r#type: ObjType) -> bool;
406    fn wrenObjectToValue(obj: *mut Obj) -> Value;
407    fn wrenValueToNum(value: Value) -> std::os::raw::c_double;
408    fn wrenNumToValue(num: std::os::raw::c_double) -> Value;
409}
410// ===================== END_WREN_VALUE ===================== //
411
412// ===================== WREN_COMPILER ===================== //
413#[repr(C)]
414struct Compiler {
415    _private: [u8;0]
416}
417
418#[link(name = "wren")]
419extern "C" {
420    fn wrenCompile(vm: *mut WrenVM, module: *mut ObjModule, source: *const std::os::raw::c_char, isExpression: bool, printErrors: bool) -> *mut ObjFn;
421    fn wrenBindMethodCode(classObj: *mut ObjClass, r#fn: *mut ObjFn);
422    fn wrenMarkCompiler(vm: *mut WrenVM, compiler: *mut Compiler);
423}
424// ===================== END_WREN_COMPILER ===================== //
425
426// ===================== WREN_VM ===================== //
427#[repr(C)]
428enum Code {
429    CODE_CONSTANT,
430    CODE_NULL,
431    CODE_FALSE,
432    CODE_TRUE,
433    CODE_LOAD_LOCAL_0,
434    CODE_LOAD_LOCAL_1,
435    CODE_LOAD_LOCAL_2,
436    CODE_LOAD_LOCAL_3,
437    CODE_LOAD_LOCAL_4,
438    CODE_LOAD_LOCAL_5,
439    CODE_LOAD_LOCAL_6,
440    CODE_LOAD_LOCAL_7,
441    CODE_LOAD_LOCAL_8,
442    CODE_LOAD_LOCAL,
443    CODE_STORE_LOCAL,
444    CODE_LOAD_UPVALUE,
445    CODE_STORE_UPVALUE,
446    CODE_LOAD_MODULE_VAR,
447    CODE_STORE_MODULE_VAR,
448    CODE_LOAD_FIELD_THIS,
449    CODE_STORE_FIELD_THIS,
450    CODE_LOAD_FIELD,
451    CODE_STORE_FIELD,
452    CODE_POP,
453    CODE_CALL_0,
454    CODE_CALL_1,
455    CODE_CALL_2,
456    CODE_CALL_3,
457    CODE_CALL_4,
458    CODE_CALL_5,
459    CODE_CALL_6,
460    CODE_CALL_7,
461    CODE_CALL_8,
462    CODE_CALL_9,
463    CODE_CALL_10,
464    CODE_CALL_11,
465    CODE_CALL_12,
466    CODE_CALL_13,
467    CODE_CALL_14,
468    CODE_CALL_15,
469    CODE_CALL_16,
470    CODE_SUPER_0,
471    CODE_SUPER_1,
472    CODE_SUPER_2,
473    CODE_SUPER_3,
474    CODE_SUPER_4,
475    CODE_SUPER_5,
476    CODE_SUPER_6,
477    CODE_SUPER_7,
478    CODE_SUPER_8,
479    CODE_SUPER_9,
480    CODE_SUPER_10,
481    CODE_SUPER_11,
482    CODE_SUPER_12,
483    CODE_SUPER_13,
484    CODE_SUPER_14,
485    CODE_SUPER_15,
486    CODE_SUPER_16,
487    CODE_JUMP,
488    CODE_LOOP,
489    CODE_JUMP_IF,
490    CODE_AND,
491    CODE_OR,
492    CODE_CLOSE_UPVALUE,
493    CODE_RETURN,
494    CODE_CLOSURE,
495    CODE_CONSTRUCT,
496    CODE_FOREIGN_CONSTRUCT,
497    CODE_CLASS,
498    CODE_FOREIGN_CLASS,
499    CODE_METHOD_INSTANCE,
500    CODE_METHOD_STATIC,
501    CODE_END_MODULE,
502    CODE_IMPORT_MODULE,
503    CODE_IMPORT_VARIABLE,
504    CODE_END
505}
506
507#[repr(C)]
508struct WrenHandle {
509    value: Value,
510    prev: *mut WrenHandle,
511    next: *mut WrenHandle
512}
513
514#[repr(C)]
515struct WrenVM {
516    boolClass: *mut ObjClass,
517    classClass: *mut ObjClass,
518    fiberClass: *mut ObjClass,
519    fnClass: *mut ObjClass,
520    listClass: *mut ObjClass,
521    mapClass: *mut ObjClass,
522    nullClass: *mut ObjClass,
523    numClass: *mut ObjClass,
524    objectClass: *mut ObjClass,
525    rangeClass: *mut ObjClass,
526    stringClass: *mut ObjClass,
527    fiber: *mut ObjFiber,
528    modules: *mut ObjMap,
529    lastModule: *mut ObjModule,
530    bytesAllocated: usize,
531    nextGC: usize,
532    first: *mut Obj,
533    gray: *mut *mut Obj,
534    grayCount: std::os::raw::c_int,
535    grayCapacity: std::os::raw::c_int,
536    tempRoots: [*mut Obj; 8],
537    numTempRoots: std::os::raw::c_int,
538    handles: *mut WrenHandle,
539    apiStack: *mut Value,
540    config: WrenConfiguration,
541    compiler: *mut Compiler,
542    methodNames: SymbolTable
543}
544
545#[link(name = "wren")]
546extern "C" {
547    fn wrenReallocate(vm: *mut WrenVM, memory: *mut libc::c_void, oldSize: usize, newSize: usize) -> *mut libc::c_void;
548    fn wrenFinalizeForeign(vm: *mut WrenVM, foreign: *mut ObjForeign);
549    fn wrenMakeHandle(vm: *mut WrenVM, value: Value) -> *mut WrenHandle;
550    fn wrenCompileSource(vm: *mut WrenVM, module: *const std::os::raw::c_char, source: *const std::os::raw::c_char, isExpression: bool, printErrors: bool) -> *mut ObjClosure;
551    fn wrenGetModuleVariable(vm: *mut WrenVM, moduleName: Value, variableName: Value) -> Value;
552    fn wrenFindVariable(vm: *mut WrenVM, module: *mut ObjModule, name: *const std::os::raw::c_char) -> Value;
553    fn wrenDeclareVariable(vm: *mut WrenVM, module: *mut ObjModule, name: *const std::os::raw::c_char, length: usize, line: std::os::raw::c_int) -> std::os::raw::c_int;
554    fn wrenDefineVariable(vm: *mut WrenVM, module: *mut ObjModule, name: *const std::os::raw::c_char, length: usize, value: Value, line: *mut std::os::raw::c_int);
555    fn wrenCallFunction(vm: *mut WrenVM, fiber: *mut ObjFiber, closure: *mut ObjClosure, numArgs: std::os::raw::c_int);
556    fn wrenPushRoot(vm: *mut WrenVM, obj: *mut Obj);
557    fn wrenPopRoot(vm: *mut WrenVM);
558    fn wrenGetClassInLine(vm: *mut WrenVM, value: Value) -> *mut ObjClass;
559    fn wrenIsLocalName(name: *const std::os::raw::c_char) -> bool;
560}
561// ===================== END_WREN_VM ===================== //
562
563// ===================== WREN_PRIMITIVE ===================== //
564#[link(name = "wren")]
565extern "C" {
566    fn validateFn(vm: *mut WrenVM, arg: Value, argName: *const std::os::raw::c_char) -> bool;
567    fn validateNum(vm: *mut WrenVM, arg: Value, argName: *const std::os::raw::c_char) -> bool;
568    fn validateIntValue(vm: *mut WrenVM, value: std::os::raw::c_double, argName: *const std::os::raw::c_char) -> bool;
569    fn validateInt(vm: *mut WrenVM, arg: Value, argName: *const std::os::raw::c_char) -> bool;
570    fn validateKey(vm: *mut WrenVM, argName: *const std::os::raw::c_char) -> bool;
571    fn validateIndex(vm: *mut WrenVM, arg: Value, count: u32, argName: *const std::os::raw::c_char) -> u32;
572    fn validateString(vm: *mut WrenVM, arg: Value, argName: *const std::os::raw::c_char) -> bool;
573    fn calculateRange(vm: *mut WrenVM, range: *mut ObjRange, length: *mut u32, step: *mut std::os::raw::c_int) -> u32;
574}
575// ===================== END_WREN_PRIMITIVE ===================== //