api_bridge.rs 85.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#![allow(non_snake_case)]   // It's generated code.
#![allow(dead_code)]        // Seems Rust do not consider "taking the function pointer" as "use"

/**
 * This file contains the bridge between the C interface and the Rust implementation.
 *
 * This file contains the the functions in the C-API's `MuVM`, `MuCtx` and `MuIRBuilder` structs.
 * These functions will convert the low-level C-style argument types to the high-level Rust-level
 * argument types, and attempt to call the methods of the same name on the corresponding Rust
 * structs in api_impl.
 *
 * NOTE: Parts of this file (between GEN:BEGIN:* and GEN:END:*) are automatically generated. Do not
 * edit those parts manually because they will be overwritten. Instead, edit the muapi2rustapi.py
 * script to generate the desired code.
 */
16
use std::ptr;
17
use std::os::raw::*;
18
use std::ffi::CStr;
19 20
use std::slice;

21
use super::api_c::*;
22 23
use super::api_impl::*;
use super::deps::*;
24

25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
// hand-written functions

// The following functions "from_*" convert low-level types to high-level types.

// Get the pointer to the high-level struct.
//
// The return value is a pointer. Usually the API function body do not change the ownership of the
// self parameter, so `&mut` should suffice. However, some API functions (such as
// `MuCtx.close_context`) will free the resources, it is probably better to call the methods on
// (*ptr) directly (such as `(*pmuctx).close_context()`), and offload the decision to the concrete
// implementation.
//
// Assume the pointer is the header.  For the sake of "implementation neutrality", the header
// defined in api_c.rs is encoded as *mut c_void rather than *mut MuVM or other concrete pointers.
// But it doesn't matter, because the header is only ever read in these three functions.
40
#[inline(always)]
41
fn from_MuVM_ptr(ptr: *mut CMuVM) -> *mut MuVM {
42
    debug_assert!(!ptr.is_null());
43 44 45 46 47
    unsafe {
        (*ptr).header as *mut MuVM
    }
}

48
#[inline(always)]
49
fn from_MuCtx_ptr<'v>(ptr: *mut CMuCtx) -> *mut MuCtx {
50
    debug_assert!(!ptr.is_null());
51
    unsafe {
52
        (*ptr).header as *mut MuCtx
53 54 55
    }
}

56
#[inline(always)]
57
fn from_MuIRBuilder_ptr<'c>(ptr: *mut CMuIRBuilder) -> *mut MuIRBuilder {
58
    debug_assert!(!ptr.is_null());
59
    unsafe {
60
        (*ptr).header as *mut MuIRBuilder
61 62 63
    }
}

64
#[inline(always)]
65 66 67 68
fn from_MuName(cname: CMuName) -> MuName {
    from_MuCString(cname)
}

69
#[inline(always)]
70
fn from_MuCString(cstring: CMuCString) -> String {
71
    debug_assert!(!cstring.is_null());
72 73
    let ffi_cstr = unsafe {
        CStr::from_ptr(cstring)
74 75
    };

76
    ffi_cstr.to_string_lossy().into_owned()
77 78
}

79
#[inline(always)]
80 81 82 83 84 85 86 87
fn from_MuCString_optional(cstring: CMuCString) -> Option<String> {
    if cstring.is_null() {
        None
    } else {
        Some(from_MuCString(cstring))
    }
}

88
#[inline(always)]
89
fn from_MuID(cmuid: CMuID) -> MuID {
90
    debug_assert!(cmuid != 0);
91 92 93
    cmuid as MuID   // just zero extend
}

94
#[inline(always)]
95 96 97 98 99 100 101 102
fn from_MuID_optional(cmuid: CMuID) -> Option<MuID> {
    if cmuid == 0 {
        None
    } else {
        Some(from_MuID(cmuid))
    }
}

103
#[inline(always)]
104 105 106 107
fn from_MuBool(cbool: CMuBool) -> bool {
    cbool != 0
}

108
// APIHandle is immutable when used.
109
#[inline(always)]
110
fn from_handle<'a>(cmuvalue: CMuValue) -> &'a APIHandle {
111
    debug_assert!(!cmuvalue.is_null());
112
    unsafe {
113
        &*(cmuvalue as *const APIHandle)
114 115 116
    }
}

117
#[inline(always)]
118
fn from_handle_optional<'a>(cmuvalue: CMuValue) -> Option<&'a APIHandle> {
119 120 121 122 123 124 125 126 127
    if cmuvalue.is_null() {
        None
    } else {
        Some(from_handle(cmuvalue))
    }
}

// The following functions "from_*_array" converts from C-level arrays to Rust-level slices.

128
#[inline(always)]
129 130 131 132 133 134 135 136 137 138 139 140
fn from_array_direct<'a, T>(ptr: *const T, len: usize) -> &'a [T] {
    if ptr.is_null() {
        unsafe {
            slice::from_raw_parts(ptr::null(), len)
        }
    } else {
        unsafe {
            slice::from_raw_parts(ptr, len)
        }
    }
}

141
#[inline(always)]
142 143 144 145
fn from_char_array<'a>(ptr: *const c_char, len: usize) -> &'a [c_char] {
    from_array_direct(ptr, len)
}

146
#[inline(always)]
147 148 149 150
fn from_uint64_t_array<'a>(ptr: *const u64, len: usize) -> &'a [u64] {
    from_array_direct(ptr, len)
}

151
#[inline(always)]
152 153 154 155 156 157 158
fn from_MuFlag_array<'a>(ptr: *const CMuFlag, len: usize) -> &'a [CMuFlag] {
    from_array_direct(ptr, len)
}

/// Convert into a Vec of handle refs. It is not certain whether refs are represented in the same
/// way as raw pointers. So this function will convert each element. This function is only called
/// by `new_thread_nor`. As always, thread creation dominates the time.
159
#[inline(always)]
160
fn from_handle_array<'a>(ptr: *const CMuValue, len: usize) -> Vec<&'a APIHandle> {
161 162
    let slc = from_array_direct(ptr, len);
    slc.iter().map(|&e| {
163
        debug_assert!(!e.is_null());
164
        unsafe { &*(e as *const APIHandle) }
165 166 167
    }).collect::<Vec<_>>()
}

168 169 170 171 172 173 174 175 176 177
/// MuID is usize in this impl. Need conversion.
#[inline(always)]
fn from_MuID_array<'a>(ptr: *const CMuID, len: usize) -> Vec<MuID> {
    let slc = from_array_direct(ptr, len);
    slc.iter().map(|&e| {
        debug_assert!(e != 0);
        e as MuID
    }).collect::<Vec<_>>()
}

178
#[inline(always)]
179 180 181 182
fn from_MuCString_array<'a>(ptr: *const CMuCString, len: usize) -> Vec<String> {
    let slc = from_array_direct(ptr, len);
    slc.iter().map(|&e| from_MuCString(e)).collect::<Vec<_>>()
}
183

184 185 186 187 188 189 190 191 192
// The following functions `to_*` converts high-level types to C-like types.

#[inline(always)]
fn to_MuID(value: MuID) -> CMuID {
    debug_assert!(value <= 0xFFFFFFFFusize);
    value as CMuID
}

#[inline(always)]
193
fn to_handle(muvalue: *const APIHandle) -> CMuValue {
194 195 196 197 198 199 200 201 202 203 204 205 206
    debug_assert!(!muvalue.is_null());
    muvalue as CMuValue
}

#[inline(always)]
fn to_MuBool(value: bool) -> CMuBool {
    if value {
        1
    } else {
        0
    }
}

207
// GEN:BEGIN:Forwarders
208
extern fn _forwarder__MuVM__new_context(mvm: *mut CMuVM) -> *mut CMuCtx {
209
    let mut _arg_mvm = from_MuVM_ptr(mvm);
210 211 212 213 214
    let _rv = unsafe {
        (*_arg_mvm).new_context()
    };
    let _rv_prep = _rv;
    _rv_prep
215 216
}

217
extern fn _forwarder__MuVM__id_of(mvm: *mut CMuVM, name: CMuName) -> CMuID {
218 219
    let mut _arg_mvm = from_MuVM_ptr(mvm);
    let mut _arg_name = from_MuName(name);
220 221 222 223 224
    let _rv = unsafe {
        (*_arg_mvm).id_of(_arg_name)
    };
    let _rv_prep = to_MuID(_rv);
    _rv_prep
225 226
}

227
extern fn _forwarder__MuVM__name_of(mvm: *mut CMuVM, id: CMuID) -> CMuName {
228 229
    let mut _arg_mvm = from_MuVM_ptr(mvm);
    let mut _arg_id = from_MuID(id);
230 231 232 233 234
    let _rv = unsafe {
        (*_arg_mvm).name_of(_arg_id)
    };
    let _rv_prep = _rv;
    _rv_prep
235 236
}

237
extern fn _forwarder__MuVM__set_trap_handler(mvm: *mut CMuVM, trap_handler: CMuTrapHandler, userdata: CMuCPtr) {
238
    let mut _arg_mvm = from_MuVM_ptr(mvm);
239 240
    let mut _arg_trap_handler = trap_handler;
    let mut _arg_userdata = userdata;
241
    unsafe {
242 243
        (*_arg_mvm).set_trap_handler(_arg_trap_handler, _arg_userdata)
    };
244 245
}

246
extern fn _forwarder__MuVM__compile_to_sharedlib(mvm: *mut CMuVM, lib_name: CMuCString, extra_srcs: *mut CMuCString, n_extra_srcs: CMuArraySize) {
247
    let mut _arg_mvm = from_MuVM_ptr(mvm);
248
    let mut _arg_lib_name = from_MuCString(lib_name);
249
    let mut _arg_extra_srcs = from_MuCString_array(extra_srcs, n_extra_srcs);
250
    unsafe {
251 252 253 254 255 256 257 258 259
        (*_arg_mvm).compile_to_sharedlib(_arg_lib_name, _arg_extra_srcs)
    };
}

extern fn _forwarder__MuVM__current_thread_as_mu_thread(mvm: *mut CMuVM, threadlocal: CMuCPtr) {
    let mut _arg_mvm = from_MuVM_ptr(mvm);
    let mut _arg_threadlocal = threadlocal;
    unsafe {
        (*_arg_mvm).current_thread_as_mu_thread(_arg_threadlocal)
260 261 262
    };
}

263
extern fn _forwarder__MuCtx__id_of(ctx: *mut CMuCtx, name: CMuName) -> CMuID {
264 265
    let mut _arg_ctx = from_MuCtx_ptr(ctx);
    let mut _arg_name = from_MuName(name);
266 267 268 269 270
    let _rv = unsafe {
        (*_arg_ctx).id_of(_arg_name)
    };
    let _rv_prep = to_MuID(_rv);
    _rv_prep
271 272
}

273
extern fn _forwarder__MuCtx__name_of(ctx: *mut CMuCtx, id: CMuID) -> CMuName {
274 275
    let mut _arg_ctx = from_MuCtx_ptr(ctx);
    let mut _arg_id = from_MuID(id);
276 277 278 279 280
    let _rv = unsafe {
        (*_arg_ctx).name_of(_arg_id)
    };
    let _rv_prep = _rv;
    _rv_prep
281 282
}

283
extern fn _forwarder__MuCtx__close_context(ctx: *mut CMuCtx) {
284
    let mut _arg_ctx = from_MuCtx_ptr(ctx);
285
    unsafe {
286 287
        (*_arg_ctx).close_context()
    };
288 289
}

290
extern fn _forwarder__MuCtx__load_bundle(ctx: *mut CMuCtx, buf: *mut c_char, sz: CMuArraySize) {
291 292
    let mut _arg_ctx = from_MuCtx_ptr(ctx);
    let mut _arg_buf = from_char_array(buf, sz);
293
    unsafe {
294 295
        (*_arg_ctx).load_bundle(_arg_buf)
    };
296 297
}

298
extern fn _forwarder__MuCtx__load_hail(ctx: *mut CMuCtx, buf: *mut c_char, sz: CMuArraySize) {
299 300
    let mut _arg_ctx = from_MuCtx_ptr(ctx);
    let mut _arg_buf = from_char_array(buf, sz);
301
    unsafe {
302 303
        (*_arg_ctx).load_hail(_arg_buf)
    };
304 305
}

306
extern fn _forwarder__MuCtx__handle_from_sint8(ctx: *mut CMuCtx, num: i8, len: c_int) -> CMuIntValue {
307
    let mut _arg_ctx = from_MuCtx_ptr(ctx);
308 309
    let mut _arg_num = num;
    let mut _arg_len = len;
310 311 312 313 314
    let _rv = unsafe {
        (*_arg_ctx).handle_from_sint8(_arg_num, _arg_len)
    };
    let _rv_prep = to_handle(_rv);
    _rv_prep
315 316
}

317
extern fn _forwarder__MuCtx__handle_from_uint8(ctx: *mut CMuCtx, num: u8, len: c_int) -> CMuIntValue {
318
    let mut _arg_ctx = from_MuCtx_ptr(ctx);
319 320
    let mut _arg_num = num;
    let mut _arg_len = len;
321 322 323 324 325
    let _rv = unsafe {
        (*_arg_ctx).handle_from_uint8(_arg_num, _arg_len)
    };
    let _rv_prep = to_handle(_rv);
    _rv_prep
326 327
}

328
extern fn _forwarder__MuCtx__handle_from_sint16(ctx: *mut CMuCtx, num: i16, len: c_int) -> CMuIntValue {
329
    let mut _arg_ctx = from_MuCtx_ptr(ctx);
330 331
    let mut _arg_num = num;
    let mut _arg_len = len;
332 333 334 335 336
    let _rv = unsafe {
        (*_arg_ctx).handle_from_sint16(_arg_num, _arg_len)
    };
    let _rv_prep = to_handle(_rv);
    _rv_prep
337 338
}

339
extern fn _forwarder__MuCtx__handle_from_uint16(ctx: *mut CMuCtx, num: u16, len: c_int) -> CMuIntValue {
340
    let mut _arg_ctx = from_MuCtx_ptr(ctx);
341 342
    let mut _arg_num = num;
    let mut _arg_len = len;
343 344 345 346 347
    let _rv = unsafe {
        (*_arg_ctx).handle_from_uint16(_arg_num, _arg_len)
    };
    let _rv_prep = to_handle(_rv);
    _rv_prep
348 349
}

350
extern fn _forwarder__MuCtx__handle_from_sint32(ctx: *mut CMuCtx, num: i32, len: c_int) -> CMuIntValue {
351
    let mut _arg_ctx = from_MuCtx_ptr(ctx);
352 353
    let mut _arg_num = num;
    let mut _arg_len = len;
354 355 356 357 358
    let _rv = unsafe {
        (*_arg_ctx).handle_from_sint32(_arg_num, _arg_len)
    };
    let _rv_prep = to_handle(_rv);
    _rv_prep
359 360
}

361
extern fn _forwarder__MuCtx__handle_from_uint32(ctx: *mut CMuCtx, num: u32, len: c_int) -> CMuIntValue {
362
    let mut _arg_ctx = from_MuCtx_ptr(ctx);
363 364
    let mut _arg_num = num;
    let mut _arg_len = len;
365 366 367 368 369
    let _rv = unsafe {
        (*_arg_ctx).handle_from_uint32(_arg_num, _arg_len)
    };
    let _rv_prep = to_handle(_rv);
    _rv_prep
370 371
}

372
extern fn _forwarder__MuCtx__handle_from_sint64(ctx: *mut CMuCtx, num: i64, len: c_int) -> CMuIntValue {
373
    let mut _arg_ctx = from_MuCtx_ptr(ctx);
374 375
    let mut _arg_num = num;
    let mut _arg_len = len;
376 377 378 379 380
    let _rv = unsafe {
        (*_arg_ctx).handle_from_sint64(_arg_num, _arg_len)
    };
    let _rv_prep = to_handle(_rv);
    _rv_prep
381 382
}

383
extern fn _forwarder__MuCtx__handle_from_uint64(ctx: *mut CMuCtx, num: u64, len: c_int) -> CMuIntValue {
384
    let mut _arg_ctx = from_MuCtx_ptr(ctx);
385 386
    let mut _arg_num = num;
    let mut _arg_len = len;
387 388 389 390 391
    let _rv = unsafe {
        (*_arg_ctx).handle_from_uint64(_arg_num, _arg_len)
    };
    let _rv_prep = to_handle(_rv);
    _rv_prep
392 393
}

394
extern fn _forwarder__MuCtx__handle_from_uint64s(ctx: *mut CMuCtx, nums: *mut u64, nnums: CMuArraySize, len: c_int) -> CMuIntValue {
395 396
    let mut _arg_ctx = from_MuCtx_ptr(ctx);
    let mut _arg_nums = from_uint64_t_array(nums, nnums);
397
    let mut _arg_len = len;
398 399 400 401 402
    let _rv = unsafe {
        (*_arg_ctx).handle_from_uint64s(_arg_nums, _arg_len)
    };
    let _rv_prep = to_handle(_rv);
    _rv_prep
403 404
}

405
extern fn _forwarder__MuCtx__handle_from_float(ctx: *mut CMuCtx, num: f32) -> CMuFloatValue {
406
    let mut _arg_ctx = from_MuCtx_ptr(ctx);
407
    let mut _arg_num = num;
408 409 410 411 412
    let _rv = unsafe {
        (*_arg_ctx).handle_from_float(_arg_num)
    };
    let _rv_prep = to_handle(_rv);
    _rv_prep
413 414
}

415
extern fn _forwarder__MuCtx__handle_from_double(ctx: *mut CMuCtx, num: f64) -> CMuDoubleValue {
416
    let mut _arg_ctx = from_MuCtx_ptr(ctx);
417
    let mut _arg_num = num;
418 419 420 421 422
    let _rv = unsafe {
        (*_arg_ctx).handle_from_double(_arg_num)
    };
    let _rv_prep = to_handle(_rv);
    _rv_prep
423 424
}

425
extern fn _forwarder__MuCtx__handle_from_ptr(ctx: *mut CMuCtx, mu_type: CMuID, ptr: CMuCPtr) -> CMuUPtrValue {
426 427
    let mut _arg_ctx = from_MuCtx_ptr(ctx);
    let mut _arg_mu_type = from_MuID(mu_type);
428
    let mut _arg_ptr = ptr;
429 430 431 432 433
    let _rv = unsafe {
        (*_arg_ctx).handle_from_ptr(_arg_mu_type, _arg_ptr)
    };
    let _rv_prep = to_handle(_rv);
    _rv_prep
434 435
}

436
extern fn _forwarder__MuCtx__handle_from_fp(ctx: *mut CMuCtx, mu_type: CMuID, fp: CMuCFP) -> CMuUFPValue {
437 438
    let mut _arg_ctx = from_MuCtx_ptr(ctx);
    let mut _arg_mu_type = from_MuID(mu_type);
439
    let mut _arg_fp = fp;
440 441 442 443 444
    let _rv = unsafe {
        (*_arg_ctx).handle_from_fp(_arg_mu_type, _arg_fp)
    };
    let _rv_prep = to_handle(_rv);
    _rv_prep
445 446
}

447
extern fn _forwarder__MuCtx__handle_to_sint8(ctx: *mut CMuCtx, opnd: CMuIntValue) -> i8 {
448
    let mut _arg_ctx = from_MuCtx_ptr(ctx);
449
    let mut _arg_opnd = from_handle(opnd);
450 451 452 453 454
    let _rv = unsafe {
        (*_arg_ctx).handle_to_sint8(_arg_opnd)
    };
    let _rv_prep = _rv;
    _rv_prep
455 456
}

457
extern fn _forwarder__MuCtx__handle_to_uint8(ctx: *mut CMuCtx, opnd: CMuIntValue) -> u8 {
458
    let mut _arg_ctx = from_MuCtx_ptr(ctx);
459
    let mut _arg_opnd = from_handle(opnd);
460 461 462 463 464
    let _rv = unsafe {
        (*_arg_ctx).handle_to_uint8(_arg_opnd)
    };
    let _rv_prep = _rv;
    _rv_prep
465 466
}

467
extern fn _forwarder__MuCtx__handle_to_sint16(ctx: *mut CMuCtx, opnd: CMuIntValue) -> i16 {
468
    let mut _arg_ctx = from_MuCtx_ptr(ctx);
469
    let mut _arg_opnd = from_handle(opnd);
470 471 472 473 474
    let _rv = unsafe {
        (*_arg_ctx).handle_to_sint16(_arg_opnd)
    };
    let _rv_prep = _rv;
    _rv_prep
475 476
}

477
extern fn _forwarder__MuCtx__handle_to_uint16(ctx: *mut CMuCtx, opnd: CMuIntValue) -> u16 {
478
    let mut _arg_ctx = from_MuCtx_ptr(ctx);
479
    let mut _arg_opnd = from_handle(opnd);
480 481 482 483 484
    let _rv = unsafe {
        (*_arg_ctx).handle_to_uint16(_arg_opnd)
    };
    let _rv_prep = _rv;
    _rv_prep
485 486
}

487
extern fn _forwarder__MuCtx__handle_to_sint32(ctx: *mut CMuCtx, opnd: CMuIntValue) -> i32 {
488
    let mut _arg_ctx = from_MuCtx_ptr(ctx);
489
    let mut _arg_opnd = from_handle(opnd);
490 491 492 493 494
    let _rv = unsafe {
        (*_arg_ctx).handle_to_sint32(_arg_opnd)
    };
    let _rv_prep = _rv;
    _rv_prep
495 496
}

497
extern fn _forwarder__MuCtx__handle_to_uint32(ctx: *mut CMuCtx, opnd: CMuIntValue) -> u32 {
498
    let mut _arg_ctx = from_MuCtx_ptr(ctx);
499
    let mut _arg_opnd = from_handle(opnd);
500 501 502 503 504
    let _rv = unsafe {
        (*_arg_ctx).handle_to_uint32(_arg_opnd)
    };
    let _rv_prep = _rv;
    _rv_prep
505 506
}

507
extern fn _forwarder__MuCtx__handle_to_sint64(ctx: *mut CMuCtx, opnd: CMuIntValue) -> i64 {
508
    let mut _arg_ctx = from_MuCtx_ptr(ctx);
509
    let mut _arg_opnd = from_handle(opnd);
510 511 512 513 514
    let _rv = unsafe {
        (*_arg_ctx).handle_to_sint64(_arg_opnd)
    };
    let _rv_prep = _rv;
    _rv_prep
515 516
}

517
extern fn _forwarder__MuCtx__handle_to_uint64(ctx: *mut CMuCtx, opnd: CMuIntValue) -> u64 {
518
    let mut _arg_ctx = from_MuCtx_ptr(ctx);
519
    let mut _arg_opnd = from_handle(opnd);
520 521 522 523 524
    let _rv = unsafe {
        (*_arg_ctx).handle_to_uint64(_arg_opnd)
    };
    let _rv_prep = _rv;
    _rv_prep
525 526
}

527
extern fn _forwarder__MuCtx__handle_to_float(ctx: *mut CMuCtx, opnd: CMuFloatValue) -> f32 {
528
    let mut _arg_ctx = from_MuCtx_ptr(ctx);
529
    let mut _arg_opnd = from_handle(opnd);
530 531 532 533 534
    let _rv = unsafe {
        (*_arg_ctx).handle_to_float(_arg_opnd)
    };
    let _rv_prep = _rv;
    _rv_prep
535 536
}

537
extern fn _forwarder__MuCtx__handle_to_double(ctx: *mut CMuCtx, opnd: CMuDoubleValue) -> f64 {
538
    let mut _arg_ctx = from_MuCtx_ptr(ctx);
539
    let mut _arg_opnd = from_handle(opnd);
540 541 542 543 544
    let _rv = unsafe {
        (*_arg_ctx).handle_to_double(_arg_opnd)
    };
    let _rv_prep = _rv;
    _rv_prep
545 546
}

547
extern fn _forwarder__MuCtx__handle_to_ptr(ctx: *mut CMuCtx, opnd: CMuUPtrValue) -> CMuCPtr {
548
    let mut _arg_ctx = from_MuCtx_ptr(ctx);
549
    let mut _arg_opnd = from_handle(opnd);
550 551 552 553 554
    let _rv = unsafe {
        (*_arg_ctx).handle_to_ptr(_arg_opnd)
    };
    let _rv_prep = _rv;
    _rv_prep
555 556
}

557
extern fn _forwarder__MuCtx__handle_to_fp(ctx: *mut CMuCtx, opnd: CMuUFPValue) -> CMuCFP {
558
    let mut _arg_ctx = from_MuCtx_ptr(ctx);
559
    let mut _arg_opnd = from_handle(opnd);
560 561 562 563 564
    let _rv = unsafe {
        (*_arg_ctx).handle_to_fp(_arg_opnd)
    };
    let _rv_prep = _rv;
    _rv_prep
565 566
}

567
extern fn _forwarder__MuCtx__handle_from_const(ctx: *mut CMuCtx, id: CMuID) -> CMuValue {
568 569
    let mut _arg_ctx = from_MuCtx_ptr(ctx);
    let mut _arg_id = from_MuID(id);
570 571 572 573 574
    let _rv = unsafe {
        (*_arg_ctx).handle_from_const(_arg_id)
    };
    let _rv_prep = to_handle(_rv);
    _rv_prep
575 576
}

577
extern fn _forwarder__MuCtx__handle_from_global(ctx: *mut CMuCtx, id: CMuID) -> CMuIRefValue {
578 579
    let mut _arg_ctx = from_MuCtx_ptr(ctx);
    let mut _arg_id = from_MuID(id);
580 581 582 583 584
    let _rv = unsafe {
        (*_arg_ctx).handle_from_global(_arg_id)
    };
    let _rv_prep = to_handle(_rv);
    _rv_prep
585 586
}

587
extern fn _forwarder__MuCtx__handle_from_func(ctx: *mut CMuCtx, id: CMuID) -> CMuFuncRefValue {
588 589
    let mut _arg_ctx = from_MuCtx_ptr(ctx);
    let mut _arg_id = from_MuID(id);
590 591 592 593 594
    let _rv = unsafe {
        (*_arg_ctx).handle_from_func(_arg_id)
    };
    let _rv_prep = to_handle(_rv);
    _rv_prep
595 596
}

597
extern fn _forwarder__MuCtx__handle_from_expose(ctx: *mut CMuCtx, id: CMuID) -> CMuValue {
598 599
    let mut _arg_ctx = from_MuCtx_ptr(ctx);
    let mut _arg_id = from_MuID(id);
600 601 602 603 604
    let _rv = unsafe {
        (*_arg_ctx).handle_from_expose(_arg_id)
    };
    let _rv_prep = to_handle(_rv);
    _rv_prep
605 606
}

607
extern fn _forwarder__MuCtx__delete_value(ctx: *mut CMuCtx, opnd: CMuValue) {
608
    let mut _arg_ctx = from_MuCtx_ptr(ctx);
609
    let mut _arg_opnd = from_handle(opnd);
610
    unsafe {
611 612
        (*_arg_ctx).delete_value(_arg_opnd)
    };
613 614
}

615
extern fn _forwarder__MuCtx__ref_eq(ctx: *mut CMuCtx, lhs: CMuGenRefValue, rhs: CMuGenRefValue) -> CMuBool {
616
    let mut _arg_ctx = from_MuCtx_ptr(ctx);
617 618
    let mut _arg_lhs = from_handle(lhs);
    let mut _arg_rhs = from_handle(rhs);
619 620 621 622 623
    let _rv = unsafe {
        (*_arg_ctx).ref_eq(_arg_lhs, _arg_rhs)
    };
    let _rv_prep = to_MuBool(_rv);
    _rv_prep
624 625
}

626
extern fn _forwarder__MuCtx__ref_ult(ctx: *mut CMuCtx, lhs: CMuIRefValue, rhs: CMuIRefValue) -> CMuBool {
627
    let mut _arg_ctx = from_MuCtx_ptr(ctx);
628 629
    let mut _arg_lhs = from_handle(lhs);
    let mut _arg_rhs = from_handle(rhs);
630 631 632 633 634
    let _rv = unsafe {
        (*_arg_ctx).ref_ult(_arg_lhs, _arg_rhs)
    };
    let _rv_prep = to_MuBool(_rv);
    _rv_prep
635 636
}

637
extern fn _forwarder__MuCtx__extract_value(ctx: *mut CMuCtx, str: CMuStructValue, index: c_int) -> CMuValue {
638
    let mut _arg_ctx = from_MuCtx_ptr(ctx);
639 640
    let mut _arg_str = from_handle(str);
    let mut _arg_index = index;
641 642 643 644 645
    let _rv = unsafe {
        (*_arg_ctx).extract_value(_arg_str, _arg_index)
    };
    let _rv_prep = to_handle(_rv);
    _rv_prep
646 647
}

648
extern fn _forwarder__MuCtx__insert_value(ctx: *mut CMuCtx, str: CMuStructValue, index: c_int, newval: CMuValue) -> CMuStructValue {
649
    let mut _arg_ctx = from_MuCtx_ptr(ctx);
650 651 652
    let mut _arg_str = from_handle(str);
    let mut _arg_index = index;
    let mut _arg_newval = from_handle(newval);
653 654 655 656 657
    let _rv = unsafe {
        (*_arg_ctx).insert_value(_arg_str, _arg_index, _arg_newval)
    };
    let _rv_prep = to_handle(_rv);
    _rv_prep
658 659
}

660
extern fn _forwarder__MuCtx__extract_element(ctx: *mut CMuCtx, str: CMuSeqValue, index: CMuIntValue) -> CMuValue {
661
    let mut _arg_ctx = from_MuCtx_ptr(ctx);
662 663
    let mut _arg_str = from_handle(str);
    let mut _arg_index = from_handle(index);
664 665 666 667 668
    let _rv = unsafe {
        (*_arg_ctx).extract_element(_arg_str, _arg_index)
    };
    let _rv_prep = to_handle(_rv);
    _rv_prep
669 670
}

671
extern fn _forwarder__MuCtx__insert_element(ctx: *mut CMuCtx, str: CMuSeqValue, index: CMuIntValue, newval: CMuValue) -> CMuSeqValue {
672
    let mut _arg_ctx = from_MuCtx_ptr(ctx);
673 674 675
    let mut _arg_str = from_handle(str);
    let mut _arg_index = from_handle(index);
    let mut _arg_newval = from_handle(newval);
676 677 678 679 680
    let _rv = unsafe {
        (*_arg_ctx).insert_element(_arg_str, _arg_index, _arg_newval)
    };
    let _rv_prep = to_handle(_rv);
    _rv_prep
681 682
}

683
extern fn _forwarder__MuCtx__new_fixed(ctx: *mut CMuCtx, mu_type: CMuID) -> CMuRefValue {
684 685
    let mut _arg_ctx = from_MuCtx_ptr(ctx);
    let mut _arg_mu_type = from_MuID(mu_type);
686 687 688 689 690
    let _rv = unsafe {
        (*_arg_ctx).new_fixed(_arg_mu_type)
    };
    let _rv_prep = to_handle(_rv);
    _rv_prep
691 692
}

693
extern fn _forwarder__MuCtx__new_hybrid(ctx: *mut CMuCtx, mu_type: CMuID, length: CMuIntValue) -> CMuRefValue {
694 695
    let mut _arg_ctx = from_MuCtx_ptr(ctx);
    let mut _arg_mu_type = from_MuID(mu_type);
696
    let mut _arg_length = from_handle(length);
697 698 699 700 701
    let _rv = unsafe {
        (*_arg_ctx).new_hybrid(_arg_mu_type, _arg_length)
    };
    let _rv_prep = to_handle(_rv);
    _rv_prep
702 703
}

704
extern fn _forwarder__MuCtx__refcast(ctx: *mut CMuCtx, opnd: CMuGenRefValue, new_type: CMuID) -> CMuGenRefValue {
705
    let mut _arg_ctx = from_MuCtx_ptr(ctx);
706
    let mut _arg_opnd = from_handle(opnd);
707
    let mut _arg_new_type = from_MuID(new_type);
708 709 710 711 712
    let _rv = unsafe {
        (*_arg_ctx).refcast(_arg_opnd, _arg_new_type)
    };
    let _rv_prep = to_handle(_rv);
    _rv_prep
713 714
}

715
extern fn _forwarder__MuCtx__get_iref(ctx: *mut CMuCtx, opnd: CMuRefValue) -> CMuIRefValue {
716
    let mut _arg_ctx = from_MuCtx_ptr(ctx);
717
    let mut _arg_opnd = from_handle(opnd);
718 719 720 721 722
    let _rv = unsafe {
        (*_arg_ctx).get_iref(_arg_opnd)
    };
    let _rv_prep = to_handle(_rv);
    _rv_prep
723 724
}

725
extern fn _forwarder__MuCtx__get_field_iref(ctx: *mut CMuCtx, opnd: CMuIRefValue, field: c_int) -> CMuIRefValue {
726
    let mut _arg_ctx = from_MuCtx_ptr(ctx);
727 728
    let mut _arg_opnd = from_handle(opnd);
    let mut _arg_field = field;
729 730 731 732 733
    let _rv = unsafe {
        (*_arg_ctx).get_field_iref(_arg_opnd, _arg_field)
    };
    let _rv_prep = to_handle(_rv);
    _rv_prep
734 735
}

736
extern fn _forwarder__MuCtx__get_elem_iref(ctx: *mut CMuCtx, opnd: CMuIRefValue, index: CMuIntValue) -> CMuIRefValue {
737
    let mut _arg_ctx = from_MuCtx_ptr(ctx);
738 739
    let mut _arg_opnd = from_handle(opnd);
    let mut _arg_index = from_handle(index);
740 741 742 743 744
    let _rv = unsafe {
        (*_arg_ctx).get_elem_iref(_arg_opnd, _arg_index)
    };
    let _rv_prep = to_handle(_rv);
    _rv_prep
745 746
}

747
extern fn _forwarder__MuCtx__shift_iref(ctx: *mut CMuCtx, opnd: CMuIRefValue, offset: CMuIntValue) -> CMuIRefValue {
748
    let mut _arg_ctx = from_MuCtx_ptr(ctx);
749 750
    let mut _arg_opnd = from_handle(opnd);
    let mut _arg_offset = from_handle(offset);
751 752 753 754 755
    let _rv = unsafe {
        (*_arg_ctx).shift_iref(_arg_opnd, _arg_offset)
    };
    let _rv_prep = to_handle(_rv);
    _rv_prep
756 757
}

758
extern fn _forwarder__MuCtx__get_var_part_iref(ctx: *mut CMuCtx, opnd: CMuIRefValue) -> CMuIRefValue {
759
    let mut _arg_ctx = from_MuCtx_ptr(ctx);
760
    let mut _arg_opnd = from_handle(opnd);
761 762 763 764 765
    let _rv = unsafe {
        (*_arg_ctx).get_var_part_iref(_arg_opnd)
    };
    let _rv_prep = to_handle(_rv);
    _rv_prep
766 767
}

768
extern fn _forwarder__MuCtx__load(ctx: *mut CMuCtx, ord: CMuMemOrd, loc: CMuIRefValue) -> CMuValue {
769
    let mut _arg_ctx = from_MuCtx_ptr(ctx);
770 771
    let mut _arg_ord = ord;
    let mut _arg_loc = from_handle(loc);
772 773 774 775 776
    let _rv = unsafe {
        (*_arg_ctx).load(_arg_ord, _arg_loc)
    };
    let _rv_prep = to_handle(_rv);
    _rv_prep
777 778
}

779
extern fn _forwarder__MuCtx__store(ctx: *mut CMuCtx, ord: CMuMemOrd, loc: CMuIRefValue, newval: CMuValue) {
780
    let mut _arg_ctx = from_MuCtx_ptr(ctx);
781 782 783
    let mut _arg_ord = ord;
    let mut _arg_loc = from_handle(loc);
    let mut _arg_newval = from_handle(newval);
784
    unsafe {
785 786
        (*_arg_ctx).store(_arg_ord, _arg_loc, _arg_newval)
    };
787 788
}

789
extern fn _forwarder__MuCtx__cmpxchg(ctx: *mut CMuCtx, ord_succ: CMuMemOrd, ord_fail: CMuMemOrd, weak: CMuBool, loc: CMuIRefValue, expected: CMuValue, desired: CMuValue, is_succ: *mut CMuBool) -> CMuValue {
790
    let mut _arg_ctx = from_MuCtx_ptr(ctx);
791 792
    let mut _arg_ord_succ = ord_succ;
    let mut _arg_ord_fail = ord_fail;
793
    let mut _arg_weak = from_MuBool(weak);
794 795 796 797
    let mut _arg_loc = from_handle(loc);
    let mut _arg_expected = from_handle(expected);
    let mut _arg_desired = from_handle(desired);
    let mut _arg_is_succ = is_succ;
798 799 800 801 802
    let _rv = unsafe {
        (*_arg_ctx).cmpxchg(_arg_ord_succ, _arg_ord_fail, _arg_weak, _arg_loc, _arg_expected, _arg_desired, _arg_is_succ)
    };
    let _rv_prep = to_handle(_rv);
    _rv_prep
803 804
}

805
extern fn _forwarder__MuCtx__atomicrmw(ctx: *mut CMuCtx, ord: CMuMemOrd, op: CMuAtomicRMWOptr, loc: CMuIRefValue, opnd: CMuValue) -> CMuValue {
806
    let mut _arg_ctx = from_MuCtx_ptr(ctx);
807 808 809 810
    let mut _arg_ord = ord;
    let mut _arg_op = op;
    let mut _arg_loc = from_handle(loc);
    let mut _arg_opnd = from_handle(opnd);
811 812 813 814 815
    let _rv = unsafe {
        (*_arg_ctx).atomicrmw(_arg_ord, _arg_op, _arg_loc, _arg_opnd)
    };
    let _rv_prep = to_handle(_rv);
    _rv_prep
816 817
}

818
extern fn _forwarder__MuCtx__fence(ctx: *mut CMuCtx, ord: CMuMemOrd) {
819
    let mut _arg_ctx = from_MuCtx_ptr(ctx);
820
    let mut _arg_ord = ord;
821
    unsafe {
822 823
        (*_arg_ctx).fence(_arg_ord)
    };
824 825
}

826
extern fn _forwarder__MuCtx__new_stack(ctx: *mut CMuCtx, func: CMuFuncRefValue) -> CMuStackRefValue {
827
    let mut _arg_ctx = from_MuCtx_ptr(ctx);
828
    let mut _arg_func = from_handle(func);
829 830 831 832 833
    let _rv = unsafe {
        (*_arg_ctx).new_stack(_arg_func)
    };
    let _rv_prep = to_handle(_rv);
    _rv_prep
834 835
}

836
extern fn _forwarder__MuCtx__new_thread_nor(ctx: *mut CMuCtx, stack: CMuStackRefValue, threadlocal: CMuRefValue, vals: *mut CMuValue, nvals: CMuArraySize) -> CMuThreadRefValue {
837
    let mut _arg_ctx = from_MuCtx_ptr(ctx);
838 839 840
    let mut _arg_stack = from_handle(stack);
    let mut _arg_threadlocal = from_handle_optional(threadlocal);
    let mut _arg_vals = from_handle_array(vals, nvals);
841 842 843 844 845
    let _rv = unsafe {
        (*_arg_ctx).new_thread_nor(_arg_stack, _arg_threadlocal, _arg_vals)
    };
    let _rv_prep = to_handle(_rv);
    _rv_prep
846 847
}

848
extern fn _forwarder__MuCtx__new_thread_exc(ctx: *mut CMuCtx, stack: CMuStackRefValue, threadlocal: CMuRefValue, exc: CMuRefValue) -> CMuThreadRefValue {
849
    let mut _arg_ctx = from_MuCtx_ptr(ctx);
850 851 852
    let mut _arg_stack = from_handle(stack);
    let mut _arg_threadlocal = from_handle_optional(threadlocal);
    let mut _arg_exc = from_handle(exc);
853 854 855 856 857
    let _rv = unsafe {
        (*_arg_ctx).new_thread_exc(_arg_stack, _arg_threadlocal, _arg_exc)
    };
    let _rv_prep = to_handle(_rv);
    _rv_prep
858 859
}

860
extern fn _forwarder__MuCtx__kill_stack(ctx: *mut CMuCtx, stack: CMuStackRefValue) {
861
    let mut _arg_ctx = from_MuCtx_ptr(ctx);
862
    let mut _arg_stack = from_handle(stack);
863
    unsafe {
864 865
        (*_arg_ctx).kill_stack(_arg_stack)
    };
866 867
}

868
extern fn _forwarder__MuCtx__set_threadlocal(ctx: *mut CMuCtx, thread: CMuThreadRefValue, threadlocal: CMuRefValue) {
869
    let mut _arg_ctx = from_MuCtx_ptr(ctx);
870 871
    let mut _arg_thread = from_handle(thread);
    let mut _arg_threadlocal = from_handle(threadlocal);
872
    unsafe {
873 874
        (*_arg_ctx).set_threadlocal(_arg_thread, _arg_threadlocal)
    };
875 876
}

877
extern fn _forwarder__MuCtx__get_threadlocal(ctx: *mut CMuCtx, thread: CMuThreadRefValue) -> CMuRefValue {
878
    let mut _arg_ctx = from_MuCtx_ptr(ctx);
879
    let mut _arg_thread = from_handle(thread);
880 881 882 883 884
    let _rv = unsafe {
        (*_arg_ctx).get_threadlocal(_arg_thread)
    };
    let _rv_prep = to_handle(_rv);
    _rv_prep
885 886
}

887
extern fn _forwarder__MuCtx__new_cursor(ctx: *mut CMuCtx, stack: CMuStackRefValue) -> CMuFCRefValue {
888
    let mut _arg_ctx = from_MuCtx_ptr(ctx);
889
    let mut _arg_stack = from_handle(stack);
890 891 892 893 894
    let _rv = unsafe {
        (*_arg_ctx).new_cursor(_arg_stack)
    };
    let _rv_prep = to_handle(_rv);
    _rv_prep
895 896
}

897
extern fn _forwarder__MuCtx__next_frame(ctx: *mut CMuCtx, cursor: CMuFCRefValue) {
898
    let mut _arg_ctx = from_MuCtx_ptr(ctx);
899
    let mut _arg_cursor = from_handle(cursor);
900
    unsafe {
901 902
        (*_arg_ctx).next_frame(_arg_cursor)
    };
903 904
}

905
extern fn _forwarder__MuCtx__copy_cursor(ctx: *mut CMuCtx, cursor: CMuFCRefValue) -> CMuFCRefValue {
906
    let mut _arg_ctx = from_MuCtx_ptr(ctx);
907
    let mut _arg_cursor = from_handle(cursor);
908 909 910 911 912
    let _rv = unsafe {
        (*_arg_ctx).copy_cursor(_arg_cursor)
    };
    let _rv_prep = to_handle(_rv);
    _rv_prep
913 914
}

915
extern fn _forwarder__MuCtx__close_cursor(ctx: *mut CMuCtx, cursor: CMuFCRefValue) {
916
    let mut _arg_ctx = from_MuCtx_ptr(ctx);
917
    let mut _arg_cursor = from_handle(cursor);
918
    unsafe {
919 920
        (*_arg_ctx).close_cursor(_arg_cursor)
    };
921 922
}

923
extern fn _forwarder__MuCtx__cur_func(ctx: *mut CMuCtx, cursor: CMuFCRefValue) -> CMuID {
924
    let mut _arg_ctx = from_MuCtx_ptr(ctx);
925
    let mut _arg_cursor = from_handle(cursor);
926 927 928 929 930
    let _rv = unsafe {
        (*_arg_ctx).cur_func(_arg_cursor)
    };
    let _rv_prep = to_MuID(_rv);
    _rv_prep
931 932
}

933
extern fn _forwarder__MuCtx__cur_func_ver(ctx: *mut CMuCtx, cursor: CMuFCRefValue) -> CMuID {
934
    let mut _arg_ctx = from_MuCtx_ptr(ctx);
935
    let mut _arg_cursor = from_handle(cursor);
936 937 938 939 940
    let _rv = unsafe {
        (*_arg_ctx).cur_func_ver(_arg_cursor)
    };
    let _rv_prep = to_MuID(_rv);
    _rv_prep
941 942
}

943
extern fn _forwarder__MuCtx__cur_inst(ctx: *mut CMuCtx, cursor: CMuFCRefValue) -> CMuID {
944
    let mut _arg_ctx = from_MuCtx_ptr(ctx);
945
    let mut _arg_cursor = from_handle(cursor);
946 947 948 949 950
    let _rv = unsafe {
        (*_arg_ctx).cur_inst(_arg_cursor)
    };
    let _rv_prep = to_MuID(_rv);
    _rv_prep
951 952
}

953
extern fn _forwarder__MuCtx__dump_keepalives(ctx: *mut CMuCtx, cursor: CMuFCRefValue, results: *mut CMuValue) {
954
    let mut _arg_ctx = from_MuCtx_ptr(ctx);
955 956
    let mut _arg_cursor = from_handle(cursor);
    let mut _arg_results = results;
957
    unsafe {
958 959
        (*_arg_ctx).dump_keepalives(_arg_cursor, _arg_results)
    };
960 961
}

962
extern fn _forwarder__MuCtx__pop_frames_to(ctx: *mut CMuCtx, cursor: CMuFCRefValue) {
963
    let mut _arg_ctx = from_MuCtx_ptr(ctx);
964
    let mut _arg_cursor = from_handle(cursor);
965
    unsafe {
966 967
        (*_arg_ctx).pop_frames_to(_arg_cursor)
    };
968 969
}

970
extern fn _forwarder__MuCtx__push_frame(ctx: *mut CMuCtx, stack: CMuStackRefValue, func: CMuFuncRefValue) {
971
    let mut _arg_ctx = from_MuCtx_ptr(ctx);
972 973
    let mut _arg_stack = from_handle(stack);
    let mut _arg_func = from_handle(func);
974
    unsafe {
975 976
        (*_arg_ctx).push_frame(_arg_stack, _arg_func)
    };
977 978
}

979
extern fn _forwarder__MuCtx__tr64_is_fp(ctx: *mut CMuCtx, value: CMuTagRef64Value) -> CMuBool {
980
    let mut _arg_ctx = from_MuCtx_ptr(ctx);
981
    let mut _arg_value = from_handle(value);