jed-users mailing list

[2004 Date Index] [2004 Thread Index] [Other years]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]

Re: jed 0.99-17 looks good


On 25.11.04, John E. Davis wrote:
> G. Milde <g.milde@xxxxxx> wrote:
 
> I plan to add a control variable to slang that will cause an error or
> warning to be generated when a statement leaves something on the
> stack.  The control variable would be local to the file, e.g.,
> 
>   __stack_check=1;
> 	.
> 	.
>        right (1);
>         .
> 	.
>   __stack_check=0;
> 
> would generate a warning.

Maybe a library function working similar to tic() / toc() would do instead:

static variable last_stkdepth = 0;
% modus: 0 set, 1 warn, 2 error
define stack_check(modus)
{
   variable str, change = _stkdepth - last_stkdepth;
   if (modus == 0)
     { 
	last_stkdepth = _stkdepth(); 
	return; 
     }
   
   str = sprintf("stackcheck: Stack changed by %d", change);
   
   if (modus == 1)
     message(str);
   else if (modus == 2 and (_stkdepth() != last_stkdepth))
     error(str);
}

now,    

stack_check(0);   % set stack checker (determine _stkdepth)

right(1);

stack_check(1);   % produce warning

will give you the message
   
   stackcheck: Stack changed by 1


More verbose is the version I have in my evalbuf wrapper:

% evaluate buffer or region (if defined), show stack leftovers
% needs diagnose.sl
public define slang_run_buffer ()
{
   variable buf = whatbuf(), stkdepth_before = _stkdepth();
   if(is_visible_mark())
     narrow_to_region();
   evalbuffer();
   setbuf(buf);
   widen_region();
   if (_stkdepth() > stkdepth_before)
     {
	show(whatbuf() + " leaved stuff on stack!");
	show_stack();
     }
   message(buf + " evaluated " + MESSAGE_BUFFER);
}

Günter

-- 
G.Milde web.de

--------------------------
To unsubscribe send email to <jed-users-request@xxxxxxxxxxx> with
the word "unsubscribe" in the message body.
Need help? Email <jed-users-owner@xxxxxxxxxxx>.


[2004 date index] [2004 thread index]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]