/* * Finds all function maps and combines into one function map. Looks for multiple main methods. * */ private static InstructionInvocation link(InstructionInvocation[] instructionInvocations) { InstructionInvocation firstInvocation = instructionInvocations[0]; CompliationUnitNode compliationUnitNode = (CompliationUnitNode)firstInvocation.InstructionList[0]; Dictionary <string, Node> functionNodeMap = new Dictionary <string, Node>(); //JAVA TO C# CONVERTER TODO TASK: There is no .NET Dictionary equivalent to the Java 'putAll' method: functionNodeMap.putAll(firstInvocation.FunctionNodeMap); //JAVA TO C# CONVERTER TODO TASK: Java lambdas satisfy functional interfaces, while .NET lambdas satisfy delegates - change the appropriate interface to a delegate: long oneMainFunction = functionNodeMap.Keys.stream().filter(f => "main".Equals(f)).count(); if (instructionInvocations.Length > 0) { for (int i = 1; i < instructionInvocations.Length; i++) { compliationUnitNode.Instructions.AddRange(instructionInvocations[i].InstructionList); //JAVA TO C# CONVERTER TODO TASK: Java lambdas satisfy functional interfaces, while .NET lambdas satisfy delegates - change the appropriate interface to a delegate: oneMainFunction += instructionInvocations[i].FunctionNodeMap.Keys.stream().filter(f => "main".Equals(f)).count(); //JAVA TO C# CONVERTER TODO TASK: There is no .NET Dictionary equivalent to the Java 'putAll' method: functionNodeMap.putAll(instructionInvocations[i].FunctionNodeMap); } } if (oneMainFunction == 1) { IList <Node> inst = new List <Node>(); inst.Add(compliationUnitNode); return(new InstructionInvocation(inst, functionNodeMap)); } if (oneMainFunction > 1) { throw new Exception("Multiple main methods were found during linking"); } throw new Exception("No main functions were found during linking"); }
public static InstructionInvocation loadAndLink(string[] filesToLoad) { int fileCount = filesToLoad.Length; ReadWriteBinaryFile read = new ReadWriteBinaryFile(); InstructionInvocation[] instructionInvocations = new InstructionInvocation[fileCount]; int count = 0; foreach (string file in filesToLoad) { instructionInvocations[count] = read.read(file); if (instructionInvocations[count].InstructionList.Count == 0) { throw new Exception("Invalid library. Make sure there were no compilation errors"); } count++; } InstructionInvocation instructionInvocation = link(instructionInvocations); //read.write( "a.out", ); return(instructionInvocation); }
/* * private class operatorBinding { * public * } */ public Interpreter(InstructionInvocation invocation) { if (!InstanceFieldsInitialized) { InitializeInstanceFields(); InstanceFieldsInitialized = true; } try { EvaluateAssignments.create(this); IList <Node> inst = invocation.InstructionList; activationFrameStack.push(new ActivationFrame("compliationUnit")); functionNodeMap = invocation.FunctionNodeMap; functionMap[NodeType.VariableReassignmentType] = (EvaluateAssignments::evalReassignment); functionMap[NodeType.AssignmentType] = (EvaluateAssignments::evalAssignment); functionMap[NodeType.PrimitiveType] = (EvaluatePrimitives::evalPrimitives); //JAVA TO C# CONVERTER TODO TASK: Java lambdas satisfy functional interfaces, while .NET lambdas satisfy delegates - change the appropriate interface to a delegate: functionMap[NodeType.CompliationUnitType] = ((n, activationFrame, callback) => evalCompilationUnit()); //JAVA TO C# CONVERTER TODO TASK: Java lambdas satisfy functional interfaces, while .NET lambdas satisfy delegates - change the appropriate interface to a delegate: functionMap[NodeType.AddType] = ((n, activationFrame, callback) => evalAdd()); //JAVA TO C# CONVERTER TODO TASK: Java lambdas satisfy functional interfaces, while .NET lambdas satisfy delegates - change the appropriate interface to a delegate: functionMap[NodeType.CommandType] = ((n, activationFrame, callback) => evalCommand(n)); //JAVA TO C# CONVERTER TODO TASK: Java lambdas satisfy functional interfaces, while .NET lambdas satisfy delegates - change the appropriate interface to a delegate: functionMap[NodeType.SummationType] = ((n, activationFrame, callback) => evalSummation()); //JAVA TO C# CONVERTER TODO TASK: Java lambdas satisfy functional interfaces, while .NET lambdas satisfy delegates - change the appropriate interface to a delegate: functionMap[NodeType.FunctionaCallType] = ((n, activationFrame, callback) => evalFunctionCall(n)); //JAVA TO C# CONVERTER TODO TASK: Java lambdas satisfy functional interfaces, while .NET lambdas satisfy delegates - change the appropriate interface to a delegate: functionMap[NodeType.FunctionDeclType] = ((n, activationFrame, callback) => evalFunctionDecl(n)); //JAVA TO C# CONVERTER TODO TASK: Java lambdas satisfy functional interfaces, while .NET lambdas satisfy delegates - change the appropriate interface to a delegate: functionMap[NodeType.VariableType] = ((n, activationFrame, callback) => evalActivationFrame(n)); //JAVA TO C# CONVERTER TODO TASK: Java lambdas satisfy functional interfaces, while .NET lambdas satisfy delegates - change the appropriate interface to a delegate: functionMap[NodeType.BinaryType] = ((n, activationFrame, callback) => evalBinaryNode(n)); //JAVA TO C# CONVERTER TODO TASK: Java lambdas satisfy functional interfaces, while .NET lambdas satisfy delegates - change the appropriate interface to a delegate: functionMap[NodeType.StatementType] = ((n, activationFrame, callback) => evalStatement(n)); //JAVA TO C# CONVERTER TODO TASK: Java lambdas satisfy functional interfaces, while .NET lambdas satisfy delegates - change the appropriate interface to a delegate: functionMap[NodeType.ExpressionType] = ((n, activationFrame, callback) => evalStatement(n)); //JAVA TO C# CONVERTER TODO TASK: Java lambdas satisfy functional interfaces, while .NET lambdas satisfy delegates - change the appropriate interface to a delegate: functionMap[NodeType.FinalType] = ((n, activationFrame, callback) => evalFinal()); //JAVA TO C# CONVERTER TODO TASK: Java lambdas satisfy functional interfaces, while .NET lambdas satisfy delegates - change the appropriate interface to a delegate: functionMap[NodeType.EvaluatableType] = ((n, activationFrame, callback) => evaluateEvauatable(n, activationFrame, callback)); //JAVA TO C# CONVERTER TODO TASK: Java lambdas satisfy functional interfaces, while .NET lambdas satisfy delegates - change the appropriate interface to a delegate: functionMap[NodeType.UserDefinedFunctionReferenceType] = ((n, activationFrameStack, callback) => evalUserDefinedFunctionCall(n)); functionMap[NodeType.AggregateType] = (this::evaluateAggregate); functionMap[NodeType.ReturnValueType] = (this::evalReturn); functionMap[NodeType.BooleanType] = (this::evalBooleanNode); functionMap[NodeType.BooleanOperatorType] = (this::evalBooleanOperator); functionMap[NodeType.IfExprType] = (this::evalIfStatement); functionMap[NodeType.WhileExpressionType] = (this::evalWhileExpression); functionMap[NodeType.VariableDeclarationType] = (this::evalVariableDeclration); //functionMap.put(NodeType.VariableDeclarationType, (n-> eval(n))); //functionMap.put(NodeType.ReturnValueType , (n-> evalReassignment(n) )); execute(inst); } catch (Exception ex) { JuliarLogger.log(ex); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void generate(InstructionInvocation invocation, String outputfile) throws java.io.IOException public virtual void generate(InstructionInvocation invocation, string outputfile) { IList <Node> inst = invocation.InstructionList; generate(inst, outputfile); }