private void GenerateBranches()
{
foreach(var branch in _generatedBranches)
{
if(_debug)
{
_logger.Information($"Generating Branch: {branch.BranchName}");
}
ushort voidOpcode = _opcodes.GetTypeInfo("void").Opcode;
// create script entry
Script script = new Script
{
Name = branch.BranchName,
ReturnType = (short)voidOpcode,
ExecutionType = (short)_opcodes.GetScriptTypeOpcode("static"),
RootExpressionIndex = _currentIndex,
};
_scripts.Add(script);
CreateInitialBegin("void", branch.TextPosition);
LinkDatum();
// create the sleep_until call
FunctionInfo sleepInfo = _opcodes.GetFunctionInfo("sleep_until").First();
CreateFunctionCall(sleepInfo, voidOpcode, branch.TextPosition, 0);
// Adjust the condition expression and add it.
LinkDatum();
ScriptExpression condition = branch.Condition;
condition.Index = _currentIndex;
condition.Next = DatumIndex.Null;
AddExpressionIncrement(condition);
// Adjust the script reference and add it.
LinkDatum();
ScriptExpression scriptReference = branch.TargetScript;
scriptReference.Index = _currentIndex;
scriptReference.Next = DatumIndex.Null;
AddExpressionIncrement(scriptReference);
}
}