scoop:scoop.core:0.1.0
src/ffi.scoop
Selected production source · src/ffi.scoop
1
// Typed raw-pointer core contract (spec 13.10, M12 DESIGN section 4.1).2
// HIR validates these declarations exactly and normalizes applications to3
// dedicated Ptr/FunPtr types; downstream stages never identify them by name.5
/**6
* A typed native data address. Unsafe users must ensure valid lifetime, alignment, bounds, and7
* access permissions; pointer values do not own or root their pointees.8
*/9
@Intrinsic("core_ptr")10
public struct Ptr<T : value> : Equals<Ptr<T>> {11
/**12
* Compares the stored addresses without dereferencing either pointer.13
*/14
public override operator fun equals(other: Ptr<T>): Boolean {15
@Unsafe {16
return this.toULong() == other.toULong()17
}18
}21
/**22
* Returns the address as an unsigned integer without extending the pointee's lifetime.23
*/24
@NoGC25
@Unsafe26
@Intrinsic("ptr_to_ulong")27
public fun toULong(): ULong29
/**30
* Reinterprets the same address with another pointee type. The caller must establish the new31
* type's alignment and access validity.32
*/33
@NoGC34
@Unsafe35
@Intrinsic("ptr_cast")36
public fun <U : value> cast(): Ptr<U>38
/**39
* Reads a value at this address or the specified element offset. The caller must provide40
* readable, properly aligned initialized storage.41
*/42
@NoGC43
@Unsafe44
@Intrinsic("ptr_load")45
public fun load(): T47
/**48
* Reads a value at this address or the specified element offset. The caller must provide49
* readable, properly aligned initialized storage.50
*/51
@NoGC52
@Unsafe53
@Intrinsic("ptr_load_offset")54
public fun load(offset: Long): T56
/**57
* Writes a value at this address or the specified element offset. The caller must provide58
* writable, properly aligned storage.59
*/60
@NoGC61
@Unsafe62
@Intrinsic("ptr_store")63
public fun store(value: T)65
/**66
* Writes a value at this address or the specified element offset. The caller must provide67
* writable, properly aligned storage.68
*/69
@NoGC70
@Unsafe71
@Intrinsic("ptr_store_offset")72
public fun store(offset: Long, value: T)74
/**75
* Moves forward by `offset` elements of T, not bytes. It does not check allocation bounds.76
*/77
@NoGC78
@Unsafe79
@Intrinsic("ptr_plus")80
public operator fun plus(offset: Long): Ptr<T>82
/**83
* Moves backward by `offset` elements of T, not bytes. It does not check allocation bounds.84
*/85
@NoGC86
@Unsafe87
@Intrinsic("ptr_minus")88
public operator fun minus(offset: Long): Ptr<T>89
}91
/**92
* A native function address with a statically checked function signature; it does not own callback93
* state.94
*/95
@Intrinsic("core_fun_ptr")96
public struct FunPtr<F>98
/**99
* A native function address whose caller promises the GC-leaf contract. Its machine100
* representation matches FunPtr, but the call mode is part of its static type.101
*/102
@Intrinsic("core_gc_leaf_fun_ptr")103
public struct GCLeafFunPtr<F>105
/**106
* Returns the same native function address with the NativeSafe calling boundary.107
*/108
@NoGC109
@Intrinsic("gc_leaf_fun_ptr_as_fun_ptr")110
public fun <F> GCLeafFunPtr<F>.asFunPtr(): FunPtr<F>112
/**113
* Treats the same native function address as a GC-leaf call target. The caller must ensure that114
* every invocation satisfies the GC-leaf contract.115
*/116
@NoGC117
@Unsafe118
@Intrinsic("fun_ptr_as_gc_leaf")119
public fun <F> FunPtr<F>.asGCLeaf(): GCLeafFunPtr<F>121
/**122
* Borrows the address of addressable value storage. The unsafe caller must not let the pointer123
* outlive that storage.124
*/125
@Unsafe126
@Intrinsic("address_of")127
public fun <T : value> addressOf(value: T): Ptr<T>129
/**130
* Returns the target ABI size in bytes of a concrete value type.131
*/132
@NoGC133
@Intrinsic("size_of")134
public fun <T : value> sizeOf(): ULong136
/**137
* Returns the target ABI alignment in bytes of a concrete value type.138
*/139
@NoGC140
@Intrinsic("align_of")141
public fun <T : value> alignOf(): ULong