public MipsProgram VisitStringConstant(ASTCILStringConstantNode StringConstant)
        {
            var result      = new MipsProgram();
            var stringValue = Regex.Unescape(StringConstant.Value);

            if (!StringConstantGenerated.TryGetValue(StringConstant.Value, out var labelStringConstant))
            {
                result.SectionData.Append(MipsGenerationHelper.NewScript()
                                          .AddData(StringConstant.ObjectLabel,
                                                   new[]
                {
                    MipsGenerationHelper.AddIntData(
                        labelGenerator.GenerateLabelTypeInfo(CompilationUnit.TypeEnvironment.String.Name)),
                    MipsGenerationHelper.AddIntData(StringConstant.ValueLabel),
                    MipsGenerationHelper.AddIntData(stringValue.Length)
                })
                                          .Comment(StringConstant.Value)
                                          .AddData(StringConstant.ValueLabel, new[]
                {
                    MipsGenerationHelper.AddByteData(Regex.Unescape(StringConstant.Value).Select(x => (int)x))
                }));
                StringConstantGenerated.Add(StringConstant.Value, StringConstant.ObjectLabel);
                labelStringConstant = StringConstant.ObjectLabel;
            }

            result.SectionCode.Append(MipsGenerationHelper.NewScript()
                                      .LoadFromAddress(MipsRegisterSet.a0, labelStringConstant)
                                      .Add(MipsRegisterSet.a0, 4));
            return(result);
        }
        public MipsProgram VisitType(ASTCILTypeNode Type)
        {
            var result = new MipsProgram();

            foreach (var method in Type.Methods)
            {
                result += method.Accept(this);
            }

            var typeName        = Type.Type.Name;
            var typeNameParent  = Type.Type.Parent?.Name;
            var label_type_name = labelGenerator.GenerateLabelTypeName(typeName);

            result.SectionData.Append(MipsGenerationHelper.NewScript()
                                      .AddData(label_type_name.value, new[]
            {
                MipsGenerationHelper.AddStringData(typeName)
            }));
            result.SectionData.Append(MipsGenerationHelper.NewScript()
                                      .AddData(label_type_name.@object, new[]
            {
                MipsGenerationHelper.AddIntData(label_type_name.value),
                MipsGenerationHelper.AddIntData(typeName.Length)
            }));

            var label_virtual_table = labelGenerator.GenerateLabelVirtualTable(typeName);

            result.SectionData.Append(MipsGenerationHelper.NewScript()
                                      .AddData(label_virtual_table,
                                               Type.VirtualTable.Select(x =>
                                                                        MipsGenerationHelper.AddIntData(labelGenerator.GenerateFunc(x.Type.Name, x.Name)))));

            var typeInfo_label        = labelGenerator.GenerateLabelTypeInfo(typeName);
            var typeInfo_label_parent = typeNameParent != null?labelGenerator.GenerateLabelTypeInfo(typeNameParent) : labelGenerator.GenerateVoid();

            result.SectionData.Append(MipsGenerationHelper.NewScript()
                                      .AddData(typeInfo_label, new[]
            {
                MipsGenerationHelper.AddIntData(label_type_name.@object),
                MipsGenerationHelper.AddIntData(Type.Type.AllocateSize),
                MipsGenerationHelper.AddIntData(label_virtual_table),
                MipsGenerationHelper.AddIntData(typeInfo_label_parent)
            }));

            result.SectionDataGlobals.Append(MipsGenerationHelper.NewScript().GlobalSection(label_type_name.value)
                                             .GlobalSection(label_type_name.@object)
                                             .GlobalSection(label_virtual_table).GlobalSection(typeInfo_label));

            return(result);
        }
        public MipsProgram VisitProgram(ASTCILProgramNode Program)
        {
            var bufferlabel = MipsGenerationHelper.BufferLabel;

            var result = new MipsProgram();

            result.SectionDataGlobals.Append(MipsGenerationHelper.NewScript().GlobalSection(bufferlabel));
            result.SectionData.Append(MipsGenerationHelper.NewScript()
                                      .AddData(bufferlabel, new[] { MipsGenerationHelper.AddDynamycString(MipsGenerationHelper.BufferSize) }));

            List <string> all = new List <string>();

            foreach (var item in RuntimeErrors.GetRuntimeErrorString)
            {
                var exception = labelGenerator.GetException(item.Key);
                all.Add(exception);
                result.SectionDataGlobals.Append(MipsGenerationHelper.NewScript()
                                                 .GlobalSection(exception));
                result.SectionData.Append(MipsGenerationHelper.NewScript()
                                          .AddData(exception, new[] { MipsGenerationHelper.AddStringData(item.Value) }));
            }

            var exceptions = MipsGenerationHelper.Exceptions;

            result.SectionDataGlobals.Append(MipsGenerationHelper.NewScript()
                                             .GlobalSection(exceptions));
            result.SectionData.Append(MipsGenerationHelper.NewScript()
                                      .AddData(exceptions, all.Select(x => MipsGenerationHelper.AddIntData(x))));

            CompilationUnit.TypeEnvironment.GetTypeDefinition("Main", null, out var main);
            var entryPoint = new ASTCILAllocateNode(main).Accept(this).SectionCode
                             .Append(MipsGenerationHelper.NewScript().Push(MipsRegisterSet.a0))
                             .Append(new ASTCILFuncVirtualCallNode(main, Functions.Init, new ASTCILExpressionNode[] { }).Accept(this).SectionCode)
                             .Append(new ASTCILFuncVirtualCallNode(main, "main", new ASTCILExpressionNode[] { }).Accept(this).SectionCode)
                             .Append(MipsGenerationHelper.NewScript().Add(MipsRegisterSet.sp, 12))
                             .Append(MipsGenerationHelper.NewScript().Exit());


            result.SectionCode.Append(MipsGenerationHelper.NewScript().MainTag()).Append(entryPoint);

            var voidLabel = labelGenerator.GenerateVoid();

            result.SectionDataGlobals.Append(MipsGenerationHelper.NewScript()
                                             .GlobalSection(voidLabel).GlobalSection(labelGenerator.GetNewLine()));
            result.SectionData.Append(MipsGenerationHelper.NewScript()
                                      .AddData(voidLabel, new[] { MipsGenerationHelper.AddStringData(String.Empty) }).AddData(
                                          labelGenerator.GetNewLine(), new[]
            {
                MipsGenerationHelper.AddStringData(Environment.NewLine)
            }));

            result.SectionTextGlobals.Append(MipsGenerationHelper.NewScript().GlobalSection(MipsGenerationHelper.StringEqualsLabel));
            result.SectionCode.Append(MipsGenerationHelper.NewScript().StringEquals());

            foreach (var item in Program.Types)
            {
                result += item.Accept(this);
            }

            return(result);
        }