diff --git a/src/compiler/abepi.rs b/src/compiler/abepi.rs index caa11804..b58685ae 100644 --- a/src/compiler/abepi.rs +++ b/src/compiler/abepi.rs @@ -65,8 +65,8 @@ impl + TryInto + Clone + Debug, V: Clone + Debug> CompilationU Statement::Transition(dsym, id, stmt) => { self.compiler_statement_transition(dsym, id, *stmt) } - Statement::HyperTransition(dsym, ids, machine, exprs, state) => { - self.compiler_statement_hyper_transition(dsym, ids, machine, exprs, state) + Statement::HyperTransition(dsym, state, call) => { + self.compiler_statement_hyper_transition(dsym, state, *call) } _ => vec![], } @@ -427,10 +427,8 @@ impl + TryInto + Clone + Debug, V: Clone + Debug> CompilationU fn compiler_statement_hyper_transition( &self, _dsym: DebugSymRef, - _ids: Vec, - _machine: V, - _exprs: Vec>, _state: V, + _call: Statement, ) -> Vec> { todo!("Compile expressions?") } diff --git a/src/compiler/compiler.rs b/src/compiler/compiler.rs index 27ee0b39..ba6f965f 100644 --- a/src/compiler/compiler.rs +++ b/src/compiler/compiler.rs @@ -818,27 +818,23 @@ mod test { assert!(result.is_ok()); - // Wrong transition operator let circuit = " machine caller (signal n) (signal b: field) { - a', b, c' <== fibo(d, e, f + g) --> final; + -> final { + a', b, c' <== fibo(d, e, f + g); + } } "; let debug_sym_ref_factory = DebugSymRefFactory::new("", circuit); let result = TLDeclsParser::new().parse(&debug_sym_ref_factory, circuit); - assert!(result.is_err()); - let err = result.err().unwrap(); - assert_eq!( - err.to_string(), - "Unrecognized token `-` found at 99:100\nExpected one of \"->\"" - ); + assert!(result.is_ok()); - // No transition + // Wrong transition operator let circuit = " machine caller (signal n) (signal b: field) { - a', b, c' <== fibo(d, e, f + g); + a', b, c' <== fibo(d, e, f + g) --> final; } "; @@ -849,7 +845,7 @@ mod test { let err = result.err().unwrap(); assert_eq!( err.to_string(), - "Unrecognized token `;` found at 98:99\nExpected one of \"->\"" + "Unrecognized token `-` found at 99:100\nExpected one of \"->\" or \";\"" ); } } diff --git a/src/compiler/semantic/analyser.rs b/src/compiler/semantic/analyser.rs index 1314b89e..28011d1a 100644 --- a/src/compiler/semantic/analyser.rs +++ b/src/compiler/semantic/analyser.rs @@ -272,12 +272,16 @@ impl Analyser { Statement::SignalDecl(_, _) => {} Statement::WGVarDecl(_, _) => {} - Statement::HyperTransition(_, ids, _machine, exprs, _state) => { - // TODO analyze machine? analyze state? + Statement::HyperTransition(_, state, call) => { + self.analyse_statement(*call); + self.collect_id_usages(&[state]); + } + Statement::Call(_, ids, _machine, exprs) => { + // TODO analyze machine? + self.collect_id_usages(&ids); exprs .into_iter() - .for_each(|expr| self.analyse_expression(expr)); - self.collect_id_usages(&ids); + .for_each(|expr| self.analyse_expression(expr)) } } } diff --git a/src/compiler/setup_inter.rs b/src/compiler/setup_inter.rs index 8434bae9..2b2d4f18 100644 --- a/src/compiler/setup_inter.rs +++ b/src/compiler/setup_inter.rs @@ -250,7 +250,8 @@ impl SetupInterpreter { SignalAssignment(_, _, _) | WGAssignment(_, _, _) => vec![], SignalDecl(_, _) | WGVarDecl(_, _) => vec![], - HyperTransition(_, _, _, _, _) => todo!(), + Call(_, _, _, _) => todo!(), + HyperTransition(_, _, _) => todo!(), }; self.add_poly_constraints(result.into_iter().map(|cr| cr.anti_booly).collect()); diff --git a/src/interpreter/mod.rs b/src/interpreter/mod.rs index 6c98822e..8dfd421d 100644 --- a/src/interpreter/mod.rs +++ b/src/interpreter/mod.rs @@ -206,7 +206,8 @@ impl<'a, F: Field + Hash> Interpreter<'a, F> { Block(_, stmts) => self.exec_step_block(stmts), Assert(_, _) => Ok(None), StateDecl(_, _, _) => Ok(None), - HyperTransition(_, _, _, _, _) => Ok(None), // TODO execute transition? + Call(_, _, _, _) => todo!("execute call?"), + HyperTransition(_, _, _) => todo!("execute hypertransition?"), } } diff --git a/src/parser/ast/statement.rs b/src/parser/ast/statement.rs index a297c090..82398485 100644 --- a/src/parser/ast/statement.rs +++ b/src/parser/ast/statement.rs @@ -35,15 +35,20 @@ pub enum Statement { Transition(DebugSymRef, V, Box>), // -> x { y } Block(DebugSymRef, Vec>), // { x } - /// Call into another machine with assertion and subsequent transition to another - /// state. + /// Call into another machine with assertion. /// Tuple values: /// - debug symbol reference; /// - assigned/asserted ids vector; /// - machine ID; - /// - call argument expressions vector; + /// - call argument expressions vector. + Call(DebugSymRef, Vec, V, Vec>), + /// Call into another machine with assertion and subsequent transition to another + /// state. + /// Tuple values: + /// - debug symbol reference; /// - next state ID. - HyperTransition(DebugSymRef, Vec, V, Vec>, V), + /// - machine call; + HyperTransition(DebugSymRef, V, Box>), } impl Debug for Statement { @@ -93,15 +98,11 @@ impl Debug for Statement { .join(" ") ) } - Statement::HyperTransition(_, ids, machine, exprs, state) => { - write!( - f, - "{:?} <== {} ({:?}) --> {:?};", - ids, - machine.name(), - exprs, - state - ) + Statement::Call(_, ids, machine, exprs) => { + write!(f, "{:?} <== {} ({:?});", ids, machine.name(), exprs) + } + Statement::HyperTransition(_, state, call) => { + write!(f, "{:?} -> {:?};", call, state) } } } @@ -121,7 +122,8 @@ impl Statement { Statement::StateDecl(dsym, _, _) => dsym.clone(), Statement::Transition(dsym, _, _) => dsym.clone(), Statement::Block(dsym, _) => dsym.clone(), - Statement::HyperTransition(dsym, _, _, _, _) => dsym.clone(), + Statement::Call(dsym, _, _, _) => dsym.clone(), + Statement::HyperTransition(dsym, _, _) => dsym.clone(), } } } diff --git a/src/parser/build.rs b/src/parser/build.rs index 03348fd8..3fea23b1 100644 --- a/src/parser/build.rs +++ b/src/parser/build.rs @@ -61,3 +61,11 @@ pub fn build_transition( ) -> Statement { Statement::Transition(dsym, id, Box::new(block)) } + +pub fn build_hyper_transition( + dsym: DebugSymRef, + state: Identifier, + call: Statement, +) -> Statement { + Statement::HyperTransition(dsym, state, Box::new(call)) +} diff --git a/src/parser/chiquito.lalrpop b/src/parser/chiquito.lalrpop index 35c2d04a..d1ee42f2 100644 --- a/src/parser/chiquito.lalrpop +++ b/src/parser/chiquito.lalrpop @@ -53,7 +53,8 @@ StatementType: Statement = { ParseWGVarDecl, ParseTransitionSimple, ParseTransition, - HyperTransition + HyperTransition, + Call, } AssertEq: Statement = { @@ -113,7 +114,11 @@ ParseTransition: Statement = { } HyperTransition: Statement = { - "<==" "(" ")" "->" => Statement::HyperTransition(dsym_factory.create(l,r), ids, machine, es, st), + "->" => build_hyper_transition(dsym_factory.create(l,r), st, call), +} + +Call: Statement = { + "<==" "(" ")" => Statement::Call(dsym_factory.create(l,r), ids, machine, es), } ParseSignalDecl: Statement = {