Skip to content

Commit

Permalink
Familiarise myself with the serialisation framework again.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Boerman committed Mar 20, 2024
1 parent 090d78f commit 391b71c
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,5 @@ public String toString() {
+ ",longs = " + Arrays.toString(longs)
+ ",booleanss = " + Arrays.deepToString(booleanss)
+ "}";

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.logging.Logger;
import java.util.stream.Collectors;

import xyz.janboerman.scalaloader.configurationserializable.ConfigurationSerializable;
import static xyz.janboerman.scalaloader.example.java.ExamplePlugin.assertionsEnabled;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import java.io.File;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.EnumMap;
import java.util.Map;
import java.util.Objects;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public static ParameterType from(Set<? extends Annotation> annotations, Type typ
return from(annotations, upperBound);
} else {
//this branch should never be taken actually.
//when it is take, TypeUtils.asRawType will throw an IllegalArgumentException
//when it is taken, TypeUtils.asRawType will throw an IllegalArgumentException.
return new ParameterType(annotations, TypeUtils.asRawType(type));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public abstract class ScalaCollection {
static final String SCALA_MUTABLE_ARRAY_SEQ = "scala.collection.mutable.ArraySeq";
static final String SCALA_IMMUTABLE_LIST = "scala.collection.immutable.List";
//TODO static final String SCALA_IMMUTABLE_NUMERIC_RANGE = "scala.collection.immutable.NumericRange"; //can't handle this (yet), because we need to obtain the Integral instances first.
//TODO but we have Explicit now. does this help us?
//TODO also need to special-case the 'sorted' collections: TreeSet etc

public ScalaCollection() {}
Expand Down Expand Up @@ -211,6 +212,7 @@ public String toString() {
}

//TODO do I still need this?
//TODO I think we want to generate this code, amiright?
@SerializableAs("THE_SEQ_IMPLEMENTATION_CLASS_NAME")
/*public*/ final class SeqAdapter extends ScalaSeq {
private final scala.collection.Seq seq;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ else if (ScalaConversions.isScalaCollection(typeSignature, (ClassLoader) pluginC
methodVisitor.visitMethodInsn(INVOKEVIRTUAL, "java/util/UUID", "toString", "()Ljava/lang/String;", false);
operandStack.replaceTop(STRING_TYPE);
break;
//TODO java.util.Date maybe? anything else?
//TODO java.util.Date/java.time.Instant maybe?
//TODO scala.math.BigInt
//TODO scala.math.BigDecimal

Expand Down Expand Up @@ -1811,6 +1811,7 @@ static void serializeCollection(IScalaPluginClassLoader classLoader, MethodVisit

//TODO if I really feel ambitious, I might implement recursive lookups too!
//TODO I should probably factor this out to a separate "ImplicitSearch" class.
//TODO a humble beginning is started in the 'Explicit.java' file.

}

Expand All @@ -1820,7 +1821,6 @@ static void serializeCollection(IScalaPluginClassLoader classLoader, MethodVisit
//TODO - immutable.NumericRange --- done! (but not yet tested)
//TODO - immutable.ArraySeq
//TODO - mutable.ArraySeq
//TODO - mutable.ArrayBuilder (debatable)
//TODO


Expand Down Expand Up @@ -2202,11 +2202,12 @@ static void deserializeCollection(IScalaPluginClassLoader classLoader, MethodVis
//TODO - immutable.NumericRange --- TODO requires ImplicitSearch for deserialization.
//TODO --- TODO Also we need to generate instanceof bytecodes to check the runtime type of the elements
//TODO --- TODO and use the correct component types for the start, end and step values of the NumericRange.
//TODO - immutable.ArraySeq
//TODO - mutable.ArraySeq
//TODO - mutable.ArrayBuilder (debatable)
//TODO --- TODO implement this later after the other types are done.
//TODO - immutable.ArraySeq --- TODO why does this need a special case? because the ArraySeq is potentially backed by primitive arrays. and for the case of Unit we only have to save a length. boolean arrays can be backed by a long (where the bits equal booleans).
//TODO - mutable.ArraySeq --- TODO why does this need a special case? Do we have a custom serialization strategy? I think we do! We could also re-use our array serialisation code.
//TODO

//

//best effort
final TypeSignature elementTypeSignature = typeSignature.hasTypeArguments() ? typeSignature.getTypeArgument(0) : TypeSignature.OBJECT_TYPE_SIGNATURE;
Expand Down Expand Up @@ -2318,7 +2319,7 @@ private static void generateNewBuilderCall(IScalaPluginClassLoader classLoader,
}

private static void generateOrdering(IScalaPluginClassLoader classLoader, MethodVisitor methodVisitor, TypeSignature elementType, LocalCounter localCounter, LocalVariableTable localVariableTable, OperandStack operandStack) {
switch(elementType.internalName()) {
switch (elementType.internalName()) {
//java primitives
case "B":
methodVisitor.visitFieldInsn(GETSTATIC, "scala/math/Ordering$Byte$", "MODULE$", "Lscala/math/Ordering$Byte$;");
Expand Down Expand Up @@ -2462,6 +2463,7 @@ private static void generateOrdering(IScalaPluginClassLoader classLoader, Method
//assume the Ordering instance can be found in the companion object.
//TODO we need to inspect the fields & methods of the companion object and generate the appropriate calls!
//TODO need to Adjust GlobalScanner or something so that CompanionObjectScanResult is part of the result?
//TODO can we use Explicit here?
break;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ public static Object getTypeClassInstance(Class<?> typeClassTrait, Class<?> inst
return getCompanionObjectInstance(Class.forName(ORDERING + "$Symbol", true, classLoader));
//can't know the orderings for Option, Seq, Either or Tuple, because we would need the ordering instances for the elements,
//and we don't know the type arguments sadly.
//TODO is it possible to find out? TypeclassTrait should become a Parameterized(Parameter)Type, right?
//TODO can we make it that? and can we actually provide the type arguments?
}
break;
case CLASSTAG:
Expand All @@ -204,6 +206,8 @@ public static Object getTypeClassInstance(Class<?> typeClassTrait, Class<?> inst
}
}
}

// tough luck, nothing to do
throw ex;
}

Expand Down

0 comments on commit 391b71c

Please sign in to comment.