Skip to content

Old attempt at an update of the Pork idea - Java classfile assembler/dissassembler in Clojure. Unlike Pork, still in need of some work! Disassembly works, assembly is ugly to say the least.

Notifications You must be signed in to change notification settings

CodeFarmer/old-sporkle

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sporkle: Pure-Clojure Java classfile assembler and disassembler

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:

  1. 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.

  2. 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.

  3. 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.

Current State

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.

License

Copyright (C) 2017 Joel Gluth

Distributed under the Eclipse Public License, the same as Clojure.

About

Old attempt at an update of the Pork idea - Java classfile assembler/dissassembler in Clojure. Unlike Pork, still in need of some work! Disassembly works, assembly is ugly to say the least.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages