/* Translate a call to a custom defined function. Custom defined functions * are handled similarly to builtin math functions with the exception * that for languages that do not support an implicit "this" variable, * the data is passed in as the first argument. */ protected virtual string Translate(Instructions.Function instruction, Context context) { string name = context.FunctionCallName(instruction.FunctionCall); List <string> args = new List <string>(); if (context.This("") == "") { args.Add(context.Program.StateTable.Name); } if (!instruction.FunctionCall.IsCustom) { foreach (Tree.Embedding.Argument argument in instruction.FunctionCall.OrderedArguments) { args.Add(TranslateChildV(context.Node.FromPath(argument.Path), context)); } } else { foreach (Tree.Node child in context.Node.Children) { args.Add(TranslateChildV(child, context)); } } return(String.Format("{0}({1})", name, String.Join(", ", args.ToArray()))); }
protected virtual string TranslateV(Instructions.Function instruction, Context context) { string name = context.FunctionCallName(instruction.FunctionCall); List <string> args = new List <string>(); if (context.This("") == "") { args.Add(context.Program.StateTable.Name); } string ret = null; if (!context.Node.Dimension.IsOne && !InstructionHasStorage(instruction, context)) { // The return value is given as the first argument to the function ret = context.PeekRet(); args.Add(ret); } if (!instruction.FunctionCall.IsCustom) { foreach (Tree.Embedding.Argument argument in instruction.FunctionCall.OrderedArguments) { args.Add(TranslateChildV(context.Node.FromPath(argument.Path), context)); } } else { foreach (Tree.Node child in context.Node.Children) { args.Add(TranslateChildV(child, context)); } } return(String.Format("{0}({1})", name, String.Join(", ", args.ToArray()))); }