Beispiel #1
0
        private JsFunction CompileFunction(string sourceCode, ReadOnlyArray<string> parameters)
        {
            BodySyntax newBody;

            if (sourceCode == String.Empty)
                newBody = new BodySyntax(BodyType.Function, ReadOnlyArray<SyntaxNode>.Empty, ReadOnlyArray<IIdentifier>.Empty, false, null);
            else
                newBody = ParseBlockStatement(sourceCode, parameters);

            var function = new FunctionSyntax(null, parameters, newBody, null);

            var scriptBuilder = TypeSystem.CreateScriptBuilder(null);
            var bindingVisitor = new BindingVisitor(scriptBuilder);

            var boundFunction = bindingVisitor.DeclareFunction(function);

            DefiniteAssignmentPhase.Perform(boundFunction);
            TypeMarkerPhase.Perform(boundFunction);

            boundFunction = SquelchPhase.Perform(boundFunction);

            return (JsFunction)Delegate.CreateDelegate(
                typeof(JsFunction),
                new CodeGenerator(Global, scriptBuilder).BuildFunction(boundFunction, sourceCode)
            );
        }