-
-
Notifications
You must be signed in to change notification settings - Fork 9
Anything
Anything represents the type of a value that can be anything at runtime.
| Type | Size | Possible Values | Memory Management Model | File |
|---|---|---|---|---|
Anything |
32 bytes | Everything | Ownership | 2.7/Anything.adept |
struct Anything (struct Any, ownership Ownership, defer_func func(ptr) void)
where Any is defined as
struct Any (type *AnyType, placeholder ulong)
| 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. |
-
func __defer__(this *Anything) voidCalls
this.defer_funcif it isn'tnull. Used to deconstruct objects that require it. -
func __assign__(this *Anything, other POD Anything) voidTransfers ownership of values with
this.ownership == Ownership::GIVEN, otherwise assigns self to be a weak reference to the data ofother. -
func __pass__(anything POD Anything) AnythingTransfers ownership of values with
this.ownership == Ownership::GIVENto beOwnership::OWN, otherwise if the passed value doesn't havethis.ownership == Ownership::OWN, then a value will be returned with a weak reference to data of the passed value.
Anything values are automatically freed when they run out of scope and have ownership.
-
func Anything(primitive $T~__primitive__) AnythingConstructs an
Anythingcontaining a primitive value -
func Anything(pointer *$T) AnythingConstructs an
Anythingcontaining a pointer to a value -
func Anything(thing POD $T) AnythingConstructs an
Anythingcontaining a new zero-initialized value of type$Tand then assignsthingto the new contained value -
func AnythingFromAny(any Any) AnythingConstructs an
Anythingfrom anAnyby weakly referencing the data referenced in theAny -
func Anything(data ptr, type *AnyType, ownership Ownership, __defer__ func(ptr) void) AnythingConstructs an
Anythingfrom individual fields
-
func set(this *Anything, object *$T, ownership Ownership) voidSets an
Anythingto an object. If the suppliedownershipisOwnership::OWNorOwnership::GIVEN, then theAnythingwill gain ownership of the heap-allocated memory pointed to byobjectand responsibility for__defer__. Otherwise, theAnythingwill weakly reference the data pointed to byobject. -
func set(this *Anything, data ptr, type *AnyType, ownership Ownership, defer_func func(ptr) void) voidSets an
Anythingto an object. If the suppliedownershipisOwnership::OWNorOwnership::GIVEN, then theAnythingwill gain ownership of the heap-allocated memory pointed to byobjectand responsibility for__defer__. Otherwise, theAnythingwill weakly reference the data pointed to byobject. The__defer__method must be manually specified asdefer_funcand may be null. -
func commit(this *Anything) AnythingChanges the ownership of an
Anythingto beOwnership::REFERENCE. If theAnythingpreviously had ownership, then anAnythingvalue will be returned withOwnership::GIVEN, otherwise the originalAnythingwill be returned. This method is used for transferring ownership of internal data ofAnythingvalues to otherAnythingvalues. -
func donate(this *Anything) AnythingIf the
Anythinghas ownership, then the subject's ownership will be changed toOwnership::DONORand anAnythingvalue will be returned withOwnership::GIVEN, otherwise the originalAnythingwill be returned. This method is used for transferring ownership of internal data ofAnythingvalues to otherAnythingvalues. If ownership was transferred, then the subject value will be completely invalidated and will be unable to be used afterwards.
- This file requires runtime type information