Next Previous Contents

4. Built-in CGL procedures

When the CGL interpreter starts up, it registers many built-in procedures that are implemented in C. Many of these built-in routines are general in nature. While other built-in's work with the compiler engine of AMC to control the compilation of source modules.

4.1 String manipulation built-in's

Of course, CGL is designed primarily to manipulate strings. To do this efficiently, CGL has quite a few built-in string manipulation functions:

4.2 Arithmatic built-in's

CGL keeps all numbers in string format. While this does incur a performance penalty, it is well worth simplifying the language. Furthermore, few CGL applications do large amounts of arithmatic, making the performance penalty a minimum. The following procedures are available in CGL for doing integer arithmatic:

4.3 Looping and flow-control built-in's

Because built-in's can selectively evaluate their arguments (unlike ordinary user-defined CGL procedures) or evaluate their arguments multiple times, looping and flow-control primitives can be done as CGL built-in's.

4.4 Exception handling

CGL normally propagates exceptions back to the initial caller of a CGL program. CGL programs can raise their own exceptions which will abort back to the inner-most catch block. Memory is never leaked during a raised excpetion but depending on your CGL program it may be necessary to do some other kinds of cleanup (reset state variables, delete tables, etc).

Exception processing is done with two built-in functions, catch and throw. Catch is used at where errors should be handled. The first argument is evaluated. If no exception is thrown, catch ignores its second argument.

If throw is called any time while executing under the context of a catch, the processing is aborted and execution resumes in the second argument of the inner-most catch function. The argument to throw is bound to the variable exception while the handler in the catch block is running.

4.5 File Operations

CGL has the ability to manipulate operating system files similar to the standard I/O library in ANSI C. The built-in procedures for doing this deal with a ``file ID'' which is a string that is used to refer to an open file. The string is very similar (but not identical) to a file handle in most operating systems.

4.6 File name built-in's

To remain portable, AMC uses a set of routines to handle the manipulation of file names. These routines are exposed to CGL so that CGL routines are also portable. The abstraction AMC uses for filenames is simple and quite portable among different operating systems. Basically, a filename is a string that contains three components separated by certain lexicographic separators. The three components of a filename are:

Location

This is basically where to find a particular file.

Base-name

This is the actual name of a file

Type

This is an identifier of what information the file contains.

The following CGL routines manipulate filenames when they are stored as CGL strings:

Miscellaneous built-in's

CGL also contains various ``useful'' utility routines that don't fit in other categories:


Next Previous Contents