Skip to content

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.

Terms to simplify in a function call:

  1. Arithmetic expressions
  2. Static variables
  3. Conditionals

Current Approach:

  1. Search the function for terms that can be simplified
  2. Replace the terms with simplified terms
  3. Search the function multiple times till no other terms can be simplified

Arithmetic Expressions

  1. Arithmetic Expressions are converted to a parse tree of a standard form
  2. Expression are expanded into a sum of products
  3. Terms are combined if they are the same

Arithmetic Operators

  • 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

Static variables

  1. Look through the parse tree for static variables
  2. Replace them with their corresponding values

Conditionals

  1. Look through the parse tree for conditional statements and conditional expressions
  2. If the conditions can be evaluated, partially evaluate to one of its branches
  3. If not, partially evaluate its conditions and both branches