/// <summary> /// Generates function for some function node /// </summary> /// <param name="funcNode">The function node.</param> private void GenerateMethod(FunctionDefinition funcNode) { Type returnType = ILTypeTranslator.Translate(funcNode.ReturnType); List <Type> paramsTypes = new List <Type>(); foreach (ArgumentDefinition arg in funcNode.Args) { paramsTypes.Add(ILTypeTranslator.Translate(arg.Type)); } MethodBuilder currentMethod = mainClass.DefineMethod(funcNode.Name, MethodAttributes.Static | MethodAttributes.Public, returnType, paramsTypes.ToArray()); currentFunction = new ILFunctionRef(this, funcNode, currentMethod); il = currentMethod.GetILGenerator(); BlockEnter(); int index = 1; foreach (ArgumentDefinition arg in funcNode.Args) { new ILArgument(new TypeEntity(arg.Type), arg.Name, this, currentMethod, index++); } statementEvaluator.GenerateCode(funcNode.Body); il.Emit(OpCodes.Ret); BlockLeave(); entryPoint = currentMethod; }
void IExpressionVisitor.Visit(FunctionCall This) { string name = This.Name; ILFunctionRef call = GetNamedObject(name) as ILFunctionRef; if (call == null) { call = ILFunctionRef.LookForDotNetMethod(generator, This); } if (call == null) { throw new AnalizeException("The function " + name + " does not exist in the current context (or have wrong signature)", This); } call.SetCallNode(This); result = call; }