Skip to content
Cameron Purdy edited this page Aug 5, 2021 · 4 revisions

In general, the term prefix expression is used to describe a unary operator that precedes an expression. Ecstasy has six operators that it combines into the PrefixExpression construct, and a seventh unary prefix operator, &, that forms the ReferenceExpression. The six operators and expressions for PrefixExpression are well-known expression forms:

+a
-a
!a
~a
++a
--a

Unlike most other expressions, the corresponding internal operations related to these operators are not completely obvious at first:

Op @Op Default method name Description
+ posation[1]
- -# neg negation
! ~ not logical complement
~ ~ not bitwise complement
++ nextValue pre-increment
-- prevValue pre-decrement
  • First, the unary + operator does not do anything past the syntax and type analysis stage of compilation; it is compiled out completely. That is because +n === n for all values of n that are not otherwise a compiler error.

  • Second, the compiler searches for the @Op operator string -# (instead of the obvious -) for the negation operator, because the operator string - is already assigned to the numeric subtraction behavior.

  • Third, there is no operator for !, because it is just syntactic sugar (reserved for the Boolean type) of the more general form, ~.

  • Fourth, neither ++ nor -- are an operator in the simple sense, because they incur an effect on an L-Value. In order to apply either of these operators, the compiler requires that the type of that L-Value be Sequential, which implies the presence of the methods nextValue() and prevValue().

(On a positive note, the seldom-used ~ operator does specify its runtime operator in the normal, predictable manner.)

Despite appearing to be primitive-type operators, Ecstasy has no primitive type system, and the input and output types of these operators are defined entirely by the types against which the operators execute. Specifically, the type of the expression a must have an unambiguously single best operator method (selected by the operator symbol and method name -- or not, as described above). The implicit type of the expression is the return type of the operator method, or in the case of the unary + operator, the implicit type of the expression is the implicit type of a.

Other than the case of the unary + operator, the execution of the expression is an invocation of the selected operator method, against a target reference yielded by the expression a; the result of the expression is the return value from the operator method.

The expression short-circuits if a short-circuits.

The expression uses the default left-to-right definite assignment rules:

  • The VAS before a is the VAS before the expression.
  • The VAS after the expression is the VAS after a.

These expressions group to the left, but combining more than one of these unary operations will result in a career-ending injury.

    PrefixExpression:
        PostfixExpression
        + PrefixExpression
        - PrefixExpression
        ! PrefixExpression
        ~ PrefixExpression
        ++ PrefixExpression
        -- PrefixExpression

[1]

Yes, "posation" is a fake term, which is fitting for a fake operator.