Ejemplo n.º 1
0
        public void CompileProgram(Program program)
        {
            AstNode prevNode = null;
            int     counter  = 0;

            while (counter < program.Statements.Length)
            {
                foreach (var pair in program.Labels)
                {
                    if (pair.Value.Address == counter)
                    {
                        textWriter.WriteLine("{0}:", SafeName(pair.Key));
                    }
                }

                AstNode node = program.Statements[counter];
                if (prevNode != null && (
                        node is ClassDefinition || prevNode is ClassDefinition ||
                        node is FunctionDecl || prevNode is FunctionDecl ||
                        (node is ImportDirective ^ prevNode is ImportDirective)))
                {
                    textWriter.WriteLine();
                }

                node.AcceptCompiler(this);
                if (node is Expression)
                {
                    textWriter.WriteLine(";");
                }
                prevNode = node;
                ++counter;
            }
        }
Ejemplo n.º 2
0
 private void MayBeIndent(AstNode stmt)
 {
     if (stmt.GetType() == typeof(Block))
     {
         stmt.AcceptCompiler(this);
     }
     else
     {
         ++textWriter.Indentation;
         stmt.AcceptCompiler(this);
         if (stmt is Expression)
         {
             textWriter.WriteLine(";");
         }
         --textWriter.Indentation;
     }
 }