The new compiler is complete!

Here you can post threads on the development of the current release of the core (100)

Moderator: POL Developer

Post Reply
Syzygy
POL Developer
Posts: 6
Joined: Fri Apr 17, 2020 10:02 pm

The new compiler is complete!

Post by Syzygy » Tue Sep 15, 2020 8:35 pm

Hi everyone! I wanted to announce here that the new eScript compiler is complete.

It’s available on the master branch and in nightly builds.

Please be sure to run ecompile in comparison mode, as described in core-changes, in order to ensure that the new compiler doesn’t change the behavior of any of your scripts.

The original compiler is still available. I’ll delete it only after both compilers have been available in an official release for at least several months.

I also wanted to mention some of the reasons why I rewrote the compiler:
  • I began work on the original compiler when I was 20 years old! It’s an embarrassing mess. It’s hard to work with. I imagine it’s nearly impossible for anyone but me to understand. It’s difficult to add anything new or change anything. The new compiler is composed of manageable pieces and is a lot easier to understand.
  • As a project, the new compiler was safe because it is testable. In the time that I haven’t been working on POL, the good people maintaining it have extended the test suite. That decreases risk. I’ve been away from the codebase for a long time, so this was a nice way to start to re-familiarize myself with it.
  • Because the new compiler produces output that is identical* to that of the original compiler, it's easy to know that it didn't break any scripts. This has been tested against the test suite, ModernDistro, and ClassicDistro.
    • *with a few exceptions, like changed operator precedence, but ecompile’s “comparison mode” will find any scripts that changed. Notably, the operator precedence changes did not change the .ecl output of any script in ModernDistro or ClassicDistro. The changes to operator precedence are intended to make it so more expressions do what you want without parentheses, rather than having to add them.
  • It’s a lot easier to see what is in the instructions that the compiler emits for the executor, because the compiler creates each instruction right before emitting it.
  • We can improve eScript and the compiler much more easily. For example:
    • add a ternary operator
    • add an “is” operator as an alternative to TypeOfInt
    • warn about expressions that are likely to be in error
    • better expression optimizations
    • optimize the instruction set (generally by reducing the number of instructions required to do some common things)
    • add short-circuit logical operators
      • this was possible with the original compiler, but tricky. I did it with the “Elvis” operator, which is similar to short-circuit OR, but it had to be done in the optimizer. Compare:
        • PR-137 adding the Elvis operator to the original compiler (relevant code)
        • PR-293 adding the Elvis operator to the new compiler
  • The new compiler shares far fewer datatypes with the executor, so we’ll be able to simplify some of the executor’s datatypes after deleting the old compiler.

Yukiko
Distro Developer
Posts: 2767
Joined: Thu Feb 02, 2006 1:41 pm
Location: San Antonio, Texas
Contact:

Re: The new compiler is complete!

Post by Yukiko » Tue Sep 15, 2020 8:58 pm

For those who may not be aware, Syzygy is the creator of the Penultimate OnLine emulator, POL.

Thank you Syzygy for the new compiler.

ThisIsMe
Distro Developer
Posts: 97
Joined: Sun Jul 17, 2016 1:29 am
Contact:

Re: The new compiler is complete!

Post by ThisIsMe » Tue Sep 15, 2020 9:23 pm

Curious, whats a Short-Circuit Logical expression?

Syzygy
POL Developer
Posts: 6
Joined: Fri Apr 17, 2020 10:02 pm

Re: The new compiler is complete!

Post by Syzygy » Tue Sep 15, 2020 9:46 pm

Given this example code

Code: Select all

    if(( item.IsA( POLCLASS_CONTAINER ) || item.IsA( POLCLASS_DOOR )) && item.locked )
      SendSysMessage( mobile, "That item is locked!" );
      return 0;
    endif
With short-circuit logical evaluation, if

Code: Select all

item.IsA( POLCLASS_CONTAINER ) 
is true, then

Code: Select all

item.IsA( POLCLASS_DOOR )
would not need to be evaluated.

If both of those are false (if the left-hand side of the && condition is false), then item.locked would not need to be evaluated.

Post Reply