Examples about program part of GRP files

Example #1: library, global, local

.
.
ProgramPart
{
  Process: proc1
  HeaderSection
  {
    Heads  {@#include <string.h>}
    Global {@int i;}
    Local  {@double d;}
  }
  PortSection {}
  ProgramSection {}
}
.
.

In this example we use identifier proc1 after Process keyword. The Grapnel Compiler will generate source of the process in file named 'proc1.c'. Every process definition must have three sections: header, port, and program. Sections can be empty but they must exist. The generated C source will be following:

#include <stdio.h>
#include <math.h>
#include "pvm3.h"
#include "grpdef.h"
#include "grapnel.h"
#include <string.h>

struct channel Channels[0];

int i;

#define WHICH Grp2cInternalWhich
#define TRUE  1
#define true  1
#define True  1
#define FALSE 0
#define false 0
#define False 0

typedef struct channel Tchannel;
typedef struct channel *Pchannel;

void main(int argc, char *argv[])
{
  int Grp2cInternalRecv;
  int      Grp2cInternalWhich;
  Pchannel Grp2cInternalAlt;
  int      Grp2cInternalCyc;
  int      Grp2cInternalBlock;
  Tchannel Grp2cInternalCh;
  double d;

  grp_start(DISK_STORE);

  for (Grp2cInternalCyc= 0; Grp2cInternalCyc < 0; Grp2cInternalCyc++)
    Channels[Grp2cInternalCyc].msgtag= 0;
  for (Grp2cInternalCyc= 0; Grp2cInternalCyc < 0; Grp2cInternalCyc++)
    grp_init_channel(Channels);


  grp_exit(0);
}
Last include file (<string.h>) was defined in Heads part of the header section. We can use more than one heads part or define more than one include file in the same heads part. The previouse include files are included automatically. The <stdio.h>, <math.h>, "grpdef.h", "grapnel.h" will be included into every GRP process.

The following part of the source file contains definitions from Global part of the header section. Generaly global variables are defined here. C source code from the Local part of the header section is included into main function. Grapnel Compiler generates some local variables automaticaly for internal use and after that it puts local definitions picked up from GRP file. Header section can appear once only in every process definition.


Example #2: defining ports

.
.
Process: proc2
HeaderSection {}
PortSection
{
  InPort(none) 1: name1
  {
    Proc: proc1; PortID: 1;
    Type double[1];
    Type int[2];
  }
  OutPort(none) 2: name2
  {
    Proc: proc1; PortID: 2;
    Type int[10];
  }
}
ProgramSection {}
.
.

This GRP file defines two ports for proc2 process. First port is an input port and the second one is an output. Every ports are numbered and the port number must be unique. Generated C code will be following (in proc2.c):

.
.
struct channel Channels[2];

#define from_proc1      0
#define to_proc1        1
.
.
void main(int argc, char *argv[])
{
  int Grp2cInternalRecv;
  .
  .
  Channels[from_proc1].port_num= 1;
  Channels[to_proc1].port_num= 2;


  grp_start(DISK_STORE);

  for (Grp2cInternalCyc= 0; Grp2cInternalCyc < 2; Grp2cInternalCyc++)
    Channels[Grp2cInternalCyc].msgtag= 0;
  for (Grp2cInternalCyc= 0; Grp2cInternalCyc < 2; Grp2cInternalCyc++)
    grp_init_channel(Channels);
.
.
Grapnel Compiler generates additional local variables and channel initialization code for each port. In definition of proc1 must be matched port definitions.

More examples about program section.


Examples about header part.
Examples about program blocks.

Back to definition of GRP language.
Back to Grapnel Compiler.