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.
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:
Takes you to the begining of a line
Moves the cursor left
Deletes the current character
Moves to the end of a line
Moves the cursor to the right
Deletes the previous character (backspace)
Toggle insert/overwrite mode (default is insert)
Previous history element (also up-arrow key)
Next history element (also down-arrow key)
Once starting the shell, a prompt containing the name of the project file is displayed. Any of these commands may be submitted:
build
Build cleans up all of the output of AMC and rebuilds either all of
the project roots or (if specified) the listed modules. As with the
-r command line option, if a colon character (:)
is present in the parameter, the string to the left of the colon is
taken to be a location and the string to the right is taken to
be the actual module name.
cgl
This command evaluates a CGL expression. The results of the expression are sent to the standard output. This is a very useful command when writing new syntax. It allows you to interactively see what your CGL code will do. Most CGL built-in's are allowed (except those that require a module be under compilation).
For example, one can go:
project> cgl "The answer is: " add(1,2,3);
The answer is: 6
project>
clean
This command removes the output of a project. It can be used to gain disk space or just get things back to a ``known state.''
exit
This exits the AMC shell back to the host operating system.
help
This command prints a list of all available commands along with a summary describing each command.
make
This command compiles files by doing the appropriate dependency checking.
It accepts the same command line syntax as build.
keep
With no arguments, it displays if AMC is set to keep its temporary
output files or delete them. With an argument of on, the keep
flag will be turned on. If the argument is off, the keep flag
will be turned off. An invalid argument displays the current status of
the setting.
set
The set command requires two parameters. The first is the name
of an environment variable and the second is the value to assign to it.
wrap
As with the keep command, if this command is invoked with no
arguments it displays if AMC is set to word-wrap error messages. If
the argument provided is on, error messages are word wrapped
as appropriate based on the perceived width of the terminal. If the
argument is off, AMC will simply output an error message as
a single string to the console.
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.
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.
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.
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:
entry
Trace function entry. When a function with this flag is first entered, a trace record indicating the entry is printed.
exit
Trace on function exit. When a function with this flag set returns to its caller a trace record is printed.
error
A trace record is printed if the function with this flag handles an error.
args
If this flag is set trace records will include the argument list of the function.
out
If this flag is set trace records will include the results (even partial results if an error occurs) generated by that function.
off
This will turn off all trace flags.
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_*
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.