Symbolic Logic:Programming:Program Model

A "Program Model" is a representation of a program as objects.

In Object Oriented Programming the domain we wish to describe is modeled as objects. This gives an object representation of the domain we choose. For example, applying OOP to the trading domain gives a Trading Model. Orders, Executions and Trades are modelled as objects.

Applying Object Oriented Programming to programs gives a Program Model. Classes, Functions, Function Calls, and Variables are modelled as objects.

History
When a program is compiled, internally the compiler must implicitly construct a model of the program. However this model is thrown away. All the compiler and linker finally produces is the executable. The programmer only wants the program to execute correctly. The programmers target audience is the user running the program.

The programmer makes compromises in writing the program between really general solutions that would run slowly, and specific solutions that run fast, but have limitted applicability.

Purpose
The purpose of the Program Model is to add another level of processing, before the program is turned into an executable. This level performs analysis on the program prior to generating the executable. The most easy to implement analysis is partial evaluation. There are many other kinds of analysis that may be done.

Easy Implementation
Starting with a basic set of classes to represent the program objects,

In a language like C++ that has operators it is possible to write expressions that look like the calculation of a value, which instead return a Program Model Object that represents the calculation.

Class Constants
Constants of type PMClass. ???? How high level should these be (e.g precision) ????
 * PMInteger
 * PMReal

Built in functions

 * PMIf

Example
PMClass *math = new PMClass("math"); PMVariable *n = new PMVariable(PMInteger); PMFunction *factorial = math->HasFunction("factorial", PMInteger)->Parameter(n) ->SetBody( PMIf(n == 0, new PMConstant(1), n * factorial->parameter(n-1)) );