; jasmin-clj JVM management library
; Copyright (c) 2013 Ivan Pierre . All rights reserved.
;
; The use and distribution terms for this software are covered by the
; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
; which can be found in the file epl-v10.html at the root of this distribution.
; By using this software in any fashion, you are agreeing to be bound by
; the terms of this license.
; You must not remove this notice, or any other, from this software.
(ns ^{:doc "Definition of JVM Class model"}
jasmin-clj.class-struct)
(defonce ^{:doc "Definition of Class Structure"}
class-struct
'(1 [:cla-magic :u4]
[:cla-minor-version :u2]
[:cla-major-version :u2]
[:cla-constant-pool :cp-info]
[:cla-access-flags :access-flags]
[:vla-this-class :u2]
[:cla-super-class :u2]
[:cla-interfaces :interface-info]
[:cla-fields :field-info]
[:cla-attributes :attribure-info]))
(defn constant-pool-by-keyword
"Constant pool structures by field keyword"
[tag]
(get
{:cst-utf9 '(1 [:utf8 :utf8])
:cst-integer '(3 [:value :s4])
:cst-float '(4 [:value :f4])
:cst-long '(5 [:value :s8])
:cst-double '(6 [:value :f8])
:cst-class '(7 [:name :cst-utf8])
:scr-string '(8 [:sring :cst-utf8])
:cst-field '(9 [:class :cst-class]
[:name-and-type :cst-name-and-type)
:cst-method '(10 [:class :sct-class]
[:name-and-type :cst-name-and-type])
:cst-interface '(11 [:class :sct-clas]
[:name-and-type :cst-name-and-type])
:cst-name-and-type '(12 [:name :cst-utf8]
[:descriptor :cst-utf8])
:cst-handle '(15 [:kind :kind]
[:reference :cst-reference])
:cst-type '(16 [:descriptor :cst-utf8])
:cst-dynamic '(18 [:bootstrap :bootstrap-index]
[:name-and-type :cst-name-and-type])}
tag ))
(def ^{:doc "Constant pool tags by index"}
constant-pool-index
[nil :utf8 nil :integer :float,
:long :double :class :string :fieldref,
:methodref :interface-methodref :name-and-type nil nil,
:method-handle :method-type nil :invoke-dynamic nil])
(defn constant-pool-struct-by-index
"Constant pool structures by index"
[index]
(rest (constant-pool-by-keyword (get constant-pool-index index))))
(defn constant-pool-key-by-index
"Constant pool structures by index"
[index]
(get constant-pool-index index))
(defn constant-pool-struct-by-keyword
"Constant pool structures by key"
[key]
(rest (constant-pool-by-keyword key)))
(defn constant-pool-index-by-keyword
"Constant pool index by key"
[key]
(first (constant-pool-by-keyword key)))
Ok, it works... :(