Skip to documentation
SLOP

tiny.chant.ast.expr

Reference tiny.chant ast expr

Defined in ast.

API (16)

Types and contracts

Public types and contracts.

No direct callersNo direct callsastexpr
Static calls · unresolved targets: unknown · external targets: unknown.

Source

Source: lib/chant/src/ast/expr.zig

zig
const std = @import("std");const types = @import("type/root.zig");pub const BinaryOp = enum {    add,    sub,    mul,    div,    rem,    lt,    gt,    le,    ge,    eq,    ne,    logical_and,    logical_or,    bit_and,    bit_or,    bit_xor,    shl,    shr,};pub const UnaryOp = enum {    negate,    logical_not,    bit_not,    address_of,    deref,};pub const IntegerLiteral = struct {    value: u64,    type: *const types.Type,};pub const FloatLiteral = struct {    value: f64,    type: *const types.Type,};pub const StringLiteral = struct {    text: []const u8,};pub const Identifier = struct {    name: []const u8,};pub const Binary = struct {    op: BinaryOp,    lhs: *Expr,    rhs: *Expr,};pub const Unary = struct {    op: UnaryOp,    operand: *Expr,};pub const Assign = struct {    op: ?BinaryOp,    target: *Expr,    value: *Expr,};pub const Conditional = struct {    condition: *Expr,    then_value: *Expr,    else_value: *Expr,};pub const Call = struct {    callee: []const u8,    arguments: []*Expr,};pub const Index = struct {    base: *Expr,    subscript: *Expr,};pub const Cast = struct {    target: *const types.Type,    operand: *Expr,};pub const InitializerItem = struct {    designator: []const u64 = &.{},    value: *Expr,};pub const InitializerList = struct {    type: *const types.Type,    items: []InitializerItem,};pub const Expr = union(enum) {    integer_literal: IntegerLiteral,    float_literal: FloatLiteral,    string_literal: StringLiteral,    identifier: Identifier,    binary: Binary,    unary: Unary,    assign: Assign,    conditional: Conditional,    call: Call,    index: Index,    cast: Cast,    initializer_list: InitializerList,};test "expressions compose as arena nodes" {    var arena = std.heap.ArenaAllocator.init(std.testing.allocator);    defer arena.deinit();    const allocator = arena.allocator();    const lhs = try allocator.create(Expr);    lhs.* = .{ .identifier = .{ .name = "i" } };    const rhs = try allocator.create(Expr);    rhs.* = .{ .integer_literal = .{ .value = 1, .type = &types.int_type } };    const sum = try allocator.create(Expr);    sum.* = .{ .binary = .{ .op = .add, .lhs = lhs, .rhs = rhs } };    try std.testing.expectEqual(BinaryOp.add, sum.binary.op);    try std.testing.expectEqualStrings("i", sum.binary.lhs.identifier.name);}

Source: lib/chant/src/ast/root.zig:2

zig
pub const expr = @import("expr.zig");

Audit

Definitions17
Public names18
Members62
Version26.7.0
Revisiondaab053ee433