Mad-Pascal icon indicating copy to clipboard operation
Mad-Pascal copied to clipboard

Feature: Direct parameter reference of functions and procedures.

Open GSoftwareDevelopment opened this issue 2 years ago • 0 comments

Currently, passing parameters to functions and procedures is performed by creating local variables for them. This solution is good and safe, but it generates the code needed to assign the values of passed variables to the local variables of the procedure/function.

My suggestion is to be able to pass a parameter as a direct reference - something like 'var' but without creating a local variable, i.e. a global variable, but inside the block, would be represented by an individual name. You could use a modifier, e.g. & or a textual ref or as reference, which would be presented in the code e.g.

procedure Opn(&chn,&ax1,&ax2:byte @device:PString);

or

procedure Opn(ref chn,ax1,ax2:byte ref device:PString);

or

procedure Opn(chn,ax1,ax2:byte as reference; device:PString as reference);

The example of the CIO.Opn(chn, ax1, ax2: byte; device: PByte); procedure is here for a reason. Using this procedure is a double rewrite of information:

  1. from the contents of the passed parameters to the procedure;
  2. inside the procedure, where local variables are "plugged" into the IOCB block.

This is not the only case where such a solution would shorten the resulting code.

Technically, this would be done by replacing the address of the variable used as a direct reference. I don't know how much the compiler design would allow you to do this?

The plus side of this approach, is the clarity that the block accepts parameters. You don't have to parse the code to know that global variables must be set before using such a function or procedure. An additional advantage is not rewriting the parameters to local variables - the programmer decides for himself.

GSoftwareDevelopment avatar Jun 10 '22 19:06 GSoftwareDevelopment