Plane
Plane
cat
Plane
cat
I added tests to scratcher, this makes sure the language is holding up to its promises before I press release. I currently only have very simple tests, but I’ve already fixed 4 bugs in the compiler.
Added github workflows so it gets released automatically!
Made the Compiler completely isolated, this means it can run multiple times without having the JVM restarted.
Added compact float lists!
I did some small refactors and added a new CLI, built with Clikt
It’s very simple to use:
scratcher check file --options //check the file for any compilation errors without compiling
scratcher compile file --options outFile //compile into a .sb3 file
scratcher standard-library //print out the standard library
Clikt also provides easy to use help menus
I also added a sort function to the array and list libraries
Errors are the one thing that I knew were terrible but I could never build up the courage to fix.
So I just fixed them.
Now all errors in the language are formatted nicely, show you exactly where the error happened and give you a nice description.
Along with this, I made a new system for collecting errors, so now the compiler won’t stop at the first error and will continue going and give you all errors at once. This makes fixing code a lot easier.
This also opens up the possibility of an LSP server later on
(before and after in images)
Try it out: https://scratch.mit.edu/projects/1387804691/
1 + 1) and get the result.I added demo programs to scratcher, these show the language actually being used
Try one out! https://scratch.mit.edu/projects/1385339395/
for and repeat statement which allows way easier index tracking://Before:
int index = 0;
repeat(10) {
...
index++;
}
//After:
repeat(10) { index ->
...
}
I also made the PooledList get garbage collected with the refcount gc
Did some really small refactors aswell
Static lists are cool, but they are very limited expressiveness wise because they must be known at compile time
Pools fix this by having a pool of static lists that the user code can allocate at any time
PooledList a = allocate();
But because the pool is limited, the pooled list must be freed when not needed, the garbage collector will not handle it(yet)
a.free();
Other than that, the PooledList behaves just like a List and can do almost anything a List does
Out of memory errors.I added a shit ton of quality of life stuff:
int[] myArray = [1, 2, 3, 4, 5, 6];
Result.Success? a = res as? Result.Success;
if(a) b++;
while(true) {
if(a) break;
if(b) continue;
}
static str[] myList;
This also allows for file reading:
static str[] myList = "hello.json";
So you can properly store data(like ROMs)
'a' === 'A'
RETURNS FALSE
Added a “private” keyword, anything declared private cannot be accessed from outside the current file.
This prevents the user from messing with internal states of libraries they are using
For example, the list library from the standard library.
Now you can’t directly mess with the list pointer
triangles.ptr[5] = ...;
This now results in an error because “ptr” is private!
I also added some small optimizations for lambdas.
Added operator overloading, now you can define overloads for specific operators so that code looks cleaner
Just use the operator keyword with the correct signature and you’re done!
You can overload the operators: +, -, /, *, %, [], []=
For example:
warp operator <T> void T[].set(int index, T item) {
self::replace(this, item, index);
}
//use
array[index] = item
//compiler translates to
set(array, index, item)
I also realized that my previous refactor of arrays broke my nullability system:
int[] a = Array(int, 5);
say(a[3]);
This would print null, which my type system missed
I fixed this by moving arrays to a standard library module, the same array import works, but you have to change how you create the array:
//before:
int[] a = Array(int, 5); //doesn't need to be marked as null!!!
int[] a = Array(int, 5);
a[0] = ...;
a[1] = ...;
...
//after
int?[] a = arrayOfNulls(5); //null filled
int[] a = arrayOf(5, (int index) -> {
return index * 5; //value of the array at that index
});
Previously if you wanted to check sealed enums types and use them, you had to do very ugly syntax for actually getting the variant instance:
auto out = tryGet();
when(out) {
Result.Success -> {
auto suc = out as Result.Success;
looks::say("Success! ${suc.out.x}");
Now you don’t have to do all of this:
when(tryGet()) {
Result.Success suc -> {
looks::say("Success! ${suc.out.x}");
This is just syntax improvement, doesn’t change the generated code or anything, just helps the developer
The new implementation is more clear, more expressive and more like regular programming languages
For over 2 months, scratcher has had an “export” keyword, which was fully unused, until today:
I implemented the export keyword on functions, which allows for code written in plain scratch to interact with scratcher code:
export warp void myFunction() { ... }
Export requires that your function arguments are all primitives and that the return is also a primitive, but other than that, it does not change anything, just exposes the function cleanly to regular scratch code.
However, scratcher type checking still applies, so if the native scratch code passes in a string to a float argument, it will still cause a panic
Even when you have obfuscation enabled, exports will stay and let native scratch use it with its original name