All expressions have a value category. In C-like languages, the two main value categories are usually lvalue
and rvalue
. In Panther, there are also two main categories: concrete
and ephemeral
. These are very similar to lvalue
and rvalue
respectively, but they are different enough that it warranted new names.
Ephemeral values are very similar to rvalue
values. Ephemeral values are any values that do not have storage. This means they cannot be assigned to nor can the address of them be gotten. Ephemeral values are not necessarily explicitly typed as fluid literals
are ephemeral.
The following are ephemeral expressions:
literals
def variables
Concrete values are similar to lvalue
values. Concrete values are any value that have storage. An important difference between concrete values lvalue
values is that ephemeral values cannot be used as an assignment value. The correct way to use a concrete value as an assignment value is with an operator copy
, a operator move
, or a operator destructive move
. There are three subcategories of concrete values: concrete-mutable
, concrete-const
, and destructive-movable-concrete-const
Concrete-mutable values are values that are concrete
and mutable.
The following are concrete-mutable expressions:
var variables
dereference
of a non-read-only pointermut parameters
unwrap
of a non-const optional
accessor
of a concrete-mutable valueConcrete-forwardable values are values that are concrete
, and mutable. Concrete-forwardable is the only value category that is allowed to be argument of an operator forward
.
The following are concrete-forwardable expressions:
in parameters
Concrete-const values are values that are concrete
and non-mutable. Mutating a concrete-const value is undefined behavior
.
The following are concrete-const expressions:
const variables
in global scope scoperead parameters
dereference
of a read-only pointeraccessor
of a concrete-const valueDestructive-movable-concrete-const values are values that are concrete
and only mutable by operator destructive move
. Mutating a destructive-movable-concrete-const value in any way other than operator destructive move
is undefined behavior
.
The following are destructive-movable-concrete-const expressions:
const variables
in function scopeunwrap
of a const optional