mirror of
https://github.com/fluencelabs/aquavm
synced 2025-04-24 23:02:16 +00:00
This PR intended to reduce stream usage scope in order to make AquaVM truly deterministic. Refs: #297. Co-authored-by: Ivan Boldyrev <ivan@fluence.one> Co-authored-by: Anatoly Laskaris <github_me@nahsi.dev>
160 lines
3.6 KiB
Rust
160 lines
3.6 KiB
Rust
/*
|
|
* Copyright 2021 Fluence Labs Limited
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
use super::*;
|
|
|
|
impl<'i> Ap<'i> {
|
|
pub fn new(argument: ApArgument<'i>, result: ApResult<'i>) -> Self {
|
|
Self { argument, result }
|
|
}
|
|
}
|
|
|
|
impl<'i> Call<'i> {
|
|
pub fn new(
|
|
triplet: Triplet<'i>,
|
|
args: Rc<Vec<ImmutableValue<'i>>>,
|
|
output: CallOutputValue<'i>,
|
|
) -> Self {
|
|
Self {
|
|
triplet,
|
|
args,
|
|
output,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl<'i> Canon<'i> {
|
|
pub fn new(
|
|
peer_id: ResolvableToPeerIdVariable<'i>,
|
|
stream: Stream<'i>,
|
|
canon_stream: CanonStream<'i>,
|
|
) -> Self {
|
|
Self {
|
|
peer_id,
|
|
stream,
|
|
canon_stream,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl<'i> Seq<'i> {
|
|
pub fn new(
|
|
left_instruction: Box<Instruction<'i>>,
|
|
right_instruction: Box<Instruction<'i>>,
|
|
) -> Self {
|
|
Self(left_instruction, right_instruction)
|
|
}
|
|
}
|
|
|
|
impl<'i> Par<'i> {
|
|
pub fn new(
|
|
left_instruction: Box<Instruction<'i>>,
|
|
right_instruction: Box<Instruction<'i>>,
|
|
) -> Self {
|
|
Self(left_instruction, right_instruction)
|
|
}
|
|
}
|
|
|
|
impl<'i> Xor<'i> {
|
|
pub fn new(
|
|
left_instruction: Box<Instruction<'i>>,
|
|
right_instruction: Box<Instruction<'i>>,
|
|
) -> Self {
|
|
Self(left_instruction, right_instruction)
|
|
}
|
|
}
|
|
|
|
impl<'i> Match<'i> {
|
|
pub fn new(
|
|
left_value: ImmutableValue<'i>,
|
|
right_value: ImmutableValue<'i>,
|
|
instruction: Box<Instruction<'i>>,
|
|
) -> Self {
|
|
Self {
|
|
left_value,
|
|
right_value,
|
|
instruction,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl<'i> MisMatch<'i> {
|
|
pub fn new(
|
|
left_value: ImmutableValue<'i>,
|
|
right_value: ImmutableValue<'i>,
|
|
instruction: Box<Instruction<'i>>,
|
|
) -> Self {
|
|
Self {
|
|
left_value,
|
|
right_value,
|
|
instruction,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl<'i> FoldScalar<'i> {
|
|
pub fn new(
|
|
iterable: FoldScalarIterable<'i>,
|
|
iterator: Scalar<'i>,
|
|
instruction: Instruction<'i>,
|
|
last_instruction: Option<Instruction<'i>>,
|
|
span: Span,
|
|
) -> Self {
|
|
Self {
|
|
iterable,
|
|
iterator,
|
|
instruction: Rc::new(instruction),
|
|
last_instruction: last_instruction.map(Rc::new),
|
|
span,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl<'i> FoldStream<'i> {
|
|
pub fn new(
|
|
iterable: Stream<'i>,
|
|
iterator: Scalar<'i>,
|
|
instruction: Instruction<'i>,
|
|
last_instruction: Option<Instruction<'i>>,
|
|
span: Span,
|
|
) -> Self {
|
|
Self {
|
|
iterable,
|
|
iterator,
|
|
instruction: Rc::new(instruction),
|
|
last_instruction: last_instruction.map(Rc::new),
|
|
span,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl<'i> Next<'i> {
|
|
pub fn new(iterator: Scalar<'i>) -> Self {
|
|
Self { iterator }
|
|
}
|
|
}
|
|
|
|
impl<'i> New<'i> {
|
|
#[allow(clippy::self_named_constructors)]
|
|
pub fn new(argument: NewArgument<'i>, instruction: Box<Instruction<'i>>, span: Span) -> Self {
|
|
Self {
|
|
argument,
|
|
instruction,
|
|
span,
|
|
}
|
|
}
|
|
}
|