@@ -17,6 +17,7 @@ mod serde;
1717pub mod str;
1818pub mod tracker;
1919pub mod types;
20+ pub mod unstable_flags;
2021pub mod value;
2122mod witness;
2223
@@ -34,6 +35,7 @@ use crate::debug::DebugSymbols;
3435use crate :: error:: { ErrorCollector , WithFile } ;
3536use crate :: parse:: ParseFromStrWithErrors ;
3637pub use crate :: types:: ResolvedType ;
38+ pub use crate :: unstable_flags:: { UnstableFlags , with_flags} ;
3739pub use crate :: value:: Value ;
3840pub use crate :: witness:: { Arguments , Parameters , WitnessTypes , WitnessValues } ;
3941
@@ -53,10 +55,17 @@ impl TemplateProgram {
5355 /// ## Errors
5456 ///
5557 /// The string is not a valid SimplicityHL program.
56- pub fn new < Str : Into < Arc < str > > > ( s : Str , deny_all_warnings : bool ) -> Result < Self , String > {
58+ pub fn new < Str : Into < Arc < str > > > (
59+ s : Str ,
60+ deny_all_warnings : bool ,
61+ flags : UnstableFlags ,
62+ ) -> Result < Self , String > {
5763 let file = s. into ( ) ;
5864 let mut error_handler = ErrorCollector :: new ( Arc :: clone ( & file) ) ;
59- let parse_program = parse:: Program :: parse_from_str_with_errors ( & file, & mut error_handler) ;
65+ let parse_program =
66+ with_flags ( flags, || {
67+ parse:: Program :: parse_from_str_with_errors ( & file, & mut error_handler)
68+ } ) ;
6069 if let Some ( program) = parse_program {
6170 let ( ast_program, warnings) =
6271 ast:: Program :: analyze ( & program) . with_file ( Arc :: clone ( & file) ) ?;
@@ -199,8 +208,9 @@ impl CompiledProgram {
199208 arguments : Arguments ,
200209 include_debug_symbols : bool ,
201210 deny_all_warnings : bool ,
211+ flags : UnstableFlags ,
202212 ) -> Result < Self , String > {
203- TemplateProgram :: new ( s, deny_all_warnings)
213+ TemplateProgram :: new ( s, deny_all_warnings, flags )
204214 . and_then ( |template| template. instantiate ( arguments, include_debug_symbols) )
205215 }
206216
@@ -285,9 +295,10 @@ impl SatisfiedProgram {
285295 witness_values : WitnessValues ,
286296 include_debug_symbols : bool ,
287297 deny_all_warnings : bool ,
298+ flags : UnstableFlags ,
288299 ) -> Result < Self , String > {
289300 let compiled =
290- CompiledProgram :: new ( s, arguments, include_debug_symbols, deny_all_warnings) ?;
301+ CompiledProgram :: new ( s, arguments, include_debug_symbols, deny_all_warnings, flags ) ?;
291302 compiled. satisfy ( witness_values)
292303 }
293304
@@ -390,7 +401,11 @@ pub(crate) mod tests {
390401 }
391402
392403 pub fn template_text ( program_text : Cow < str > ) -> Self {
393- let program = match TemplateProgram :: new ( program_text. as_ref ( ) ) {
404+ Self :: template_text_with_flags ( program_text, UnstableFlags :: new ( ) )
405+ }
406+
407+ pub fn template_text_with_flags ( program_text : Cow < str > , flags : UnstableFlags ) -> Self {
408+ let program = match TemplateProgram :: new ( program_text. as_ref ( ) , false , flags) {
394409 Ok ( x) => x,
395410 Err ( error) => panic ! ( "{error}" ) ,
396411 } ;
@@ -731,6 +746,8 @@ fn main() {
731746 Arguments :: default ( ) ,
732747 WitnessValues :: default ( ) ,
733748 false ,
749+ false ,
750+ UnstableFlags :: new ( ) ,
734751 ) {
735752 Ok ( _) => panic ! ( "Accepted faulty program" ) ,
736753 Err ( error) => {
@@ -780,7 +797,13 @@ fn main() {
780797 . assert_run_success ( ) ;
781798 }
782799
783- // --- infix operator integration tests ---
800+ // --- infix operator integration tests (require -Z infix_arithmetic_operators) ---
801+
802+ fn arith_flags ( ) -> UnstableFlags {
803+ let mut f = UnstableFlags :: new ( ) ;
804+ f. enable ( crate :: unstable_flags:: UnstableFlag :: InfixArithmeticOperators ) ;
805+ f
806+ }
784807
785808 #[ test]
786809 fn infix_op_add_u8 ( ) {
@@ -790,7 +813,8 @@ fn main() {
790813 let (_, sum): (bool, u8) = a + b;
791814 assert!(jet::eq_8(sum, 19));
792815}"# ;
793- TestCase :: program_text ( Cow :: Borrowed ( prog) )
816+ TestCase :: template_text_with_flags ( Cow :: Borrowed ( prog) , arith_flags ( ) )
817+ . with_arguments ( Arguments :: default ( ) )
794818 . with_witness_values ( WitnessValues :: default ( ) )
795819 . assert_run_success ( ) ;
796820 }
@@ -803,7 +827,8 @@ fn main() {
803827 let (_, diff): (bool, u8) = a - b;
804828 assert!(jet::eq_8(diff, 13));
805829}"# ;
806- TestCase :: program_text ( Cow :: Borrowed ( prog) )
830+ TestCase :: template_text_with_flags ( Cow :: Borrowed ( prog) , arith_flags ( ) )
831+ . with_arguments ( Arguments :: default ( ) )
807832 . with_witness_values ( WitnessValues :: default ( ) )
808833 . assert_run_success ( ) ;
809834 }
@@ -816,7 +841,8 @@ fn main() {
816841 let product: u16 = a * b;
817842 assert!(jet::eq_16(product, 42));
818843}"# ;
819- TestCase :: program_text ( Cow :: Borrowed ( prog) )
844+ TestCase :: template_text_with_flags ( Cow :: Borrowed ( prog) , arith_flags ( ) )
845+ . with_arguments ( Arguments :: default ( ) )
820846 . with_witness_values ( WitnessValues :: default ( ) )
821847 . assert_run_success ( ) ;
822848 }
@@ -829,7 +855,8 @@ fn main() {
829855 let quotient: u8 = a / b;
830856 assert!(jet::eq_8(quotient, 5));
831857}"# ;
832- TestCase :: program_text ( Cow :: Borrowed ( prog) )
858+ TestCase :: template_text_with_flags ( Cow :: Borrowed ( prog) , arith_flags ( ) )
859+ . with_arguments ( Arguments :: default ( ) )
833860 . with_witness_values ( WitnessValues :: default ( ) )
834861 . assert_run_success ( ) ;
835862 }
@@ -842,7 +869,8 @@ fn main() {
842869 let remainder: u8 = a % b;
843870 assert!(jet::eq_8(remainder, 2));
844871}"# ;
845- TestCase :: program_text ( Cow :: Borrowed ( prog) )
872+ TestCase :: template_text_with_flags ( Cow :: Borrowed ( prog) , arith_flags ( ) )
873+ . with_arguments ( Arguments :: default ( ) )
846874 . with_witness_values ( WitnessValues :: default ( ) )
847875 . assert_run_success ( ) ;
848876 }
@@ -856,7 +884,14 @@ fn main() {
856884 let sum: u8 = a + b;
857885 assert!(jet::eq_8(sum, 3));
858886}"# ;
859- match SatisfiedProgram :: new ( prog, Arguments :: default ( ) , WitnessValues :: default ( ) , false ) {
887+ match SatisfiedProgram :: new (
888+ prog,
889+ Arguments :: default ( ) ,
890+ WitnessValues :: default ( ) ,
891+ false ,
892+ false ,
893+ arith_flags ( ) ,
894+ ) {
860895 Ok ( _) => panic ! ( "Expected type error for `+` with plain u8 output" ) ,
861896 Err ( error) => assert ! (
862897 error. contains( "Expected expression of type" ) ,
0 commit comments