Example of generated code:

Here is a simple C# method:

public Class RecursiveTest
{
    public static int Fib(int n)
    {
        if (n < 2)
        {
            return n;
        }
        else
        {
            return Fib(n - 2) + Fib(n - 1);
        }
    }
}


Here is the generated C++ code:

::System::Int32 CrossNetUnitTest::_Benchmark::RecursiveTest::Fib(::System::Int32 n)
{
    if ((n < 2))
    {
        return (n);
    }
    return ((::CrossNetUnitTest::_Benchmark::RecursiveTest::Fib((((n - 2)))) + ::CrossNetUnitTest::_Benchmark::RecursiveTest::Fib((((n - 1))))));
}


Note that all the types are fully qualified, System::Int32 is a typedef to int.

An example with delegates and strings:

C# Code:

const int SCALE = 1;
DoTest("Binary Tree", BinaryTreesTest.Test, SCALE * 1000);


With BinaryTreesTest.Test a static method, TestDelegate and DoTest being defined as:

public delegate bool TestDelegate(int N);

public static void DoTest(string text, TestDelegate del, int n)
{
    ...
}


Will generate this code:

::CSharpBenchmark::_Benchmark::Benchmark::DoTest(scsharpbenchmark__Binary_Tre, ::CrossNetRuntime::Cast<::CSharpBenchmark::_Benchmark::Benchmark__TestDelegate>
    (new ::CSharpBenchmark::_Benchmark::Benchmark__TestDelegate__FUNCTOR__<::CSharpBenchmark::_Benchmark::BinaryTreesTest>(&::CSharpBenchmark::_Benchmark::BinaryTreesTest::Test)),
    1000);


The fully qualified types makes it a bit cryptic, but you can see few things here:
  • C strings are replaced by .NET strings. Static strings are actually pooled and constructed one time when initializing the assembly. Each string has actually an unique identifier (the 10 first characters of the string prefixed with the assembly name, a counter is appended if two strings have differences after the 10th character). In that case, C String "Binary Tree" is replaced by global System.String pointer scsharpbenchmarkBinary_Tre.
  • Delegates are manipulated with C++ functors, macros exist to create the delegate type. Crossnet Functors can manipulate member methods, static methods and interface methods.
  • SCALE * 1000 has been directly converted to 1000.

Last edited Sep 7, 2007 at 7:37 PM by OlivierNallet, version 2

Comments

No comments yet.