HGPPascal JVM Backend

HGPPascal can generate JVM .class files with the jvm backend.

clojure -M:run examples/hello.pas --target jvm -o out/classes
java -cp out/classes Hello

The same backend is available through explicit bytecode target aliases: bytecode, java-bytecode, and jvm-bytecode.

The backend lowers the Pascal AST to Java source internally, compiles that source with javax.tools.JavaCompiler, and writes the resulting .class bytes. This keeps the backend dependency-free while producing real JVM class files.

Current Mapping

Runtime

Every generated JVM class includes a nested HGPRuntime class. It contains:

The backend result map includes runtime metadata:

{:runtime {:linked? true
           :engines [:secd :sstd :numeric :heap]
           :carrier :generated-java}}

Example Programs

These examples specifically exercise the JVM runtime layer:

clojure -M:run examples/record_pointer.pas --target jvm -o out/classes
java -cp out/classes RecordPointer

clojure -M:run examples/pointer_new_dispose.pas --target jvm -o out/classes
java -cp out/classes PointerNewDispose

clojure -M:run examples/object_methods.pas --target jvm -o out/classes
java -cp out/classes ObjectMethods

clojure -M:run examples/object_methods.pas --target java-bytecode -o out/classes
java -cp out/classes ObjectMethods

clojure -M:run examples/higher_order_lambda.pas --target jvm -o out/classes
java -cp out/classes HigherOrderLambda

The test suite also compiles every example program through the JVM backend and checks that the expected main .class file is produced.

Limits

The JVM backend supports the same front-end subset as the C and P-Code backends. By-reference parameters are parsed but not implemented yet for JVM output. The first higher-order closure slice supports integer parameters, integer captures, and integer return values; the runtime shape is intentionally general enough to widen later.