Skip to content

Commit

Permalink
CodeGen.m: Add if-then-else style conditional
Browse files Browse the repository at this point in the history
  • Loading branch information
ianhinder committed May 25, 2011
1 parent b56e3c5 commit a612d99
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions Tools/CodeGen/CodeGen.m
Expand Up @@ -43,6 +43,9 @@
DeclareVariable::usage = "DeclareVariable[name, type] returns a block of code " <>
"that declares a variable of given name and type. 'name' and 'type' should be " <>
"strings.";
DeclareVariableNoInit::usage = "DeclareVariableNoInit[name, type] returns a block of code " <>
"that declares a variable of given name and type without initialising it. 'name' and 'type' should be " <>
"strings.";
DeclareVariables::usage = "DeclareVariables[names, type] returns a block of code " <>
"that declares a list of variables of given name and type. 'names' should be a list" <>
" of strings and 'type' should be a string string.";
Expand Down Expand Up @@ -130,6 +133,7 @@
Quote::usage = "Quote[x] returns x surrounded by quotes";
DataType::usage = "DataType[] returns a string for the grid function data type (e.g. CCTK_REAL)";
SetDataType::usage = "SetDataType[type] sets a string for the grid function data type (e.g. CCTK_REAL)";
Conditional;

Begin["`Private`"];

Expand Down Expand Up @@ -247,6 +251,12 @@
{type, " :: ", name, EOL[]} (* no value init here to avoid implicit SAVE attribute *)
];

DeclareVariableNoInit[name_, type_] :=
If[SOURCELANGUAGE == "C",
{type, " ", name, EOL[]},
{type, " :: ", name, EOL[]} (* no value init here to avoid implicit SAVE attribute *)
];


DeclareVariables[names_?ListQ, type_] :=
If[SOURCELANGUAGE == "C",
Expand Down Expand Up @@ -748,12 +758,16 @@
]}
]]]};

conditional[condition_, block_] :=
Conditional[condition_, block_] :=
{"if (", condition, ")\n",
CBlock[block]};

Conditional[condition_, block1_, block2_] :=
{"if (", condition, ")\n",
CBlock[block1], "else\n", CBlock[block2]};

onceInGridLoop[block_] :=
conditional["i == 5 && j == 5 && k == 5",
Conditional["i == 5 && j == 5 && k == 5",
block];

InfoVariable[name_] :=
Expand Down

0 comments on commit a612d99

Please sign in to comment.