mirror of
https://github.com/AleoHQ/leo.git
synced 2024-12-02 12:22:08 +03:00
add main, record, registers, state, state_leaf sections to types
This commit is contained in:
parent
5ae8d550e5
commit
b9b459ecff
@ -1,4 +1,4 @@
|
|||||||
use crate::{ast::Rule, common::EOI, sections::Section};
|
use crate::{ast::Rule, common::EOI, sections::Section, tables::Table};
|
||||||
|
|
||||||
use pest::Span;
|
use pest::Span;
|
||||||
use pest_ast::FromPest;
|
use pest_ast::FromPest;
|
||||||
@ -6,6 +6,7 @@ use pest_ast::FromPest;
|
|||||||
#[derive(Clone, Debug, FromPest, PartialEq)]
|
#[derive(Clone, Debug, FromPest, PartialEq)]
|
||||||
#[pest_ast(rule(Rule::file))]
|
#[pest_ast(rule(Rule::file))]
|
||||||
pub struct File<'ast> {
|
pub struct File<'ast> {
|
||||||
|
pub tables: Vec<Table<'ast>>,
|
||||||
pub sections: Vec<Section<'ast>>,
|
pub sections: Vec<Section<'ast>>,
|
||||||
pub eoi: EOI,
|
pub eoi: EOI,
|
||||||
#[pest_ast(outer())]
|
#[pest_ast(outer())]
|
||||||
|
@ -182,7 +182,7 @@ private = { "private" }
|
|||||||
visibility = { public | private }
|
visibility = { public | private }
|
||||||
|
|
||||||
// Declared in sections/table.rs
|
// Declared in sections/table.rs
|
||||||
table = {visibility ~ NEWLINE+ ~ section*}
|
table = {"[[" ~ visibility ~ "]]" ~ NEWLINE+ ~ section*}
|
||||||
|
|
||||||
/// Utilities
|
/// Utilities
|
||||||
|
|
||||||
@ -192,4 +192,4 @@ WHITESPACE = _{ " " | "\t" ~ (NEWLINE)* }
|
|||||||
/// Files
|
/// Files
|
||||||
|
|
||||||
// Declared in files/file.rs
|
// Declared in files/file.rs
|
||||||
file = { SOI ~ NEWLINE* ~ section* ~ NEWLINE* ~ EOI }
|
file = { SOI ~ NEWLINE* ~ table* ~ NEWLINE* ~ section* ~ NEWLINE* ~ EOI }
|
||||||
|
@ -1,16 +1,20 @@
|
|||||||
use crate::{FunctionInput, InputValue};
|
use crate::{FunctionInput, InputValue, ProgramInputs, ProgramState};
|
||||||
use leo_inputs::{files::File, InputParserError};
|
use leo_inputs::{files::File, sections::header::Header, InputParserError};
|
||||||
|
|
||||||
static MAIN_INPUT_FILE_HEADER: &'static str = "main";
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Inputs {
|
pub struct Inputs {
|
||||||
program_inputs: Vec<Option<InputValue>>,
|
program_inputs: Vec<Option<InputValue>>,
|
||||||
|
inputs: ProgramInputs,
|
||||||
|
state: ProgramState,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Inputs {
|
impl Inputs {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self { program_inputs: vec![] }
|
Self {
|
||||||
|
program_inputs: vec![],
|
||||||
|
inputs: ProgramInputs::new(),
|
||||||
|
state: ProgramState::new(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_inputs(&self) -> Vec<Option<InputValue>> {
|
pub fn get_inputs(&self) -> Vec<Option<InputValue>> {
|
||||||
@ -29,7 +33,8 @@ impl Inputs {
|
|||||||
let mut program_inputs = vec![];
|
let mut program_inputs = vec![];
|
||||||
|
|
||||||
for section in file.sections.into_iter() {
|
for section in file.sections.into_iter() {
|
||||||
if section.header.name.value.eq(MAIN_INPUT_FILE_HEADER) {
|
match section.header {
|
||||||
|
Header::Main(_main) => {
|
||||||
for input in &expected_inputs {
|
for input in &expected_inputs {
|
||||||
// find input with matching name
|
// find input with matching name
|
||||||
let matched_input = section.assignments.clone().into_iter().find(|assignment| {
|
let matched_input = section.assignments.clone().into_iter().find(|assignment| {
|
||||||
@ -41,7 +46,8 @@ impl Inputs {
|
|||||||
|
|
||||||
match matched_input {
|
match matched_input {
|
||||||
Some(assignment) => {
|
Some(assignment) => {
|
||||||
let value = InputValue::from_expression(assignment.parameter.type_, assignment.expression)?;
|
let value =
|
||||||
|
InputValue::from_expression(assignment.parameter.type_, assignment.expression)?;
|
||||||
|
|
||||||
// push value to vector
|
// push value to vector
|
||||||
program_inputs.push(Some(value));
|
program_inputs.push(Some(value));
|
||||||
@ -50,8 +56,14 @@ impl Inputs {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
_ => unimplemented!("section not impl"),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Self { program_inputs })
|
Ok(Self {
|
||||||
|
program_inputs,
|
||||||
|
inputs: ProgramInputs::new(),
|
||||||
|
state: ProgramState::new(),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,3 +3,9 @@ pub use inputs::*;
|
|||||||
|
|
||||||
pub mod input_value;
|
pub mod input_value;
|
||||||
pub use input_value::*;
|
pub use input_value::*;
|
||||||
|
|
||||||
|
pub mod program_inputs;
|
||||||
|
pub use program_inputs::*;
|
||||||
|
|
||||||
|
pub mod program_state;
|
||||||
|
pub use program_state::*;
|
||||||
|
10
types/src/inputs/program_inputs/main_inputs.rs
Normal file
10
types/src/inputs/program_inputs/main_inputs.rs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
use crate::InputValue;
|
||||||
|
|
||||||
|
#[derive(Clone, PartialEq, Eq)]
|
||||||
|
pub struct MainInputs(Vec<Option<InputValue>>);
|
||||||
|
|
||||||
|
impl MainInputs {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self(vec![])
|
||||||
|
}
|
||||||
|
}
|
8
types/src/inputs/program_inputs/mod.rs
Normal file
8
types/src/inputs/program_inputs/mod.rs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
pub mod main_inputs;
|
||||||
|
pub use main_inputs::*;
|
||||||
|
|
||||||
|
pub mod program_inputs;
|
||||||
|
pub use program_inputs::*;
|
||||||
|
|
||||||
|
pub mod registers;
|
||||||
|
pub use registers::*;
|
16
types/src/inputs/program_inputs/program_inputs.rs
Normal file
16
types/src/inputs/program_inputs/program_inputs.rs
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
use crate::{MainInputs, Registers};
|
||||||
|
|
||||||
|
#[derive(Clone, PartialEq, Eq)]
|
||||||
|
pub struct ProgramInputs {
|
||||||
|
main: MainInputs,
|
||||||
|
registers: Registers,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ProgramInputs {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
main: MainInputs::new(),
|
||||||
|
registers: Registers::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
10
types/src/inputs/program_inputs/registers.rs
Normal file
10
types/src/inputs/program_inputs/registers.rs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
use crate::InputValue;
|
||||||
|
|
||||||
|
#[derive(Clone, PartialEq, Eq)]
|
||||||
|
pub struct Registers(Vec<Option<InputValue>>);
|
||||||
|
|
||||||
|
impl Registers {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self(vec![])
|
||||||
|
}
|
||||||
|
}
|
8
types/src/inputs/program_state/mod.rs
Normal file
8
types/src/inputs/program_state/mod.rs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
pub mod private_state;
|
||||||
|
pub use private_state::*;
|
||||||
|
|
||||||
|
pub mod program_state;
|
||||||
|
pub use program_state::*;
|
||||||
|
|
||||||
|
pub mod public_state;
|
||||||
|
pub use public_state::*;
|
8
types/src/inputs/program_state/private_state/mod.rs
Normal file
8
types/src/inputs/program_state/private_state/mod.rs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
pub mod private_state;
|
||||||
|
pub use private_state::*;
|
||||||
|
|
||||||
|
pub mod record;
|
||||||
|
pub use record::*;
|
||||||
|
|
||||||
|
pub mod state_leaf;
|
||||||
|
pub use state_leaf::*;
|
@ -0,0 +1,16 @@
|
|||||||
|
use crate::{Record, StateLeaf};
|
||||||
|
|
||||||
|
#[derive(Clone, PartialEq, Eq)]
|
||||||
|
pub struct PrivateState {
|
||||||
|
record: Record,
|
||||||
|
state_leaf: StateLeaf,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PrivateState {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
record: Record::new(),
|
||||||
|
state_leaf: StateLeaf::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
10
types/src/inputs/program_state/private_state/record.rs
Normal file
10
types/src/inputs/program_state/private_state/record.rs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
use crate::InputValue;
|
||||||
|
|
||||||
|
#[derive(Clone, PartialEq, Eq)]
|
||||||
|
pub struct Record(Vec<Option<InputValue>>);
|
||||||
|
|
||||||
|
impl Record {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self(vec![])
|
||||||
|
}
|
||||||
|
}
|
10
types/src/inputs/program_state/private_state/state_leaf.rs
Normal file
10
types/src/inputs/program_state/private_state/state_leaf.rs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
use crate::InputValue;
|
||||||
|
|
||||||
|
#[derive(Clone, PartialEq, Eq)]
|
||||||
|
pub struct StateLeaf(Vec<Option<InputValue>>);
|
||||||
|
|
||||||
|
impl StateLeaf {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self(vec![])
|
||||||
|
}
|
||||||
|
}
|
16
types/src/inputs/program_state/program_state.rs
Normal file
16
types/src/inputs/program_state/program_state.rs
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
use crate::{PrivateState, PublicState};
|
||||||
|
|
||||||
|
#[derive(Clone, PartialEq, Eq)]
|
||||||
|
pub struct ProgramState {
|
||||||
|
public: PublicState,
|
||||||
|
private: PrivateState,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ProgramState {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
public: PublicState::new(),
|
||||||
|
private: PrivateState::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
5
types/src/inputs/program_state/public_state/mod.rs
Normal file
5
types/src/inputs/program_state/public_state/mod.rs
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
pub mod public_state;
|
||||||
|
pub use public_state::*;
|
||||||
|
|
||||||
|
pub mod state;
|
||||||
|
pub use state::*;
|
12
types/src/inputs/program_state/public_state/public_state.rs
Normal file
12
types/src/inputs/program_state/public_state/public_state.rs
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
use crate::State;
|
||||||
|
|
||||||
|
#[derive(Clone, PartialEq, Eq)]
|
||||||
|
pub struct PublicState {
|
||||||
|
state: State,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PublicState {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self { state: State::new() }
|
||||||
|
}
|
||||||
|
}
|
10
types/src/inputs/program_state/public_state/state.rs
Normal file
10
types/src/inputs/program_state/public_state/state.rs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
use crate::InputValue;
|
||||||
|
|
||||||
|
#[derive(Clone, PartialEq, Eq)]
|
||||||
|
pub struct State(Vec<Option<InputValue>>);
|
||||||
|
|
||||||
|
impl State {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self(vec![])
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user