Example #1
0
        public HappyLambdaScriptCode Analyze(Module module, SourceUnit sourceUnit)
        {
            Dictionary<string, HappyNamespaceTracker> rootNamespaces = LoadAllAssemblies(module.LoadDirectives);

            AstVisitorBase[] visitors =
                {
                    new BinaryExpressionFixerVisitor(),
                    new BuildSymbolTablesVisitor(this, _errorCollector, rootNamespaces),
                    new ResolveSymbolsVisitor(_errorCollector),
                    new SemanticVisitor(_errorCollector)
                };

            foreach (var v in visitors)
                module.Accept(v);

            prepareAssemblyGenerator();

            module.Accept(this);

            Expression expression = _expressionStack.Pop();
            DebugAssert.IsZero(_expressionStack.Count, "AstAnalyzer didn't consume all expressions on the stack");

            var runtimeContextInitializer = (LambdaExpression)expression;
            return new HappyLambdaScriptCode(sourceUnit, compileDynamicAssembly(runtimeContextInitializer));
        }
Example #2
0
        public override void AfterVisit(Module node)
        {
            //body contains a array of expressions, that when compiled, populate a single expando object
            //with the functions and default values of the global variables.
            //and more
            List<Expression> body = new List<Expression>();

            var functions = _expressionStack.Pop(node.Functions.Length);
            var globalDefStatements = _expressionStack.Pop(node.GlobalDefStatements.Length);
            var useStatements = _expressionStack.Pop(node.UseStatements.UseStatements.Length, false);
            var loadDirectives = _expressionStack.Pop(node.LoadDirectives.Length);

            emitLoadAssemblies(body, loadDirectives);
            emitUseStatements(body, useStatements);
            body.AddRange(globalDefStatements);
            body.AddRange(functions);

            //Add an empty expression--prevents an exception by Expression.Lambda when body is empty.
            //This allows compilation of empty template sets.
            body.Add(Expression.Empty());

            _expressionStack.Push(node,
                Expression.Lambda(
                    typeof(Action<HappyRuntimeContext>),
                    Expression.Block(new[] {_rootNamespaceDict}, body),
                    new[] { _runtimeContextExp }));
        }
Example #3
0
 public virtual void AfterVisit(Module node)
 {
     this.AfterVisitCatchAll(node);
 }
Example #4
0
 public virtual void BeforeVisit(Module node)
 {
     this.BeforeVisitCatchAll(node);
 }
 public override void AfterVisit(Module node)
 {
     PopAndAssert(node.GetExtension<ScopeExtension>().SymbolTable);
     PopAndAssert(node.UseStatements.GetExtension<ScopeExtension>().SymbolTable);
 }
        public override void BeforeVisit(Module node)
        {
            _currentModule = node;

            node.UseStatements.GetExtension<ScopeExtension>().SymbolTable = new HappySymbolTable("UseStatementList (Import Scope)", null);
            node.GetExtension<ScopeExtension>().SymbolTable = new HappySymbolTable("Globals", node.UseStatements.GetExtension<ScopeExtension>().SymbolTable);

            _scopeStack.Push(node.UseStatements.GetExtension<ScopeExtension>().SymbolTable);
            _scopeStack.Push(node.GetExtension<ScopeExtension>().SymbolTable);

            foreach(var ns in _defaultUseNamespaces)
            {
                string[] namespaceSegments = ns.Split('.');
                addTrackerForDeepestNamespaceToModuleSymbolTable(namespaceSegments,
                                                                 s =>
                                                                 {
                                                                     throw new InternalException("Failed to load default namespace: {0}", ns);
                                                                 });
            }

            foreach (HappyNamespaceTracker tracker in _rootNamespaces.Values)
            {
                node.GetExtension<ScopeExtension>().SymbolTable.Add(new HappyNamedExpressionSymbol(tracker.Name, _getGlobalGetter));
            }
        }