Next Previous Contents

11. Interactive mode

AMC is unlike most compilers because it can stay resident in memory. Many compiler writers tend not to worry about memory leaks because the operating system usually cleans up after the compile cycle. I am hoping that AMC is robust enough to keep running continually, without problems. In fact, the AMC shell originally started because I wanted an easier way to test for memory leaks in AMC.

If you run AMC with the -i option, it will parse the project file and then print a prompt by which you can issue commands to AMC.

11.1 Editing

On some platforms, you may be able to edit commands and recall past commands.

The POSIX.1 operating system interface supports this feature. As in tcsh and bash, the up and down arrow keys cycle through history. The following keys are supported by the POSIX.1 editor:

Ctrl-A

Takes you to the begining of a line

Ctrl-B

Moves the cursor left

Ctrl-D

Deletes the current character

Ctrl-E

Moves to the end of a line

Ctrl-F

Moves the cursor to the right

Ctrl-H

Deletes the previous character (backspace)

Ctrl-O

Toggle insert/overwrite mode (default is insert)

Ctrl-P

Previous history element (also up-arrow key)

Ctrl-N

Next history element (also down-arrow key)

11.2 Commands

Once starting the shell, a prompt containing the name of the project file is displayed. Any of these commands may be submitted:

If a line begins with the exclamation mark character, the remainder of the line is submitted to the operating system as a command. A common use for the AMC shell is to edit a file (starting your favorite editor) and then issue a make command to compile the newly edited module.

The best way to get familiar with AMC is to get into the shell and issue some CGL commands. Or perhaps use the AMC shell to continually modify a module and re-compile it to see how the changes affect it.

Commands that are submitted to the shell (with the exception of cgl and operating system commands) are normally parsed so that each argument is separated by one or more whitespace characters. If you desire to put a whitespace character within an argument the argument must be quoted. There are two quoting characters available for use: ' and ".

If an argument in a command begins with either of these characters, all characters upto the matching quote character are taken to be a single argument. The reason for allowing two quoting characters is to allow for the other quoting character to be within the argument. For example:

  project> build 'my module'
  project> build "my module"
Both pass the string my module, including the space to the build command.

It is not possible to allow both quoting characters to be within a single argument.

11.3 CGL Debugging

Just like any other program, CGL procedures can have bugs. A simple debugging mechanism allows for tracing of CGL programs to discover problems in them.

Function searching

The lkup interactive command searches for function definitions matching the specified pattern and outputs information about that function. The specified function names do not have to be complete matches. Simple regular expressions consisting of * (match anything) and ? (match a single unknown character) can be used.

Tracing

To trace CGL programs, AMC must have debugging support compiled in. In addition, it must be started in "interactive" mode. Once AMC has compiled the CGL code, tracing may be controlled using the shells trace command. The trace command takes at a minimum two arguments. The first is the kind of tracing to perform and the second and subsequent arguments are patterns of function names to apply the tracing to.

The flags are supported and they can be combined with commas:

These flags can be combined with commas so that multiple trace flags for a function may be set.

The same regular expression mechanism that can be used with lkup can also be used with trace.

For example, to turn on error and entry tracing with arguments for all functions that begin with the string Decl_ this shell command should be entered:

  trace error,entry,args Decl_*

To turn off tracing for those functions:

  trace off Decl_*

Directing trace output

Sometimes it is necessary to take traces of a CGL program and send them back to the author. Normally, trace records appear mixed in with the error stream of the AMC compiler. This can be changed with the trout command. This command can direct trace output to a file as well as supress the trace records printed to the error stream. To send trace records to a file called /tmp/traces.1, the following command should be entered:

  trout file /tmp/traces.1

If traces should be viewed with the error stream, in addition to a file, the following syntax will work:

  trout console file /tmp/traces.1
To restore tracing to just use the console, omit the file /tmp/traces.1 component.


Next Previous Contents