r/Protos • • 1d ago

Building a programming language's website in itself exposed an interesting closure semantics bug

One of the most interesting aspects of building Protos, a prototype-based programming language running on GraalVM and Truffle, is discovering subtle language implementation problems through real application development.

While migrating the Protos website to Protos itself, I encountered an unexpected interaction between object factories, methods, lexical closures and non-local returns.

This simple example exposed the problem:

make: () => {
    {
        value: () => { ^42 }
    }
}
obj: make()
print(obj.value())

A method invocation must establish its own return home, rather than reuse the return home of the factory that created its Closure.

However, extracting that Closure and invoking it as an ordinary function must preserve its lexical return semantics.

The fix is now published in Protos 0.4.268-SNAPSHOT, with 205 targeted tests passing and the complete local test suite green.

The implementation preserves the existing Truffle specialization infrastructure without introducing new production Java classes or changing the language specification.

For developers familiar with Self, Smalltalk, Ruby, JavaScript or GraalVM: how do you approach the distinction between lexical closures and dynamically invoked methods in your language implementations?

Source code: https://github.com/guillermomolina/protos

Community: r/ProtosLang

1 Upvotes

0 comments sorted by