Control the generation of function callback code
Int_Type _bofeof_info
This value of this variable dictates whether or not the S-Lang interpreter will generate code to call the beginning and end of function callback handlers. The value of this variable is local to the compilation unit, but is inherited by other units loaded by the current unit.
If the value of this variable is 1 when a function is defined, then
when the function is executed, the callback handlers defined via
_set_bof_handler
and _set_eof_handler
will be called.
Control the generation of BOS/EOS callback code
Int_Type _boseos_info
This value of this variable dictates whether or not the S-Lang interpreter will generate code to call the beginning and end of statement callback handlers. The value of this variable is local to the compilation unit, but is inherited by other units loaded by the current unit.
The lower 8 bits of _boseos_info
controls the generation of code for
callbacks as follows:
Value Description
-----------------------------------------------------------------
0 No code for making callbacks will be produced.
1 Callback generation will take place for all non-branching
and looping statements.
2 Same as for 1 with the addition that code will also be
generated for branching statements (if, !if, loop, ...)
3 Same as 2, but also including break and continue
statements.
A non-branching statement is one that does not effect chain of
execution. Branching statements include all looping statements,
conditional statement, break
, continue
, and return
.
If bit 0x100 is set, callbacks will be generated for preprocessor statements.
Consider the following:
_boseos_info = 1;
define foo ()
{
if (some_expression)
some_statement;
}
_boseos_info = 2;
define bar ()
{
if (some_expression)
some_statement;
}
The function foo
will be compiled with code generated to call the
BOS and EOS handlers when some_statement
is executed. The
function bar
will be compiled with code to call the handlers
for both some_expression
and some_statement
.
The sldb debugger and slsh's stkcheck.sl
make use of this
facility.
Clear an error condition (deprecated)
_clear_error ()
This function has been deprecated. New code should make use of try-catch exception handling.
This function may be used in error-blocks to clear the error that triggered execution of the error block. Execution resumes following the statement, in the scope of the error-block, that triggered the error.
Consider the following wrapper around the putenv
function:
define try_putenv (name, value)
{
variable status;
ERROR_BLOCK
{
_clear_error ();
status = -1;
}
status = 0;
putenv (sprintf ("%s=%s", name, value);
return status;
}
If putenv
fails, it generates an error condition, which the
try_putenv
function catches and clears. Thus try_putenv
is a function that returns -1 upon failure and 0 upon
success.
Get information about a stack frame
Struct_Type _get_frame_info (Integer_Type depth)
_get_frame_info
returns a structure with information about
the function call stack from of depth depth
. The structure
contains the following fields:
file: The file that contains the code of the stack frame.
line: The line number the file the stack frame is in.
function: the name of the function containing the code of the stack
frame; it might be NULL if the code isn't inside a function.
locals: Array of String_Type containing the names of variables local
to the stack frame; it might be NULL if the stack frame doesn't
belong to a function.
namespace: The namespace the code of this stack frame is in.
Get the value of a variable local to a stack frame
Any_Type _get_frame_variable (Integer_Type depth, String_Type name)
This function returns value of the variable name
in the stack
frame at depth depth
. This might not only be a local variable but
also variables from outer scopes, e.g., a variable private to the
namespace.
If no variable with this name is found an UndefinedNameError
will be thrown. An VariableUninitializedError
will be
generated if the variable has no value.
Set the beginning of function callback handler
_set_bof_handler (Ref_Type func)
This function is used to set the function to be called prior to the
execution of the body S-Lang function but after its arguments have
been evaluated, provided that function was defined
with _bofeof_info
set appropriately. The callback function
must be defined to take a single parameter representing the name of
the function and must return nothing.
private define bof_handler (fun)
{
() = fputs ("About to execute $fun"$, stdout);
}
_set_bos_handler (&bof_handler);
Set the beginning of statement callback handler
_set_bos_handler (Ref_Type func)
This function is used to set the function to be called prior to the beginning of a statement. The function will be passed two parameters: the name of the file and the line number of the statement to be executed. It should return nothing.
private define bos_handler (file, line)
{
() = fputs ("About to execute $file:$line\n"$, stdout);
}
_set_bos_handler (&bos_handler);
The beginning and end of statement handlers will be called for
statements in a file only if that file was compiled with the variable
_boseos_info
set to a non-zero value.
Set the beginning of function callback handler
_set_eof_handler (Ref_Type func)
This function is used to set the function to be called at the end of
execution of a S-Lang function, provided that function was compiled with
_bofeof_info
set accordingly.
The callback function will be passed no parameters and it must return nothing.
private define eof_handler ()
{
() = fputs ("Done executing the function\n", stdout);
}
_set_eof_handler (&eof_handler);
Set the end of statement callback handler
_set_eos_handler (Ref_Type func)
This function is used to set the function to be called at the end of a statement. The function will be passed no parameters and it should return nothing.
private define eos_handler ()
{
() = fputs ("Done executing the statement\n", stdout);
}
_set_eos_handler (&eos_handler);
The beginning and end of statement handlers will be called for
statements in a file only if that file was compiled with the variable
_boseos_info
set to a non-zero value.
Turn function tracing on or off
Integer_Type _slangtrace
The _slangtrace
variable is a debugging aid that when set to a
non-zero value enables tracing when function declared by
_trace_function
is entered. If the value is greater than
zero, both intrinsic and user defined functions will get traced.
However, if set to a value less than zero, intrinsic functions will
not get traced.
Generate a traceback upon error
Integer_Type _traceback
_traceback
is an intrinsic integer variable whose bitmapped value
controls the generation of the call-stack traceback upon error.
When set to 0, no traceback will be generated. Otherwise its value
is the bitwise-or of the following integers:
1 Create a full traceback
2 Omit local variable information
4 Generate just one line of traceback
The default value of this variable is 4.
Running slsh with the -g
option causes this variable to be
set to 1.
Set the function to trace
_trace_function (String_Type f)
_trace_function
declares that the S-Lang function with name
f
is to be traced when it is called. Calling
_trace_function
does not in itself turn tracing on. Tracing
is turned on only when the variable _slangtrace
is non-zero.
Selects the namespace of a stack frame
_use_frame_namespace (Integer_Type depth)
This function sets the current namespace to the one belonging to the
call stack frame at depth depth
.