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*);
|
||||
for (int32_t i = 0; i < map->size; ++i) {
|
||||
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) {
|
||||
if (first == second) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (first->characters->size != second->characters->size) {
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -204,7 +204,7 @@ class MetadataCIntrinsic implements Generator {
|
|||
int hashCode = key.hashCode();
|
||||
int collisionRatio = 0;
|
||||
while (true) {
|
||||
int index = mod(hashCode++, table.length);
|
||||
int index = Integer.remainderUnsigned(hashCode++, table.length);
|
||||
if (table[index] == null) {
|
||||
table[index] = key;
|
||||
break;
|
||||
|
@ -249,14 +249,6 @@ class MetadataCIntrinsic implements Generator {
|
|||
context.writerBefore().outdent().print("}");
|
||||
}
|
||||
|
||||
private static int mod(int a, int b) {
|
||||
a %= b;
|
||||
if (a < 0) {
|
||||
a += b;
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
class MethodGenerator {
|
||||
private MethodReference targetMethod;
|
||||
private MetadataGenerator generator;
|
||||
|
|
|
@ -95,6 +95,7 @@ public class PlatformPlugin implements TeaVMPlugin, MetadataRegistration {
|
|||
|
||||
TeaVMCHost cHost = host.getExtension(TeaVMCHost.class);
|
||||
if (cHost != null) {
|
||||
host.add(new ResourceCTransformer());
|
||||
MetadataCIntrinsic metadataCIntrinsic = new MetadataCIntrinsic();
|
||||
cHost.addGenerator(ctx -> {
|
||||
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,15 +61,28 @@ class ResourceProgramTransformer {
|
|||
insn.delete();
|
||||
}
|
||||
} else if (insn instanceof CastInstruction) {
|
||||
CastInstruction cast = (CastInstruction) insn;
|
||||
removeCastToResource((CastInstruction) insn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void removeCasts() {
|
||||
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());
|
||||
insn.replace(assign);
|
||||
}
|
||||
}
|
||||
cast.replace(assign);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user