1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
 * AquaVM Workflow Engine
 *
 * Copyright (C) 2024 Fluence DAO
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation version 3 of the
 * License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

mod impls;
mod traits;

use crate::parser::lexer::AirPos;

use air_lambda_parser::LambdaAST;
use serde::Deserialize;
use serde::Serialize;

/// A scalar value without a lambda.
#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
pub struct Scalar<'i> {
    pub name: &'i str,
    pub position: AirPos,
}

/// A scalar value with a lambda expression.
#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
pub struct ScalarWithLambda<'i> {
    pub name: &'i str,
    #[serde(borrow)]
    pub lambda: LambdaAST<'i>,
    pub position: AirPos,
}

/// A stream without a lambda.
#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
pub struct Stream<'i> {
    pub name: &'i str,
    pub position: AirPos,
}

/// A canonicalized stream without a lambda.
#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
pub struct CanonStream<'i> {
    pub name: &'i str,
    pub position: AirPos,
}

/// A canonicalized stream map without a lambda.
#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
pub struct CanonStreamMap<'i> {
    pub name: &'i str,
    pub position: AirPos,
}

/// A canonicalized stream with a lambda.
#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
pub struct CanonStreamWithLambda<'i> {
    pub name: &'i str,
    #[serde(borrow)]
    pub lambda: LambdaAST<'i>,
    pub position: AirPos,
}

/// A canonicalized stream map with a lambda.
#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
pub struct CanonStreamMapWithLambda<'i> {
    pub name: &'i str,
    #[serde(borrow)]
    pub lambda: LambdaAST<'i>,
    pub position: AirPos,
}

/// A variable that could be either scalar or stream without lambda.
#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
pub enum ImmutableVariable<'i> {
    #[serde(borrow)]
    Scalar(Scalar<'i>),
    #[serde(borrow)]
    CanonStream(CanonStream<'i>),
    #[serde(borrow)]
    CanonStreamMap(CanonStreamMap<'i>),
}

/// A variable that could be either scalar or stream with possible lambda expression.
#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
pub enum ImmutableVariableWithLambda<'i> {
    #[serde(borrow)]
    Scalar(ScalarWithLambda<'i>),
    #[serde(borrow)]
    CanonStream(CanonStreamWithLambda<'i>),
    #[serde(borrow)]
    CanonStreamMap(CanonStreamMapWithLambda<'i>),
}

/// A map based on top of a stream.
#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
pub struct StreamMap<'i> {
    pub name: &'i str,
    pub position: AirPos,
}

/// An error wrapper with an optional lens.
#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
pub struct InstructionErrorAST<'lens> {
    #[serde(borrow)]
    pub lens: Option<LambdaAST<'lens>>,
}