[comp.std.mumps] Alternative Error Trapping

hokey@plus5.UUCP (Hokey) (03/25/88)

Title: Alternative Error Trapping

Advocate: Hokey <hokey@plus5.com>

History: 20 Mar 88 - Submitted

Abstract:
	An alternative error trapping proposal is presented.  Advantages of
	this proposal over X11/SC1/TG5/87-1 include:
	- Ability to emulate the three known existing error trap mechanisms.
	  Each subroutine can choose its own mechanism.
	- More functional condition reporting.
	- Execution stack backtrace facility (including Xecute and indirection).
	- Doesn't require/use the ETRAP or EPOP commands.

	This is little more than a reformatting of my 1986 proposal, which
	has been in your hands for about 2 years.

Proposal: (Page and section numbers are from X11/SC1/TG5/87-1)
	
	Delete the following three lines fro the top of page 2:

		At section 1.2 6 add ...
		ETRAP	...
		EPOP	...
	
	Replace the 3.2.7 additions with:

	    $EC[ODE]	contains information about an error condition.
			This information is loaded by the implementation
			after detecting an erroneous condition, or by
			the application via the SET command.  When $EC
			contains the empty string, normal routine execution
			rules are in effect.  When $EC contains anything
			else, error condition execution rules are in effect.
			See section 3.5.10 for additional information.

			The syntax of a non-null value returned by $EC is
			as follows:

			    , L <ecode> , | <SEP> <msgstring> | ...

					| M |
			    <ecode> ::= | I | [ <ecodestring> ]
					| U |

					Note: <ecode>s beginning with:
					    M are reserved for the MDC
					    I are reserved for the implementor
					    U are reserved for the user
					    any other characters are reserved.

			    <SEP> ::= _		Note: underscore

			    <ecodestring> ::= <any graphic character except
						comma and SEP>

			    <msgstring> ::= <any graphic character except SEP>

	    $EL[INE]	holds backtrace information regarding the point
			at which an error condition occurred, and may contain
			code or data as well.

			$ELine takes values as the value of $ECode changes.
			If an error condition is not being processed, $ELine
			is extended as indirection and subroutine (DO,
			XECUTE, exfunc, exvar, etc.) are popped, thereby
			providing backtrace information.

			The value of $ELine is the last subscript which
			contains data in the subscripted form of $ELine.

			The actual address information and code or data is
			stored in subscripts of	$ELine.	 Odd numbered
			subscripts of $Eline contain the <place> reporting
			the error, while even numbered subscripts contain
			the value (in the case of indirection) or the <line>
			(or the empty string if the <line> is not available)
			for which the condition is being reported.

				 | [[tag][+offset][^routine]][SP+offset] |
		     <place> ::= |					 |
				 | @[+offset]				 |

			NOTE: regardless of the syntactic definition,
			<place> will always resolve to a non-empty string.

	    $EStack	can be NEWed.  NEW $EStack causes the "old" value of
			$EStack to be saved and the "new" value of $EStack to
			be zero.  The value of $EStack is incremented as
			subroutine levels are encountered, and decremented
			or replaced from the NEW stack as these levels are
			exited.

	    $ETrap	contains code which is invoked in the event an
			error condition occurs.  This invocation is
			equivalent to the XECUTE mechanism with the exception
			of the transference of control to the invoked code;
			the XECUTE command effects a transfer via a DO
			command, while the error trap mechanism effects
			a transfer via a GOTO command.

			The value of $ETrap is stacked with the NEW command.

			The value of $ETrap is changed with the SET command.

			Changing the value of $ETrap instantiates a new trap;
			it does not save the old trap.

			A QUIT from $ETrap, either explicit or implicit (i.e.,
			s $ET="d ^etrap" has an implicit QUIT at its end) will
			function as if a QUIT had been issued at the "current"
			$STacklevel.  Behavior at the "popped" level will be
			determined by the value of $ECode.  If $ECode is empty,
			execution proceeds normally.  Otherwise, $ETrap is
			invoked at the new level.

			A HALT from $ETrap will pop the stack back to the most
			recent direct mode level or NEWed $ETrap level, or,
			finally, out of mumps.

	    $STacklevel contains the current level of the DO/XECUTE stack.
	
	Replace the contents of the proposed section 3.5.10 with:

	    Error trapping provides a mechanism by which a MUMPS job can
	    execute specifiable commands in the event that $ECode becomes
	    non-empty.  The following facilities are provided.

	    The $ETrap special variablemay be SET to either the empty string
	    or to code to be invoked when $ECode becomes non-empty.  Stacking
	    of the contents of $ETrap is performed via the NEW command.

	    $ECode provides information describing existing error conditions.
	    The first "section" of $ECode is a comma-surrounded list of
	    conditions.  (This makes it easy to identify conditions using the
	    contains operator.)  Subsequent sections of $ECode are available
	    to the implementor, who may choose to use them for more verbose
	    messages describing error conditions.

	    $ELine provides backtrace information.  In its unsubscripted form,
	    $ELine returns the highest numbered subscript of $ELine(intexpr)
	    which contains data.  If any such information is available, it
	    starts with subscript 1.  In other words, all backtrace information
	    can be had from the command sequence:

		For I=1:1:$EL ...
	
	    $EStack counts subroutine levels since $EStack was last NEWed.

	    When  the value of $ECode becomes non-empty or is non-empty
	    after a subroutine level is popped off the execution stack,
	    the following actions are performed:

	    1. Increment $ELine by two, and update the contents of $EL($EL-1)
	       and $EL($EL) with backtrace information.  If this backtrace
	       information was made by indirection, pop the indirection frame
	       and restart this step.

	    2. Execute the value of $ETrap.  When x is the value of $ETrap,
	       this is equivalent to the execution of GOTO y, where y is
	       the spelling of an otherwise unused label attached to the
	       following two-line sequence considered to be part of the
	       currently executing routine:

			y ls x ; eol
			  ls QUIT eol
		
	       If an error is detected in this step, the value of $ECode
	       is updated, step 1 above is invoked, and an effective QUIT
	       is executed.

(I don't have time to finish this section.  The only parts I think are missing
are the extensions of the NEW command to allow for NEW $ETrap and NEW $EStack,
and SET $ETrap.  I will attempt to have these sections ready at the April
meeting.)
-- 
Hokey