Skip to main content

jvm_assembler/program/
pool.rs

1/// JVM constant pool
2#[derive(Debug, Clone, Default)]
3pub struct JvmConstantPool {
4    /// List of constant pool entries
5    pub entries: Vec<JvmConstantPoolEntry>,
6}
7
8impl JvmConstantPool {
9    /// Creates a new empty constant pool
10    pub fn new() -> Self {
11        Self::default()
12    }
13}
14
15/// JVM constant pool entry
16#[derive(Debug, Clone)]
17pub enum JvmConstantPoolEntry {
18    /// No operation
19    Nop,
20    /// UTF-8 string
21    Utf8(String),
22    /// Integer value
23    Integer {
24        /// The value
25        value: i32,
26    },
27    /// Float value
28    Float {
29        /// The value
30        value: f32,
31    },
32    /// Long value
33    Long {
34        /// The value
35        value: i64,
36    },
37    /// Double value
38    Double {
39        /// The value
40        value: f64,
41    },
42    /// Class reference
43    Class {
44        /// Class name
45        name: String,
46    },
47    /// String reference
48    String {
49        /// The string value
50        value: String,
51    },
52    /// Field reference
53    Fieldref {
54        /// Class name
55        class_name: String,
56        /// Field name
57        name: String,
58        /// Field descriptor
59        descriptor: String,
60    },
61    /// Method reference
62    Methodref {
63        /// Class name
64        class_name: String,
65        /// Method name
66        name: String,
67        /// Method descriptor
68        descriptor: String,
69    },
70    /// Interface method reference
71    InterfaceMethodref {
72        /// Class name
73        class_name: String,
74        /// Method name
75        name: String,
76        /// Method descriptor
77        descriptor: String,
78    },
79    /// Name and type reference
80    NameAndType {
81        /// Name
82        name: String,
83        /// Descriptor
84        descriptor: String,
85    },
86    /// Method handle
87    MethodHandle {
88        /// Reference kind
89        reference_kind: u8,
90        /// Reference index
91        reference_index: u16,
92    },
93    /// Method type
94    MethodType {
95        /// Method descriptor
96        descriptor: String,
97    },
98    /// Dynamic constant
99    Dynamic {
100        /// Bootstrap method attribute index
101        bootstrap_method_attr_index: u16,
102        /// Name and type index
103        name_and_type_index: u16,
104    },
105    /// Invoke dynamic constant
106    InvokeDynamic {
107        /// Bootstrap method attribute index
108        bootstrap_method_attr_index: u16,
109        /// Name and type index
110        name_and_type_index: u16,
111    },
112    /// Module reference
113    Module {
114        /// Module name
115        name: String,
116    },
117    /// Package reference
118    Package {
119        /// Package name
120        name: String,
121    },
122}