private void ParseOpCodes() { //add our base block to root BlockSyntax block = BlockHelper.CreateNewBlock("name"); //add block to root GlobalStatementSyntax globalStatement = SyntaxFactory.GlobalStatement(block); BlockHelper.Root = BlockHelper.Root.AddMembers(globalStatement); //set as current BlockHelper.SetBlockAsCurrent(block); OpCodeProcessor opCodeProcessor = new OpCodeProcessor(); opCodeProcessor.OpCodes = ParsedContent.OpCodeList; opCodeProcessor.VariableSet = this.variableSet; opCodeProcessor.ProcessOpCodes(); }
private void ProcessFunction() { DataIndex function = (DataIndex)stack.Pop(); string functionName = FunctionTable.Functions[function.Value]; ExpressionSyntax expressionSyntax = SyntaxFactory.IdentifierName(functionName); ArgumentListSyntax argumentList = SyntaxFactory.ArgumentList(); List <ArgumentSyntax> arguments = new List <ArgumentSyntax>(); //reverse the stacks stack = new Stack <object>(stack); while (stack.Count > 0) { ExpressionSyntax paramSyntax = PopVariable(); arguments.Add(SyntaxFactory.Argument(paramSyntax)); // IsCharacterDead only takes one parameter and we need to cope with bug if (functionName == "IsCharacterDead" && stack.Count > 0) { // cope with bug if (OpCodes[codePointer + 1].OpCode == OpCodeType.OP_EQUAL) { arguments.Clear(); ExpressionSyntax paramSyntax2 = PopVariable(); arguments.Add(SyntaxFactory.Argument(paramSyntax2)); stack.Push(paramSyntax); } break; } } argumentList = argumentList.AddArguments(arguments.ToArray()); InvocationExpressionSyntax invocationExpression = SyntaxFactory.InvocationExpression(expressionSyntax, argumentList); ExpressionStatementSyntax expressionStatement = SyntaxFactory.ExpressionStatement(invocationExpression, semi); // are we assigning to an equal as a bug? if (OpCodes[codePointer + 1].OpCode == OpCodeType.OP_EQUAL) { var variableIdentifier = PopVariable(); var binaryExpression = SyntaxFactory.BinaryExpression(SyntaxKind.EqualsExpression, variableIdentifier, invocationExpression); expressionStatement = SyntaxFactory.ExpressionStatement(binaryExpression, semi); //make sure we move past the OP_EQUAL codePointer++; } { //are we assigning to a variable? if (OpCodes[codePointer + 1].OpCode == OpCodeType.OP_GETTOP) { var variableIdentifier = SyntaxFactory.IdentifierName(VariableSet.Variables[OpCodes[codePointer + 1].DataIndex.Value].Name); var assignment = SyntaxFactory.AssignmentExpression(SyntaxKind.SimpleAssignmentExpression, variableIdentifier, expressionStatement.Expression); expressionStatement = SyntaxFactory.ExpressionStatement(assignment, semi); //make sure we move past the OP_GETTOP codePointer++; } if (OpCodes[codePointer + 1].OpCode == OpCodeType.OP_GETTOP) { //add to the current block var variableIdentifier = SyntaxFactory.IdentifierName(VariableSet.Variables[OpCodes[codePointer + 1].DataIndex.Value].Name); var assignment = SyntaxFactory.AssignmentExpression(SyntaxKind.SimpleAssignmentExpression, variableIdentifier, expressionStatement.Expression); expressionStatement = SyntaxFactory.ExpressionStatement(assignment, semi); //make sure we move past the OP_GETTOP codePointer++; } } //add to the current block BlockHelper.AddToCurrentBlock(expressionStatement); }