Written as a compare-and-contrast programming exercise, loosely based on Pork (http://github.com/CodeFarmer/pork).
ABANDONED CODE - starting again in the 'sporkle' project.
Has three main parts:
-
Classfile read/write - parsing JVM class file streams into structs that correspond to the format laid out in the JVM spec, and writing those structs back into byte streams.
-
Class struct creation with a sorta-DSL - creating classfile structs (above) by describing in a friendly form the fields and attributes of the class, as well as a pseudo-bytecode JCM assembler for describing methods.
-
Friendly view of classfile structs - the reverse process of 2. above, creating a human-readable view onto the classfile struct that should eventually be the same DSL, so we can run the view through a reader and get Java classes.
This works at the moment:
(jc-with-method
(jc-with-empty-constructor
(public (java-class "Nothing"))
ACC_PUBLIC)
ACC_PUBLIC
"doNothing"
"()V"
0
1 ;; this
[:return])
Ugly eh? This is the plan:
(public
(java-class "Nothing"
(private
(field java.lang.Object "x")
(public
(method :void "doNothing" [] [:return]))
(method java.lang.Object "getX" []
[:aload_0 ; this
:getfield "x" ; infer containing class unless specified, guess type if unambiguous
:areturn]))))
The shortish term goal is feature parity with Pork, so support for exception tables, smart arguments for JVM bytecode instructions, line number tables, labels (for jumping) and so on will be next once the syntax is nice.
Copyright (C) 2017 Joel Gluth
Distributed under the Eclipse Public License, the same as Clojure.