Esempio n. 1
0
        public static StringBuilder GenerateSourceStringBuilder(MethodInterpreter interpreter, List <Type> typeClosure,
                                                                List <MethodInterpreter> closure,
                                                                VirtualMethodTable typeTable, CrRuntimeLibrary crRuntime)
        {
            var sb = new StringBuilder();

            sb.AppendLine("#include \"sloth.h\"");

            var virtualMethodTableCodeWriter = new VirtualMethodTableCodeWriter(typeTable, closure);

            WriteClosureStructBodies(typeClosure.ToArray(), sb, crRuntime);
            WriteClosureDelegateBodies(closure, sb);
            WriteClosureHeaders(closure, sb, crRuntime);

            sb.AppendLine("#include \"runtime_base.hpp\"");

            sb.AppendLine(virtualMethodTableCodeWriter.GenerateTypeTableCode());
            WriteCppMethods(closure, sb);
            WriteClosureMethods(closure, sb, typeTable.TypeTable, crRuntime);

            WriteMainBody(interpreter, sb);
            sb.AppendLine(PlatformInvokeCodeWriter.LoadDllMethods());
            sb.AppendLine(ConstByteArrayList.BuildConstantTable());
            sb.AppendLine(LinkingData.Instance.Strings.BuildStringTable());

            return(sb);
        }
Esempio n. 2
0
        public static StringBuilder GenerateSourceStringBuilder(MethodInterpreter interpreter, TypeDescriptionTable table, List <MethodInterpreter> closure, ClosureEntities closureEntities)
        {
            var headerSb = new StringBuilder();

            headerSb.AppendLine("#include \"sloth.h\"");
            headerSb.AppendLine("#include <functional>");


            var initializersSb = new StringBuilder();

            TypeBodiesCodeGenerator.WriteClosureStructBodies(initializersSb, closureEntities);
            WriteClosureDelegateBodies(closure, initializersSb);
            WriteClosureHeaders(closure, initializersSb, closureEntities);

            initializersSb.AppendLine("#include \"runtime_base.hpp\"");


            var bodySb = new StringBuilder();

            bodySb.AppendLine(VirtualMethodTableCodeWriter.GenerateTypeTableCode(table, closureEntities)); // We need to use this type table to generate missing jumps for subclasses  that dont override a base method
            WriteCppMethods(closure, bodySb, closureEntities);
            WriteClosureMethods(closure, bodySb, table, closureEntities);

            WriteMainBody(interpreter, bodySb, closureEntities);
            bodySb.AppendLine(PlatformInvokeCodeWriter.LoadDllMethods());
            bodySb.AppendLine(ConstByteArrayList.BuildConstantTable());

            LinkingData.Instance.IsInstTable.BuildTypeMatchingTable(table, closureEntities);
            bodySb.AppendLine(LinkingData.Instance.Strings.BuildStringTable());

            //Add Logic to Automatically include std class features that are needed ...
            if (closureEntities.Features.Count > 0)
            {
                foreach (var runtimeFeature in closureEntities.Features)
                {
                    if (runtimeFeature.IsUsed)
                    {
                        if (runtimeFeature.Headers.Count > 0)
                        {
                            headerSb.AppendLine("//Headers For Feature: " + runtimeFeature.Name + "\n" +
                                                runtimeFeature.Headers.Select(g => "#include<" + g + ">").Aggregate((a, b) => a + "\n" + b) + "\n//End Of Headers For Feature: " + runtimeFeature.Name + "\n");
                        }
                        if (runtimeFeature.Declarations.Count > 0)
                        {
                            initializersSb.AppendLine("//Initializers For: " + runtimeFeature.Name + "\n" + runtimeFeature.Declarations.Aggregate((a, b) => a + "\n" + b) + "\n//End OF Initializers For: " + runtimeFeature.Name + "\n");
                        }
                        if (!String.IsNullOrEmpty(runtimeFeature.Functions))
                        {
                            bodySb.AppendLine("//Functions For Feature: " + runtimeFeature.Name + "\n" + runtimeFeature.Functions + "\n//End Of Functions For Feature: " + runtimeFeature.Name + "\n");
                        }
                    }
                }
            }

            return(headerSb.Append(initializersSb).Append(bodySb));
        }
        public CodeOutput GenerateSourceCodeOutput(
            MethodInterpreter interpreter,
            TypeDescriptionTable table,
            List <MethodInterpreter> closure,
            ClosureEntities closureEntities)
        {
            var headerSb = _createCodeOutput();

            headerSb.Append("#include \"sloth.h\"")
            .BlankLine();
            if (!string.IsNullOrEmpty(TypeNamerUtils.SmartPtrHeader))
            {
                headerSb
                .AppendFormat("#include {0}", TypeNamerUtils.SmartPtrHeader)
                .BlankLine();
            }

            var initializersCodeOutput = _createCodeOutput();

            TypeBodiesCodeGenerator.WriteClosureStructBodies(initializersCodeOutput, closureEntities);
            WriteClosureDelegateBodies(closure, initializersCodeOutput);
            WriteClosureHeaders(closure, initializersCodeOutput, closureEntities);

            initializersCodeOutput.BlankLine();
            initializersCodeOutput.Append("#include \"runtime_base.hpp\"");
            initializersCodeOutput.BlankLine();

            var bodySb = _createCodeOutput();

            bodySb.Append(VirtualMethodTableCodeWriter.GenerateTypeTableCode(table, closureEntities));
            // We need to use this type table to generate missing jumps for subclasses  that dont override a base method
            WriteCppMethods(closure, bodySb, closureEntities);
            WriteClosureMethods(closure, bodySb, table, closureEntities);

            WriteMainBody(interpreter, bodySb, closureEntities);
            bodySb.Append(PlatformInvokeCodeWriter.LoadDllMethods());
            bodySb.Append(ConstByteArrayList.BuildConstantTable());

            LinkingData.Instance.IsInstTable.BuildTypeMatchingTable(table, closureEntities, initializersCodeOutput.StringBuilderOutput);
            bodySb.Append(LinkingData.Instance.Strings.BuildStringTable());


            return(headerSb
                   .Append(initializersCodeOutput.ToString())
                   .Append(bodySb.ToString()));
        }