--- /dev/null
+package org.simantics.scl.compiler.internal.serialization;
+
+import java.util.ArrayList;
+
+import org.cojen.classfile.TypeDesc;
+import org.objenesis.strategy.StdInstantiatorStrategy;
+import org.simantics.scl.compiler.common.datatypes.Constructor;
+import org.simantics.scl.compiler.common.names.Name;
+import org.simantics.scl.compiler.common.precedence.Associativity;
+import org.simantics.scl.compiler.common.precedence.Precedence;
+import org.simantics.scl.compiler.constants.BooleanConstant;
+import org.simantics.scl.compiler.constants.ByteConstant;
+import org.simantics.scl.compiler.constants.CharacterConstant;
+import org.simantics.scl.compiler.constants.ClassConstant;
+import org.simantics.scl.compiler.constants.Constant;
+import org.simantics.scl.compiler.constants.DoubleConstant;
+import org.simantics.scl.compiler.constants.FloatConstant;
+import org.simantics.scl.compiler.constants.GetPrimitiveConstant;
+import org.simantics.scl.compiler.constants.IntegerConstant;
+import org.simantics.scl.compiler.constants.JavaComparisonOperation;
+import org.simantics.scl.compiler.constants.JavaComparisonToZeroOperation;
+import org.simantics.scl.compiler.constants.JavaConstructor;
+import org.simantics.scl.compiler.constants.JavaConversionOperation;
+import org.simantics.scl.compiler.constants.JavaMathOperation;
+import org.simantics.scl.compiler.constants.JavaMethod;
+import org.simantics.scl.compiler.constants.JavaStaticField;
+import org.simantics.scl.compiler.constants.JavaStaticMethod;
+import org.simantics.scl.compiler.constants.JavaTypeClassMethod;
+import org.simantics.scl.compiler.constants.JavaTypeClassSuper;
+import org.simantics.scl.compiler.constants.JavaTypeInstanceConstructor;
+import org.simantics.scl.compiler.constants.LocalBoxedArrayElementConstant;
+import org.simantics.scl.compiler.constants.LocalFieldConstant;
+import org.simantics.scl.compiler.constants.LocalVariableConstant;
+import org.simantics.scl.compiler.constants.LongConstant;
+import org.simantics.scl.compiler.constants.NoRepConstant;
+import org.simantics.scl.compiler.constants.SCLConstant;
+import org.simantics.scl.compiler.constants.SCLConstructor;
+import org.simantics.scl.compiler.constants.ShortConstant;
+import org.simantics.scl.compiler.constants.StringConstant;
+import org.simantics.scl.compiler.constants.StringInterpolation;
+import org.simantics.scl.compiler.constants.ThisConstant;
+import org.simantics.scl.compiler.constants.generic.CallJava;
+import org.simantics.scl.compiler.constants.generic.ConvertToListFilter;
+import org.simantics.scl.compiler.constants.generic.MethodRef;
+import org.simantics.scl.compiler.constants.generic.OutputFilter;
+import org.simantics.scl.compiler.constants.generic.ParameterStackItem;
+import org.simantics.scl.compiler.constants.generic.PopOutputFilter;
+import org.simantics.scl.compiler.constants.generic.StackItem;
+import org.simantics.scl.compiler.constants.generic.ThreadLocalStackItem;
+import org.simantics.scl.compiler.constants.singletons.BindingConstant;
+import org.simantics.scl.compiler.constants.singletons.FailFunction;
+import org.simantics.scl.compiler.constants.singletons.JustConstant;
+import org.simantics.scl.compiler.constants.singletons.NothingConstant;
+import org.simantics.scl.compiler.constants.singletons.TypeOfConstant;
+import org.simantics.scl.compiler.constants.singletons.UnsafeCoerce;
+import org.simantics.scl.compiler.elaboration.expressions.Assignment;
+import org.simantics.scl.compiler.elaboration.expressions.Case;
+import org.simantics.scl.compiler.elaboration.expressions.EApply;
+import org.simantics.scl.compiler.elaboration.expressions.EApplyType;
+import org.simantics.scl.compiler.elaboration.expressions.EAsPattern;
+import org.simantics.scl.compiler.elaboration.expressions.EBinary;
+import org.simantics.scl.compiler.elaboration.expressions.EBinaryRightSide;
+import org.simantics.scl.compiler.elaboration.expressions.EBind;
+import org.simantics.scl.compiler.elaboration.expressions.EBlock;
+import org.simantics.scl.compiler.elaboration.expressions.EConstant;
+import org.simantics.scl.compiler.elaboration.expressions.EEnforce;
+import org.simantics.scl.compiler.elaboration.expressions.EError;
+import org.simantics.scl.compiler.elaboration.expressions.EExternalConstant;
+import org.simantics.scl.compiler.elaboration.expressions.EFieldAccess;
+import org.simantics.scl.compiler.elaboration.expressions.EGetConstraint;
+import org.simantics.scl.compiler.elaboration.expressions.EIf;
+import org.simantics.scl.compiler.elaboration.expressions.EIntegerLiteral;
+import org.simantics.scl.compiler.elaboration.expressions.ELambda;
+import org.simantics.scl.compiler.elaboration.expressions.ELambdaType;
+import org.simantics.scl.compiler.elaboration.expressions.ELet;
+import org.simantics.scl.compiler.elaboration.expressions.EListComprehension;
+import org.simantics.scl.compiler.elaboration.expressions.EListLiteral;
+import org.simantics.scl.compiler.elaboration.expressions.ELiteral;
+import org.simantics.scl.compiler.elaboration.expressions.EMatch;
+import org.simantics.scl.compiler.elaboration.expressions.EPlaceholder;
+import org.simantics.scl.compiler.elaboration.expressions.EPreLet;
+import org.simantics.scl.compiler.elaboration.expressions.EPreRuleset;
+import org.simantics.scl.compiler.elaboration.expressions.ERange;
+import org.simantics.scl.compiler.elaboration.expressions.ERealLiteral;
+import org.simantics.scl.compiler.elaboration.expressions.ERecord;
+import org.simantics.scl.compiler.elaboration.expressions.ERuleset;
+import org.simantics.scl.compiler.elaboration.expressions.ESelect;
+import org.simantics.scl.compiler.elaboration.expressions.ESimpleLambda;
+import org.simantics.scl.compiler.elaboration.expressions.ESimpleLet;
+import org.simantics.scl.compiler.elaboration.expressions.EStringLiteral;
+import org.simantics.scl.compiler.elaboration.expressions.ETransformation;
+import org.simantics.scl.compiler.elaboration.expressions.ETypeAnnotation;
+import org.simantics.scl.compiler.elaboration.expressions.EVar;
+import org.simantics.scl.compiler.elaboration.expressions.EVariable;
+import org.simantics.scl.compiler.elaboration.expressions.EWhen;
+import org.simantics.scl.compiler.elaboration.expressions.Expression;
+import org.simantics.scl.compiler.elaboration.expressions.GuardedExpression;
+import org.simantics.scl.compiler.elaboration.expressions.GuardedExpressionGroup;
+import org.simantics.scl.compiler.elaboration.expressions.Variable;
+import org.simantics.scl.compiler.elaboration.expressions.accessor.ExpressionAccessor;
+import org.simantics.scl.compiler.elaboration.expressions.accessor.IdAccessor;
+import org.simantics.scl.compiler.elaboration.expressions.accessor.StringAccessor;
+import org.simantics.scl.compiler.elaboration.expressions.block.BindStatement;
+import org.simantics.scl.compiler.elaboration.expressions.block.GuardStatement;
+import org.simantics.scl.compiler.elaboration.expressions.block.LetStatement;
+import org.simantics.scl.compiler.elaboration.expressions.block.RuleStatement;
+import org.simantics.scl.compiler.elaboration.expressions.list.ListAssignment;
+import org.simantics.scl.compiler.elaboration.expressions.list.ListGenerator;
+import org.simantics.scl.compiler.elaboration.expressions.list.ListGuard;
+import org.simantics.scl.compiler.elaboration.expressions.list.ListSeq;
+import org.simantics.scl.compiler.elaboration.expressions.list.ListThen;
+import org.simantics.scl.compiler.elaboration.fundeps.Fundep;
+import org.simantics.scl.compiler.elaboration.java.EmptyListConstructor;
+import org.simantics.scl.compiler.elaboration.java.EqualsFunction;
+import org.simantics.scl.compiler.elaboration.java.HashCodeFunction;
+import org.simantics.scl.compiler.elaboration.java.ListConstructor;
+import org.simantics.scl.compiler.elaboration.macros.StandardMacroRule;
+import org.simantics.scl.compiler.elaboration.modules.DeprecatedProperty;
+import org.simantics.scl.compiler.elaboration.modules.DerivedProperty;
+import org.simantics.scl.compiler.elaboration.modules.InlineProperty;
+import org.simantics.scl.compiler.elaboration.modules.MethodImplementation;
+import org.simantics.scl.compiler.elaboration.modules.PrivateProperty;
+import org.simantics.scl.compiler.elaboration.modules.SCLValue;
+import org.simantics.scl.compiler.elaboration.modules.TypeClass;
+import org.simantics.scl.compiler.elaboration.modules.TypeClassInstance;
+import org.simantics.scl.compiler.elaboration.modules.TypeClassMethod;
+import org.simantics.scl.compiler.elaboration.query.QAlternative;
+import org.simantics.scl.compiler.elaboration.query.QAtom;
+import org.simantics.scl.compiler.elaboration.query.QConjunction;
+import org.simantics.scl.compiler.elaboration.query.QDisjunction;
+import org.simantics.scl.compiler.elaboration.query.QExists;
+import org.simantics.scl.compiler.elaboration.query.QIf;
+import org.simantics.scl.compiler.elaboration.query.QMapping;
+import org.simantics.scl.compiler.elaboration.query.QNegation;
+import org.simantics.scl.compiler.elaboration.query.Query;
+import org.simantics.scl.compiler.errors.CompilationError;
+import org.simantics.scl.compiler.internal.codegen.continuations.BranchRef;
+import org.simantics.scl.compiler.internal.codegen.continuations.ContRef;
+import org.simantics.scl.compiler.internal.codegen.continuations.ReturnCont;
+import org.simantics.scl.compiler.internal.codegen.references.BoundVar;
+import org.simantics.scl.compiler.internal.codegen.references.ValRef;
+import org.simantics.scl.compiler.internal.codegen.references.ValSpecialization;
+import org.simantics.scl.compiler.internal.codegen.ssa.SSABlock;
+import org.simantics.scl.compiler.internal.codegen.ssa.SSAFunction;
+import org.simantics.scl.compiler.internal.codegen.ssa.exits.If;
+import org.simantics.scl.compiler.internal.codegen.ssa.exits.Jump;
+import org.simantics.scl.compiler.internal.codegen.ssa.exits.Switch;
+import org.simantics.scl.compiler.internal.codegen.ssa.exits.Throw;
+import org.simantics.scl.compiler.internal.codegen.ssa.statements.LetApply;
+import org.simantics.scl.compiler.internal.codegen.ssa.statements.LetFunctions;
+import org.simantics.scl.compiler.internal.codegen.types.StandardTypeConstructor;
+import org.simantics.scl.compiler.internal.serialization.serializers.FiniteClassSerializer;
+import org.simantics.scl.compiler.internal.serialization.serializers.NameSerializer;
+import org.simantics.scl.compiler.internal.serialization.serializers.SSABlockSerializer;
+import org.simantics.scl.compiler.internal.serialization.serializers.SSAFunctionSerializer;
+import org.simantics.scl.compiler.internal.serialization.serializers.SingletonSerializer;
+import org.simantics.scl.compiler.internal.serialization.serializers.TConSerializer;
+import org.simantics.scl.compiler.internal.serialization.serializers.TPredSerializer;
+import org.simantics.scl.compiler.internal.serialization.serializers.TUnionSerializer;
+import org.simantics.scl.compiler.internal.serialization.serializers.TypeDescSerializer;
+import org.simantics.scl.compiler.internal.serialization.serializers.ValRefSerializer;
+import org.simantics.scl.compiler.module.ConcreteModule;
+import org.simantics.scl.compiler.module.ImportDeclaration;
+import org.simantics.scl.compiler.types.TApply;
+import org.simantics.scl.compiler.types.TCon;
+import org.simantics.scl.compiler.types.TForAll;
+import org.simantics.scl.compiler.types.TFun;
+import org.simantics.scl.compiler.types.TMetaVar;
+import org.simantics.scl.compiler.types.TPred;
+import org.simantics.scl.compiler.types.TUnion;
+import org.simantics.scl.compiler.types.TVar;
+import org.simantics.scl.compiler.types.Type;
+import org.simantics.scl.compiler.types.kinds.KArrow;
+import org.simantics.scl.compiler.types.kinds.KCon;
+import org.simantics.scl.compiler.types.kinds.KMetaVar;
+import org.simantics.scl.compiler.types.kinds.Kinds;
+import org.simantics.scl.compiler.types.util.Polarity;
+
+import com.esotericsoftware.kryo.Kryo;
+
+import gnu.trove.map.hash.THashMap;
+
+public class KryoRegistration {
+
+ public static void registerClasses(Kryo kryo) {
+ kryo.setInstantiatorStrategy(new Kryo.DefaultInstantiatorStrategy(new StdInstantiatorStrategy()));
+ kryo.setRegistrationRequired(true);
+
+ // External types
+ kryo.register(String[].class);
+ kryo.register(byte[].class);
+ kryo.register(ArrayList.class);
+ kryo.register(THashMap.class);
+
+ kryo.register(TypeDesc.OBJECT.getClass(), TypeDescSerializer.INSTANCE);
+ kryo.register(TypeDesc.INT.getClass(), TypeDescSerializer.INSTANCE);
+ kryo.register(TypeDesc.forClass(Object[].class).getClass(), TypeDescSerializer.INSTANCE);
+ kryo.register(TypeDesc[].class);
+
+ // Types
+ kryo.register(KArrow.class);
+ kryo.register(KCon.class, new FiniteClassSerializer<KCon>(Kinds.STAR, Kinds.EFFECT));
+ kryo.register(KMetaVar.class);
+
+ kryo.register(TApply.class);
+ kryo.register(TCon.class, TConSerializer.INSTANCE);
+ kryo.register(TForAll.class);
+ kryo.register(TFun.class);
+ kryo.register(TMetaVar.class);
+ kryo.register(TPred.class, TPredSerializer.INSTANCE);
+ kryo.register(TPred[].class);
+ kryo.register(TUnion.class, TUnionSerializer.INSTANCE);
+ kryo.register(TVar.class);
+ kryo.register(TVar[].class);
+ kryo.register(Type[].class);
+
+ kryo.register(Polarity.class);
+
+ // SSA
+ kryo.register(ValRef.class, ValRefSerializer.INSTANCE);
+ kryo.register(ValRef[].class);
+ kryo.register(BoundVar.class);
+ kryo.register(BoundVar[].class);
+ kryo.register(ValSpecialization.class);
+ kryo.register(ContRef.class);
+ kryo.register(BranchRef.class);
+ kryo.register(BranchRef[].class);
+ kryo.register(ReturnCont.class);
+ kryo.register(If.class);
+ kryo.register(Jump.class);
+ kryo.register(Switch.class);
+ kryo.register(Throw.class);
+ kryo.register(LetApply.class);
+ kryo.register(LetFunctions.class);
+ kryo.register(LetApply.class);
+ kryo.register(SSABlock.class, SSABlockSerializer.INSTANCE);
+ kryo.register(SSAFunction.class, SSAFunctionSerializer.INSTANCE);
+
+ // Expression
+ kryo.register(EApply.class);
+ kryo.register(EApplyType.class);
+ kryo.register(EAsPattern.class);
+ kryo.register(EBinary.class);
+ kryo.register(EBinaryRightSide.class);
+ kryo.register(EBind.class);
+ kryo.register(EBlock.class);
+ kryo.register(EConstant.class);
+ kryo.register(EEnforce.class);
+ kryo.register(EError.class);
+ kryo.register(EExternalConstant.class);
+ kryo.register(EFieldAccess.class);
+ kryo.register(EGetConstraint.class);
+ kryo.register(EIf.class);
+ kryo.register(EIntegerLiteral.class);
+ kryo.register(ELambda.class);
+ kryo.register(ELambdaType.class);
+ kryo.register(ELet.class);
+ kryo.register(EListComprehension.class);
+ kryo.register(EListLiteral.class);
+ kryo.register(ELiteral.class);
+ kryo.register(EMatch.class);
+ kryo.register(EPlaceholder.class);
+ kryo.register(EPreLet.class);
+ kryo.register(EPreRuleset.class);
+ kryo.register(ERange.class);
+ kryo.register(ERealLiteral.class);
+ kryo.register(ERecord.class);
+ kryo.register(ERuleset.class);
+ kryo.register(ESelect.class);
+ kryo.register(ESimpleLambda.class);
+ kryo.register(ESimpleLet.class);
+ kryo.register(EStringLiteral.class);
+ kryo.register(ETransformation.class);
+ kryo.register(ETypeAnnotation.class);
+ kryo.register(EVar.class);
+ kryo.register(EVar.class);
+ kryo.register(EVar[].class);
+ kryo.register(EVariable.class);
+ kryo.register(EWhen.class);
+ kryo.register(GuardedExpression.class);
+ kryo.register(GuardedExpression[].class);
+ kryo.register(GuardedExpressionGroup.class);
+ kryo.register(Expression[].class);
+
+ kryo.register(Variable.class);
+ kryo.register(Variable[].class);
+
+ kryo.register(ExpressionAccessor.class);
+ kryo.register(IdAccessor.class);
+ kryo.register(StringAccessor.class);
+
+ kryo.register(BindStatement.class);
+ kryo.register(GuardStatement.class);
+ kryo.register(LetStatement.class);
+ kryo.register(RuleStatement.class);
+
+ kryo.register(ListAssignment.class);
+ kryo.register(ListGenerator.class);
+ kryo.register(ListGuard.class);
+ kryo.register(ListSeq.class);
+ kryo.register(ListThen.class);
+
+ kryo.register(Assignment.class);
+ kryo.register(Assignment[].class);
+ kryo.register(Case.class);
+ kryo.register(Case[].class);
+
+ // Queries
+ kryo.register(QAlternative.class);
+ kryo.register(QAtom.class);
+ kryo.register(QConjunction.class);
+ kryo.register(QDisjunction.class);
+ kryo.register(QExists.class);
+ kryo.register(QIf.class);
+ kryo.register(QMapping.class);
+ kryo.register(QNegation.class);
+ kryo.register(Query[].class);
+
+ //
+ kryo.register(Name.class, NameSerializer.INSTANCE);
+
+ kryo.register(ConcreteModule.class);
+ kryo.register(ImportDeclaration.class);
+ kryo.register(ImportDeclaration.ImportSpec.class);
+ kryo.register(TypeClassInstance.class);
+ kryo.register(TypeClassMethod.class);
+ kryo.register(MethodImplementation.class);
+ kryo.register(Constructor.class);
+ kryo.register(Constructor[].class);
+ kryo.register(TypeClass.class);
+ kryo.register(SCLValue.class);
+ kryo.register(SCLValue[].class);
+ kryo.register(Fundep.class);
+ kryo.register(Fundep[].class);
+ kryo.register(Precedence.class);
+ kryo.register(Associativity.class);
+ kryo.register(StandardTypeConstructor.class);
+ kryo.register(PrivateProperty.class);
+ kryo.register(InlineProperty.class);
+ kryo.register(DerivedProperty.class);
+ kryo.register(StandardMacroRule.class);
+ kryo.register(DeprecatedProperty.class);
+ kryo.register(CompilationError.class);
+ kryo.register(CompilationError[].class);
+
+ // Constants
+ kryo.register(BooleanConstant.class);
+ kryo.register(ByteConstant.class);
+ kryo.register(CharacterConstant.class);
+ kryo.register(ClassConstant.class);
+ kryo.register(DoubleConstant.class);
+ kryo.register(EmptyListConstructor.class);
+ kryo.register(EqualsFunction.class);
+ kryo.register(FloatConstant.class);
+ kryo.register(GetPrimitiveConstant.class);
+ kryo.register(HashCodeFunction.class);
+ kryo.register(IntegerConstant.class);
+ kryo.register(JavaComparisonOperation.class);
+ kryo.register(JavaComparisonToZeroOperation.class);
+ kryo.register(JavaConstructor.class);
+ kryo.register(JavaConversionOperation.class);
+ kryo.register(JavaMathOperation.class);
+ kryo.register(JavaMethod.class);
+ kryo.register(JavaStaticField.class);
+ kryo.register(JavaStaticMethod.class);
+ kryo.register(JavaTypeClassMethod.class);
+ kryo.register(JavaTypeClassSuper.class);
+ kryo.register(JavaTypeInstanceConstructor.class);
+ kryo.register(ListConstructor.class);
+ kryo.register(LocalBoxedArrayElementConstant.class);
+ kryo.register(LocalFieldConstant.class);
+ kryo.register(LocalVariableConstant.class);
+ kryo.register(LongConstant.class);
+ kryo.register(NoRepConstant.class);
+ kryo.register(SCLConstant.class);
+ kryo.register(SCLConstructor.class);
+ kryo.register(ShortConstant.class);
+ kryo.register(StringConstant.class);
+ kryo.register(StringInterpolation.class);
+ kryo.register(ThisConstant.class);
+ kryo.register(BindingConstant.class, new SingletonSerializer<BindingConstant>(BindingConstant.INSTANCE));
+ kryo.register(FailFunction.class, new SingletonSerializer<FailFunction>(FailFunction.INSTANCE));
+ kryo.register(JustConstant.class, new SingletonSerializer<JustConstant>(JustConstant.INSTANCE));
+ kryo.register(NothingConstant.class, new SingletonSerializer<NothingConstant>(NothingConstant.INSTANCE));
+ kryo.register(TypeOfConstant.class, new SingletonSerializer<TypeOfConstant>(TypeOfConstant.INSTANCE));
+ kryo.register(UnsafeCoerce.class, new SingletonSerializer<UnsafeCoerce>(UnsafeCoerce.INSTANCE));
+
+ kryo.register(CallJava.class);
+ kryo.register(ParameterStackItem.class);
+ kryo.register(ThreadLocalStackItem.class);
+ kryo.register(StackItem[].class);
+ kryo.register(MethodRef.ConstructorRef.class);
+ kryo.register(MethodRef.FieldRef.class);
+ kryo.register(MethodRef.ObjectMethodRef.class);
+ kryo.register(MethodRef.SetFieldRef.class);
+ kryo.register(MethodRef.StaticFieldRef.class);
+ kryo.register(MethodRef.StaticMethodRef.class);
+ kryo.register(MethodRef[].class);
+ kryo.register(ConvertToListFilter.class);
+ kryo.register(PopOutputFilter.class);
+ kryo.register(OutputFilter[].class);
+
+ kryo.register(Constant[].class);
+ }
+
+}