This chapter discusses the HLA compile-time language. This discussion includes what is perhaps the most important component of the HLA compile-time language, macros. Many people judge the power of an assembler by the power of its macro processing capabilities. If you happen to be one of these people, you'll probably agree that HLA is one of the more powerful assemblers on the planet after reading this chapter, because HLA has one of the most powerful macro processing facilities of any computer language processing system.
HLA is actually two languages rolled into a single program. The runtime language is the standard 80x86/HLA assembly language you've been reading about in all the previous chapters. This is called the runtime 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 (CTL), which 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 runtime 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 runtime executable that HLA emits, although the CTL application can write part of the runtime program for you, and, in fact, this is the major purpose of the CTL (see Figure 9-1).
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 the parameter list and generates calls to various other Standard Library procedures; it chooses the procedure to call based on the type of the parameter it is currently processing. For example, the stdout.put
"application" above will emit the following statements to the runtime 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 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 many HLA CTL examples. In addition to Standard Library usage, the HLA CTL is quite adept at handling "one-use" applications. A classic example is filling in the data for a lookup table. Chapter 8 noted that it is possible to construct lookup 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 tables.
Although the CTL itself is relatively inefficient and you would not normally use it to write end-user applications, it does maximize the use of 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).