]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
(refs #6178) Module serialization code from scl repository 30/530/7 feature/scl-module-serialization
authorHannu Niemistö <hannu.niemisto@semantum.fi>
Tue, 16 May 2017 06:55:57 +0000 (09:55 +0300)
committerHannu Niemistö <hannu.niemisto@semantum.fi>
Fri, 6 Oct 2017 10:50:17 +0000 (13:50 +0300)
Registered also some new classes

Change-Id: I914c2b79ac08e6046507f2c02c33dfe534b72814

19 files changed:
bundles/org.simantics.scl.compiler/META-INF/MANIFEST.MF
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/ssa/SSAFunction.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/serialization/KryoRegistration.java [new file with mode: 0644]
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/serialization/serializers/FiniteClassSerializer.java [new file with mode: 0644]
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/serialization/serializers/NameSerializer.java [new file with mode: 0644]
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/serialization/serializers/SSABlockSerializer.java [new file with mode: 0644]
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/serialization/serializers/SSAFunctionSerializer.java [new file with mode: 0644]
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/serialization/serializers/SerializationUtils.java [new file with mode: 0644]
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/serialization/serializers/SingletonSerializer.java [new file with mode: 0644]
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/serialization/serializers/TConSerializer.java [new file with mode: 0644]
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/serialization/serializers/THashMapSerializer.java [new file with mode: 0644]
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/serialization/serializers/TPredSerializer.java [new file with mode: 0644]
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/serialization/serializers/TUnionSerializer.java [new file with mode: 0644]
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/serialization/serializers/TypeDescSerializer.java [new file with mode: 0644]
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/serialization/serializers/ValRefSerializer.java [new file with mode: 0644]
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/ConcreteModule.java
features/org.simantics.scl.feature/feature.xml
tests/org.simantics.scl.compiler.tests/META-INF/MANIFEST.MF
tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/serialization/TestSerialization.java [new file with mode: 0644]

index 1007cf675ad96610a625a8d228e9f09c174c9582..2bd500d0648afbd5827caec9e33a9fb5fc327e92 100644 (file)
@@ -10,7 +10,11 @@ Require-Bundle: gnu.trove3;bundle-version="3.0.0",
  org.objectweb.asm;bundle-version="[5.0.0,6.0.0)",
  org.objectweb.asm.commons;bundle-version="[5.0.0,6.0.0)",
  org.objectweb.asm.util;bundle-version="[5.0.0,6.0.0)",
- org.slf4j.api;bundle-version="1.7.2"
+ org.slf4j.api;bundle-version="1.7.2",
+ com.esotericsoftware.kryo;bundle-version="3.0.3",
+ org.objenesis;bundle-version="2.2.0",
+ com.esotericsoftware.minlog;bundle-version="1.3.0",
+ com.esotericsoftware.reflectasm;bundle-version="1.11.3"
 Export-Package: org.cojen.classfile,
  org.simantics.scl.compiler.commands,
  org.simantics.scl.compiler.common.datatypes,
@@ -55,6 +59,7 @@ Export-Package: org.cojen.classfile,
  org.simantics.scl.compiler.internal.parsing,
  org.simantics.scl.compiler.internal.parsing.exceptions,
  org.simantics.scl.compiler.internal.parsing.parser,
+ org.simantics.scl.compiler.internal.serialization,
  org.simantics.scl.compiler.markdown.html,
  org.simantics.scl.compiler.markdown.inlines,
  org.simantics.scl.compiler.markdown.internal,
index 209c92a64af4016687339f559e6639369093a7bb..948a876fe5b835f984c1c5594268aa061bbb16b3 100644 (file)
@@ -466,4 +466,11 @@ public final class SSAFunction extends SSAClosure {
         for(SSABlock block = firstBlock; block != null; block = block.next)
             block.cleanup();
     }
+
+    public int getBlockCount() {
+        int count = 0;
+        for(SSABlock block = firstBlock;block != null;block = block.next, ++count);
+        return count;
+    }
+
 }
diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/serialization/KryoRegistration.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/serialization/KryoRegistration.java
new file mode 100644 (file)
index 0000000..4f3f42d
--- /dev/null
@@ -0,0 +1,406 @@
+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);
+    }
+    
+}
diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/serialization/serializers/FiniteClassSerializer.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/serialization/serializers/FiniteClassSerializer.java
new file mode 100644 (file)
index 0000000..2f95690
--- /dev/null
@@ -0,0 +1,49 @@
+package org.simantics.scl.compiler.internal.serialization.serializers;
+
+import com.esotericsoftware.kryo.Kryo;
+import com.esotericsoftware.kryo.Serializer;
+import com.esotericsoftware.kryo.io.Input;
+import com.esotericsoftware.kryo.io.Output;
+
+import gnu.trove.impl.Constants;
+import gnu.trove.map.hash.TObjectIntHashMap;
+
+public class FiniteClassSerializer<T> extends Serializer<T> {
+
+    private final T[] items;
+    private final TObjectIntHashMap<T> map;
+    
+    public FiniteClassSerializer(T... items) {
+        this.items = items;
+        this.map = new TObjectIntHashMap<T>(items.length, Constants.DEFAULT_LOAD_FACTOR, -1);
+        for(int i=0;i<items.length;++i)
+            map.put(items[i], i);
+        setImmutable(true);
+    }
+
+    @Override
+    public void write(Kryo kryo, Output output, T object) {
+        int id = map.get(object);
+        if(id == -1)
+            throw new IllegalArgumentException("Object " + object + " is not one of the allowed.");
+        if(items.length < 0x100)
+            output.writeByte(id);
+        else if(items.length < 0x10000)
+            output.writeShort(id);
+        else
+            output.writeInt(id);
+    }
+
+    @Override
+    public T read(Kryo kryo, Input input, Class<T> type) {
+        int id;
+        if(items.length < 0x100)
+            id = input.readByteUnsigned();
+        else if(items.length < 0x10000)
+            id = input.readShortUnsigned();
+        else
+            id = input.readInt();
+        return items[id];
+    }
+
+}
diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/serialization/serializers/NameSerializer.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/serialization/serializers/NameSerializer.java
new file mode 100644 (file)
index 0000000..bf510f4
--- /dev/null
@@ -0,0 +1,25 @@
+package org.simantics.scl.compiler.internal.serialization.serializers;
+
+import org.simantics.scl.compiler.common.names.Name;
+
+import com.esotericsoftware.kryo.Kryo;
+import com.esotericsoftware.kryo.Serializer;
+import com.esotericsoftware.kryo.io.Input;
+import com.esotericsoftware.kryo.io.Output;
+
+public class NameSerializer extends Serializer<Name> {
+    public static final NameSerializer INSTANCE = new NameSerializer();
+
+    @Override
+    public void write(Kryo kryo, Output output, Name object) {
+        SerializationUtils.writeModuleName(kryo, output, object.module);
+        output.writeString(object.name);
+    }
+
+    @Override
+    public Name read(Kryo kryo, Input input, Class<Name> type) {
+        String module = SerializationUtils.readModuleName(kryo, input);
+        String name = input.readString();
+        return Name.create(module, name);
+    }
+}
diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/serialization/serializers/SSABlockSerializer.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/serialization/serializers/SSABlockSerializer.java
new file mode 100644 (file)
index 0000000..bc79fe6
--- /dev/null
@@ -0,0 +1,52 @@
+package org.simantics.scl.compiler.internal.serialization.serializers;
+
+import org.simantics.scl.compiler.internal.codegen.references.BoundVar;
+import org.simantics.scl.compiler.internal.codegen.ssa.SSABlock;
+import org.simantics.scl.compiler.internal.codegen.ssa.SSAExit;
+import org.simantics.scl.compiler.internal.codegen.ssa.SSAStatement;
+
+import com.esotericsoftware.kryo.Kryo;
+import com.esotericsoftware.kryo.Serializer;
+import com.esotericsoftware.kryo.io.Input;
+import com.esotericsoftware.kryo.io.Output;
+
+public class SSABlockSerializer extends Serializer<SSABlock> {
+    public static final SSABlockSerializer INSTANCE = new SSABlockSerializer();
+
+    @Override
+    public void write(Kryo kryo, Output output, SSABlock object) { 
+        {
+            BoundVar[] parameters = object.getParameters();
+            output.writeVarInt(parameters.length, true);
+            for(BoundVar parameter : parameters)
+                kryo.writeObject(output, parameter);
+        }
+        {
+            output.writeVarInt(object.getStatementCount(), true);
+            for(SSAStatement stat = object.getFirstStatement();stat != null;stat = stat.getNext())
+                kryo.writeClassAndObject(output, stat);
+        }
+        kryo.writeClassAndObject(output, object.getExit());
+    }
+
+    @Override
+    public SSABlock read(Kryo kryo, Input input, Class<SSABlock> type) {
+        BoundVar[] parameters;
+        {
+            int parametersLength = input.readVarInt(true);
+            parameters = new BoundVar[parametersLength];
+            for(int i=0;i<parametersLength;++i)
+                parameters[i] = kryo.readObject(input, BoundVar.class);
+        }
+        SSABlock result = new SSABlock(parameters);
+        kryo.reference(result);
+        {
+            int statementCount = input.readVarInt(true);
+            for(int i=0;i<statementCount;++i)
+                result.addStatement((SSAStatement)kryo.readClassAndObject(input));
+        }
+        result.setExit((SSAExit)kryo.readClassAndObject(input));
+        return result;
+    }
+
+}
diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/serialization/serializers/SSAFunctionSerializer.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/serialization/serializers/SSAFunctionSerializer.java
new file mode 100644 (file)
index 0000000..23c5f64
--- /dev/null
@@ -0,0 +1,44 @@
+package org.simantics.scl.compiler.internal.serialization.serializers;
+
+import org.simantics.scl.compiler.internal.codegen.continuations.ReturnCont;
+import org.simantics.scl.compiler.internal.codegen.references.Val;
+import org.simantics.scl.compiler.internal.codegen.ssa.SSABlock;
+import org.simantics.scl.compiler.internal.codegen.ssa.SSAFunction;
+import org.simantics.scl.compiler.types.TVar;
+import org.simantics.scl.compiler.types.Type;
+
+import com.esotericsoftware.kryo.Kryo;
+import com.esotericsoftware.kryo.Serializer;
+import com.esotericsoftware.kryo.io.Input;
+import com.esotericsoftware.kryo.io.Output;
+
+public class SSAFunctionSerializer extends Serializer<SSAFunction> {
+    public static final SSAFunctionSerializer INSTANCE = new SSAFunctionSerializer();
+
+    @Override
+    public void write(Kryo kryo, Output output, SSAFunction object) { 
+        SerializationUtils.writeTVars(kryo, output, object.getTypeParameters());
+        kryo.writeClassAndObject(output, object.getEffect());
+        kryo.writeClassAndObject(output, object.getTarget());
+        kryo.writeObject(output, object.getReturnCont());
+        output.writeVarInt(object.getBlockCount(), true);
+        for(SSABlock block = object.getFirstBlock();block != null;block = block.getNext())
+            kryo.writeObject(output, block);
+    }
+
+    @Override
+    public SSAFunction read(Kryo kryo, Input input, Class<SSAFunction> type) {
+        TVar[] typeParameters = SerializationUtils.readTVars(kryo, input);
+        Type effect = (Type)kryo.readClassAndObject(input);
+        ReturnCont returnCont = kryo.readObject(input, ReturnCont.class);
+        SSAFunction result = new SSAFunction(typeParameters, effect, returnCont);
+        kryo.reference(result);
+        Val target = (Val)kryo.readClassAndObject(input);
+        result.setTarget(target);
+        int blockCount = input.readVarInt(true);
+        for(int i=0;i<blockCount;++i)
+            result.addBlock(kryo.readObject(input, SSABlock.class));
+        return result;
+    }
+
+}
diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/serialization/serializers/SerializationUtils.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/serialization/serializers/SerializationUtils.java
new file mode 100644 (file)
index 0000000..d387215
--- /dev/null
@@ -0,0 +1,79 @@
+package org.simantics.scl.compiler.internal.serialization.serializers;
+
+import java.util.ArrayList;
+
+import org.simantics.scl.compiler.types.TVar;
+import org.simantics.scl.compiler.types.Type;
+
+import com.esotericsoftware.kryo.Kryo;
+import com.esotericsoftware.kryo.io.Input;
+import com.esotericsoftware.kryo.io.Output;
+
+import gnu.trove.map.hash.TObjectIntHashMap;
+
+public class SerializationUtils {
+
+    private static final String MODULE_NAME_CACHE = "moduleNameCache";
+    
+    @SuppressWarnings("unchecked")
+    public static void writeModuleName(Kryo kryo, Output output, String moduleName) {
+        Object cache_ = kryo.getGraphContext().get(MODULE_NAME_CACHE);
+        if(cache_ == null) {
+            cache_ = new TObjectIntHashMap<String>();
+            kryo.getGraphContext().put(MODULE_NAME_CACHE, cache_);
+        }
+        TObjectIntHashMap<String> cache = (TObjectIntHashMap<String>)cache_;
+        int id = cache.get(moduleName);
+        output.writeVarInt(id, true);
+        if(id == 0) {
+            output.writeString(moduleName);
+            cache.put(moduleName, cache.size()+1);
+        }
+    }
+    
+    @SuppressWarnings("unchecked")
+    public static String readModuleName(Kryo kryo, Input input) {
+        Object cache_ = kryo.getGraphContext().get(MODULE_NAME_CACHE);
+        if(cache_ == null) {
+            cache_ = new ArrayList<String>();
+            kryo.getGraphContext().put(MODULE_NAME_CACHE, cache_);
+        }
+        ArrayList<String> cache = (ArrayList<String>)cache_;
+        int id = input.readVarInt(true);
+        if(id == 0) {
+            String moduleName = input.readString();
+            cache.add(moduleName);
+            return moduleName;
+        }
+        else
+            return cache.get(id-1);
+    }
+    
+    public static void writeTypes(Kryo kryo, Output output, Type[] types) {
+        output.writeVarInt(types.length, true);
+        for(Type type : types)
+            kryo.writeClassAndObject(output, type);
+    }
+    
+    public static Type[] readTypes(Kryo kryo, Input input) {
+        int length = input.readVarInt(true);
+        Type[] result = new Type[length];
+        for(int i=0;i<length;++i)
+            result[i] = (Type)kryo.readClassAndObject(input);
+        return result;
+    }
+    
+    public static void writeTVars(Kryo kryo, Output output, TVar[] types) {
+        output.writeVarInt(types.length, true);
+        for(TVar type : types)
+            kryo.writeObject(output, type);
+    }
+    
+    public static TVar[] readTVars(Kryo kryo, Input input) {
+        int length = input.readVarInt(true);
+        TVar[] result = new TVar[length];
+        for(int i=0;i<length;++i)
+            result[i] = (TVar)kryo.readObject(input, TVar.class);
+        return result;
+    }
+}
diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/serialization/serializers/SingletonSerializer.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/serialization/serializers/SingletonSerializer.java
new file mode 100644 (file)
index 0000000..9027763
--- /dev/null
@@ -0,0 +1,26 @@
+package org.simantics.scl.compiler.internal.serialization.serializers;
+
+import com.esotericsoftware.kryo.Kryo;
+import com.esotericsoftware.kryo.Serializer;
+import com.esotericsoftware.kryo.io.Input;
+import com.esotericsoftware.kryo.io.Output;
+
+public class SingletonSerializer<T> extends Serializer<T> {
+
+    private final T singleton;
+    
+    public SingletonSerializer(T singleton) {
+        this.singleton = singleton;
+        setImmutable(true);
+    }
+
+    @Override
+    public void write(Kryo kryo, Output output, T object) {
+    }
+
+    @Override
+    public T read(Kryo kryo, Input input, Class<T> type) {
+        return singleton;
+    }
+
+}
diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/serialization/serializers/TConSerializer.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/serialization/serializers/TConSerializer.java
new file mode 100644 (file)
index 0000000..a0177b4
--- /dev/null
@@ -0,0 +1,26 @@
+package org.simantics.scl.compiler.internal.serialization.serializers;
+
+import org.simantics.scl.compiler.types.TCon;
+import org.simantics.scl.compiler.types.Types;
+
+import com.esotericsoftware.kryo.Kryo;
+import com.esotericsoftware.kryo.Serializer;
+import com.esotericsoftware.kryo.io.Input;
+import com.esotericsoftware.kryo.io.Output;
+
+public class TConSerializer extends Serializer<TCon> {
+    public static final TConSerializer INSTANCE = new TConSerializer();
+
+    @Override
+    public void write(Kryo kryo, Output output, TCon object) {
+        SerializationUtils.writeModuleName(kryo, output, object.module);
+        output.writeString(object.name);
+    }
+
+    @Override
+    public TCon read(Kryo kryo, Input input, Class<TCon> type) {
+        String module = SerializationUtils.readModuleName(kryo, input);
+        String name = input.readString();
+        return Types.con(module, name);
+    }
+}
diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/serialization/serializers/THashMapSerializer.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/serialization/serializers/THashMapSerializer.java
new file mode 100644 (file)
index 0000000..4fbda44
--- /dev/null
@@ -0,0 +1,43 @@
+package org.simantics.scl.compiler.internal.serialization.serializers;
+
+import com.esotericsoftware.kryo.Kryo;
+import com.esotericsoftware.kryo.Serializer;
+import com.esotericsoftware.kryo.io.Input;
+import com.esotericsoftware.kryo.io.Output;
+
+import gnu.trove.map.hash.THashMap;
+import gnu.trove.procedure.TObjectObjectProcedure;
+
+
+@SuppressWarnings("rawtypes")
+public class THashMapSerializer extends Serializer<THashMap> {
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public void write(final Kryo kryo, final Output output, THashMap object) {
+        output.writeVarInt(object.size(), true);
+        object.forEachEntry(new TObjectObjectProcedure<Object, Object>() {
+            @Override
+            public boolean execute(Object key, Object value) {
+                kryo.writeClassAndObject(output, key);
+                kryo.writeClassAndObject(output, value);
+                return true;
+            }
+        });
+    }
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public THashMap read(Kryo kryo, Input input,
+            Class<THashMap> type) {
+        int size = input.readVarInt(true);
+        THashMap result = new THashMap(size); 
+        while((size--) > 0) {
+            Object key = kryo.readClassAndObject(input);
+            Object value = kryo.readClassAndObject(input);
+            result.put(key, value);
+        }
+        return result;
+    }
+
+}
diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/serialization/serializers/TPredSerializer.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/serialization/serializers/TPredSerializer.java
new file mode 100644 (file)
index 0000000..f0679b2
--- /dev/null
@@ -0,0 +1,28 @@
+package org.simantics.scl.compiler.internal.serialization.serializers;
+
+import org.simantics.scl.compiler.types.TCon;
+import org.simantics.scl.compiler.types.TPred;
+import org.simantics.scl.compiler.types.Type;
+import org.simantics.scl.compiler.types.Types;
+
+import com.esotericsoftware.kryo.Kryo;
+import com.esotericsoftware.kryo.Serializer;
+import com.esotericsoftware.kryo.io.Input;
+import com.esotericsoftware.kryo.io.Output;
+
+public class TPredSerializer extends Serializer<TPred> {
+    public static final TPredSerializer INSTANCE = new TPredSerializer();
+
+    @Override
+    public void write(Kryo kryo, Output output, TPred object) {
+        kryo.writeObject(output, object.typeClass);
+        SerializationUtils.writeTypes(kryo, output, object.parameters);
+    }
+
+    @Override
+    public TPred read(Kryo kryo, Input input, Class<TPred> type) {
+        TCon typeClass = kryo.readObject(input, TCon.class);
+        Type[] parameters = SerializationUtils.readTypes(kryo, input);
+        return Types.pred(typeClass, parameters);
+    }
+}
diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/serialization/serializers/TUnionSerializer.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/serialization/serializers/TUnionSerializer.java
new file mode 100644 (file)
index 0000000..484c6e1
--- /dev/null
@@ -0,0 +1,23 @@
+package org.simantics.scl.compiler.internal.serialization.serializers;
+
+import org.simantics.scl.compiler.types.TUnion;
+import org.simantics.scl.compiler.types.Types;
+
+import com.esotericsoftware.kryo.Kryo;
+import com.esotericsoftware.kryo.Serializer;
+import com.esotericsoftware.kryo.io.Input;
+import com.esotericsoftware.kryo.io.Output;
+
+public class TUnionSerializer extends Serializer<TUnion> {
+    public static final TUnionSerializer INSTANCE = new TUnionSerializer();
+
+    @Override
+    public void write(Kryo kryo, Output output, TUnion object) {
+        SerializationUtils.writeTypes(kryo, output, object.effects);
+    }
+
+    @Override
+    public TUnion read(Kryo kryo, Input input, Class<TUnion> type) {
+        return (TUnion)Types.union(SerializationUtils.readTypes(kryo, input));
+    }
+}
diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/serialization/serializers/TypeDescSerializer.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/serialization/serializers/TypeDescSerializer.java
new file mode 100644 (file)
index 0000000..e7c4b36
--- /dev/null
@@ -0,0 +1,23 @@
+package org.simantics.scl.compiler.internal.serialization.serializers;
+
+import org.cojen.classfile.TypeDesc;
+
+import com.esotericsoftware.kryo.Kryo;
+import com.esotericsoftware.kryo.Serializer;
+import com.esotericsoftware.kryo.io.Input;
+import com.esotericsoftware.kryo.io.Output;
+
+public class TypeDescSerializer extends Serializer<TypeDesc> {
+    public static final TypeDescSerializer INSTANCE = new TypeDescSerializer();
+
+    @Override
+    public void write(Kryo kryo, Output output, TypeDesc object) {
+        output.writeString(object.getDescriptor());
+    }
+
+    @Override
+    public TypeDesc read(Kryo kryo, Input input, Class<TypeDesc> type) {
+        return TypeDesc.forDescriptor(input.readString());
+    }
+    
+}
diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/serialization/serializers/ValRefSerializer.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/serialization/serializers/ValRefSerializer.java
new file mode 100644 (file)
index 0000000..e81f069
--- /dev/null
@@ -0,0 +1,28 @@
+package org.simantics.scl.compiler.internal.serialization.serializers;
+
+import org.simantics.scl.compiler.internal.codegen.references.Val;
+import org.simantics.scl.compiler.internal.codegen.references.ValRef;
+
+import com.esotericsoftware.kryo.Kryo;
+import com.esotericsoftware.kryo.Serializer;
+import com.esotericsoftware.kryo.io.Input;
+import com.esotericsoftware.kryo.io.Output;
+
+public class ValRefSerializer extends Serializer<ValRef> {
+    public static final ValRefSerializer INSTANCE = new ValRefSerializer();
+
+    @Override
+    public void write(Kryo kryo, Output output, ValRef object) {
+        SerializationUtils.writeTypes(kryo, output, object.getTypeParameters()); 
+        kryo.writeClassAndObject(output, object.getBinding());
+    }
+
+    @Override
+    public ValRef read(Kryo kryo, Input input, Class<ValRef> type) {
+        ValRef result = new ValRef(SerializationUtils.readTypes(kryo, input));
+        kryo.reference(result);
+        result.setBinding((Val)kryo.readClassAndObject(input));
+        return result;
+    }
+
+}
index 73311e99ab9ab4a17f087d1f215b15de89286929..b973edd5a91a3bd2c8d680048dc98476dec87e19 100644 (file)
@@ -49,7 +49,7 @@ public class ConcreteModule implements Module {
     CompilationError[] warnings = CompilationError.EMPTY_ARRAY;
     
     Map<String, byte[]> classes = Collections.emptyMap();
-    ClassLoader parentClassLoader;
+    transient ClassLoader parentClassLoader;
     ModuleInitializer moduleInitializer;
 
     protected Documentation documentation;
index c0ee33b4ef2f2ad106edabb6d6a0152686bfe504..8a58a540b39a6584e2309879bb1c30c1e33762c5 100644 (file)
@@ -241,4 +241,32 @@ This Agreement is governed by the laws of the State of New York and the intellec
          version="0.0.0"
          unpack="false"/>
 
+   <plugin
+         id="com.esotericsoftware.reflectasm"
+         download-size="0"
+         install-size="0"
+         version="0.0.0"
+         unpack="false"/>
+
+   <plugin
+         id="com.esotericsoftware.minlog"
+         download-size="0"
+         install-size="0"
+         version="0.0.0"
+         unpack="false"/>
+
+   <plugin
+         id="org.objenesis"
+         download-size="0"
+         install-size="0"
+         version="0.0.0"
+         unpack="false"/>
+
+   <plugin
+         id="com.esotericsoftware.kryo"
+         download-size="0"
+         install-size="0"
+         version="0.0.0"
+         unpack="false"/>
+
 </feature>
index 710abbf56c92c3e98a40ff18a4973e7af8ec9cd6..3a791c7d98c324065fca4de125a31f40a1ade080 100644 (file)
@@ -12,4 +12,8 @@ Require-Bundle: org.junit;bundle-version="4.12.0",
  ch.qos.logback.classic;bundle-version="1.1.7",
  ch.qos.logback.core;bundle-version="1.1.7",
  org.apache.commons.collections;bundle-version="3.2.2",
- org.eclipse.equinox.ds;bundle-version="1.4.300"
+ org.eclipse.equinox.ds;bundle-version="1.4.300",
+ com.esotericsoftware.kryo,
+ com.esotericsoftware.minlog;bundle-version="1.3.0",
+ com.esotericsoftware.reflectasm;bundle-version="1.11.3",
+ org.objenesis;bundle-version="2.2.0"
diff --git a/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/serialization/TestSerialization.java b/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/serialization/TestSerialization.java
new file mode 100644 (file)
index 0000000..751dbf4
--- /dev/null
@@ -0,0 +1,61 @@
+package org.simantics.scl.compiler.tests.serialization;
+
+import java.io.IOException;
+
+import org.junit.Ignore;
+import org.junit.Test;
+import org.simantics.scl.compiler.internal.serialization.KryoRegistration;
+import org.simantics.scl.compiler.module.ConcreteModule;
+import org.simantics.scl.compiler.module.repository.ImportFailureException;
+import org.simantics.scl.compiler.tests.TestBase;
+import org.simantics.scl.compiler.top.SCLExpressionCompilationException;
+
+import com.esotericsoftware.kryo.Kryo;
+import com.esotericsoftware.kryo.io.Output;
+
+import gnu.trove.map.hash.THashMap;
+
+public class TestSerialization {
+
+    @Ignore
+    @Test
+    public void typeSerialization() throws IOException, ImportFailureException, SCLExpressionCompilationException {
+        final Kryo kryo = new Kryo();
+        KryoRegistration.registerClasses(kryo);
+        
+        Output output = new Output(1024, -1);
+        ConcreteModule module = (ConcreteModule)TestBase.PRELUDE_MODULE_REPOSITORY.getModule("Prelude").getResult();
+        module.setClasses(new THashMap<String,byte[]>());
+        kryo.writeClassAndObject(output, module);
+        //kryo.writeClassAndObject(output, Environments.getType(env, "forall a. Integer -> <Proc> [Maybe a]"));
+        byte[] bytes = output.toBytes();
+        /*Class[] keys = kryo.classCounter.keys(new Class[kryo.classCounter.size()]);
+        Arrays.sort(keys, new Comparator<Class>() {
+            @Override
+            public int compare(Class o1, Class o2) {
+                int c1 = kryo.classCounter.get(o1);
+                int c2 = kryo.classCounter.get(o2);
+                return Integer.compare(c2, c1);
+            }
+        });*/
+        //for(Class key : keys)
+        //    System.out.println((key == null ? "null" : key.getSimpleName()) + " " + kryo.classCounter.get(key));
+        
+        System.out.println(bytes.length);
+        /*for(byte b : bytes) {
+            int i = (int)b;
+            if(i < 0)
+                i += 256;
+            System.out.print(i);
+            if(i >= 128)
+                i -= 128;
+            if(i >= 20 && i < 128)
+                System.out.print(" (" + (char)i + ")");
+            System.out.println();
+        }*/
+        
+        /*Input input = new Input(bytes);
+        Type type = (Type)kryo.readClassAndObject(input);
+        System.out.println(type);*/
+    }
+}