Ejemplo n.º 1
0
        private static IType getTargetAtomicType(Context context, IType type)
        {
            IDeclaration decl = context.getRegisteredDeclaration <IDeclaration>(type.GetTypeName());

            if (decl == null)
            {
                throw new SyntaxError("Unknown identifier: " + type.GetTypeName());
            }
            else if (decl is MethodDeclarationMap)
            {
                MethodDeclarationMap map = (MethodDeclarationMap)decl;
                if (map.Count == 1)
                {
                    return(new MethodType(map.GetFirst()));
                }
                else
                {
                    throw new SyntaxError("Ambiguous identifier: " + type.GetTypeName());
                }
            }
            else
            {
                return(decl.GetIType(context));
            }
        }
Ejemplo n.º 2
0
        public override IValue interpretReference(Context context)
        {
            // resolve parent to keep clarity
            IExpression parent   = resolveParent(context);
            IValue      instance = parent.interpret(context);

            if (instance == null || instance == NullValue.Instance)
            {
                throw new NullReferenceError();
            }
            else if (instance is IInstance)
            {
                CategoryDeclaration  category = ((IInstance)instance).getDeclaration();
                MethodDeclarationMap methods  = category.getMemberMethods(context, name);
                IMethodDeclaration   method   = methods.GetFirst();             // TODO check prototype
                return(new ClosureValue(context.newInstanceContext((IInstance)instance, true), new MethodType(method)));
            }
            else
            {
                throw new SyntaxError("Should never get here!");
            }
        }
Ejemplo n.º 3
0
        private IMethodDeclaration getDeclaration(Context context)
        {
            IExpression expression = this.expression;

            if (expression is UnresolvedSelector)
            {
                IExpression parent = ((UnresolvedSelector)expression).getParent();
                if (parent != null)
                {
                    IType type = parent.check(context);
                    if (type is CategoryType)
                    {
                        expression = new UnresolvedIdentifier(((UnresolvedSelector)expression).getName(), Dialect.O);
                        context    = context.newInstanceContext((CategoryType)type, true);
                    }
                    else
                    {
                        return(null);                        // TODO report problem
                    }
                }
            }
            if (expression is UnresolvedIdentifier)
            {
                String name = ((UnresolvedIdentifier)expression).ToString();
                MethodDeclarationMap methods = context.getRegisteredDeclaration <MethodDeclarationMap>(name);
                if (methods != null)
                {
                    return(methods.GetFirst());
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                throw new NotImplementedException();
            }
        }