0
$\begingroup$

In the following discussion, we use the term old programming language to refer to programming languages which had their first release prior to the year 1990.

In old programming languages, there was a strong distinction between:

  1. run-time functions.
  2. compile-time macros.

In a running example, suppose that a computer programmer wrote code to emulate a Word Processor such as Libre Office Impress.

Before a computer programme was compiled, a computer programmer typed-in code for compile-time macros.

After at run-time, a non-computer programmer might write their resume for a job as a fork-lift operator inside of a word process such as Libre Office Impress.

Clearly, run-time code depends on what the prospective fork-lift operator would type into their resume.

  1. In an older programming language, the compile-time macro MACRO_CONCATENATE("Insert", "Picture") might be replaced by "Insert Picture" at compile-time.

  2. The runtime function concatenate(x, y) would execute at run-time.

What name has been previously established in the computer science literature for a compiler which ignores the traditional distinction between run-time functions and compile-time macros?

What do you call a compiler that does the following?

  • At compile-time, the compiler executes functions calls if the function call had constant literal inputs at compile-time

  • The compiler executes functions which have run-time dependent inputs at run-time?

As another example, consider the following...

big_letters = "".join(chr(x) for x in range(ord("A"), ord("Z")))

That code could be simplified, as follows:

big_letters = 'ABCDEFGHIJKLMNOPQRSTUVWXY'

Some compilers execute all function-calls in a given programme if both of the following conditions are met:

  1. The inputs to the function-call are constant literals such as "A"

  2. The tree of callees (descendants) of the function-call contain no calls to runtime-only functions. Runtime-only function read from file, write to file, use stdout, stdin, cin, fprinf, print, etc...

Some compilers build trees of nodes such that:

  • Each node $p$ in the tree represents a function-call $f$ or a constant literal such as 3.9020
  • Suppose that function-call $f$ calls the function defined in the defintion for function $F$.
  • A child of node $p$ is node $k$ such that node $k$ represents a function-call $g$.
  • function-call $g$ is associated with the definition of a function $G$. function-call $g$ is a function-call present inside of definition of function $F$.

For example, if a function named MakeDinner() calls MakeSpinachSauce() and MakeFlatBread(), then MakeSpinachSauce() and MakeFlatBread() are children of foo.

Make Dinner Tree

So, if the inputs are known at run-time, the work gets done at run-time.

If the inputs to a function are not known until an unemployed warehouse worker types their resume for a Fork-Lift operator job, then the work for those functions is done at run-time.

Leaf-nodes of the tree are:

  • constant literals, such as 12.8302 or "hello world".
  • calls to run-time only functions which have no callees

The compiler identifies constant literal leaf nodes.

We compute the parents of constant literal leaf nodes.

After the parent of some constant literal leaf nodes is calculated, we delete the constant literal leaves.

Computing the parents of leaf nodes continues in a recursive manner until all nodes have one or more children which are run-time only functions.

What is the name of this type of programming language?

Functions are executed at run-time if the functions call a function which calls a function which calls a run-time only function.

Functions are executed at compile-time if the function only calls functions which call functions which call functions which process constant literal integers, strings, floats, etc...

$\endgroup$

1 Answer 1

2
$\begingroup$

This is known as partial evaluation.

See also constant propagation and compile-time function evaluation.

$\endgroup$
1
  • $\begingroup$ Another related concept is Just-in-time compilation (kind of the opposite thing -- delaying compilation as long as possible). $\endgroup$ May 7, 2023 at 4:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.