Skip to content

Compiler steps for an RCfunction (or nimbleFunction class method)

perrydv edited this page Apr 26, 2017 · 4 revisions

Steps in processing an "RCfunction", which is a simple nimbleFunction (no setup code) or a method of a nimbleFunction class.

These steps are in the process method of RCfunProcessing.

  • matchKeywords ("Keyword processing step 1"): fills and order arguments.

    • matchKeywords_recurse walks the parse tree.

    • matchFunctions contains the prototypes for matching.

    • Note: For a nimbleFunction class, keyword processing is invoked in a separate step.

  • processKeywords ("Keyword processing step 2"): Creates new setup code and setup outputs, and optionally modifies a call.

  • setupSymbolTables: Initialize local symbol table from arguments and set up returnSymbol.

  • convert the body (code) to exprClass objects (bidirectional syntax tree for later processing)

Most of the following steps have a dedicated "genCpp_XYZ.R" file.

  • exprClasses_processSpecificCalls: (mostly) lightweight processing based on call names, such as changing the name.

    • specificHandlers is a list of R function names (to process the call) indexed by DSL function name.
  • exprClasses_buildInterms : Vestigial step to insert intermediates (temporaries).

  • exprClasses_initSizes initialize typeEnv with types from arguments and return type.

  • exprClasses_setSizes ("size processing"):

    • annotate syntax tree with dimensionality, type, and eigenizability (["yes"|"no"|"maybe"]).
    • generate intermediates and run-time checks (asserts) for later insertion
    • populates symbol table (newLocalSymbolTable) with local variables.
  • exprClasses_insertAssertions: Adds "assertions" (misnamed) collected during size processing to AST.

  • exprClasses_labelForEigenization: Inserts an eigenize(x) node in the AST around each node (line) x to be eigenized.

  • exprClasses_eigenize ("eigenization"): Add Eigen::Map<>s, initialization code, and AST changes for Eigen.

  • exprClasses_liftMaps : Handle maps (slices) that will be implement in C++ NimArr<>s, not Eigen.

Note: C++ generation is done from some kind of "cppDef" object, which contains the AST, using nimGenerateCpp.

Clone this wiki locally