duskphantom_frontend/ir/expr.rs
1// Copyright 2024 Duskphantom Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//
15// SPDX-License-Identifier: Apache-2.0
16
17use super::*;
18
19/// A term that can be evaluated.
20/// Example: `f("224")`
21#[derive(Clone, PartialEq, Debug)]
22pub enum Expr {
23 /// A single variable.
24 /// Example: `x`
25 Var(String),
26
27 /// An array, union or struct.
28 /// Example: `{ 1, 2, 3 }`
29 Array(Vec<Expr>),
30
31 /// Array indexing.
32 /// Example: `x[8]`
33 Index(Box<Expr>, Box<Expr>),
34
35 /// A single 32-bit integer.
36 /// Example: `8`
37 Int(i32),
38
39 /// A single-precision floating-point number.
40 /// Example: `3.6`
41 Float(f32),
42
43 /// A string literal.
44 /// Example: `"good"`
45 String(String),
46
47 /// A boolean literal.
48 /// Example: `false`
49 Bool(bool),
50
51 /// A function call.
52 /// Example: `f(x, y)`
53 Call(Box<Expr>, Vec<Expr>),
54
55 /// Application of unary operator.
56 /// Example: `!false`, `x++`
57 Unary(UnaryOp, Box<Expr>),
58
59 /// Application of binary operator.
60 /// Example: `a + b`
61 Binary(Box<Expr>, Vec<(BinaryOp, Expr)>),
62
63 /// Zero initializer.
64 /// Example: `zeroinitializer`
65 Zero(Box<Type>),
66}