darkfi/zkas/
ast.rs

1/* This file is part of DarkFi (https://dark.fi)
2 *
3 * Copyright (C) 2020-2026 Dyne.org foundation
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Affero General Public License as
7 * published by the Free Software Foundation, either version 3 of the
8 * License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 * GNU Affero General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
17 */
18
19use super::{LitType, Opcode, VarType};
20
21#[derive(Clone, Debug)]
22pub struct Constant {
23    pub name: String,
24    pub typ: VarType,
25    pub line: usize,
26    pub column: usize,
27}
28
29#[derive(Clone, Debug)]
30pub struct Witness {
31    pub name: String,
32    pub typ: VarType,
33    pub line: usize,
34    pub column: usize,
35}
36
37#[derive(Clone, Debug)]
38pub struct Variable {
39    pub name: String,
40    pub typ: VarType,
41    pub line: usize,
42    pub column: usize,
43}
44
45#[derive(Clone, Debug)]
46pub struct Literal {
47    pub name: String,
48    pub typ: LitType,
49    pub line: usize,
50    pub column: usize,
51}
52
53#[derive(Debug)]
54pub enum Var {
55    Constant(Constant),
56    Witness(Witness),
57    Variable(Variable),
58}
59
60#[derive(Clone, Debug)]
61pub enum Arg {
62    Var(Variable),
63    Lit(Literal),
64    Func(Statement),
65}
66
67#[derive(Copy, Clone, PartialEq, Eq, Debug)]
68#[repr(u8)]
69pub enum StatementType {
70    Noop = 0x00,
71    Assign = 0x01,
72    Call = 0x02,
73}
74
75#[derive(Clone, Debug)]
76pub struct Statement {
77    pub typ: StatementType,
78    pub opcode: Opcode,
79    pub lhs: Option<Variable>,
80    pub rhs: Vec<Arg>,
81    pub line: usize,
82}
83
84impl Default for Statement {
85    fn default() -> Self {
86        Self { typ: StatementType::Noop, opcode: Opcode::Noop, lhs: None, rhs: vec![], line: 0 }
87    }
88}