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

new topic     » goto parent     » topic index » view thread      » older message » newer message

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 thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu