summaryrefslogtreecommitdiff
path: root/tests/src/JIT/Methodical/Boxing/misc/nestval.cs
blob: 2aa4f72c390b4a58171b5c61c3c8b7bce745a1a2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;

namespace BoxTest
{
    internal struct MyBool { public bool val; }
    internal struct MyInt { public int val; }

    internal struct ArgInfo
    {
        public MyBool m_flag;
        public MyInt m_num;
    }

    internal class Test
    {
        protected object Fibonacci(object args)
        {
            if (args.GetType() != typeof(ArgInfo))
                throw new Exception();
            return FibonacciImpl(args);
        }

        protected object FibonacciImpl(object args)
        {
            object N;
            if (((ArgInfo)args).m_num.val <= 1)
                N = ((ArgInfo)args).m_num.val;
            else
            {
                ArgInfo newargs1 = new ArgInfo();
                newargs1.m_num.val = ((ArgInfo)args).m_num.val - 2;
                newargs1.m_flag.val = false;
                ArgInfo newargs2 = new ArgInfo();
                newargs2.m_num.val = ((ArgInfo)args).m_num.val - 1;
                newargs2.m_flag.val = ((ArgInfo)args).m_flag.val;
                N = (int)Fibonacci(newargs1) + (int)Fibonacci(newargs2);
            }
            if (((ArgInfo)args).m_flag.val)
            {
                if ((((ArgInfo)args).m_num.val % 2) == 0)
                    Console.Write(N.ToString() + " ");
                else
                    Console.Write(N.ToString() + " ");
            }
            return N;
        }

        private static int Main()
        {
            ArgInfo args = new ArgInfo();
            args.m_flag.val = true;
            args.m_num.val = 20;
            new Test().Fibonacci(args);
            Console.WriteLine();
            Console.WriteLine("*** PASSED ***");
            return 100;
        }
    }
}