ast.rs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /* This file is part of DarkFi (https://dark.fi)
  2. *
  3. * Copyright (C) 2020-2024 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. use super::{LitType, Opcode, VarType};
  19. #[derive(Clone, Debug)]
  20. pub struct Constant {
  21. pub name: String,
  22. pub typ: VarType,
  23. pub line: usize,
  24. pub column: usize,
  25. }
  26. #[derive(Clone, Debug)]
  27. pub struct Witness {
  28. pub name: String,
  29. pub typ: VarType,
  30. pub line: usize,
  31. pub column: usize,
  32. }
  33. #[derive(Clone, Debug)]
  34. pub struct Variable {
  35. pub name: String,
  36. pub typ: VarType,
  37. pub line: usize,
  38. pub column: usize,
  39. }
  40. #[derive(Clone, Debug)]
  41. pub struct Literal {
  42. pub name: String,
  43. pub typ: LitType,
  44. pub line: usize,
  45. pub column: usize,
  46. }
  47. #[derive(Debug)]
  48. pub enum Var {
  49. Constant(Constant),
  50. Witness(Witness),
  51. Variable(Variable),
  52. }
  53. #[derive(Clone, Debug)]
  54. pub enum Arg {
  55. Var(Variable),
  56. Lit(Literal),
  57. Func(Statement),
  58. }
  59. #[derive(Copy, Clone, PartialEq, Eq, Debug)]
  60. #[repr(u8)]
  61. pub enum StatementType {
  62. Noop = 0x00,
  63. Assign = 0x01,
  64. Call = 0x02,
  65. }
  66. #[derive(Clone, Debug)]
  67. pub struct Statement {
  68. pub typ: StatementType,
  69. pub opcode: Opcode,
  70. pub lhs: Option<Variable>,
  71. pub rhs: Vec<Arg>,
  72. pub line: usize,
  73. }
  74. impl Default for Statement {
  75. fn default() -> Self {
  76. Self { typ: StatementType::Noop, opcode: Opcode::Noop, lhs: None, rhs: vec![], line: 0 }
  77. }
  78. }