Example #1
0
        public override void Visit(ProgramNode node)
        {
            var visitor1 = new NestedUseVisitor1();

            node.Accept(visitor1);
            var visitor2 = new NestedUseVisitor2(visitor1.DeclToFunction);

            node.Accept(visitor2);
        }
Example #2
0
 public ProgramNode CheckSemantic(ProgramNode node, IScope scope, ICollection <string> errors)
 {
     this.scope  = scope;
     this.errors = errors;
     node.Accept(this);
     return(node);
 }
        /// <summary>
        /// Return all function definitions contained in this program AST.
        /// </summary>
        internal static IReadOnlyCollection <FunctionDefinitionNode> GetAllFunctionDefinitions(
            this ProgramNode node)
        {
            var visitor = new FunctionSplitterVisitor();

            node.Accept(visitor);
            return(visitor.Functions);
        }
        public ProgramNode Optimize(ProgramNode node, IScope scope)
        {
            Scope = scope;

            node.Accept(this);

            return(node);
        }
Example #5
0
        public TinyProgram Compile(ProgramNode programNode)
        {
            _parts     = new Dictionary <AstNode, object>();
            _variables = new Dictionary <char, int>();
            _loader    = (name, value) => _variables[name] = value;

            programNode.Accept(this);

            var variableList = _variables.Keys.ToList();

            Func <int> runner = (Func <int>)_parts[programNode.Program];

            return(new TinyProgram(variableList,
                                   _loader,
                                   runner));
        }
Example #6
0
        public List <ThreeCode> GetIntermediateCode(ProgramNode node, IScope scope)
        {
            Scope = scope;



            IC = new List <ThreeCode>();
            VariableManager = new VariableManager();
            VirtualTable    = new VirtualTable(scope);

            VariableManager.PushVariableCounter();
            InitCode();
            VariableManager.PopVariableCounter();

            node.Accept(this);

            VariableManager.PushVariableCounter();
            StartFunctionCode();
            VariableManager.PopVariableCounter();

            return(IC);
        }
Example #7
0
        public List <CodeLine> GetIntermediateCode(ProgramNode node, IScope scope)
        {
            Scope = scope;

            node = (new OptimizationTour()).Optimize(node, scope);

            IC = new List <CodeLine>();
            VariableManager = new VariableManager();
            VirtualTable    = new VirtualTable(scope);

            VariableManager.PushVariableCounter();
            InitCode();
            VariableManager.PopVariableCounter();

            node.Accept(this);

            VariableManager.PushVariableCounter();
            StartFunctionCode();
            VariableManager.PopVariableCounter();

            return(IC);
        }
        public List <CodeLine> GetIntermediateCode(ProgramNode node, IScope scope)
        {
            Scope = scope;



            Code            = new List <CodeLine>();
            VariableManager = new VariableManager();
            ClassManager    = new ClassManager(scope);

            VariableManager.PushVariableCounter();
            InitCode();
            VariableManager.PopVariableCounter();

            node.Accept(this);

            VariableManager.PushVariableCounter();
            StepOne();
            VariableManager.PopVariableCounter();

            return(Code);
        }
Example #9
0
 /// <summary>
 ///     Names of all variables must be resolved before use of this visitor.
 /// </summary>
 /// <param name="node">Root of AST tree</param>
 internal static void FillInNestedUseFlag(this ProgramNode node)
 {
     node.Accept(new NestedUseVisitor());
 }