Got it! This site uses cookies. You consent to this by clicking on "Got it!" or by continuing to use this website.nbsp; Note: This appears on each machine/browser from which this site is accessed.
Abstract interpretation is a programming language technique whereby the running of code (e.g., a program) is simulated.
One purpose is to transform the code to a different (e.g., more efficient in some way) form.
3. PDF
The Adobe PDF (Portable Document Format) is, in part, an abstract interpretation of the page description language PostScript such that loops and conditionals are removed (and certain other transformations are made). Then, some additional features are added such as meta information, font embedding support, etc.
4. C program and data analogy
In a C program, for example, the only statements that do anything are input, assignment, and output - primitive statements.
The other statements such as while and if effect control flow. Functions are abstractions.
An abstract interpretation of a C program with the data for that program would record just the primitive statements. The resulting program would run and just do one and only one thing - ever. That is what is done with PDF.
5. Stack-based expression code
Let us return to the example of a stack-based expression code. Details are at Stack-based code execution .
In those example, the goal was evaluation given values for variables.
Here, only the generated code is of interest.
Consider the following example code.
Here is the JavaScript code.
Here is the output of the JavaScript code.
6. Observations
Notice that the needed stack size can be determined from the code. In this case, the stack will have exactly 3 elements on it.
The push and pop instructions do a lot of work (even without error checking).
Instead of push and pop, which takes time to increment/decrement the stack pointer and then load and store from the (dynamic) stack, a fixed number of variables (variable locations) can be used, such as the following. These could be on the run-time stack or registers on a processor. Here they are variables prefixed with temp for "temporary" (expression) variables.
temp0
temp1
temp2
The above code can then be converted the the following - which can be pre-processed and part of the generated code.
Note that these temporary variables are automatically reused as they would have been on an actual stack.
7. Intro programming analogy
In a beginning course in programming, students learn variables and then later how to replace a sequence of similar variable names with an array reference and index.
Here, the opposite is happening. An array and index references are being replaced with individual variable names (memory locations).
Here is the JavaScript code.
Here is the output of the JavaScript code.
8. Observations
Instead of an explicit stack, the code can be generated to use the original variables or to use (and reuse) temporary variables.
This results in more compact code that runs faster.
There is still room for improvement, but the example shows how abstract interpretation of the generated postfix code can be used to create more compact and faster running code.
9. Turing and the Halting Problem
We will return to abstract interpretation when we get to Alan Turing and the Halting Problem and what is and what is not computable.