private static SdfType ParseArraySignature(IEnumerator <SigToken> tokens, int dim) { if (tokens.Current is Eof) { throw new SigParseException("Unexpected end of function signature"); } SdfType elementtype = ParseOneType(tokens); return(new ArrayType(elementtype, dim)); }
// ParseType: from stream of signature tokens to a Type object. public static SdfType ParseType(String signature) { IEnumerator <SigToken> tokens = Scanner(signature); tokens.MoveNext(); // There's at least Eof in the stream SdfType res = ParseOneType(tokens); if (tokens.Current is Eof) { return(res); } else { throw new SigParseException("Extraneous characters in signature"); } }
private static SdfType ParseFunctionSignature(IEnumerator <SigToken> tokens) { List <SdfType> arguments = new List <SdfType>(); while (!(tokens.Current is Eof) && !(tokens.Current is RPar)) { arguments.Add(ParseOneType(tokens)); } if (tokens.Current is RPar) { tokens.MoveNext(); } else { throw new SigParseException("Unexpected end of function signature"); } SdfType returntype = ParseOneType(tokens); return(new FunctionType(arguments.ToArray(), returntype)); }
public FunctionType(SdfType[] arguments, SdfType returntype) { this.arguments = arguments; this.returntype = returntype; }
public ArrayType(SdfType elementtype, int dim) { this.elementtype = elementtype; this.dim = dim; }
private ExternalFunction(String nameAndSignature) { int firstParen = nameAndSignature.IndexOf('('); if (firstParen <= 0 || firstParen == nameAndSignature.Length - 1) { throw new Exception("#ERR: Ill-formed name and signature"); } isStatic = nameAndSignature[firstParen - 1] == '$'; String name = nameAndSignature.Substring(0, isStatic ? firstParen - 1 : firstParen); String signature = nameAndSignature.Substring(firstParen); int lastDot = name.LastIndexOf('.'); if (lastDot <= 0 || lastDot == name.Length - 1) { throw new Exception("#ERR: Ill-formed .NET method name"); } String typeName = name.Substring(0, lastDot); String methodName = name.Substring(lastDot + 1); // Experimental: Search appdomain's assemblies Type declaringType = FindType(typeName); if (declaringType == null) { throw new Exception("#ERR: Unknown .NET type " + typeName); } FunctionType ft = SdfType.ParseType(signature) as FunctionType; if (ft == null) { throw new Exception("#ERR: Ill-formed .NET method signature"); } argTypes = ft.ArgumentDotNetTypes(); resType = ft.returntype.GetDotNetType(); if (methodName == "new" && isStatic) { mcInfo = declaringType.GetConstructor(argTypes); } else { mcInfo = declaringType.GetMethod(methodName, argTypes); } if (mcInfo == null) { throw new Exception("#ERR: Unknown .NET method"); } argConverters = new Func <Value, Object> [argTypes.Length]; for (int i = 0; i < argTypes.Length; i++) { argConverters[i] = GetToObjectConverter(argTypes[i]); } resConverter = GetFromObjectConverter(ft.returntype.GetDotNetType()); if (isStatic) { arity = argTypes.Length; } else { arity = argTypes.Length + 1; recType = declaringType; recConverter = GetToObjectConverter(recType); } argValues = new Object[argTypes.Length]; // Allocate once, reuse at calls }