Next: , Previous: , Up: Compiler   [Contents][Index]


4.5.2 Code Generation Compiler Back-End

The code generation back-end is provided by the (rpc compiler) module. Given an XDR/RPC description, it returns a list of S-expressions, each of which is a top-level Scheme expression implementing an element of the input description. These expressions are meant to be dumped to a Scheme file; this is what the command-line interface of the compiler does (see grpc-compile).

Here is an example XDR/RPC description and the resulting client code, as obtained, e.g., with grpc-compile --xdr --constants --client:

const max = 010;

struct foo
{
  int   x;
  float y<max>;
};

=>

(define max 8)
(define foo
  (make-xdr-struct-type
    (list xdr-integer
          (make-xdr-vector-type xdr-float max))))

As can be seen here, the generated code uses the run-time support routines described earlier (see Implementation of XDR); an optimization would consist in generating specialized code that does not depend on the run-time support, but it is not implemented yet.

This front-end consists of two procedures:

Scheme Procedure: rpc-language->scheme-client input type-defs? constant-defs?
Scheme Procedure: rpc-language->scheme-server input type-defs? constant-defs?

These procedures return a list of top-level Scheme expressions implementing input for an RPC client or, respectively, a server.

input can be either an input port, a string, or an AST as returned by rpc-language->sexp (see Parser). If type-defs? is #t, then type definition code is produced; if constant-defs? is #t, then constant definition code is produced.

Both procedures can raise error conditions having a sub-type of &compiler-error.