1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
use super::*;
mod display;
/// always equivalent to a statement that returns `( )`, and cannot be used as an `rvalue`.
#[derive(Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ControlNode {
/// The type of control flow
pub kind: ControlKind,
/// In theory, all jumps need a destination
pub label: LabelNode,
/// The label of the control flow
pub expression: Option<ExpressionKind>,
/// The range of the node
pub span: Range<u32>,
}
/// `goto ^label`
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum LabelNode {
/// Find the nearest loop
Nearest,
/// Find the loop with the given label
Named(IdentifierNode),
}
/// The control flow keywords
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum ControlKind {
/// `goto ^label`, equivalent to `call/cc`, can't construct from frontend
Goto,
/// `raise ^label`
Raise,
/// `break ^label`
Break,
/// `continue ^label`, equivalent to `goto`
Continue,
/// `fallthrough ^label`
Fallthrough,
/// `fallthrough! ^label`
FallthroughUnchecked,
/// `return ^LABEL`
Return,
/// `resume ^LABEL`
Resume,
/// `yield ^LABEL`
YieldReturn,
/// `yield break ^LABEL`, `yield! ^LABEL`
YieldBreak,
/// `yield from iterator`, `yield* iterator`
YieldFrom,
/// `let v = yield wait`, `let v = yield?`
YieldSend,
/// `let v = await AWAITABLE`
Await,
/// `await? AWAITABLE`
AwaitNever,
/// `violence { await! AWAITABLE }`
AwaitBlockOn,
}