Compiler changes in upcoming build 2.8

The compiler for the upcoming 2.8 build of X# has received an "overhaul". We have updated the Roslyn code to the latest C# level (the same C# that comes with VS 2019 Preview 4). This means that we now benefit from many changes in the C# compiler. You should see that the compiler is a bit faster. The new compiler requires .Net framework 4.7.2 or .Net core 3.0. The apps created with the new compiler can still target the framework versions from 2.0 until 4.8, .Net Core 2.0, 3.0 and .Net 5 and .Net 6.

We have also taken the opportunity to add a few new things to the language:

Local Functions and Local Procedures

You can declare local function  and local procedures inside methods, properties, functions and procedures.

The syntax is

LOCAL FUNCTION <Name> (<Parameters>) AS <Type>
.
. statements
.
END FUNCTION

Some remarks:

  • parameters are optional but must be typed
  • return type is mandatory
  • the local function automatically has access to the local variables and instance variables from its surrounding code.
  • the local function cannot have attributes

Embedded bodied Members

C# has the option to write simple bodies of methods, functions and properties with a one liner and the => operator. We support that too now. For example:

FUNCTION Multiply ( nLhs AS LONG, nRhs AS LONG) AS LONG => nLhs * nRhs

This does the same as

FUNCTION Multiply ( nLhs AS LONG, nRhs AS LONG) AS LONG
   RETURN nLhs * nRhs

 but is a bit compacter.
You can use this notation for FUNCTION, PROCEDURE, ACCESS, ASSIGN, METHOD, PROPERTY etc.

Using declarations

You can now declare a variable and tell the compiler to automatically dispose it at the end of the block where it is declared. This means that you will no longer have to use a BEGIN USING .. END USING block. Behind the scenes the compiler will automatically create such as block.

Example

USING VAR reader := StringReader{manyLines}

Null Coalescing Operator and Null Coalescing assignment

This operator allows you to choose the first non NULL value of 2 or more values. Note that the values MUST be reference typed. Otherwise the compiler will complain that the value cannot be null.

 x := A ?? B

This assigns the reference value A to x, but when A is NULL then B is assigned. So this is the equivalent of x := iif (A != NULL, A, B)

A ??= B

This assigns B to A when A is NULL. So this is the equivalent of

A := IIF(A != NULL, A, B) 

Native Integers

We have added 2 new data types:

  • NINT (signed native integer)
  • NUINT (unsigned native integer)

These types are  32 bit integer on x86 machines and a 64 bit integer on x64 machines.

More changes will follow in the coming months.

A prerelease version of this new compiler will be released to our FOX subscribers in a few days.


5 comments

  • This is great.

    Can I do this now?

    table?:Close()

    I can do that from C#, where table is on X# assembly.

    I will try it today with the current compiler....

    Moments later, I actually open a production code and did this:

    table?:Close()

    The X# 2.7 compiler allows it. Did it work like on C#?

    I have to discover a lot.... 8)
  • Hello X# Team,

    I realized, I really need 2.8

    We are not starting gRPC development and it only works on .NET 5

    I can test drive early 2.8 build for this. I really assume that this means: all X# runtime and VO stuff are .NET 5 already.

    Clarification is welcome.

    Thanks X# Team
  • Rene,
    This message is ONLY about a new compiler.
    To fully support .Net 5 we need to also make sure that the Runtime works (which is 99.9% done) and we need to make sure that the build system understand the new way how MsBuild works for .Net 5, including the new project file format and the support for that in our project system.
  • [quote name=&quot;Robert van der Hulst&quot;]Rene,
    This message is ONLY about a new compiler.
    To fully support .Net 5 we need to also make sure that the Runtime works (which is 99.9% done) and we need to make sure that the build system understand the new way how MsBuild works for .Net 5, including the new project file format and the support for that in our project system.[/quote]

    Hi Robert,

    No worries. I am still in exploratory and learning on gRPC. I can adjust according to your timeline. Btw, I posted a bug report on encoding. Let me know if this requires 2.8 or just a fixed on 2.7.

    Thanks for the reply.

    Rene