Exemplo n.º 1
0
        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));
        }
Exemplo n.º 2
0
        // 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");
            }
        }
Exemplo n.º 3
0
        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));
        }
Exemplo n.º 4
0
		public FunctionType(SdfType[] arguments, SdfType returntype) {
			this.arguments = arguments;
			this.returntype = returntype;
		}
Exemplo n.º 5
0
 public ArrayType(SdfType elementtype, int dim)
 {
     this.elementtype = elementtype;
       this.dim = dim;
 }
Exemplo n.º 6
0
 public ArrayType(SdfType elementtype, int dim)
 {
     this.elementtype = elementtype;
     this.dim         = dim;
 }
Exemplo n.º 7
0
 public FunctionType(SdfType[] arguments, SdfType returntype)
 {
     this.arguments  = arguments;
     this.returntype = returntype;
 }
Exemplo n.º 8
0
        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
        }