mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 08:14:09 -08:00
C: fix support for resources
This commit is contained in:
parent
7726d47795
commit
b34e25414e
|
@ -29,7 +29,7 @@ TeaVM_Array* teavm_resourceMapKeys(TeaVM_ResourceMap *map) {
|
||||||
void** data = TEAVM_ARRAY_DATA(array, void*);
|
void** data = TEAVM_ARRAY_DATA(array, void*);
|
||||||
for (int32_t i = 0; i < map->size; ++i) {
|
for (int32_t i = 0; i < map->size; ++i) {
|
||||||
if (map->entries[i].key != NULL) {
|
if (map->entries[i].key != NULL) {
|
||||||
data[index++] = map->entries[i].key;
|
data[index++] = *map->entries[i].key;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,10 @@ int32_t teavm_hashCode(TeaVM_String* string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t teavm_equals(TeaVM_String* first, TeaVM_String* second) {
|
int32_t teavm_equals(TeaVM_String* first, TeaVM_String* second) {
|
||||||
|
if (first == second) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
if (first->characters->size != second->characters->size) {
|
if (first->characters->size != second->characters->size) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -204,7 +204,7 @@ class MetadataCIntrinsic implements Generator {
|
||||||
int hashCode = key.hashCode();
|
int hashCode = key.hashCode();
|
||||||
int collisionRatio = 0;
|
int collisionRatio = 0;
|
||||||
while (true) {
|
while (true) {
|
||||||
int index = mod(hashCode++, table.length);
|
int index = Integer.remainderUnsigned(hashCode++, table.length);
|
||||||
if (table[index] == null) {
|
if (table[index] == null) {
|
||||||
table[index] = key;
|
table[index] = key;
|
||||||
break;
|
break;
|
||||||
|
@ -249,14 +249,6 @@ class MetadataCIntrinsic implements Generator {
|
||||||
context.writerBefore().outdent().print("}");
|
context.writerBefore().outdent().print("}");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int mod(int a, int b) {
|
|
||||||
a %= b;
|
|
||||||
if (a < 0) {
|
|
||||||
a += b;
|
|
||||||
}
|
|
||||||
return a;
|
|
||||||
}
|
|
||||||
|
|
||||||
class MethodGenerator {
|
class MethodGenerator {
|
||||||
private MethodReference targetMethod;
|
private MethodReference targetMethod;
|
||||||
private MetadataGenerator generator;
|
private MetadataGenerator generator;
|
||||||
|
|
|
@ -95,6 +95,7 @@ public class PlatformPlugin implements TeaVMPlugin, MetadataRegistration {
|
||||||
|
|
||||||
TeaVMCHost cHost = host.getExtension(TeaVMCHost.class);
|
TeaVMCHost cHost = host.getExtension(TeaVMCHost.class);
|
||||||
if (cHost != null) {
|
if (cHost != null) {
|
||||||
|
host.add(new ResourceCTransformer());
|
||||||
MetadataCIntrinsic metadataCIntrinsic = new MetadataCIntrinsic();
|
MetadataCIntrinsic metadataCIntrinsic = new MetadataCIntrinsic();
|
||||||
cHost.addGenerator(ctx -> {
|
cHost.addGenerator(ctx -> {
|
||||||
metadataCIntrinsic.init(ctx.getClassSource(), ctx.getClassLoader(),
|
metadataCIntrinsic.init(ctx.getClassSource(), ctx.getClassLoader(),
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2014 Alexey Andreev.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.teavm.platform.plugin;
|
||||||
|
|
||||||
|
import org.teavm.model.ClassHolder;
|
||||||
|
import org.teavm.model.ClassHolderTransformer;
|
||||||
|
import org.teavm.model.ClassHolderTransformerContext;
|
||||||
|
import org.teavm.model.MethodHolder;
|
||||||
|
import org.teavm.model.Program;
|
||||||
|
|
||||||
|
class ResourceCTransformer implements ClassHolderTransformer {
|
||||||
|
@Override
|
||||||
|
public void transformClass(ClassHolder cls, ClassHolderTransformerContext context) {
|
||||||
|
for (MethodHolder method : cls.getMethods()) {
|
||||||
|
Program program = method.getProgram();
|
||||||
|
if (program != null) {
|
||||||
|
new ResourceProgramTransformer(context.getHierarchy(), program).removeCasts();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -61,18 +61,31 @@ class ResourceProgramTransformer {
|
||||||
insn.delete();
|
insn.delete();
|
||||||
}
|
}
|
||||||
} else if (insn instanceof CastInstruction) {
|
} else if (insn instanceof CastInstruction) {
|
||||||
CastInstruction cast = (CastInstruction) insn;
|
removeCastToResource((CastInstruction) insn);
|
||||||
if (hierarchy.isSuperType(RESOURCE, cast.getTargetType(), false)) {
|
}
|
||||||
AssignInstruction assign = new AssignInstruction();
|
}
|
||||||
assign.setReceiver(cast.getReceiver());
|
}
|
||||||
assign.setAssignee(cast.getValue());
|
|
||||||
assign.setLocation(cast.getLocation());
|
void removeCasts() {
|
||||||
insn.replace(assign);
|
for (BasicBlock block : program.getBasicBlocks()) {
|
||||||
|
for (Instruction insn : block) {
|
||||||
|
if (insn instanceof CastInstruction) {
|
||||||
|
removeCastToResource((CastInstruction) insn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void removeCastToResource(CastInstruction cast) {
|
||||||
|
if (hierarchy.isSuperType(RESOURCE, cast.getTargetType(), false)) {
|
||||||
|
AssignInstruction assign = new AssignInstruction();
|
||||||
|
assign.setReceiver(cast.getReceiver());
|
||||||
|
assign.setAssignee(cast.getValue());
|
||||||
|
assign.setLocation(cast.getLocation());
|
||||||
|
cast.replace(assign);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private List<Instruction> transformInvoke(InvokeInstruction insn) {
|
private List<Instruction> transformInvoke(InvokeInstruction insn) {
|
||||||
if (insn.getType() != InvocationType.VIRTUAL) {
|
if (insn.getType() != InvocationType.VIRTUAL) {
|
||||||
return null;
|
return null;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user