XEROX SIGNAL 2 4 1 Signal 1 4 By: Henry Thompson (HThompson.pa@Xerox.com) INTRODUCTION The package Signal implements a first pass at the CEDAR/MESA signal mechanism. It allows signals to be raised, caught, examined, and resumed or exited. Catch phrases are introduced with the clisp-word enable; signals are raised with the function Signal. FUNCTIONS (Signal type arg) [Function] Raises a signal of type type. If the signal is resumed, will return with the argument to sresume, see below. Otherwise will not return. (enable s1 => a1 a2 a3 ... . . . sn => n1 n2 n3 ... form l1 -> la1 la2 ... . . . ln -> ln1 ln2 ...) [Function] The double arrow lines above are called catch phrases, the single arrow lines are called finish phrases. Evaluates form so as to catch signals s1, ... sn if they are raised during its evaluation. If e.g. s1 is raised, the forms a1 ... an (the catch phrase for s1) will be evaluated in the context of the call to Signal which raised s1, with the addition of the fact that the variables type and arg will be locally bound to type and arg. For a catch phrase to be well formed, all control paths through it must end with one of the following four quit forms: (exit) [Function] Causes the stack to unwind back through the enclosing enable form, which is exited with value NIL. (sresume form) [Function] Returns from the call to Signal with the value of form as the value of that call. (goto label) Causes the stack to unwind back to the enclosing enable form, where the finish phrase for label is evaluated. The value of the last form in the phrase is the value of the enable. The variables $SignalType$, $SignalArg$, and $Exit$ will be bound to type and arg of the original call to Signal and label respectively, but otherwise the environment of the call to Signal is lost. (reject) [Function] Causes the signal handling process to act as if the catch phrase had not been there at all. Operation When a signal is raised the stack is scanned upwards for a catch phrase for that signal. If none is found (or if all those found are rejected) an Uncaught Signal break will occur. Otherwise the one of the three other options listed above will occur. There is one signal name which receives special interpretation. A catch phrase with the name any will catch any signal not explicitly caught elsewhere in the enable. There is a special label whose name is unwind, which cannot be gone to and has a special meaning. The finish clause for the unwind label will be evaluated as the stack unwinds upwards from a call to Signal to the enable clause which caught it (or to the UserExec if ERROR! is envoked). Implementation At the moment the package does use ERROR! and NLSETQ itself to implement the stack unwinding. This means the package interacts correctly with RESETSAVE, but has the unfortunate consequence that interleaving on the stack of calls to ERRORSET in any of its forms and enable clauses has consequences which are confusing at best. As there are many ways in which the semantics of signals and catchers are much cleaner than those of errors and errorsets, it is hoped that at some point a more sophisticated implementation of the signal mechanism undoing the resetsaves directly and redefining ERRORSET in terms of enable will be made available. As an interim measure however, a mechanism for turning errors into signals has been provided. The function (MakeErrorsSignals) will arrange that all errors will be converted into a signal with name LispError and argument an instance of the following record: (RECORD LispError ((eMess eFn . eType) ePos eBkChk . ePntMsg)) [Record] where eMess is the standard error message pair (for printing with ERRORMESS), eFn the name of the function which the old package would have broken, eType its type, and ePos a stack pointer to its frame. If you catch this signal, you should free the stack pointer. If you don't catch it (or catch and reject it), a break may or may not happen, depending on eBkChk and ePntMsg, which are the values of BREAKCHECK AND PRINTMESS respectively. Things from the old package that still work are ERRORTYPELST, user interrupts, and the various other funnies to do with hash arrays and EOFs which the error code handles. To go back to the old way of life, call (MakeErrorsErrorsAgain) [Function] EXAMPLES There follows on the next page an toy example of the use of thepackage, which is in fact included in the file itself - enjoy! (ST [LAMBDA NIL (* ht: "20-JAN-83 21:40") (enable s1 => (PRINT "s1 caught" T) (goto s1) s2 => (PRINT "s2 caught") (sresume 37) s3 => (PRINT "s3 caught") (reject) s4 => (PRINT "s4 caught") (exit) any => (printout T type " caught by any" T) (exit) (TestSignals) s1 -> (PRINT "s1 unwound") unwind -> (PRINT "unwinding"))]) (TestSignals [LAMBDA NIL (* ht: "18-JAN-83 16:39") (printout T T (SELECTQ (PROGN (printout T T ">") (READ)) (1 (Signal 's1 1)) (2 (Signal 's2 2)) (3 (Signal 's3 3)) (4 (Signal 's4 4)) (5 (Signal 'foo 5)) 6) '_]) (LIST ((PAGE NIL (PAPERSIZE Letter FOLIOINFO (ARABIC ) STARTINGPAGE# 1) (0 0 612 792) ((FOLIO NIL (PARALOOKS (QUAD CENTERED) CHARLOOKS (SUPERSCRIPT 0 INVISIBLE OFF SELECTPOINT OFF PROTECTED OFF SIZE 10 FAMILY MODERN OVERLINE OFF STRIKEOUT OFF UNDERLINE OFF EXPANSION REGULAR SLOPE REGULAR WEIGHT MEDIUM INVERTED OFF USERINFO NIL STYLE NIL) FORMATINFO (ARABIC )) (174 36 288 36) NIL) (HEADING NIL (HEADINGTYPE RUNNINGHEAD) (84 744 528 36) NIL) (TEXT NIL NIL (84 96 456 600) NIL))) (PAGE NIL (PAPERSIZE Letter FOLIOINFO (ARABIC )) (0 0 612 792) ((FOLIO NIL (PARALOOKS (QUAD CENTERED) CHARLOOKS (SUPERSCRIPT 0 INVISIBLE OFF SELECTPOINT OFF PROTECTED OFF SIZE 10 FAMILY MODERN OVERLINE OFF STRIKEOUT OFF UNDERLINE OFF EXPANSION REGULAR SLOPE REGULAR WEIGHT MEDIUM INVERTED OFF USERINFO NIL STYLE NIL) FORMATINFO (ARABIC )) (174 36 288 36) NIL) (HEADING NIL (HEADINGTYPE RUNNINGHEAD) (84 744 528 36) NIL) (TEXT NIL NIL (84 96 456 600) NIL))) (PAGE NIL (PAPERSIZE Letter FOLIOINFO (ARABIC )) (0 0 612 792) ((FOLIO NIL (PARALOOKS (QUAD CENTERED) CHARLOOKS (SUPERSCRIPT 0 INVISIBLE OFF SELECTPOINT OFF PROTECTED OFF SIZE 10 FAMILY MODERN OVERLINE OFF STRIKEOUT OFF UNDERLINE OFF EXPANSION REGULAR SLOPE REGULAR WEIGHT MEDIUM INVERTED OFF USERINFO NIL STYLE NIL) FORMATINFO (ARABIC )) (174 36 288 36) NIL) (HEADING NIL (HEADINGTYPE RUNNINGHEAD) (84 744 528 36) NIL) (TEXT NIL NIL (84 96 456 600) NIL))))) 1$$¤ ¼È1$$¤ È1È ¼È1È È(È (È(ŠŠ8(ŠŠ8DÈÈ PAGEHEADING RUNNINGHEAD(TERMINAL MODERN MODERN MODERN MODERN MODERNLOGO   HRULE.GETFNMODERN  HRULE.GETFNMODERN  HRULE.GETFNMODERN  HRULE.GETFNMODERN  HRULE.GETFNMODERN -      n    t4FYzc  2Z›$M\ ý¨ H: CCºí($ ~ÙE¤«zº