Skip to content
← Back

src/semantic/symbols/enum_not_operator.ghul

1
namespace Semantic.Symbols is
2
// Supplies the unary `\` (bitwise complement) operator for an enum
3
// type, mirroring the scalar `\` intrinsics declared in the
4
// runtime's staging namespace (see `intrinsics.ghul`) — the same
5
// reason `ENUM_AND_OPERATOR` and its siblings exist rather than a
6
// single declaration in the runtime: each enum is its own type.
7
//
8
// Unlike `&`/`|`/`^`, this is an `INNATE_FUNCTION` rather than an
9
// `INNATE_METHOD`: unary operator resolution only considers static
10
// operators — a type's own instance operators are deliberately left
11
// out of that route, since a unary static would otherwise be
12
// ambiguous with one taking the operand as a receiver (see
13
// `_static_operator_candidates`/`_takes_receiver` in
14
// `compile_operators.ghul`). So the operand is an explicit argument
15
// rather than the receiver, the same shape the scalar `\` takes.
16
class ENUM_NOT_OPERATOR is
17
register(owner: Classy) static is
18
let type = owner.type
19
20
if !type? then
21
return
22
fi
23
24
let operator =
25
INNATE_FUNCTION(owner.location, owner, "\\", owner, "arithmetic.not")
26
27
operator.argument_names = Collections.LIST[string](["value"])
28
operator.arguments = Collections.LIST[Types.Type]([type])
29
operator.return_type = type
30
31
operator.mark_declared_pure()
32
33
owner.add_member(operator)
34
si
35
si
36
si