Jelajahi Sumber

zkas/ast: Introduce literal types.

Luther Blissett 4 tahun lalu
induk
melakukan
9d301fb161
1 mengubah file dengan 28 tambahan dan 50 penghapusan
  1. 28 50
      src/zkas/ast.rs

+ 28 - 50
src/zkas/ast.rs

@@ -1,70 +1,48 @@
-use indexmap::IndexMap;
+use super::{LitType, Opcode, VarType};
 
-use super::{lexer::Token, opcode::Opcode, types::Type};
-
-#[derive(Copy, PartialEq, Eq, Clone, Debug)]
-#[repr(u8)]
-pub enum StatementType {
-    Assignment = 0x00,
-    Call = 0x01,
-    Noop = 0xff,
+pub struct Constant {
+    pub name: String,
+    pub typ: VarType,
+    pub line: usize,
+    pub column: usize,
 }
 
-pub enum Var {
-    Constant(Constant),
-    Witness(Witness),
-    Variable(Variable),
+pub struct Witness {
+    pub name: String,
+    pub typ: VarType,
+    pub line: usize,
+    pub column: usize,
 }
 
-#[derive(Clone, Debug)]
 pub struct Variable {
     pub name: String,
-    pub typ: Type,
+    pub typ: VarType,
     pub line: usize,
     pub column: usize,
 }
 
-#[derive(Clone, Debug)]
-pub struct Statement {
-    pub typ: StatementType,
-    pub variable: Option<Variable>,
-    pub opcode: Opcode,
-    pub args: Vec<Variable>,
+pub struct Literal {
+    pub name: String,
+    pub typ: LitType,
     pub line: usize,
+    pub column: usize,
 }
 
-impl Default for Statement {
-    fn default() -> Self {
-        Statement {
-            typ: StatementType::Noop,
-            variable: None,
-            opcode: Opcode::Noop,
-            args: vec![],
-            line: 0,
-        }
-    }
+pub enum Arg {
+    Var(Variable),
+    Lit(Literal),
 }
 
-pub type UnparsedConstants = IndexMap<String, (Token, Token)>;
-pub type UnparsedWitnesses = IndexMap<String, (Token, Token)>;
-
-pub type Constants = Vec<Constant>;
-pub type Witnesses = Vec<Witness>;
-pub type Variables = Vec<Variable>;
-pub type Statements = Vec<Statement>;
-
-#[derive(Clone, Debug)]
-pub struct Constant {
-    pub name: String,
-    pub typ: Type,
-    pub line: usize,
-    pub column: usize,
+#[repr(u8)]
+pub enum StatementType {
+    Assign = 0x00,
+    Call = 0x01,
 }
 
-#[derive(Clone, Debug)]
-pub struct Witness {
-    pub name: String,
-    pub typ: Type,
+pub struct Statement {
+    pub typ: StatementType,
+    pub opcode: Opcode,
+    pub lhs: Option<Variable>,
+    pub rhs: Vec<Arg>,
     pub line: usize,
-    pub column: usize,
 }