[slang-users] debug: points where left on the stack

Marko Mahnic marko.mahnic at email.si
Tue Aug 23 03:40:40 EDT 2005


Joerg Sommer wrote:
> "John E. Davis" <davis at space.mit.edu> wrote:
> 
>>Joerg Sommer <joerg at alea.gnuu.de> wrote:
>>
>>>I'm interested in functions they leave values on the stack after quit
>>>without using the return statement. I'm not interested in such constructs:
>>>
>>>do_check();
>>>do_something();
>>>if ( () )
>>
>>You should try to minimize the use of such constructs.
> 
> 
> Why? Is a cool feature of slang.
> 
It is a cool feature but it makes the code harder to read,
understand and mantain. In the example above you already
wrote two interpretations (does do_check push the status
or does do_something do it?).


One way to control the stack would be to use sth similar
to _auto_declare (or _boseos_info).
If the compilation unit would for example declare
   _strict_return = 1

then all functions that leave sth on the stack would have
to push the result on the stack with return.


Such byte-compiled functions would look like this
    A = stack_pointer
    .... compiled body ....
    if (stack_pointer - A != _NRESULTS) do_error(...)

In some cases one would need to return a different number of
values even when _strict_return = 1. This could be done by
setting _NRESULTS inside the function:

define foo()
{
    _NRESULTS = 2;
    push("abcde");
    ....
    return 5;
}

_NRESULTS is similar to _NARGS but it is compiled
only when _strict_return = 1, otherwise it is ignored.
(can this be done ?)


There are cases when the number of results is not known
at compile time, but in such cases the function should
return a list or an array (one object with multiple values,
_NRESULTS = 1).

IMO this would lead to better documented code.

Marko






More information about the slang-users-l mailing list