💾 Archived View for jun.skein.city › projects › glass4j.gmi captured on 2024-12-17 at 09:46:18. Gemini links have been rewritten to link to archived content
-=-=-=-=-=-=-
This is my implementation of the Glass programming language, written in Java and running on the JVM. Glass is an esoteric, object oriented programming language with global stack-based semantics. While the goal was to keep Glass4J as true to Glass as possible, the specification leaves a lot of room to be explored. As such, some liberties have been taken to make Glass4J as powerful and odd as possible.
This library has its own interpreter executable, execution library, and it implements the ScriptEngine interface for use with the Java Script API.
This is a quick summary of what I would consider "extensions" to Glass, as well as some information about how it is internally represented.
Glass4J supports partial Java interoperation: Using a fully qualified Java class path (using dot notation), you can create Java classes and push them onto the stack. Constructors with parameters are not supported at present. Parameters for methods are a "best fit" sort of approach, testing for methods with either:
While this approach has a million edge cases, most Java APIs I have tested have worked well with this approach.
Methods are invoked through a "MethodExecutor" object that is generated through the "." instruction. The ".", on top of marshalling around a variable name, can resolve methods via a direct object value. Internally, the object must implement the "GlassObject" interface, and I do not believe there is a way to break this condition using purely Glass code without extensive use of the Java Reflections API.
The class "R" allows decompiling and recompiling of Glass methods and objects, allowing for an entire category of metaprogramming that is not supported in the base language. The API of this class is as follows:
{R 'Compiles a class based on provided source code' [(cc) ...] 'Decompiles a class by class name' [(dc) ...] 'Compiles a method based on the provided source code and class name' [c ...] 'Decompiles a method based on the provided method and class names' [d ...] }
This class naturally only works with Glass native classes and methods, and will not decompile Java types. That said, it allows for quite a lot, including a REPL:
{M [mt$rR!iI!oO!(_line)"def"= /(_line)"GLASS> "oo.?(_line)il.?=(_line)*Mlrc.?tl.?\]}