10.2 Introduction to the Compile Time Language (CTL)


10.2 Introduction to the Compile Time Language (CTL)

HLA is actually two languages rolled into a single program. The run-time language is the standard 80x86/HLA assembly language you've been reading about in all the past chapters. This is called the run-time language because the programs you write execute when you run the executable file. HLA contains an interpreter for a second language, the HLA compile time language (or CTL) that executes programs while HLA is compiling a program. The source code for the CTL program is embedded in an HLA assembly language source file; that is, HLA source files contain instructions for both the HLA CTL and the run-time program. HLA executes the CTL program during compilation. Once HLA completes compilation, the CTL program terminates; the CTL application is not a part of the run-time executable that HLA emits, although the CTL application can write part of the run-time program for you and, in fact, this is the major purpose of the CTL.

click to expand
Figure 10-1: Compile Time Versus Run-Time Execution.

It may seem confusing to have two separate languages built into the same compiler. Perhaps you're even questioning why anyone would need a compile time language. To understand the benefits of a compile time language, consider the following statement that you should be very comfortable with at this point:

 stdout.put( "i32=", i32, " strVar=", strVar, " charVar=", charVar, nl ); 

This statement is neither a statement in the HLA language nor a call to some HLA Standard Library procedure. Instead, stdout.put is actually a statement in a CTL application provided by the HLA Standard Library. The stdout.put"application" processes a list of objects (the parameter list) and makes calls to various other Standard Library procedures; it chooses the procedure to call based on the type of the object it is currently processing. For example, the stdout.put "application" above will emit the following statements to the run-time executable:

 stdout.puts( "i32=" ); stdout.puti32( i32 ); stdout.puts( " strVar=" ); stdout.puts( strVar ); stdout.puts( " charVar=" ); stdout.putc( charVar ); stdout.newln(); 

Clearly the stdout.put statement is much easier to read and write than the sequence of statements that stdout.put emits in response to its parameter list. This is one of the more powerful capabilities of the HLA programming language: the ability to modify the language to simplify common programming tasks. Printing lots of different data objects in a sequential fashion is a common task; the stdout.put "application" greatly simplifies this process.

The HLA Standard Library is loaded with lots of HLA CTL examples. In addition to Standard Library usage, the HLA CTL is quite adept at handling "one-off" or "one-use" applications. A classic example is filling in the data for a look-up table. The previous chapter in this text noted that it is possible to construct look-up tables using the HLA CTL. Not only is this possible, but it is often far less work to use the HLA CTL to construct these look-up tables. This chapter abounds with examples of exactly this application of the CTL.

Although the CTL itself is relatively inefficient and you would not use it to write end-user applications, it does maximize the use of that one precious commodity of which there is so little available: your time. By learning how to use the HLA CTL and applying it properly, you can develop assembly language applications as rapidly as high level language applications (even faster because HLA's CTL lets you create very high level language constructs).




The Art of Assembly Language
The Art of Assembly Language
ISBN: 1593272073
EAN: 2147483647
Year: 2005
Pages: 246
Authors: Randall Hyde

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net