local x = 1
local y = 2.e
local z = @
if (x + y) < 3 then
print("smaller")
else
print("bigger")
end
for i = 1, 10, z do
print(i)
end
while true do
end
A more extreme example than not, but the point is how the compiler reacts to this snippet. Running this program as is in a ComputerCraft terminal produces the following error:
For input string: "2.e"
Not very helpful, unfortunately. Here's what ATLX spits out:
Compiling test..
Lexical Analyzer Time: 0.00099992752075195
Syntax Analyzer Time: 0
Semantic Analyzer Time: 0
Compilation time: 0.00099992752075195
test: compilation errors (4)
Lexical Analyzer:
[ERR] line:2:11-13: unfinished scientific notation
local y = 2.e
^^^
[ERR] line:3:11: foreign character '@' (0x40)
local z = @
^
Syntax Analyzer:
[ERR] line:3:9: expression(s) expected to follow '=' operator for local variable assignment on line 3:1
local z =
^
Semantic Analyzer:
[WRN] line:5:1: unreachable code past 'if' statement
[ERR] line:11:18: expected variable 'z' (nil) to be of type 'number' in numeric 'for' loop for step value
[WRN] line:15:1: empty 'while' statement; absent of code
Off to a good start! The compiler won't stop at the first error it sees and, much like many modern compilers, it will list all the errors it can find in the code at once.
I've been working on this on and off for the past month or so– but there's still much to do!
Over that time I've created what I believe to be a rather vigorous test suite, consisting of 5,570 Lua programs, 31 MB in total. These come from a variety of sources, including the ComputerCraft forums, OpenComputer forums, and even real-world applications of Lua found in various Github repositories.
It's able to parse all of them. Now, I say parse rather than compile because the compiler doesn't actually do that yet. It turns out that the first three stages of compilation (Lexical, Syntax, Semantics) are rather complex in their own right– at least for me! But of course, the plan is to indeed compile, and to do so first to an intermediate form based on SSA, or single static assignment. To put it simply, Lua programs will see optimization the likes of which they haven't before, allowing for example constant propagation, function inlining, local value numbering, and many others! Exciting– at least for me. :)/>
So! What does this mean for the average user? Probably not much; most Lua programs are small enough that speed nor the best error messages don't matter anyway. But! For those few like me who enjoy making massive Lua programs for no real reason, this is the tool for you, enabling one to focus optimization efforts more on algorithm implementation rather than having to choose between debug-ability and speed while offering them advanced analysis of their programs to give the most accurate errors (read: plural!) that it's able to.
Unfortunately, I have no real ETA on when it will be released. I'm likely to at least give an update about progress here, and the code will be made available once I deem it both stable and functional enough.