package org.simantics.scl.compiler.elaboration.java; import org.cojen.classfile.TypeDesc; import org.simantics.databoard.binding.mutable.Variant; import org.simantics.scl.compiler.common.datatypes.Constructor; import org.simantics.scl.compiler.common.names.Name; import org.simantics.scl.compiler.common.names.Names; 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.Constant; import org.simantics.scl.compiler.constants.JavaStaticField; import org.simantics.scl.compiler.constants.JavaStaticMethod; 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.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.TypeOfProxyConstant; import org.simantics.scl.compiler.constants.singletons.TypeProxyConstant; import org.simantics.scl.compiler.elaboration.fundeps.Fundep; import org.simantics.scl.compiler.elaboration.modules.Documentation; import org.simantics.scl.compiler.elaboration.modules.SCLValue; import org.simantics.scl.compiler.elaboration.modules.TypeClass; import org.simantics.scl.compiler.errors.Locations; import org.simantics.scl.compiler.internal.codegen.effects.EffectConstructor; 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.SSAFunction; import org.simantics.scl.compiler.internal.codegen.ssa.exits.Jump; import org.simantics.scl.compiler.internal.codegen.ssa.statements.LetApply; import org.simantics.scl.compiler.internal.codegen.types.MaybeType; import org.simantics.scl.compiler.internal.codegen.types.StandardTypeConstructor; import org.simantics.scl.compiler.internal.codegen.types.VectorType; import org.simantics.scl.compiler.internal.codegen.utils.Constants; import org.simantics.scl.compiler.module.ConcreteModule; import org.simantics.scl.compiler.types.TApply; import org.simantics.scl.compiler.types.TCon; import org.simantics.scl.compiler.types.TFun; 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.Types; import org.simantics.scl.compiler.types.kinds.Kind; import org.simantics.scl.compiler.types.kinds.Kinds; import org.simantics.scl.runtime.profiling.BranchPoint; public class Builtins extends ConcreteModule { public static SCLValue[] TUPLE_CONSTRUCTORS = new SCLValue[Constants.MAX_TUPLE_LENGTH+1]; public static SCLValue[] LIST_CONSTRUCTORS = new SCLValue[Constants.MAX_LIST_LITERAL_LENGTH+1]; public static final Builtins INSTANCE = new Builtins(); public static SCLValue Nothing; public static SCLValue Just; public static SCLValue EQUALS; private Builtins() { super(Types.BUILTIN); TVar A = Types.var(Kinds.STAR); StandardTypeConstructor Boolean = new StandardTypeConstructor(Types.BOOLEAN, Kinds.STAR, TypeDesc.BOOLEAN); Boolean.documentation = "Data type representing truth values `True` and `False`."; addTypeDescriptor("Boolean", Boolean); addTypeDescriptor("Byte", new StandardTypeConstructor(Types.BYTE, Kinds.STAR, TypeDesc.BYTE, "8-bit signed integer")); addTypeDescriptor("Character", new StandardTypeConstructor(Types.CHARACTER, Kinds.STAR, TypeDesc.CHAR, "16-bit Unicode character.")); addTypeDescriptor("Short", new StandardTypeConstructor(Types.SHORT, Kinds.STAR, TypeDesc.SHORT, "16-bit signed integer")); addTypeDescriptor("Integer", new StandardTypeConstructor(Types.INTEGER, Kinds.STAR, TypeDesc.INT, "32-bit signed integer")); addTypeDescriptor("Long", new StandardTypeConstructor(Types.LONG, Kinds.STAR, TypeDesc.LONG, "64-bit signed integer")); addTypeDescriptor("Float", new StandardTypeConstructor(Types.FLOAT, Kinds.STAR, TypeDesc.FLOAT, "32-bit floating point number")); addTypeDescriptor("Double", new StandardTypeConstructor(Types.DOUBLE, Kinds.STAR, TypeDesc.DOUBLE, "64-bit floating point number")); addTypeDescriptor("String", new StandardTypeConstructor(Types.STRING, Kinds.STAR, TypeDesc.STRING, "Unicode string")); addTypeDescriptor("BooleanArray", new StandardTypeConstructor(Types.BOOLEAN_ARRAY, Kinds.STAR, TypeDesc.forClass(boolean[].class))); addTypeDescriptor("ByteArray", new StandardTypeConstructor(Types.BYTE_ARRAY, Kinds.STAR, TypeDesc.forClass(byte[].class))); addTypeDescriptor("CharacterArray", new StandardTypeConstructor(Types.CHARACTER_ARRAY, Kinds.STAR, TypeDesc.forClass(char[].class))); addTypeDescriptor("ShortArray", new StandardTypeConstructor(Types.SHORT_ARRAY, Kinds.STAR, TypeDesc.forClass(short[].class))); addTypeDescriptor("IntegerArray", new StandardTypeConstructor(Types.INTEGER_ARRAY, Kinds.STAR, TypeDesc.forClass(int[].class))); addTypeDescriptor("LongArray", new StandardTypeConstructor(Types.LONG_ARRAY, Kinds.STAR, TypeDesc.forClass(long[].class))); addTypeDescriptor("FloatArray", new StandardTypeConstructor(Types.FLOAT_ARRAY, Kinds.STAR, TypeDesc.forClass(float[].class))); addTypeDescriptor("DoubleArray", new StandardTypeConstructor(Types.DOUBLE_ARRAY, Kinds.STAR, TypeDesc.forClass(double[].class))); addTypeDescriptor("Array", new StandardTypeConstructor(Types.con(Types.BUILTIN, "Array"), Kinds.STAR_TO_STAR, TypeDesc.forClass(Object[].class))); addTypeDescriptor("Maybe", MaybeType.INSTANCE); addTypeDescriptor("Variant", new StandardTypeConstructor(Types.VARIANT, Kinds.STAR, TypeDesc.forClass(Variant.class))); addEffectConstructor("Proc", new EffectConstructor(Types.PROC)); //addTypeDescriptor("->", new StandardTypeConstructor(Kinds.STAR_TO_STAR_TO_STAR, Constants.FUNCTION)); addTypeDescriptor("[]", new StandardTypeConstructor(Types.LIST, Kinds.STAR_TO_STAR, Constants.LIST)); addTypeDescriptor("@", new StandardTypeConstructor(Types.PUNIT, Kinds.STAR, Constants.TUPLE[0])); addTypeDescriptor("TypeProxy", new StandardTypeConstructor(Types.TYPE_PROXY, Kinds.STAR_TO_STAR, Constants.TUPLE[0])); // *** Tuples *** Kind tupleKind = Kinds.STAR; for(int arity=0;arity<=Constants.MAX_TUPLE_LENGTH;++arity) { if(arity != 1) { TVar[] vars = new TVar[arity]; for(int i=0;i a -> Type addValue("typeOf", TypeOfConstant.INSTANCE) .documentation = "Returns the type of the value given as a parameter."; addValue("typeOfProxy", TypeOfProxyConstant.INSTANCE) .documentation = "Returns the type of the type proxy given as a parameter."; addValue("TypeProxy", TypeProxyConstant.INSTANCE); } // *** Serializable *** { /* class Serializable a */ TypeClass SerializableC = new TypeClass(Locations.NO_LOCATION, TPred.EMPTY_ARRAY, Types.SERIALIZABLE, "org/simantics/databoard/binding/Binding", new TVar[] {A}, Fundep.EMPTY_ARRAY); SerializableC.documentation = "A class of types having a `Binding`"; addTypeClass("Serializable", SerializableC); /* data TypeRep = TCon String * | TApply TypeRep TypeRep */ StandardTypeConstructor BindingC = new StandardTypeConstructor(Types.BINDING, Kinds.STAR_TO_STAR, TypeDesc.forClass("org/simantics/databoard/binding/Binding")); BindingC.setType(Types.BINDING, A); BindingC.documentation = "`Binding` represents a data type in the form supported by Databoard library. " + "It is used to serialize and deserialize values."; addTypeDescriptor("Binding", BindingC); // typeOf :: Typeable a => a -> TypeReps addValue("binding", BindingConstant.INSTANCE) .documentation = "Gives a binding for the required type."; } // Relations { addRelation("Eq", EqRelation.INSTANCE); addRelation("Optional", OptionalRelation.INSTANCE); addRelation("Execute", new ExecuteRelation(0)); addRelation("Execute10", new ExecuteRelation(10)); } { EQUALS = new SCLValue(Names.Builtin_equals, EqualsFunction.INSTANCE); EQUALS.setPrecedence(new Precedence(4, Associativity.NONASSOC)); addValue(EQUALS); addValue("hashCode", HashCodeFunction.INSTANCE); } // Coverage { StandardTypeConstructor branchPoint = new StandardTypeConstructor(Types.BRANCH_POINT, Kinds.STAR, TypeDesc.forClass(BranchPoint.class)); addTypeDescriptor("BranchPoint", branchPoint); addValue("visitBranchPoint", VisitBranchPoint.INSTANCE); } setParentClassLoader(getClass().getClassLoader()); } @Override public Documentation getDocumentation() { return documentation; } }