GetFile builtin function_(re)

Mon, 4 Aug 1997 13:37:30 +0200 (MET DST)


Hi, Bill!  Hi, everybody!

According to Bill Currie:
> 
> Isn't.  That is: the function is provided in rts-file.c (_p_getfile), 
> but it's not supported by the compiler.

You can write `Function GetFile: Pointer; AsmName `_p_getfile';' into
your program and just use it, but I see, you want more than this.  :-)

> How do I go about adding 
> this (or others) function?  I'ld rather get instructions on how to do 
> it myself rather than a patch (though I can study the patch) so I can 
> learn how do to it to add more functions later on (such as Lo, Hi 
> etc).

That would be great!

Here is a recipe how to introduce a new built-in function into GPC.
If it looks like French for you, feel free to ask me - I can speak
French (more or less).

  * Edit `util.c', go into the `KItable[]' and add this identifier with
    the appropriate flags (`GNU_PASCAL' since it is not part of any other
    standard).  (Perhaps after `DefineSize' is a nice place?)  (First
    Letter Capitalized.)

  * Edit `parse.y' and add `gpc_GETFILE' (my suggested name for it) to the
    list of tokens (= constant definitions), perhaps after `p_DEFINESIZE'.

  * In `parse.y', look how something similar is implemented (e.g., again,
    `p_DEFINESIZE') and do it similarly.  This means:

      - Give it a return type:  "%type  gpc_GETFILE".

      - Add it to `new_identifier_1', so the name remains redefinable.

      - Add it to `rts_fun_onepar', so the parser will take it into account.

    In case you are not familiar with Bison (I was not when I found GPC):
    This language essentially is a machine-readable form of syntax diagrams.
    The `bison' program translates this into a C file not intened to be read
    by humans.  The C stuff indented with two tabs is the "action" to be
    taken if the pascal parser reads this syntax.

  * Again in `util.c', function `build_rts_call', write a handler for
    `gpc_GETFILE'.  This is where the real work is done; all the above is
    administrative stuff.

    But in this case, it's quite simple:  Do the same as `case p_DEFINESIZE'
    does, i.e. warn about ISO violation, check for errors (hmm ... these
    functions don't count their arguments ... looks like a bug in GPC ...
    we should check it ...), and pass the argument to the other parts of
    `build_rts_call' which will do the work.

  * Don't forget to follow the GNU coding style guidelines.

  * Don't forget to send me a patch, so I can study it.  ;-)

  * What about doing the same for `ParamCount' and `ParamStr'?  The RTL
    functions do *almost* the same as their BP equivalents do.  Perhaps
    we should make them truly compatible and built-in?  (One problem:
    `ParamStr' must return a String of unknown length.  Where to allocate
    it?)

Welcome to the GNU Pascal development team!

Yours,

    Peter

 Dipl.-Phys. Peter Gerwinski, Essen, Germany, free physicist and programmer
peter.gerwinski@uni-essen.de - http://home.pages.de/~peter.gerwinski/ [970201]
 maintainer GNU Pascal [970714] - http://home.pages.de/~gnu-pascal/ [970125]


Peter Gerwinski (peter@agnes.dida.physik.uni-essen.de)

HTML conversion by Lluís de Yzaguirre i Maura
Institut de Lingüística Aplicada - Universitat "Pompeu Fabra"
e-mail: de_yza@upf.es