Skip to content

Default constructor for Record? #10

@bsless

Description

@bsless

I got curious and tried emitting a record with the library.
The awesome part is it just worked. The "hard" part was it did not emit the default constructor emitted by javac, so I had to write one myself.
Looking at some bytecode, generating it seems straightforward:

(defn emit-record-constructor
  [fields]
  (conj
   (into
    [[:aload 0]
     [:invokespecial :super :init [:void]]]
    cat
    (map-indexed
     (fn [i {:keys [name type]}]
       [[:aload 0]
        [:aload (inc i)]
        [:putfield :this name type]])
     fields))
   [:return]))

Do you think it should be added by default when no init is provided with the same desc? (when the class's flags have :record)

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions