You are browsing as a guest. Sign up (or log in) to start making projects!

BetterClient

@BetterClient

Joined May 31st, 2026

  • 70Devlogs
  • 4Projects
  • 1Ships
  • 19Votes
#1 java glazer in hc
Ship

Scratcher is a high level language that compiles to scratch. Some of Scratcher’s features:

  • Lambdas
  • Closures
  • Function pointers
  • Structs
  • Arrays
  • Lists
  • Generics
  • Sealed enums
  • Pattern matching
  • Compile time null safety
  • Extension functions
  • Operator overloading
  • String interpolation
  • Function returns

Along with having support for all of these:

  • Scratcher is memory safe
  • Scratcher has 2 garbage collectors.
  • Scratcher has a big optimizer pass, making your code very performant.
  • Scratcher has very good documentation

Scratcher can also safely interop with normal scratch code: You can expose your functions to normal scratch code using the export keyword, which makes normal scratch code able to safely call your code.

  • You can use on GreenFlag {} or on KeyPressed("key") {} to handle scratch events.

  • Advanced loop control:

Scratcher allows you to write expressive code like for(int i in list)

Scratcher also has support for continue and break which is fully absent on scratch.

What I’m proud of

Return values: Normal scratch has no idea what a function call is, it only knows procedures(which don’t have returns)!

The double GC: Scratcher comes with 2 garbage collectors, which can run at the same time, one is reference counting GC and the other one is a Tracing Mark and sweep GC.

Lambdas: Scratcher allows you to use lambdas very expressively, allowing you to capture local variables from outside the lambda, use it, modify it while also keeping that modified instance in the original function, its just like kotlin’s lambdas(which I love)

The expression control flow: Scratcher allows you to write if statements and when statements INSIDE other expressions, this lets you write very expressive code:

func(
    if(something) { funcB() } else 5 
)

Short circuits: Normal scratch executes the right side of an and/or block no matter what, scratcher doesn’t, if the left side of and is false, the right side won’t run.

Very rich type system: The scratcher type system allows you to do a lot of things, I love sealed enums, they’re just like rust enums:

sealed enum Result<T, E> {
    Success(T value),
    Error(E error)
}

Testing the compiler

If you don’t wanna bother downloading the CLI and writing your own program, look at the example programs in this folder

If you wanna use the CLI and maybe even write your own programs, check out the documentation: https://github.com/betterclient/Scratcher/blob/master/docs/hello_world.md

  • 55 devlogs
  • 188h
  • 19.92x multiplier
  • 3741 Stardust
Try project → See source code →
Open comments for this post

5h 43m 13s logged

Tests

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.

Other shit

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!

0
1
60
Open comments for this post

5h 33m 36s logged

CLI

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

0
0
28
Open comments for this post

7h 32m 52s logged

PROPER ERRORS

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)

0
0
34
Open comments for this post

6h 38m 41s logged

More demos and QOL

Try it out: https://scratch.mit.edu/projects/1387804691/

Demos

  • Math lexer, parser and interpreter: New demo that lets you input math expressions (eg: 1 + 1) and get the result.
  • 3d cube renderer: a spinning 3d cube and player controls

QOL

  • Smarter inlining cost calculation
  • A math centered optimization for removing identities
  • Get rid of PromoteToGlobals (temp)
  • GC documentation
  • Codegen fixes (receiver functions generate the same block, causing scratch to get confused)
  • Stack size optimization (reuse stack slots of the same type)
  • Fix crash when the garbage collector is disabled
0
0
37
Open comments for this post

7h 30m 46s logged

Demo programs and general improvements

I added demo programs to scratcher, these show the language actually being used

Try one out! https://scratch.mit.edu/projects/1385339395/

General improvements

  • Bug fixes
  • Dummy sprite
  • Make the type checker ignored in inlined functions
  • Make topLevelInit smaller and remove unused functions from final compilation
  • TurboWarp specific compilation mode with faster operations on strings/lists (not compatible with vanilla scratch if enabled)
0
0
48
Open comments for this post

2h 8m 16s logged

Indexed repeat and general improvements

  • Added a new indexed 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

0
0
57
Open comments for this post

2h 33m 23s logged

List pools

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

  • I also added proper documentation for Out of memory errors.
0
0
47
Open comments for this post

10h 16m 45s logged

QOL

I added a shit ton of quality of life stuff:

  • Tons of bug fixes
  • Big array syntax:
int[] myArray = [1, 2, 3, 4, 5, 6];
  • Safe casting for enums(previously a panic):
Result.Success? a = res as? Result.Success;
  • Out of memory detection: Scratch caps lists at 200k elements, after that it silently stops adding stuff to the list
  • Compact int list: Store pretty much infinite integers without wasting heap space
  • SHORT CIRCUITS: DONT EXECUTE RIGHT SIDE OF && or || if left side is false/true!
  • If statements without braces:
if(a) b++;
  • CONTINUE AND BREAK:
while(true) {
     if(a) break;
     if(b) continue;
}
  • STATIC LISTS: store data outside of the heap in scratch lists so that you dont run out of heap space:
static str[] myList;

This also allows for file reading:

static str[] myList = "hello.json";

So you can properly store data(like ROMs)

  • CASE SENSITIVE EQUALS:
    DID YOU KNOW THAT SCRATCH “=” BLOCK IS CASE INSENSITIVE??? And its pretty hard to make it case sensitive
    Now you can do “===” and its case sensitive:
'a' === 'A' 
RETURNS FALSE
2
0
154
Open comments for this post

2h 34m 5s logged

Privates

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.

0
0
60
Open comments for this post

3h 58m 59s logged

Operator overloading

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
});
0
0
49
Open comments for this post

1h 10m 14s logged

Import some

import names into unqualified co ntext

Before:

//import
import list;

//use
list::List<str> myList = list::newList();

After:

//import
import list::*;

//use
List<str> myList = newList();
0
0
41
Open comments for this post

1h 12m 30s logged

Pattern matching for sealed enums

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

0
0
42
Open comments for this post

3h 56m 8s logged

ACTUAL ARRAYS!!

  • Previously, scratcher “arrays” were just lists, you could add more items, it would dynamically resize, it was written in the kotlin DSL, so technically it was just a list.
  • I removed the previous list code, reused some of it and added a new Array system
  • Along with that, the normal lists got rewritten in 100% scratcher with no internal functions
  • The new system is almost fully backwards compatible in source code, you just have to make a few changes

The new implementation is more clear, more expressive and more like regular programming languages

0
0
33
Open comments for this post

2h 11m 31s logged

I’m sorry

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

2
0
62
Loading more…

Followers

Loading…