public void Visit(FunctionNode function) { const string stackLimit = ".limit stack 256"; //TODO: Arbitrary limit - should be determined by analyzing the depth of the expressions in the method body string localsLimit = string.Format(".limit locals {0}", function.Parameters.Count + function.LocalVariableCount); _currentFunctionIsMain = (function.Name.Name == "Main"); if (_currentFunctionIsMain) { _output.WriteLine(".method public static main([Ljava/lang/String;)V"); Emit(stackLimit); if (function.LocalVariableCount > 0) Emit(localsLimit); Emit("new java/util/Scanner"); Emit("dup"); Emit("getstatic", "java/lang/System/in", "Ljava/io/InputStream;"); Emit("invokespecial java/util/Scanner/<init>(Ljava/io/InputStream;)V"); Emit("putstatic VslMain/scanner Ljava/util/Scanner;"); } else { var parameterTypes = new string('I', function.Parameters.Count); _output.WriteLine(".method public static {0}({1})I", function.Name.Name, parameterTypes); Emit(stackLimit); if (function.LocalVariableCount > 0) Emit(localsLimit); } _parameterCounts.Push(function.Parameters.Count); function.Body.Accept(this); _parameterCounts.Pop(); _output.WriteLine(".end method"); }
private void CheckReturnTypes(FunctionNode function) { foreach (ReturnStatement returnStatement in returnStatements) { if (returnStatement.EvaluationType != function.ReturnType) { analyzer.notifyError(new InvalidReturnValueError(returnStatement, function.ReturnType)); } } returnStatements.Clear(); }
public void Visit(FunctionNode function) { Emit("function {0}() {{", function.Name.Name); ++_indentationLevel; Emit("var locals = [];"); Emit("var params = [];"); for (int i = function.Parameters.Count - 1; i >= 0; --i) { Emit("params[{0}] = stack.pop();", i); } function.Body.Accept(this); --_indentationLevel; Emit("}"); }
public void Visit(FunctionNode function) { string parameterTypes = string.Join(", ", Enumerable.Repeat("int32", function.Parameters.Count)); _output.WriteLine(" .method public static int32 {0}({1}) cil managed {{", function.Name.Name, parameterTypes); if (function.Name.Name == "Main") Emit(".entrypoint"); if (function.LocalVariableCount > 0) { var variableTypes = string.Join(", ", Enumerable.Repeat("int32", function.LocalVariableCount)); Emit(string.Format(".locals init ({0})", variableTypes)); } function.Body.Accept(this); _output.WriteLine(" }"); }
public void Visit(FunctionNode function) { string parameterTypes = string.Join(", ", Enumerable.Repeat("int32", function.Parameters.Count)); _output.WriteLine(" .method public static int32 {0}({1}) cil managed {{", function.Name.Name, parameterTypes); if (function.Name.Name == "Main") { Emit(".entrypoint"); } if (function.LocalVariableCount > 0) { var variableTypes = string.Join(", ", Enumerable.Repeat("int32", function.LocalVariableCount)); Emit(string.Format(".locals init ({0})", variableTypes)); } function.Body.Accept(this); _output.WriteLine(" }"); }
public void VisitFunctionNode(FunctionNode node) { node.Parameters.Accept(this); node.Block.Accept(this); if (returnStatements.Count == 0) { analyzer.notifyError(new FunctionDoesntReturnError(node)); } CheckReturnTypes(node); int blockStatementCount = node.Block.Statements.Count; if (blockStatementCount == 0 || !node.Block.Statements[blockStatementCount - 1].Returns) { analyzer.notifyError(new AllCodePathsDontReturnError(node)); } }
public void VisitFunctionCallNode(FunctionCallNode node) { node.Accept(this.typeChecker); VariableIdNode idNode = node.IdNode; ArgumentsNode arguments = node.ArgumentsNode; idNode.Accept(this); if (arguments != null) { arguments.Accept(this); if (!analyzer.SyntaxTree.Root.Functions.ContainsKey(idNode.ID)) { analyzer.notifyError(new NotAValidFunctionError(idNode)); } else { FunctionNode function = analyzer.SyntaxTree.Root.Functions [idNode.ID]; CompareParamsAndArgs(node, function.Parameters.Parameters, arguments.Arguments); } } }
public AllCodePathsDontReturnError(FunctionNode node) : base(ErrorConstants.SEMANTIC_ERROR_TITLE, ErrorConstants.ALL_CODE_PATHS_DONT_RETURN_MSG, node) { }
public FunctionDoesntReturnError(FunctionNode node) : base(ErrorConstants.SEMANTIC_ERROR_TITLE, ErrorConstants.FUNCTION_DOESNT_RETURN_MSG, node) { }
private static Node buildIdentifierNode(Token token) { Node nodeToReturn = null; if (Functions.FunctionLookup.ContainsKey(token.TokenString.ToLower())) { nodeToReturn = new FunctionNode(token.TokenString); nodeToReturn.AppendMeTo = AppendTokenTo.parent; } else if (Keywords.KeywordLookup.ContainsKey(token.TokenString.ToLower())) { nodeToReturn = Keywords.KeywordLookup[token.TokenString.ToLower()].BuildMethod(); nodeToReturn.AppendMeTo = Keywords.KeywordLookup[token.TokenString.ToLower()].AppendTokenTo; } return nodeToReturn; }
public void VisitFunctionNode(FunctionNode node) { }