Skip to content

Commit

Permalink
Cleanup JavaWriter Constants
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSilkMiner authored and kindlich committed Apr 19, 2024
1 parent 6d768e6 commit 28a44a8
Show file tree
Hide file tree
Showing 6 changed files with 232 additions and 101 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ public Void visitConstantSByte(ConstantSByteExpression expression) {

@Override
public Void visitConstantShort(ConstantShortExpression expression) {
getJavaWriter().siPush(expression.value);
getJavaWriter().constant(expression.value);
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private void handleArray(final int z, final JavaLocalVariableInfo arrayTypeInfo)
ArrayTypeID listType = (ArrayTypeID) statement.list.type.withoutOptional();
if (listType.elementType == BasicTypeID.BYTE) {
javaWriter.arrayLoad(Type.BYTE_TYPE);
javaWriter.siPush((short) 255);
javaWriter.constant(0xFF);
javaWriter.iAnd();
} else if (listType.elementType == BasicTypeID.USHORT) {
javaWriter.arrayLoad(Type.SHORT_TYPE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ public Void builtinStaticMethod(BuiltinMethodSymbol method, TypeID returnType, C
case BYTE_ADD_STRING:
case BYTE_CAT_STRING:
arguments[0].accept(expressionVisitor);
javaWriter.siPush((short) 0xFF);
javaWriter.constant(0xFF);
javaWriter.iAnd();
javaWriter.invokeStatic(INTEGER_TO_STRING);
arguments[1].accept(expressionVisitor);
Expand Down Expand Up @@ -570,42 +570,42 @@ public Void builtinStaticMethod(BuiltinMethodSymbol method, TypeID returnType, C
javaWriter.i2b();
break;
case BYTE_TO_SHORT:
javaWriter.siPush((short) 0xFF);
javaWriter.constant(0xFF);
javaWriter.iAnd();
javaWriter.i2s();
break;
case BYTE_TO_USHORT:
case BYTE_TO_INT:
case BYTE_TO_UINT:
case BYTE_TO_USIZE:
javaWriter.siPush((short) 0xFF);
javaWriter.constant(0xFF);
javaWriter.iAnd();
break;
case BYTE_TO_LONG:
case BYTE_TO_ULONG:
javaWriter.siPush((short) 0xFF);
javaWriter.constant(0xFF);
javaWriter.iAnd();
javaWriter.i2l();
break;
case BYTE_TO_FLOAT:
javaWriter.siPush((short) 0xFF);
javaWriter.constant(0xFF);
javaWriter.iAnd();
javaWriter.i2f();
break;
case BYTE_TO_DOUBLE:
javaWriter.siPush((short) 0xFF);
javaWriter.constant(0xFF);
javaWriter.iAnd();
javaWriter.i2d();
break;
case BYTE_TO_CHAR:
javaWriter.siPush((short) 0xFF);
javaWriter.constant(0xFF);
javaWriter.iAnd();
break;
case BYTE_TO_STRING:
if (arguments[0].type.isOptional()) {
javaWriter.invokeStatic(OBJECTS_TOSTRING);
} else {
javaWriter.siPush((short) 0xFF);
javaWriter.constant(0xFF);
javaWriter.iAnd();
javaWriter.invokeStatic(INTEGER_TO_STRING);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
import org.openzen.zenscript.javashared.JavaClass;
import org.openzen.zenscript.javashared.JavaTypeParameterInfo;

import java.util.Iterator;
import java.util.Map;

/**
* @author Stan Hebben
*/
Expand All @@ -27,36 +24,36 @@ public JavaTypeExpressionVisitor(JavaBytecodeContext context) {
public Void visitBasic(JavaWriter writer, BasicTypeID basic) {
switch (basic) {
case BOOL:
writer.constantClass(JavaClass.BOOLEAN);
writer.constant(JavaClass.BOOLEAN);
return null;
case SBYTE:
writer.constantClass(JavaClass.BYTE);
writer.constant(JavaClass.BYTE);
return null;
case SHORT:
writer.constantClass(JavaClass.SHORT);
writer.constant(JavaClass.SHORT);
return null;
case BYTE:
case USHORT:
case INT:
case UINT:
case USIZE:
writer.constantClass(JavaClass.INTEGER);
writer.constant(JavaClass.INTEGER);
return null;
case LONG:
case ULONG:
writer.constantClass(JavaClass.LONG);
writer.constant(JavaClass.LONG);
return null;
case FLOAT:
writer.constantClass(JavaClass.FLOAT);
writer.constant(JavaClass.FLOAT);
return null;
case DOUBLE:
writer.constantClass(JavaClass.DOUBLE);
writer.constant(JavaClass.DOUBLE);
return null;
case CHAR:
writer.constantClass(JavaClass.CHARACTER);
writer.constant(JavaClass.CHARACTER);
return null;
case STRING:
writer.constantClass(JavaClass.STRING);
writer.constant(JavaClass.STRING);
return null;
default:
throw new IllegalArgumentException();
Expand All @@ -70,31 +67,31 @@ public Void visitArray(JavaWriter writer, ArrayTypeID array) {

@Override
public Void visitAssoc(JavaWriter writer, AssocTypeID assoc) {
writer.constantClass(JavaClass.MAP);
writer.constant(JavaClass.MAP);
return null;
}

@Override
public Void visitGenericMap(JavaWriter writer, GenericMapTypeID map) {
writer.constantClass(JavaClass.MAP);
writer.constant(JavaClass.MAP);
return null;
}

@Override
public Void visitIterator(JavaWriter writer, IteratorTypeID iterator) {
writer.constantClass(JavaClass.ITERATOR);
writer.constant(JavaClass.ITERATOR);
return null;
}

@Override
public Void visitFunction(JavaWriter writer, FunctionTypeID function) {
writer.constantClass(context.getFunction(function).getCls());
writer.constant(context.getFunction(function).getCls());
return null;
}

@Override
public Void visitDefinition(JavaWriter writer, DefinitionTypeID definition) {
writer.constantClass(context.getJavaClass(definition.definition));
writer.constant(context.getJavaClass(definition.definition));
return null;
}

Expand All @@ -112,7 +109,7 @@ public Void visitGeneric(JavaWriter writer, GenericTypeID generic) {

@Override
public Void visitRange(JavaWriter writer, RangeTypeID range) {
writer.constantClass(context.getRange(range).cls);
writer.constant(context.getRange(range).cls);
return null;
}

Expand Down
Loading

0 comments on commit 28a44a8

Please sign in to comment.