1. Checking if routine id is of a procedure or a of function?

There does not seem to be a way to check if a routine id (obtained via
routine_id()) represents a procedure or a function.

I'm thinking of using callbacks to notify a running program of certain
events. The program would pass in a routine id, and the routine would be
called when the event occures. Some events need a function (return value
required), some only need a procedure. I would like to be able to check that
the correct type of routine has been provided (as opposed to just requiring
that only functions be used and having to always return a value,) but it
seems I can not.

Something like this would be nice:

  if func_id(routine_id) then ...
  if proc_id(routine_id) then ...

DGuy

new topic     » topic index » view message » categorize

2. Re: Checking if routine id is of a procedure or a of function?

David Guy wrote:

> There does not seem to be a way to check if a routine id (obtained via
> routine_id()) represents a procedure or a function.
>
> I'm thinking of using callbacks to notify a running program of certain
> events. The program would pass in a routine id, and the routine would be
> called when the event occures. Some events need a function (return value
> required), some only need a procedure. I would like to be able to check that
> the correct type of routine has been provided (as opposed to just requiring
> that only functions be used and having to always return a value,) but it
> seems I can not.
>
> Something like this would be nice:
>
>   if func_id(routine_id) then ...
>   if proc_id(routine_id) then ...
>
> DGuy

You can add this information yourself, e.g.:

constant FUNC=1, PROC=2

sequence r_info1, r_info2

function my_func()
   return 27
end function
r_info1 = {routine_id("my_func"), FUNC}

procedure my_proc()
   puts(1, "Hello\n")
end procedure
r_info2 = {routine_id("my_proc"), PROC}


Regards,
   Juergen

new topic     » goto parent     » topic index » view message » categorize

3. Re: Checking if routine id is of a procedure or a of function?

David Guy wrote:
> 
> There does not seem to be a way to check if a routine id (obtained via
> routine_id()) represents a procedure or a function.
> 
> I'm thinking of using callbacks to notify a running program of certain
> events. The program would pass in a routine id, and the routine would be
> called when the event occures. Some events need a function (return value
> required), some only need a procedure. I would like to be able to check that
> the correct type of routine has been provided (as opposed to just requiring
> that only functions be used and having to always return a value,) but it
> seems I can not.
> 
> Something like this would be nice:
> 
>   if func_id(routine_id) then ...
>   if proc_id(routine_id) then ...
> 
> DGuy
> 

Seconded. I would like to do that too.

Regards, Alexander Toresson

new topic     » goto parent     » topic index » view message » categorize

4. Re: Checking if routine id is of a procedure or a of function?

> > 
> > Something like this would be nice:
> > 
> >   if func_id(routine_id) then ...
> >   if proc_id(routine_id) then ...
> > 
> > DGuy
> > 
> 
> Seconded. I would like to do that too.
> 

We should get the whole function prototype -- function/procedure, how many
parameters and their types.  I've been asking for that for years...

new topic     » goto parent     » topic index » view message » categorize

5. Re: Checking if routine id is of a procedure or a of function?

Andy Serpa wrote:
> 
> 
> > > Something like this would be nice:
> > > 
> > >   if func_id(routine_id) then ...
> > >   if proc_id(routine_id) then ...
> > > 
> > > DGuy
> > > 
> > 
> > Seconded. I would like to do that too.
> > 
> 
> We should get the whole function prototype -- function/procedure, how many
> parameters
> and their types.  I've been asking for that for years...
> 

I second that too.

Regards, Alexander Toresson

new topic     » goto parent     » topic index » view message » categorize

6. Re: Checking if routine id is of a procedure or a of function?

Alexander Toresson wrote:

>Andy Serpa wrote:
>> 
>> > DGuy wrote:
>> >
>> > > Something like this would be nice:
>> > > 
>> > >   if func_id(routine_id) then ...
>> > >   if proc_id(routine_id) then ...
>> > > 
>> We should get the whole function prototype -- function/procedure, how many
>> parameters
>> and their types.  I've been asking for that for years...
<snip>

Perchance a trivial change to eu.ex. (I dunno)

So just attempt it !!!!

Three of you (at least) want it; why not work together on it?

You never know, if you come up with a slick solution,
Mr-stick-in-the-mud might just accept it, and incorporate it into the
official run-time, just where you want it...!!!

Regards,
Pete

new topic     » goto parent     » topic index » view message » categorize

7. Re: Checking if routine id is of a procedure or a of function?

Pete Lomax wrote:
> Alexander Toresson wrote:
> >Andy Serpa wrote:
> >> > DGuy wrote:
> >> > > Something like this would be nice:
> >> > > 
> >> > >   if func_id(routine_id) then ...
> >> > >   if proc_id(routine_id) then ...
> >> We should get the whole function prototype -- function/procedure, how many
> >> parameters
> >> and their types.  I've been asking for that for years...
> Perchance a trivial change to eu.ex. (I dunno)
> So just attempt it !!!!
> Three of you (at least) want it; why not work together on it?
> You never know, if you come up with a slick solution,
> Mr-stick-in-the-mud might just accept it, and incorporate it into the
> official run-time, just where you want it...!!!
>

Just for the heck of it, how's this? I guess it was fairly trivial since it only
took me less the time from this.parent.timeOfReadBy(ME) until
this.timeOfReadBy(YOU) to write it up (sorry to those who don't like OOP ;).
This will create a new function called routine_info() that will return the
   following information about a routine_id.
1. Type: 1=procedure, 2=function, 3=type
2. Name of Function/Type/Procedure
3. Parameters: Returns a sequence of the names of the types (easier to use than
the values from dll.e, and works with user-defined types, too!).

Follow these steps:
1. Add op_result[ROUTINE_INFO] = T_SEQUENCE to the list (around line 240) in
emit.e.
2. Add ROUTINE_INFO to the find() call at line 686 (just before ROUTINE_ID),
also in emit.e
3. Add {"routine_info", SC_PREDEF, FUNC, ROUTINE_INFO, 1, E_PURE} to the end of
the keylist sequence in keylist.e.
4. Add "ROUTINE_INFO" to the end of the opnames sequence in opnames.e.
5. Add ROUTINE_INFO = 169 at the end of the first list, and change MAX_OPCODE to
169 in reswords.e.
6. Add the following procedure to execute.e somewhere before InitBackEnd:
procedure opROUTINE_INFO()
-- return information on a routine id
-- {type, name, parameters}
    integer arg, n
    symtab_index sub, t
    sequence info

    a = Code[pc+1]
    target = Code[pc+2]

    if val[a] < 0 or val[a] >= length(e_routine) then
        RTFatal("invalid routine id")
    end if

    sub = e_routine[val[a]+1]
    n = SymTab[sub][S_NUM_ARGS]
    arg = SymTab[sub][S_NEXT]

    info = {find(SymTab[sub][S_TOKEN], {PROC, FUNC, TYPE}), -- Type of Function
            SymTab[sub][S_NAME], -- Name of Function
            repeat(0, n)}        -- Argument Types
    for i = 1 to n do
        t = SymTab[arg][S_VTYPE]
        info[3][i] = SymTab[t][S_NAME]
        arg = SymTab[arg][S_NEXT]
    end for

    val[target] = info
    pc += 3
end procedure


> Regards,
> Pete
> 

~[ WingZone ]~
http://wingzone.tripod.com/

new topic     » goto parent     » topic index » view message » categorize

8. Re: Checking if routine id is of a procedure or a of function?

Elliott Sales de Andrade wrote:
> 
> Pete Lomax wrote:
> > Alexander Toresson wrote:
> > >Andy Serpa wrote:
> > >> > DGuy wrote:
> > >> > > Something like this would be nice:
> > >> > > 
> > >> > >   if func_id(routine_id) then ...
> > >> > >   if proc_id(routine_id) then ...
> > >> We should get the whole function prototype -- function/procedure, how
> > >> many parameters
> > >> and their types.  I've been asking for that for years...
> > Perchance a trivial change to eu.ex. (I dunno)
> > So just attempt it !!!!
> > Three of you (at least) want it; why not work together on it?
> > You never know, if you come up with a slick solution,
> > Mr-stick-in-the-mud might just accept it, and incorporate it into the
> > official run-time, just where you want it...!!!
> >
> 
> Just for the heck of it, how's this? I guess it was fairly trivial since it
> only took
> me less the time from this.parent.timeOfReadBy(ME) until
> this.timeOfReadBy(YOU) to
> write it up (sorry to those who don't like OOP ;).
>    This will create a new function called routine_info() that will return the
>    following
> information about a routine_id.
<snip>

You rule! I'll make Xaero include that in VEEU.

Regards, Alexander Toresson

new topic     » goto parent     » topic index » view message » categorize

9. Re: Checking if routine id is of a procedure or a of function?

On Sat, 09 Apr 2005 22:45:35 -0700, Elliott Sales de Andrade
<guest at RapidEuphoria.com> wrote:

>Just for the heck of it, how's this?
Looks pretty cool to me!

Pete

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu