Object
Module
Defines the object type, which is used to represent untyped values.
Attr
A generic object’s attributes are set on construction, after which the attributes can be read and modified, but no attributes may be removed or added.
Fields:
key
The name of the attribute.
value
The value of the attribute.
Functions:
__init__
__init__(self: Self&, key: StringLiteral, value: object)
Initialize the attribute with a key and value.
Args:
- key (
StringLiteral
): The string literal key. - value (
object
): The object value of the attribute.
object
Represents an object without a concrete type.
This is the type of arguments in def
functions that do not have a type annotation, such as the type of x
in def f(x): pass
. A value of any type can be passed in as the x
argument in this case, and so that value is used to construct this object
type.
Aliases:
binary_function = fn(object, object) raises -> object
Binary function type.
nullary_function = fn() raises -> object
Nullary function type.
ternary_function = fn(object, object, object) raises -> object
Ternary function type.
unary_function = fn(object) raises -> object
Unary function type.
Functions:
__init__
__init__(self: Self&)
Initialize the object with a None
value.
__init__(self: Self&, impl: _ObjectImpl)
Initialize the object with an implementation value. This is meant for internal use only.
Args:
- impl (
_ObjectImpl
): The object implementation.
__init__(self: Self&, none: None)
Initialize a none value object from a None
literal.
Args:
- none (
None
): None.
__init__(self: Self&, value: Int)
Initialize the object with an integer value.
Args:
- value (
Int
): The integer value.
__init__(self: Self&, value: FloatLiteral)
Initialize the object with an floating-point value.
Args:
- value (
FloatLiteral
): The float value.
__init__[dt: DType](self: Self&, value: SIMD[dt, 1])
Initialize the object with a generic scalar value. If the scalar value type is bool, it is converted to a boolean. Otherwise, it is converted to the appropriate integer or floating point type.
Parameters:
- dt (
DType
): The scalar value type.
Args:
- value (
SIMD[dt, 1]
): The scalar value.
__init__(self: Self&, value: Bool)
Initialize the object from a bool.
Args:
- value (
Bool
): The boolean value.
__init__(self: Self&, value: StringLiteral)
Initialize the object from a string literal.
Args:
- value (
StringLiteral
): The string value.
__init__(self: Self&, value: StringRef)
Initialize the object from a string reference.
Args:
- value (
StringRef
): The string value.
__init__[*Ts: AnyType](self: Self&, value: ListLiteral[Ts])
Initialize the object from a list literal.
Parameters:
- Ts (
*AnyType
): The list element types.
Args:
- value (
ListLiteral[Ts]
): The list value.
__init__(self: Self&, func: fn() raises -> object)
Initialize an object from a function that takes no arguments.
Args:
- func (
fn() raises -> object
): The function.
__init__(self: Self&, func: fn(object) raises -> object)
Initialize an object from a function that takes one argument.
Args:
- func (
fn(object) raises -> object
): The function.
__init__(self: Self&, func: fn(object, object) raises -> object)
Initialize an object from a function that takes two arguments.
Args:
- func (
fn(object, object) raises -> object
): The function.
__init__(self: Self&, func: fn(object, object, object) raises -> object)
Initialize an object from a function that takes three arguments.
Args:
- func (
fn(object, object, object) raises -> object
): The function.
__init__(self: Self&, *attrs: Attr)
Initialize the object with a sequence of zero or more attributes.
Args:
- attrs (
*Attr
): Zero or more attributes.
__copyinit__
__copyinit__(self: Self&, existing: Self)
Trivially copy the object.
Args:
- existing (
Self
): The value to copy.
__bool__
__bool__(self: Self) -> Bool
Perform conversion to bool according to Python semantics. Integers and floats are true if they are non-zero, and strings and lists are true if they are non-empty.
Returns:
Whether the object is considered true.
__getitem__
__getitem__(self: Self, i: Self) -> Self
Get the i-th item from the object. This is only valid for strings, lists, and dictionaries.
Args:
- i (
Self
): The string or list index, or dictionary key.
Returns:
The value at the index or key.
__getitem__(self: Self, *i: Self) -> Self
Get the i-th item from the object, where i is a tuple of indices.
Args:
- i (
*Self
): A compound index.
Returns:
The value at the index.
__setitem__
__setitem__(self: Self&, i: Self, value: Self) -> None
Set the i-th item in the object. This is only valid for strings, lists, and dictionaries.
Args:
- i (
Self
): The string or list index, or dictionary key. - value (
Self
): The value to set.
__setitem__(self: Self&, i: Self, j: Self, value: Self) -> None
Set the (i, j)-th element in the object.
FIXME: We need this because obj[i, j] = value
will attempt to invoke this method with 3 arguments, and we can only have variadics as the last argument.
Args:
- i (
Self
): The first index. - j (
Self
): The second index. - value (
Self
): The value to set.
__neg__
__neg__(self: Self) -> Self
Negation operator. Only valid for bool, int, and float types. Negation on any bool value converts it to an integer.
Returns:
The negative of the current value.
__invert__
__invert__(self: Self) -> Self
Invert the current value. This is only valid for bool and int values.
Returns:
The inverted value.
__lt__
__lt__(self: Self, rhs: Self) -> Self
Less than comparator. This lexicographically compares strings and lists.
Args:
- rhs (
Self
): Right hand value.
Returns:
True if the object is less than the right hard argument.
__le__
__le__(self: Self, rhs: Self) -> Self
Less than or equal to comparator. This lexicographically compares strings and lists.
Args:
- rhs (
Self
): Right hand value.
Returns:
True if the object is less than or equal to the right hard argument.
__eq__
__eq__(self: Self, rhs: Self) -> Self
Equality comparator. This compares the elements of strings and lists.
Args:
- rhs (
Self
): Right hand value.
Returns:
True if the objects are equal.
__ne__
__ne__(self: Self, rhs: Self) -> Self
Inequality comparator. This compares the elements of strings and lists.
Args:
- rhs (
Self
): Right hand value.
Returns:
True if the objects are not equal.
__gt__
__gt__(self: Self, rhs: Self) -> Self
Greater than comparator. This lexicographically compares the elements of strings and lists.
Args:
- rhs (
Self
): Right hand value.
Returns:
True if the left hand value is greater.
__ge__
__ge__(self: Self, rhs: Self) -> Self
Greater than or equal to comparator. This lexicographically compares the elements of strings and lists.
Args:
- rhs (
Self
): Right hand value.
Returns:
True if the left hand value is greater than or equal to the right hand value.
__add__
__add__(self: Self, rhs: Self) -> Self
Addition and concatenation. For arithmetic types, this function will compute the sum of the left and right hand values. For strings and lists, this function will concat the objects.
Args:
- rhs (
Self
): Right hand value.
Returns:
The sum or concatenated values.
__sub__
__sub__(self: Self, rhs: Self) -> Self
Subtraction. Valid only for arithmetic types.
Args:
- rhs (
Self
): Right hand value.
Returns:
The difference.
__mul__
__mul__(self: Self, rhs: Self) -> Self
Multiplication. Valid only for arithmetic types.
Args:
- rhs (
Self
): Right hand value.
Returns:
The product.
__and__
__and__(self: Self, rhs: Self) -> Self
Bool and. If the left hand value is False, return the left hand value.
Args:
- rhs (
Self
): Right hand value.
Returns:
The current value if it is False.
__or__
__or__(self: Self, rhs: Self) -> Self
Bool and. If the left hand value is True, return the left hand value.
Args:
- rhs (
Self
): Right hand value.
Returns:
The current value if it is True.
__radd__
__radd__(self: Self, lhs: Self) -> Self
Reverse addition or concatenation.
Args:
- lhs (
Self
): Left hand value.
Returns:
The sum or concatenated value.
__rsub__
__rsub__(self: Self, lhs: Self) -> Self
Reverse subtraction.
Args:
- lhs (
Self
): Left hand value.
Returns:
The result of subtracting this from the left-hand-side value.
__rmul__
__rmul__(self: Self, lhs: Self) -> Self
Reverse multiplication.
Args:
- lhs (
Self
): Left hand value.
Returns:
The product.
__rand__
__rand__(self: Self, lhs: Self) -> Self
Reverse and.
Args:
- lhs (
Self
): Left hand value.
Returns:
The bitwise AND of the left-hand-side value and this.
__ror__
__ror__(self: Self, lhs: Self) -> Self
Reverse or.
Args:
- lhs (
Self
): Left hand value.
Returns:
The bitwise OR of the left-hand-side value and this.
__iadd__
__iadd__(self: Self&, rhs: Self) -> None
In-place addition or concatenation.
Args:
- rhs (
Self
): Right hand value.
__isub__
__isub__(self: Self&, rhs: Self) -> None
In-place subtraction.
Args:
- rhs (
Self
): Right hand value.
__imul__
__imul__(self: Self&, rhs: Self) -> None
In-place multiplication.
Args:
- rhs (
Self
): Right hand value.
__iand__
__iand__(self: Self&, rhs: Self) -> None
In-place and.
Args:
- rhs (
Self
): Right hand value.
__ior__
__ior__(self: Self&, rhs: Self) -> None
In-place or.
Args:
- rhs (
Self
): Right hand value.
__call__
__call__(self: Self) -> Self
__call__(self: Self, arg0: Self) -> Self
__call__(self: Self, arg0: Self, arg1: Self) -> Self
__call__(self: Self, arg0: Self, arg1: Self, arg2: Self) -> Self
__getattr__
__getattr__(self: Self, key: StringLiteral) -> Self
__len__
__len__(self: Self) -> Int
Return the “length” of the object. Only strings, lists, and dictionaries have lengths.
Returns:
The length of the string value or the number of elements in the list or dictionary value.
__setattr__
__setattr__(self: Self&, key: StringLiteral, value: Self) -> Self
append
append(self: Self&, value: Self) -> None
List append. Append a value to the list.
Args:
- value (
Self
): The value to append.
copy
copy(self: Self) -> Self
Copy the object. This clones the underlying string value and increases the refcount of lists or dictionaries.
TODO: Change this method to copyinit when lifetimes are nailed down.
Returns:
A copy of the object.
print
print(self: Self)
Print the value of the object.
reset
reset(self: Self&, value: Self)
Destroy the current object and then set it to a new value.
Args:
- value (
Self
): The value to set the object to.
reset_to_none
reset_to_none(self: Self&)
Destruct any memory held by the object and set its value to None
. This is a placeholder until destructors are in place.