Details of the CodeGeneration Package - Maple Programming Help

Home : Support : Online Help : Programming : Code Generation Package : CodeGeneration/Details

Details of the CodeGeneration Package

Basic Information

 • This help page contains complete information about the CodeGeneration package.  For basic information on the CodeGeneration package, see the CodeGeneration help page.

Description

 • The CodeGeneration package is a collection of commands and subpackages that enable the translation of Maple code to other languages. The exports of this package fall into two categories: translators to specific target languages and commands that allow the user to extend the translation facility.
 • The translators available are C, CSharp, Fortran, Java, Julia, Matlab, Perl, Python, R, Swift, and VisualBasic. For a description of options common to all these commands, see the CodeGenerationOptions help page. For a description of special features and limitations of the CodeGeneration package that are relevant to all these target languages, see the TranslationDetails help page.
 • Using the Translate command and the LanguageDefinition subpackage, you can extend the translation capabilities of the CodeGeneration package to new programming languages.  For an overview of this process, see the LanguageDefinitionOverview help page.
 • You can generate code using an interactive template with the Code Generation Assistant.
 • Each command in the CodeGeneration package can be accessed by using either the long form or the short form of the command name in the command calling sequence. As the underlying implementation of the CodeGeneration package is a module, you can also use the form CodeGeneration:-command to access a command from the package. For more information, see the Module Members help page.

List of CodeGeneration Package Commands

 The following is a list of available commands and subpackages.

 To display the help page for a particular CodeGeneration command, see Getting Help with a Command in a Package.

Examples

 > $\mathrm{with}\left(\mathrm{CodeGeneration}\right)$
 $\left[{C}{,}{\mathrm{CSharp}}{,}{\mathrm{Fortran}}{,}{\mathrm{IntermediateCode}}{,}{\mathrm{Java}}{,}{\mathrm{JavaScript}}{,}{\mathrm{Julia}}{,}{\mathrm{LanguageDefinition}}{,}{\mathrm{Matlab}}{,}{\mathrm{Names}}{,}{\mathrm{Perl}}{,}{\mathrm{Python}}{,}{R}{,}{\mathrm{Save}}{,}{\mathrm{Swift}}{,}{\mathrm{Translate}}{,}{\mathrm{VisualBasic}}\right]$ (1)

Generate C code and declare variable types.

 > $C\left(x-3yz,\mathrm{declare}=\left[x::\mathrm{numeric},y::'\mathrm{integer}',z::\mathrm{numeric}\right]\right)$
 cg = -0.3e1 * (double) y * z + x;

Generate MATLAB(R) code where the output is a string.

 > $\mathrm{Matlab}\left(\left[\left[x,2y+z\right],\left[xy,z\right]\right],\mathrm{output}=\mathrm{string}\right)$
 ${"cg0 = \left[x 2 * y + z; x * y z;\right];"}$ (2)

Generate Fortran code and specify single precision for floating-point variables and constants.

 > f:= proc(x) return x^2; end proc:
 > $\mathrm{Fortran}\left(f,\mathrm{precision}=\mathrm{single}\right)$
 real function f (x)         real x         f = x ** 2         return       end

Generate Visual Basic code

 > $\mathrm{VisualBasic}\left(\left[s=1.0+x,t=\mathrm{ln}\left(s\right)\mathrm{exp}\left(-x\right),r=\mathrm{exp}\left(-x\right)+xt\right]\right)$
 s = 0.10E1 + x t = Log(s) * Exp(-x) r = Exp(-x) + x * t