-
Notifications
You must be signed in to change notification settings - Fork 18
Partial Evaluator
Rezky Arizaputra edited this page Apr 28, 2020
·
1 revision
Partial Evaluator is a code processor that simplifies code if possible. Given a program and a set of its dependent variables/inputs, the program is partially evaluated given specific values to some of its inputs. It produces a specialized program (residual program) that works the same way as the initial program given these set of static values.
- Arithmetic expressions
- Static variables
- Conditionals
- Search the function for terms that can be simplified
- Replace the terms with simplified terms
- Search the function multiple times till no other terms can be simplified
- Arithmetic Expressions are converted to a parse tree of a standard form
- Expression are expanded into a sum of products
- Terms are combined if they are the same
- Subtractions ( - ) are expressed as multiplying by -1
- Multiplications ( * ) are sorted by number first and variables later
- Addition ( + ) are sorted by variables and terms are combined if variables are the same
- Division ( / ) are expressed as multiplying by a single reciprocal with a denominator being another expression
- Look through the parse tree for static variables
- Replace them with their corresponding values
- Look through the parse tree for conditional statements and conditional expressions
- If the conditions can be evaluated, partially evaluate to one of its branches
- If not, partially evaluate its conditions and both branches