MCPcopy Create free account
hub / github.com/ControlCplusControlV/Scribe / run_example

Function run_example

crates/miden-integration-tests/tests/utils.rs:20–81  ·  view source on GitHub ↗

Function to display transpile Yul code and display each step of the transpilation process in the terminal. This function is only used to demonstrate what Scribe does in a easy to read format.

(yul_code: &str, expected_output: MidenResult)

Source from the content-addressed store, hash-verified

18//Function to display transpile Yul code and display each step of the transpilation process in the terminal.
19//This function is only used to demonstrate what Scribe does in a easy to read format.
20pub fn run_example(yul_code: &str, expected_output: MidenResult) {
21 fn print_title(s: &str) {
22 let s1 = format!("=== {} ===", s).blue().bold();
23 println!("{}", s1);
24 println!(" ");
25 }
26 println!();
27 println!();
28 print_title("Input Yul");
29 println!("{}", yul_code);
30 println!();
31
32 let parsed = parser::parse_yul_syntax(yul_code);
33
34 let ast = optimize_ast(parsed);
35
36 let ast = infer_types(&ast);
37 print_title("AST");
38 println!("{}", expressions_to_tree(&ast));
39 println!();
40
41 let (transpiler, miden_code) = miden_generator::transpile_program(ast, Default::default());
42 let mut trimmed_miden_code = miden_code
43 .split('\n')
44 // .skip_while(|line| *line != "# end std lib #")
45 // .filter(|line| !line.trim().starts_with("#"))
46 // .filter(|line| !line.trim().is_empty())
47 .collect::<Vec<_>>()
48 .join("\n");
49 print_title("Generated Miden Assembly");
50 println!("{}", trimmed_miden_code);
51 println!();
52 println!("Estimated cost: {}", transpiler.cost);
53 println!();
54 fs::write(format!("./test_output.masm",), trimmed_miden_code)
55 .expect("Unable to write Miden to file.");
56
57 let execution_value = executor::execute(miden_code, vec![]).unwrap();
58 let stack = execution_value.last_stack_state();
59 let last_stack_value = stack.first().unwrap();
60
61 print_title("Miden Output");
62 match expected_output {
63 MidenResult::U256(expected) => {
64 let stack_value = miden_to_u256(execution_value);
65 println!("{}", stack_value);
66 if expected != stack_value {
67 print_title("Miden Stack");
68 println!("{:?}", stack);
69 panic!("Failed, stack result not right");
70 }
71 }
72 MidenResult::U32(expected) => {
73 println!("{}", last_stack_value);
74 if expected != last_stack_value.as_int() as u32 {
75 print_title("Miden Stack");
76 println!("{:?}", stack);
77 panic!("Failed, stack result not right");

Callers 15

u256_hex_literalFunction · 0.85
u256_literalFunction · 0.85
u256_addFunction · 0.85
u256_mulFunction · 0.85
u256_add_with_carryFunction · 0.85
u256_subFunction · 0.85
u256_sub_underflowFunction · 0.85
u256_andFunction · 0.85
u256_orFunction · 0.85
u256_xorFunction · 0.85
u256_mixed_typesFunction · 0.85
u256_stack_overflowFunction · 0.85

Calls 7

print_titleFunction · 0.85
parse_yul_syntaxFunction · 0.85
optimize_astFunction · 0.85
infer_typesFunction · 0.85
transpile_programFunction · 0.85
executeFunction · 0.85
miden_to_u256Function · 0.85

Tested by

no test coverage detected