I'm writing a constraint satisfaction solver that will read an input file with multiple functions such as
and(not_equal(X0,X1),not_equal(absolute(subtract(X2,X3)),X4))
The solver will try 100s to 100,000,000s of combinations of X1, X2, X3, X4, X5
on the above function.
Currently the solver:
- Reads the next instruction of the function from a
Vec
. - Pattern matches that instruction to an action.
- Executes the instruction and saves the result to possibly be used later in the function.
Instead, I would like pre-process the functions and convert them into static Rust code. So the above function would become:
fn func_1 (vars: &Vec<i32>) -> bool {
let t1 = if vars[0] != vars[1] {1} else {0};
let t2 = vars[2] - vars[3];
t2.abs();
let t3 = if t2 != vars[4] {1} else {0};
if t1 == 1 && t3 == 1 {return true} else {return false}
}
I plan on having a pre-processor program:
- Read the input file.
- Auto-generate a module with all functions converted into Rust.
- Edit a module of the solver so that it uses the newly generated functions.
- Invoke the compiler.
- Run the newly compiled solver.
Is there a better way to do this?
Instead of having two programs can I write a single program that edits itself, invokes the compiler on itself, and schedules itself to be run after compilation is finished?