IKVM11  11
Java SE 11 Virtual Machine for .NET
Loading...
Searching...
No Matches
RuntimePrimitiveJavaType.cs
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2015 Jeroen Frijters
3
4 This software is provided 'as-is', without any express or implied
5 warranty. In no event will the authors be held liable for any damages
6 arising from the use of this software.
7
8 Permission is granted to anyone to use this software for any purpose,
9 including commercial applications, and to alter it and redistribute it
10 freely, subject to the following restrictions:
11
12 1. The origin of this software must not be misrepresented; you must not
13 claim that you wrote the original software. If you use this software
14 in a product, an acknowledgment in the product documentation would be
15 appreciated but is not required.
16 2. Altered source versions must be plainly marked as such, and must not be
17 misrepresented as being the original software.
18 3. This notice may not be removed or altered from any source distribution.
19
20 Jeroen Frijters
21 jeroen@frijters.net
22
23*/
24using System;
25
26using IKVM.Attributes;
27
28#if IMPORTER || EXPORTER
29using IKVM.Reflection;
31
32using Type = IKVM.Reflection.Type;
33#else
34using System.Reflection;
35using System.Reflection.Emit;
36#endif
37
38namespace IKVM.Runtime
39{
40
42 {
43
44 readonly RuntimeContext context;
45
46 internal readonly RuntimePrimitiveJavaType BYTE;
47 internal readonly RuntimePrimitiveJavaType CHAR;
48 internal readonly RuntimePrimitiveJavaType DOUBLE;
49 internal readonly RuntimePrimitiveJavaType FLOAT;
50 internal readonly RuntimePrimitiveJavaType INT;
51 internal readonly RuntimePrimitiveJavaType LONG;
52 internal readonly RuntimePrimitiveJavaType SHORT;
53 internal readonly RuntimePrimitiveJavaType BOOLEAN;
54 internal readonly RuntimePrimitiveJavaType VOID;
55
61 {
62 this.context = context ?? throw new ArgumentNullException(nameof(context));
63 BYTE = new RuntimePrimitiveJavaType(context, context.Types.Byte, "B");
64 CHAR = new RuntimePrimitiveJavaType(context, context.Types.Char, "C");
65 DOUBLE = new RuntimePrimitiveJavaType(context, context.Types.Double, "D");
66 FLOAT = new RuntimePrimitiveJavaType(context, context.Types.Single, "F");
67 INT = new RuntimePrimitiveJavaType(context, context.Types.Int32, "I");
68 LONG = new RuntimePrimitiveJavaType(context, context.Types.Int64, "J");
69 SHORT = new RuntimePrimitiveJavaType(context, context.Types.Int16, "S");
70 BOOLEAN = new RuntimePrimitiveJavaType(context, context.Types.Boolean, "Z");
71 VOID = new RuntimePrimitiveJavaType(context, context.Types.Void, "V");
72 }
73
74 }
75
76 sealed class RuntimePrimitiveJavaType : RuntimeJavaType
77 {
78
79 readonly Type type;
80 readonly string sigName;
81
87 public RuntimePrimitiveJavaType(RuntimeContext context, Type type, string sigName) :
89 {
90 this.type = type;
91 this.sigName = sigName;
92 }
93
94 internal override RuntimeJavaType BaseTypeWrapper => null;
95
96 internal static bool IsPrimitiveType(RuntimeContext context, Type type)
97 {
98 return type == context.PrimitiveJavaTypeFactory.BYTE.type
99 || type == context.PrimitiveJavaTypeFactory.CHAR.type
100 || type == context.PrimitiveJavaTypeFactory.DOUBLE.type
101 || type == context.PrimitiveJavaTypeFactory.FLOAT.type
102 || type == context.PrimitiveJavaTypeFactory.INT.type
103 || type == context.PrimitiveJavaTypeFactory.LONG.type
104 || type == context.PrimitiveJavaTypeFactory.SHORT.type
105 || type == context.PrimitiveJavaTypeFactory.BOOLEAN.type
106 || type == context.PrimitiveJavaTypeFactory.VOID.type;
107 }
108
109 internal override string SigName => sigName;
110
111 internal override RuntimeClassLoader ClassLoader => Context.ClassLoaderFactory.GetBootstrapClassLoader();
112
113 internal override Type TypeAsTBD => type;
114
115 public override string ToString() => "RuntimePrimitiveJavaType[" + sigName + "]";
116
117#if EMITTERS
118
119 internal override void EmitLdind(CodeEmitter il)
120 {
121 if (this == Context.PrimitiveJavaTypeFactory.BOOLEAN)
122 il.Emit(OpCodes.Ldind_U1);
123 else if (this == Context.PrimitiveJavaTypeFactory.BYTE)
124 il.Emit(OpCodes.Ldind_U1);
125 else if (this == Context.PrimitiveJavaTypeFactory.CHAR)
126 il.Emit(OpCodes.Ldind_U2);
127 else if (this == Context.PrimitiveJavaTypeFactory.SHORT)
128 il.Emit(OpCodes.Ldind_I2);
129 else if (this == Context.PrimitiveJavaTypeFactory.INT)
130 il.Emit(OpCodes.Ldind_I4);
131 else if (this == Context.PrimitiveJavaTypeFactory.LONG)
132 il.Emit(OpCodes.Ldind_I8);
133 else if (this == Context.PrimitiveJavaTypeFactory.FLOAT)
134 il.Emit(OpCodes.Ldind_R4);
135 else if (this == Context.PrimitiveJavaTypeFactory.DOUBLE)
136 il.Emit(OpCodes.Ldind_R8);
137 else
138 throw new InternalException();
139 }
140
141 internal override void EmitStind(CodeEmitter il)
142 {
143 if (this == Context.PrimitiveJavaTypeFactory.BOOLEAN)
144 il.Emit(OpCodes.Stind_I1);
145 else if (this == Context.PrimitiveJavaTypeFactory.BYTE)
146 il.Emit(OpCodes.Stind_I1);
147 else if (this == Context.PrimitiveJavaTypeFactory.CHAR)
148 il.Emit(OpCodes.Stind_I2);
149 else if (this == Context.PrimitiveJavaTypeFactory.SHORT)
150 il.Emit(OpCodes.Stind_I2);
151 else if (this == Context.PrimitiveJavaTypeFactory.INT)
152 il.Emit(OpCodes.Stind_I4);
153 else if (this == Context.PrimitiveJavaTypeFactory.LONG)
154 il.Emit(OpCodes.Stind_I8);
155 else if (this == Context.PrimitiveJavaTypeFactory.FLOAT)
156 il.Emit(OpCodes.Stind_R4);
157 else if (this == Context.PrimitiveJavaTypeFactory.DOUBLE)
158 il.Emit(OpCodes.Stind_R8);
159 else
160 throw new InternalException();
161 }
162
163#endif
164
165 }
166
167}
System.Byte BYTE
IKVM.Reflection.Type Type
Represents an internal error that occurred within IKVM.
Maintains services relevant to an instane of the IKVM runtime.
Types Types
Gets the Types associated with this instance of the runtime.
RuntimePrimitiveJavaTypeFactory PrimitiveJavaTypeFactory
Gets the RuntimePrimitiveJavaTypeFactory associated with this instance of the runtime.
RuntimePrimitiveJavaTypeFactory(RuntimeContext context)
Initializes a new instance.
RuntimePrimitiveJavaType(RuntimeContext context, Type type, string sigName)
Initializes a new instance.