xsharp.eu • ILSpy Plugin corrections/enhancements
Page 1 of 2

ILSpy Plugin corrections/enhancements

Posted: Tue Apr 19, 2022 10:18 am
by Fabrice
Hi,
I open a new discussion here that is related to my ILSpy plugin.
If you find an issue in the generated code, please reply here with a sample.

Thanks,
Fab

ILSpy Plugin corrections/enhancements

Posted: Wed Apr 20, 2022 6:43 am
by lagraf
Hi Fabrice,
if I translate the following C# Code with your plugin

Code: Select all

public class Program
{
	static void Main()
	{
		System.Console.WriteLine("Hello XIDE from c#!");
	}
}
it says (ignore the "e" we already talked about)

Code: Select all

PUBLIC CLASS Program
	PRIVATE STATIC METHOD Main() AS VOID
		Console.WriteLine("e""Hello XIDE from c#!")
END CLASS
When I compile the X# Code I get the error "error XS1558: 'Functions' does not have a suitable static 'Start' function". Do I always need a start function in X# or why is this start Class/Method not accepted?

ILSpy Plugin corrections/enhancements

Posted: Wed Apr 20, 2022 6:57 am
by robert
Franz,
X# has chosen to use the Start function instead of the Main method as entry point.
If you change the code to

Code: Select all

public class Program
	private static method Start() as void
		Console.WriteLine("e""Hello XIDE from c#!")
end class
then you can tell the compiler to use the Program class for the entry point.
In Visual Studio this can be done on the Application page of the Project properties:
props.png
props.png (4.73 KiB) Viewed 499 times
This sets the compiler option -main: https://www.xsharp.eu/help/opt-main.html

Robert

ILSpy Plugin corrections/enhancements

Posted: Wed Apr 20, 2022 7:02 am
by lagraf
C#

Code: Select all

foreach (var readerName in readerNames) {
   ...
}
Translation

Code: Select all

LOCAL @@array AS STRING[]
@@array := readerNames
FOREACH AS STRING IN @@array 
NEXT
a little bit complicated and readerName missing in FOREACH, why not directly using array readerNames instead of @@array?

ILSpy Plugin corrections/enhancements

Posted: Wed Apr 20, 2022 7:17 am
by lagraf
Hi Robert,
thank you for info, I changed the code and putted the switch "-main:Program" to Properties/Compiler/Additional Switches in XIDE and it compiled without error.

ILSpy Plugin corrections/enhancements

Posted: Wed Apr 20, 2022 8:34 am
by lagraf
C#

Code: Select all

using System;
public class Program
{
   static void Main()
   {
      int[] arr = {1,2,3};
      foreach (var val in arr) {
         int i = 1;
         if (i == 1) {
            Console.WriteLine("if");
         } else {
            Console.WriteLine("else");
            Console.WriteLine("else");
         }
      }
   }
}
Translation to X#

Code: Select all

using System
public class Program
	private static method Main() as void
		local arr as Long[]
		local @@array as Long[]
		local i as Long
		//
		arr := <Long>;
			{1,;
			2,;
			3;
			}
		@@array := arr
		foreach as Long in @@array 
			i := 1
			if i == 1
				Console.WriteLine("e""if")
				continueendif
			Console.WriteLine("e""else")
			Console.WriteLine("e""else")
		next
end class
Else is lost, what means "continueendif"?
If I do if ... else outside of foreach it translates ok.
You also see the @@array translation of the former noted posting.

ILSpy Plugin corrections/enhancements

Posted: Wed Apr 20, 2022 9:11 am
by Fabrice

Code: Select all

LOCAL @@array AS STRING[]
@@array := readerNames
FOREACH AS STRING IN @@array 
NEXT
This is an exemple of the difference between the code you write, and the compiler generated code.
I could try to handle it, catching all FOREACH and rebuilding/guessing what was the original code.

ILSpy Plugin corrections/enhancements

Posted: Wed Apr 20, 2022 9:16 am
by Fabrice
lagraf wrote: Else is lost, what means "continueendif"?
The "continueendif" is a Plugin error, we are missing a newline between continue and endif; and continue is a C# keyword that translate to a LOOP in X#, that will jump back to the nearest FOR/FOREACH/WHILE/... so there, no need for the ELSE clause as in the IF we are jumping back on top.

ILSpy Plugin corrections/enhancements

Posted: Wed Apr 20, 2022 10:04 am
by lagraf
Fabrice,
1) FOREACH

Code: Select all

LOCAL @@array AS STRING[]
@@array := readerNames
FOREACH AS STRING IN @@array 
NEXT
The @@array is waste but not the problem, foreach has lost readerName where each @@array entry is shown, something like

Code: Select all

FOREACH readerName AS STRING IN @@array 
2) CONTINUEENDIF
if ... else ... endif is not the same like if ... loop ... endif when statements behind the endif, so I testet this and it translates right!

Code: Select all

foreach as Long in @@array 
	i := 1
	if i == 1
		 Console.WriteLine("e""if")
        else
                 Console.WriteLine("e""else")
                 Console.WriteLine("e""else")
        endif
        Console.WriteLine("ever")
next

Code: Select all

@@array := arr
foreach as Long in @@array 
	i := 1
	if i == 1
		Console.WriteLine("e""if")
	else
		Console.WriteLine("e""else")
		Console.WriteLine("e""else")
	endif
	Console.WriteLine("e""ever")
next

ILSpy Plugin corrections/enhancements

Posted: Thu Apr 21, 2022 9:15 am
by Fabrice
Hi Franz,

I have updated the ILSpy plugin :
The LOOP keyword is now generated instead of "continue"
The variable declaration in FOREACH has been corrected
Same for the "e"scaped String.

Go to the github page : https://github.com/X-Sharp/ILSpy-Plugin
On the right, you can get the latest ILSpy plugin, dated today 2022/04/21
I have also included a version for the latest V7.2.1 version of ILSpy.

Regards,
Fab