Skip to main content

Node

Enum Node 

Source
pub enum Node {
Show 16 variants Literal { id: NodeId, node_type: Type, value: LiteralValue, }, Param { id: NodeId, name: String, index: u32, node_type: Type, }, Let { id: NodeId, name: String, node_type: Type, value: Box<Node>, body: Box<Node>, }, If { id: NodeId, node_type: Type, cond: Box<Node>, then_branch: Box<Node>, else_branch: Box<Node>, }, Call { id: NodeId, node_type: Type, target: String, args: Vec<Node>, }, Return { id: NodeId, node_type: Type, value: Box<Node>, }, BinOp { id: NodeId, op: BinOpKind, node_type: Type, lhs: Box<Node>, rhs: Box<Node>, }, UnaryOp { id: NodeId, op: UnaryOpKind, node_type: Type, operand: Box<Node>, }, Block { id: NodeId, node_type: Type, statements: Vec<Node>, result: Box<Node>, }, Loop { id: NodeId, node_type: Type, body: Box<Node>, }, Match { id: NodeId, node_type: Type, scrutinee: Box<Node>, arms: Vec<MatchArm>, }, StructLiteral { id: NodeId, node_type: Type, fields: Vec<(String, Node)>, }, FieldAccess { id: NodeId, node_type: Type, object: Box<Node>, field: String, }, ArrayLiteral { id: NodeId, node_type: Type, elements: Vec<Node>, }, IndexAccess { id: NodeId, node_type: Type, array: Box<Node>, index: Box<Node>, }, Error { id: NodeId, message: String, },
}
Expand description

The core IR node enum. Each variant represents a different kind of computation in the AIRL intermediate representation.

Nodes are serialized to/from JSON with a "kind" discriminator field.

All variants share:

  • id — unique NodeId for patch targeting
  • node_type — the Type this node evaluates to (except for Node::Error)

Variants§

§

Literal

A literal value (integer, float, bool, string, unit).

Fields

§node_type: Type
§

Param

Reference to a function parameter or let-bound local variable.

Fields

§name: String
§index: u32
§node_type: Type
§

Let

let name = value in body — introduces a local binding.

Fields

§name: String
§node_type: Type
§value: Box<Node>
§body: Box<Node>
§

If

if cond then then_branch else else_branch.

Fields

§node_type: Type
§cond: Box<Node>
§then_branch: Box<Node>
§else_branch: Box<Node>
§

Call

A function call. target is a name (user-defined or builtin like std::io::println).

Fields

§node_type: Type
§target: String
§args: Vec<Node>
§

Return

return value — early exit from a function.

Fields

§node_type: Type
§value: Box<Node>
§

BinOp

Binary operator application (lhs op rhs). See BinOpKind.

Fields

§node_type: Type
§lhs: Box<Node>
§rhs: Box<Node>
§

UnaryOp

Unary operator application (op operand). See UnaryOpKind.

Fields

§node_type: Type
§operand: Box<Node>
§

Block

A sequence of statements followed by a result expression.

Fields

§node_type: Type
§statements: Vec<Node>
§result: Box<Node>
§

Loop

Infinite loop — exit only via Return or internal LoopBreak.

Fields

§node_type: Type
§body: Box<Node>
§

Match

Pattern match. Evaluates scrutinee, then the first matching arm’s body.

Fields

§node_type: Type
§scrutinee: Box<Node>
§

StructLiteral

Struct literal: { field1: v1, field2: v2 }.

Fields

§node_type: Type
§fields: Vec<(String, Node)>
§

FieldAccess

Access a struct field: object.field.

Fields

§node_type: Type
§object: Box<Node>
§field: String
§

ArrayLiteral

Array literal: [e1, e2, e3].

Fields

§node_type: Type
§elements: Vec<Node>
§

IndexAccess

Array index access: array[index].

Fields

§node_type: Type
§array: Box<Node>
§index: Box<Node>
§

Error

An explicit error node, used as a placeholder when parsing fails.

Fields

§message: String

Implementations§

Source§

impl Node

Source

pub fn id(&self) -> &NodeId

Get the NodeId of this node.

Source

pub fn node_type(&self) -> Option<&Type>

Get the type of this node (if it has one).

Trait Implementations§

Source§

impl Clone for Node

Source§

fn clone(&self) -> Node

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Node

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Node

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Node

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Node

Source§

fn eq(&self, other: &Node) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Node

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Node

Auto Trait Implementations§

§

impl Freeze for Node

§

impl RefUnwindSafe for Node

§

impl Send for Node

§

impl Sync for Node

§

impl Unpin for Node

§

impl UnsafeUnpin for Node

§

impl UnwindSafe for Node

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,