Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IL2C InternalCall doubt & In what scenarios is it primarily used #89

Open
jintemp opened this issue Oct 14, 2020 · 4 comments
Open

IL2C InternalCall doubt & In what scenarios is it primarily used #89

jintemp opened this issue Oct 14, 2020 · 4 comments

Comments

@jintemp
Copy link

jintemp commented Oct 14, 2020

I am very curious about how the InternalCall of the.net Framework handles, for example, the conversion of System.String LastIndexOf to C is not implemented。What is the main function of IL2C,There are similar products available now, https://github.com/anydream/il2cpp (The problem of Internalcall has been abandoned)

@jintemp
Copy link
Author

jintemp commented Oct 14, 2020

In my understanding, for example, Unity's IL2CPP is based on Mono (which implements the BCL interface), so there is no InterlnalCall problem。windows .NET Framework or donet is not pure

@jintemp
Copy link
Author

jintemp commented Oct 14, 2020

Looking forward to your reply

@kekyo
Copy link
Owner

kekyo commented Oct 15, 2020

In my first inspiration for IL2C's idea: "Why does it required a lot of cost in this case? What different between C language and C# (or CIL)? And/or why couldn't use .NET on embedded bare-metal environment mostly cases?" :

public static void Main(string[] args)
{
	var a = 1;
	var b = 2;
	var r = a + b;
	Console.WriteLine(r);
}

We can understand the theme easier, because it has translation problem, overheads and the runtime costs.
And has some topics:

  • How to fit into multiple platforms (many different systems, many different architecture with/without OSes)
  • How to fit translate from CIL to another language (ex: an popular but not majority different architecture in Espressif Xtensa CPU, it has only GCC C compiler)
  • What details made larger footprint in standard CLR/Core CLR? (between runtime code and runtime data includes GC structures)

For example, many tiny system can built with platform dependent C compiler. The C compiler has runtime code fragments we know 'strlen()', 'malloc()' and etc. We can write in C code:

public static int Main(string[] args)
{
	string p = "ABCDEFG";
	int r = p.Length;      // IL: get_Length(p);
	Console.WriteLine("{0}", r);
	return 0;
}

instead:

int main(int argc, char* argv[])
{
	const char* p = "ABCDEFG";
	const int r = strlen(p);
	printf("%d\n", r);
	return 0;
}

We can translate naturally both C and C# code.
(In this example doesn't include discussion in corner cases, may be you know different string encoding and string formatting features)

So we can simplicity replace from Length property to strlen function if these semantics are equals.
If it's true, the translation cost (includes additional interoperability fragments) can be minimize or makes zero by directed calling strlen(p) code fragment.

(And it's reducing code footprints because many other implicitly linked native independent libraries shared these codes.)

Curently, IL2C focuses how to dodge these problems. You know it has many lacks of implementations, includes `System.String.LastIndexOf', because I have no free times now at IL2C prgression :)

@jintemp
Copy link
Author

jintemp commented Oct 15, 2020

Thank you for your answer,Agree with your idea and have studied several IL2CPP details, including Unity's IL2CPP。Use scenarios, in micro systems, using C# to write logic code,Enjoy the convenience of a high-level language, with IL2C, less memory and less code。Hope it goes on and on

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants