Skip to content

Anything

IsaacShelton edited this page Nov 16, 2022 · 7 revisions

Anything

Anything represents the type of a value that can be anything at runtime.

Specifications

Type Size Possible Values Memory Management Model File
Anything 32 bytes Everything Ownership 2.7/Anything.adept

Definition

struct Anything (struct Any, ownership Ownership, defer_func func(ptr) void)

where Any is defined as

struct Any (type *AnyType, placeholder ulong)

Fields

Name Type Description
type *AnyType Pointer to type information
placeholder ulong 64-bits used either for value of primitive or for pointer to non-primitive
ownership Ownership Whether responsible for cleanup
defer_func func(ptr) void __defer__ function of held value. Can be null.

Value Management Definitions

  • func __defer__(this *Anything) void

    Calls this.defer_func if it isn't null. Used to deconstruct objects that require it.

    [view src]

  • func __assign__(this *Anything, other POD Anything) void

    Transfers ownership of values with this.ownership == Ownership::GIVEN, otherwise assigns self to be a weak reference to the data of other.

    [view src]

  • func __pass__(anything POD Anything) Anything

    Transfers ownership of values with this.ownership == Ownership::GIVEN to be Ownership::OWN, otherwise if the passed value doesn't have this.ownership == Ownership::OWN, then a value will be returned with a weak reference to data of the passed value.

    [view src]

Memory Management

Anything values are automatically freed when they run out of scope and have ownership.

Functions

  • func Anything(primitive $T~__primitive__) Anything

    Constructs an Anything containing a primitive value

    [view src]

  • func Anything(pointer *$T) Anything

    Constructs an Anything containing a pointer to a value

    [view src]

  • func Anything(thing POD $T) Anything

    Constructs an Anything containing a new zero-initialized value of type $T and then assigns thing to the new contained value

    [view src]

  • func AnythingFromAny(any Any) Anything

    Constructs an Anything from an Any by weakly referencing the data referenced in the Any

    [view src]

  • func Anything(data ptr, type *AnyType, ownership Ownership, __defer__ func(ptr) void) Anything

    Constructs an Anything from individual fields

    [view src]

Methods

  • func set(this *Anything, object *$T, ownership Ownership) void

    Sets an Anything to an object. If the supplied ownership is Ownership::OWN or Ownership::GIVEN, then the Anything will gain ownership of the heap-allocated memory pointed to by object and responsibility for __defer__. Otherwise, the Anything will weakly reference the data pointed to by object.

    [view src]

  • func set(this *Anything, data ptr, type *AnyType, ownership Ownership, defer_func func(ptr) void) void

    Sets an Anything to an object. If the supplied ownership is Ownership::OWN or Ownership::GIVEN, then the Anything will gain ownership of the heap-allocated memory pointed to by object and responsibility for __defer__. Otherwise, the Anything will weakly reference the data pointed to by object. The __defer__ method must be manually specified as defer_func and may be null.

    [view src]

  • func commit(this *Anything) Anything

    Changes the ownership of an Anything to be Ownership::REFERENCE. If the Anything previously had ownership, then an Anything value will be returned with Ownership::GIVEN, otherwise the original Anything will be returned. This method is used for transferring ownership of internal data of Anything values to other Anything values.

    [view src]

  • func donate(this *Anything) Anything

    If the Anything has ownership, then the subject's ownership will be changed to Ownership::DONOR and an Anything value will be returned with Ownership::GIVEN, otherwise the original Anything will be returned. This method is used for transferring ownership of internal data of Anything values to other Anything values. If ownership was transferred, then the subject value will be completely invalidated and will be unable to be used afterwards.

    [view src]

Notes

Clone this wiki locally