Exemple #1
0
        public void AddFunction(string name, VMCommand command, IType returnType, params IType[] arguments)
        {
            if (command.ParameterCount != arguments.Length)
            {
                throw new Exception("Mismatching core function parameter count: " + name);
            }
            var fun = new ExprImpl(
                new TypeFunction(new TypeTuple(arguments), returnType),
                expressions.Function(new TypeTuple(arguments), new CoreFunction(command)));

            analyzer.Context.AddVariable(new Variable(name, fun.Type));
            fun.WriteTo(vmw);
            vmw.Write(VMCommand.CurrentContext);
            vmw.Write(VMCommand.AssignContextVariable, coreFunctions++);
        }
Exemple #2
0
        public Expr ContextVariable(AnalyzerContext analyzer, ExprBuilderObj leftExpr, string varName)
        {
            var type        = new TypeContext(new Variable(varName, analyzer.ExpectedType ?? TypeSingleton.Any));
            var left        = analyzer.Analyze(leftExpr, type);
            var contextType = left.Type.ConcreteType as TypeContext;
            var variable    = contextType.Variables.GetAssignableTo(varName, analyzer.ExpectedType);

            if (variable == null)
            {
                analyzer.Fail("Unknown context variable name: " + varName);
            }
            var variable2 = contextType.Variables.GetAssignableTo(varName, analyzer.ExpectedType);

            var refIndex = contextType.Variables.GetReferenceIndex(variable) + 1; // TODO +1 is for the base context
            var expr     = new ExprImpl(variable.Type, exprWriter.ReadContextVariable(refIndex));

            return(new ExprImpl(variable.Type, exprWriter.Sequence(left, expr)));
        }