slang-users mailing list

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

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


Joerg Sommer wrote:
> "John E. Davis" <davis@xxxxxxxxxxxxx> wrote:
> 
>>Joerg Sommer <joerg@xxxxxxxxxxxx> 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



_______________________________________________
To unsubscribe, visit http://jedsoft.org/slang/mailinglists.html


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