コード例 #1
0
        /// <summary>
        /// </summary>
        /// <param name="metadata"></param>
        /// <param name="codeGenerator"></param>
        /// <param name="functionDeclaration"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public ExpressionSyntax Generate(IStandardFunctionMetadata metadata,
                                         MsilBinGenerator codeGenerator,
                                         FunctionDeclaration functionDeclaration,
                                         IReadOnlyList <Expression> parameters)
        {
            var reference = (VariableReferenceExpression)parameters[0];

            // generates {reference} = System.{type}.Parse(Console.ReadLine())
            return(SyntaxFactory.AssignmentExpression(
                       SyntaxKind.SimpleAssignmentExpression,
                       codeGenerator.CompileExpression(reference),
                       SyntaxFactory.InvocationExpression(
                           SyntaxFactory.MemberAccessExpression(
                               SyntaxKind.SimpleMemberAccessExpression,
                               SyntaxFactory.MemberAccessExpression(
                                   SyntaxKind.SimpleMemberAccessExpression,
                                   MsilBinGenerator.MapIdentifierName("System"),
                                   MsilBinGenerator.MapIdentifierName(MapTypeNames[functionDeclaration.Name])),
                               MsilBinGenerator.MapIdentifierName("Parse")))
                       .WithArgumentList(
                           SyntaxFactory.ArgumentList(
                               SyntaxFactory.SingletonSeparatedList(
                                   SyntaxFactory.Argument(
                                       SyntaxFactory.InvocationExpression(
                                           SyntaxFactory.MemberAccessExpression(
                                               SyntaxKind.SimpleMemberAccessExpression,
                                               MsilBinGenerator.MapIdentifierName("Console"),
                                               MsilBinGenerator.MapIdentifierName("ReadLine")))))))));
        }
コード例 #2
0
        private static int StartCompile(BindingContext context, FileSystemInfo inputFile, DirectoryInfo outputPath, string projectName, bool clean, bool verbose)
        {
            var m = Oberon0Compiler.CompileString(File.ReadAllText(inputFile.FullName));

            if (m.CompilerInstance.HasError)
            {
                return(1);
            }

            ICodeGenerator cg = new MsilBinGenerator {
                Module = m
            };

            cg.GenerateIntermediateCode();

            return(cg.GenerateBinary(new CreateBinaryOptions()
            {
                OutputPath = outputPath?.FullName ?? Path.GetDirectoryName(inputFile.FullName),
                CleanSolution = clean,
                OutputDataRetrieved = OutputDataRetrieved,
                ErrorDataRetrieved = ErrorDataRetrieved,
                ModuleName = projectName ?? m.Name,
                Verbose = verbose,
            }) ? 0 : 2);
        }
コード例 #3
0
 public ExpressionSyntax Generate(IStandardFunctionMetadata metadata,
                                  MsilBinGenerator codeGenerator,
                                  FunctionDeclaration functionDeclaration,
                                  IReadOnlyList <Expression> parameters)
 {
     return(SyntaxFactory.InvocationExpression(
                SyntaxFactory.MemberAccessExpression(
                    SyntaxKind.SimpleMemberAccessExpression,
                    MsilBinGenerator.MapIdentifierName("Console"),
                    MsilBinGenerator.MapIdentifierName("WriteLine"))));
 }
コード例 #4
0
 public ExpressionSyntax Generate(IStandardFunctionMetadata metadata,
                                  MsilBinGenerator codeGenerator,
                                  FunctionDeclaration functionDeclaration,
                                  IReadOnlyList <Expression> parameters)
 {
     return(SyntaxFactory.InvocationExpression(
                SyntaxFactory.MemberAccessExpression(
                    SyntaxKind.SimpleMemberAccessExpression,
                    MsilBinGenerator.MapIdentifierName("Math"),
                    MsilBinGenerator.MapIdentifierName("Abs")))
            .WithArgumentList(
                SyntaxFactory.ArgumentList(
                    SyntaxFactory.SingletonSeparatedList(
                        SyntaxFactory.Argument(codeGenerator.CompileExpression(parameters[0]))))));
 }
コード例 #5
0
        internal static ICodeGenerator CompileOberon0Code(string source, out string code,
                                                          ITestOutputHelper outputHelper = null)
        {
            var m = Oberon0Compiler.CompileString(source);

            if (m.CompilerInstance.HasError)
            {
                throw new ArgumentException("Source code contains errors", nameof(source));
            }

            ICodeGenerator cg = new MsilBinGenerator {
                Module = m
            };

            cg.GenerateIntermediateCode();

            code = cg.IntermediateCode();
            outputHelper?.WriteLine(code);
            return(cg);
        }