ffi/module.protos
- Repository
- guillermomolina/protos
- Commit
379c6fa63685c39a5954cfbd577bfda3b4df8e75- Tree
8cd4f4afe29ae4c3866381f38c1858108e9799f6- Blob
5b49e24ae85eff145740222a7bc164c2393334c2- Source
- View exact source on GitHub
// THE LICENSED WORK IS PROVIDED UNDER THE TERMS OF THE ADAPTIVE PUBLIC LICENSE
// ("LICENSE") AS FIRST COMPLETED BY: Guillermo Adrián Molina. ANY USE, PUBLIC
// DISPLAY, PUBLIC PERFORMANCE, REPRODUCTION OR DISTRIBUTION OF, OR PREPARATION OF
// DERIVATIVE WORKS BASED ON, THE LICENSED WORK CONSTITUTES RECIPIENT'S ACCEPTANCE
// OF THIS LICENSE AND ITS TERMS, WHETHER OR NOT SUCH RECIPIENT READS THE TERMS OF
// THE LICENSE. "LICENSED WORK" AND "RECIPIENT" ARE DEFINED IN THE LICENSE. A COPY
// OF THE LICENSE IS LOCATED IN THE TEXT FILE ENTITLED "LICENSE.TXT" ACCOMPANYING
// THE CONTENTS OF THIS FILE. IF A COPY OF THE LICENSE DOES NOT ACCOMPANY THIS
// FILE, A COPY OF THE LICENSE MAY ALSO BE OBTAINED AT THE FOLLOWING WEB SITE:
// https://github.com/guillermomolina/protos
//
// Software distributed under the License is distributed on an "AS IS" basis,
// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
// the specific language governing rights and limitations under the License.
//! Protos-first synchronous FFI R1 (D238-B1-SQL-R1) with declarative layouts.
//! Import grants no authority. Native libraries must be supplied by the host.
//! ABI declarations are trusted: a wrong signature can terminate the process.
//! Layout descriptors are pure Protos metadata for the Linux x86-64 LP64
//! profile; declaring or querying one never enters a foreign provider.
//! Typed pointer results are pass-only capabilities: they carry no readable
//! extent and are never converted to or from Integer addresses.
//! Native regions (allocate, slice, view) are bounded typed native memory of
//! the RootActor's provider session; allocation acquires no C library.
//! Struct and union layouts pass and return by value: an argument is a live
//! region of the exact layout, copied for the call; a result, or an out of
//! that layout, is a fresh independently owned allocation root.
//! readFields and writeFields project a struct or union region to and from
//! fresh ordinary Maps and Arrays; readAs and writeFrom do so through ordinary
//! objects of an exactly associated prototype. Every reached union names its
//! member through an explicit unionArm selection.
Interop: import("std:interop")
Arrays: import("std:collections/array")
descriptors: IdentityMap()
owners: IdentityMap()
// Exact ordinary-prototype identity -> exact layout descriptor identity.
associations: IdentityMap()
// Exact pointee layout identity -> canonical provider-side plain pointer
// descriptor of this Actor's session, created lazily by the first binding
// that needs it. A declaration map only: no pointer value is ever stored.
pointerTypes: IdentityMap()
// Private exact ordinary-object recognition; never part of the MODULE surface.
recognition: _ffiObjectRecognitionFacility
context.removeSlot("_ffiObjectRecognitionFacility")
isOrdinaryObject: (value) => recognition.ordinaryObject(value)
// Whether the ordinary selection of `createSlot`, `slotValue` or `parent` from
// an exact ordinary object is the canonical root Object behavior; a shadowing
// or absent selection is refused, never bypassed. Checked where it is used.
requireCanonicalMethod: (receiver, selector) => {
(recognition.selectsCanonicalObjectMethod(receiver, selector) === true)
.ifFalse(() => fail())
}
// Private acquisition of the RootActor's provider-session context; never
// part of the MODULE surface and never used during module initialization.
nativeContextFacility: _ffiNativeContextFacility
context.removeSlot("_ffiNativeContextFacility")
nativeContext: null
// Exact storage layout identity -> provider-side physical access metadata,
// composed lazily from the record below; never a second descriptor map.
storages: IdentityMap()
// The inverse: exact provider-side storage identity -> exact layout descriptor,
// only for storages composed by `physical` below; never a region or a value.
layouts: IdentityMap()
fail: () => Error().signal()
requireString: (value) => {
String.recognizes(value).ifFalse(() => fail())
}
// Only foreign member access is used at this boundary: a local object with
// similarly named slots cannot impersonate a provider library.
operation: (library, name, ...arguments) => {
Interop.invoke(Interop.readMember(library, name), ...arguments)
}
DescriptorsSource: import("./internal/Descriptors.protos")
Descriptors: DescriptorsSource.create(descriptors, fail)
metadata: Descriptors.slotValue("metadata")
register: Descriptors.slotValue("register")
make: Descriptors.slotValue("make")
scalar: Descriptors.slotValue("scalar")
isRegistered: Descriptors.slotValue("isRegistered")
isStorageLayout: Descriptors.slotValue("isStorageLayout")
storage: Descriptors.slotValue("storage")
isR1OrScalar: Descriptors.slotValue("isR1OrScalar")
isTypedPointer: Descriptors.slotValue("isTypedPointer")
isPointerResult: Descriptors.slotValue("isPointerResult")
isGroup: Descriptors.slotValue("isGroup")
isReturnDeclaration: Descriptors.slotValue("isReturnDeclaration")
isParameterDeclaration: Descriptors.slotValue("isParameterDeclaration")
isOutTarget: Descriptors.slotValue("isOutTarget")
voidDescriptor: scalar("void", null, null)
/// Immutable void return descriptor; calls without outputs answer null.
this.void: voidDescriptor
/// Immutable signed 8-bit Integer descriptor; inputs must fit exactly.
this.i8: scalar("i8", 1, 1)
/// Immutable unsigned 8-bit Integer descriptor; inputs must fit exactly.
this.u8: scalar("u8", 1, 1)
/// Immutable signed 16-bit Integer descriptor; inputs must fit exactly.
this.i16: scalar("i16", 2, 2)
/// Immutable unsigned 16-bit Integer descriptor; inputs must fit exactly.
this.u16: scalar("u16", 2, 2)
i32Descriptor: scalar("i32", 4, 4)
/// Immutable signed 32-bit Integer descriptor; inputs must fit exactly.
this.i32: i32Descriptor
/// Immutable unsigned 32-bit Integer descriptor; inputs must fit exactly.
this.u32: scalar("u32", 4, 4)
i64Descriptor: scalar("i64", 8, 8)
/// Immutable signed 64-bit Integer descriptor; inputs must fit exactly.
this.i64: i64Descriptor
/// Immutable unsigned 64-bit Integer descriptor; inputs must fit exactly.
this.u64: scalar("u64", 8, 8)
/// Immutable IEEE binary32 descriptor; a Float input is rounded once to binary32.
this.f32: scalar("f32", 4, 4)
f64Descriptor: scalar("f64", 8, 8)
/// Immutable IEEE binary64 Float descriptor; no Integer coercion is performed.
this.f64: f64Descriptor
sizeTDescriptor: scalar("sizeT", 8, 8)
/// Immutable unsigned 64-bit Integer descriptor for the initial LP64 profile.
this.sizeT: sizeTDescriptor
/// Immutable input-only strict UTF-8 String descriptor; interior NUL is rejected.
this.utf8z: scalar("utf8z", null, null)
// ---- declarative layouts (pure Protos metadata; no provider, no native memory)
maxLayoutSize: 9223372036854775807
pointerSize: 8
LayoutsSource: import("./internal/Layouts.protos")
Layouts: LayoutsSource.create(descriptors, fail, isRegistered, isStorageLayout, maxLayoutSize, metadata, pointerSize, register, requireString, storage, voidDescriptor)
requireArity: Layouts.slotValue("requireArity")
requirePositive: Layouts.slotValue("requirePositive")
requireNonnegative: Layouts.slotValue("requireNonnegative")
checkedSize: Layouts.slotValue("checkedSize")
checkedAdd: Layouts.slotValue("checkedAdd")
checkedMultiply: Layouts.slotValue("checkedMultiply")
alignUp: Layouts.slotValue("alignUp")
/// Declare a named member of a struct or union. Any String is a field name.
this.field: Layouts.slotValue("field")
admitFields: Layouts.slotValue("admitFields")
member: Layouts.slotValue("member")
aggregate: Layouts.slotValue("aggregate")
/// Declare a C struct: source-ordered members with internal and tail padding.
this.struct: Layouts.slotValue("struct")
/// Declare a C union: every member at offset zero, no active-member tag.
this.union: Layouts.slotValue("union")
/// Declare a fixed C array of a positive exact count; storage is not allocated.
this.array: Layouts.slotValue("array")
/// Declare a typed C data pointer to a storage layout or to FFI.void.
/// The declaration is descriptive only: it carries no address.
this.pointer: Layouts.slotValue("pointer")
/// Declare a borrowed result of a plain typed pointer: admitted only as a
/// return or out target. Each result is valid until the next call not
/// declared preserving, a release, or the end of the native session.
this.borrowedPointer: Layouts.slotValue("borrowedPointer")
/// Exact native byte size of a storage layout.
this.sizeOf: Layouts.slotValue("sizeOf")
/// Exact native alignment of a storage layout.
this.alignOf: Layouts.slotValue("alignOf")
/// Byte offset reached by an Array path of field names and array indices.
/// Pointers are never dereferenced; an empty path answers zero.
this.offsetOf: Layouts.slotValue("offsetOf")
// The session context, acquired on the first operation that needs the
// provider. It verifies the platform but opens no library.
providerContext: () => {
if(nativeContext === null) {
nativeContext = nativeContextFacility.acquire()
}
nativeContext
}
// The canonical provider descriptor of one exact pointee layout, created on
// first use through an authorized library or the session context and reused
// by every library of this session and by native regions. Distinct pointee
// layouts never share a descriptor.
NativeTypesSource: import("./internal/NativeTypes.protos")
NativeTypes: NativeTypesSource.create(Interop, fail, isGroup, layouts, metadata, operation, pointerTypes, providerContext, storage, storages, voidDescriptor)
pointerType: NativeTypes.slotValue("pointerType")
physical: NativeTypes.slotValue("physical")
nativeType: NativeTypes.slotValue("nativeType")
BindingsSource: import("./internal/Bindings.protos")
Bindings: BindingsSource.create(Arrays, Interop, fail, isGroup, isOutTarget, isParameterDeclaration, isReturnDeclaration, make, metadata, nativeType, operation, owners, pointerType, providerContext, register, requireArity, requireString, voidDescriptor, () => nativeContext)
/// Declare a logical opaque reference type in the supplied authorized library.
this.opaque: Bindings.slotValue("opaque")
AssociationsSource: import("./internal/Associations.protos")
Associations: AssociationsSource.create(associations, fail, isOrdinaryObject, requireArity, storage)
/// Associate an exact ordinary prototype with an exact storage layout and
/// answer the prototype. Repeating the same association is idempotent; a
/// different layout for an already associated prototype is an Error. The
/// prototype is neither mutated nor invoked.
this.prototype: Associations.slotValue("prototype")
/// The exact layout associated with this exact prototype; no delegation lookup.
this.layoutOf: Associations.slotValue("layoutOf")
/// Admit null in addition to a plain opaque descriptor or typed pointer.
this.nullable: Bindings.slotValue("nullable")
/// Declare result custody with a destructor returning void or i32.
/// This declaration resolves the destructor; it does not acquire a resource.
this.owned: Bindings.slotValue("owned")
/// Declare a zero-initialized output position, consuming no call argument.
this.out: Bindings.slotValue("out")
publish: Bindings.slotValue("publish")
declareBinding: Bindings.slotValue("declareBinding")
/// Bind a trusted ABI declaration and answer a fresh ordinary Closure.
/// Parameters are snapshotted. Results with outs are fresh ordinary Arrays
/// ordered [nativeReturn, out0, ...]; a C error status remains ordinary data.
/// A struct or union parameter takes a live region of that exact layout,
/// copied for the call; a struct or union return or out answers a fresh
/// independently owned region, released with FFI.release.
this.bind: Bindings.slotValue("bind")
/// Like bind, with the trusted declaration that the C function leaves earlier
/// borrowed native regions valid; such calls do not revoke them.
this.bindPreserving: Bindings.slotValue("bindPreserving")
releaseOwned: Bindings.slotValue("releaseOwned")
/// Retire an owned handle before attempting its destructor, without retries.
/// Answers the exact native destructor result, including an error status.
/// An allocated native region root is retired, revoking every view, slice
/// and pointer derived from it, and its storage freed; that answers null.
this.release: Bindings.slotValue("release")
/// Answer a pointer capability without an Integer address. For a live owned
/// C handle of this module: a pass-only void pointer that retains the handle
/// (which keeps its custody, destructor and release). For a live native
/// region or view: a pointer to its exact layout (void for a byte slice)
/// with its known extent, its permission and its provenance, and no
/// destructor authority.
this.addressOf: Bindings.slotValue("addressOf")
// ---- native memory (RootActor provider session; no C library is acquired)
// Exact C spellings of the LP64 profile -> the existing descriptor singletons.
cTypes: DescriptorsSource.aliases(i32Descriptor, i64Descriptor, sizeTDescriptor, f64Descriptor)
MemorySource: import("./internal/Memory.protos")
Memory: MemorySource.create(cTypes, checkedAdd, checkedSize, fail, nativeContextFacility, operation, owners, physical, providerContext, requireArity, requirePositive, requireString, storage)
/// The exact existing descriptor of a supported C type spelling: "int",
/// "long", "long long", "size_t" or "double". Any other String is an Error.
/// The native platform is verified; no library is acquired or called.
this.cType: Memory.slotValue("cType")
allocateRoot: Memory.slotValue("allocateRoot")
/// Allocate zero-initialized native storage of exactly a storage layout's
/// size and alignment, independently owned until FFI.release. Answers a
/// typed native region indexed by field name or element position.
this.allocate: Memory.slotValue("allocate")
/// A non-owning byte view (indexed as u8) of byteLength bytes starting at
/// byteOffset of a live region; nothing is copied and nothing is extended.
/// An empty view (byteLength 0) is admitted and has no valid index.
this.slice: Memory.slotValue("slice")
/// A borrowed typed region of a storage layout over a live pointer whose
/// known extent covers it, natively aligned, whose pointee is that exact
/// layout or void. A pointer of unknown extent is never viewed.
this.view: Memory.slotValue("view")
/// A bounded pointer for byteLength bytes at pointer, with access "read" or
/// "readWrite", anchored by: a live allocation root containing the whole
/// range, a live owned C handle of this module, the pointer itself when it
/// is borrowed, or an authorized library facade for its static storage.
/// Assertions over C storage are trusted, not proven; none widens a known
/// extent, upgrades a read-only pointer or revives an expired one.
this.assumeExtent: Memory.slotValue("assumeExtent")
// ---- explicit aggregate projection to and from ordinary Maps and Arrays
ProjectionPlanSource: import("./internal/ProjectionPlan.protos")
ProjectionPlan: ProjectionPlanSource.create(Arrays, descriptors, fail, isGroup, isRegistered, layouts, operation, providerContext, register, requireArity, requireNonnegative, requireString, storage)
/// Declare the explicit member selection of the union reached by an Array
/// path of member names (Strings) and array indices (non-negative Integers);
/// the empty path names a root union. The path is copied and frozen. The
/// declaration is checked against a concrete layout only when it is used; it
/// is never an ABI descriptor and acquires no provider.
this.unionArm: ProjectionPlan.slotValue("unionArm")
requireMap: ProjectionPlan.slotValue("requireMap")
samePath: ProjectionPlan.slotValue("samePath")
admitArms: ProjectionPlan.slotValue("admitArms")
selectArm: ProjectionPlan.slotValue("selectArm")
slots: ProjectionPlan.slotValue("slots")
selectedPosition: ProjectionPlan.slotValue("selectedPosition")
plan: ProjectionPlan.slotValue("plan")
projectionPlan: ProjectionPlan.slotValue("projectionPlan")
projectionLayout: ProjectionPlan.slotValue("projectionLayout")
// A leaf is the existing indexed read of the original region; a nested group
// is read through the existing non-owning nested view of that region.
ProjectionSource: import("./internal/Projection.protos")
Projection: ProjectionSource.create(allocateRoot, fail, operation, projectionLayout, projectionPlan, providerContext, releaseOwned, requireArity, requireMap, requireString, slots, storage)
readGroup: Projection.slotValue("readGroup")
/// Read a live struct or union region into fresh ordinary containers: a Map
/// per struct, a Map holding only the selected member per union, an Array per
/// fixed array. Scalars are copied by value; pointer members stay pointer
/// capabilities and are not dereferenced. `arms` selects every reached union.
this.readFields: Projection.slotValue("readFields")
captureGroup: Projection.slotValue("captureGroup")
writeGroup: Projection.slotValue("writeGroup")
commitPrepared: Projection.slotValue("commitPrepared")
/// Write fresh ordinary containers into a live writable struct or union
/// region and answer the region. `fields` must match the selected shape
/// exactly. Every selection and value is admitted before the destination is
/// changed: a rejected write leaves every destination byte unchanged. Bytes
/// outside the written members, padding included, keep their contents. The
/// write is not atomic with respect to concurrently running C code.
this.writeFields: Projection.slotValue("writeFields")
// ---- ordinary object snapshots of an exactly associated prototype
// The projected values of `readGroup` as ordinary objects: a fresh object of
// `parentPrototype` per struct or union, created by the ordinary literal
// (no call, construct or init), and a fresh Array per fixed array. The bound
// `createSlot` is extracted once, before any field is inserted, so a field
// named `createSlot` shadows it only for later senders.
ObjectProjectionSource: import("./internal/ObjectProjection.protos")
ObjectProjection: ObjectProjectionSource.create(associations, captureGroup, commitPrepared, fail, isOrdinaryObject, projectionLayout, projectionPlan, readGroup, requireArity, requireCanonicalMethod, slots, storage)
snapshotGroup: ObjectProjection.slotValue("snapshotGroup")
snapshotValue: ObjectProjection.slotValue("snapshotValue")
/// Read a live struct or union region into a fresh open ordinary object whose
/// immediate parent is `prototype`, exactly associated with the region's
/// layout. Its local slots are exactly the projected member names; nested
/// structs and unions are ordinary objects of Object and fixed arrays are
/// Arrays. `arms` selects every reached union. The object owns no native
/// memory; prototype's call, construct and init are never invoked.
this.readAs: ObjectProjection.slotValue("readAs")
captureSlots: ObjectProjection.slotValue("captureSlots")
captureSlotValue: ObjectProjection.slotValue("captureSlotValue")
/// Write the local slots of an ordinary object into a live writable struct or
/// union region and answer the region. The object's immediate parent, observed
/// through the canonical `parent`, must be exactly associated with the
/// region's layout; members are read through the canonical `slotValue` as
/// local slots only. Every value is admitted before the destination changes,
/// exactly as writeFields admits it.
this.writeFrom: ObjectProjection.slotValue("writeFrom")