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.SCLConstant;
import org.simantics.scl.compiler.constants.SCLConstructor;
import org.simantics.scl.compiler.constants.singletons.BindingConstant;
+import org.simantics.scl.compiler.constants.singletons.ClassConstant;
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.ThrowFunction;
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.PrivateProperty;
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.types.Types;
import org.simantics.scl.compiler.types.kinds.Kind;
import org.simantics.scl.compiler.types.kinds.Kinds;
+import org.simantics.scl.runtime.chr.CHRContext;
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 SCLValue[] TUPLE_CONSTRUCTORS = new SCLValue[Constants.MAX_TUPLE_LENGTH+1];
+ public static final SCLValue[] LIST_CONSTRUCTORS = new SCLValue[Constants.MAX_LIST_LITERAL_LENGTH+1];
- public static final Builtins INSTANCE = new Builtins();
+ public static Builtins INSTANCE = new Builtins();
public static SCLValue Nothing;
public static SCLValue Just;
+ public static SCLValue EQUALS;
+
private Builtins() {
super(Types.BUILTIN);
StandardTypeConstructor Boolean = new StandardTypeConstructor(Types.BOOLEAN, Kinds.STAR, TypeDesc.BOOLEAN);
Boolean.documentation = "Data type representing truth values `True` and `False`.";
- addTypeConstructor("Boolean", Boolean);
- addTypeConstructor("Byte", new StandardTypeConstructor(Types.BYTE, Kinds.STAR, TypeDesc.BYTE,
+ addTypeDescriptor("Boolean", Boolean);
+ addTypeDescriptor("Byte", new StandardTypeConstructor(Types.BYTE, Kinds.STAR, TypeDesc.BYTE,
"8-bit signed integer"));
- addTypeConstructor("Character", new StandardTypeConstructor(Types.CHARACTER, Kinds.STAR, TypeDesc.CHAR,
+ addTypeDescriptor("Character", new StandardTypeConstructor(Types.CHARACTER, Kinds.STAR, TypeDesc.CHAR,
"16-bit Unicode character."));
- addTypeConstructor("Short", new StandardTypeConstructor(Types.SHORT, Kinds.STAR, TypeDesc.SHORT,
+ addTypeDescriptor("Short", new StandardTypeConstructor(Types.SHORT, Kinds.STAR, TypeDesc.SHORT,
"16-bit signed integer"));
- addTypeConstructor("Integer", new StandardTypeConstructor(Types.INTEGER, Kinds.STAR, TypeDesc.INT,
+ addTypeDescriptor("Integer", new StandardTypeConstructor(Types.INTEGER, Kinds.STAR, TypeDesc.INT,
"32-bit signed integer"));
- addTypeConstructor("Long", new StandardTypeConstructor(Types.LONG, Kinds.STAR, TypeDesc.LONG,
+ addTypeDescriptor("Long", new StandardTypeConstructor(Types.LONG, Kinds.STAR, TypeDesc.LONG,
"64-bit signed integer"));
- addTypeConstructor("Float", new StandardTypeConstructor(Types.FLOAT, Kinds.STAR, TypeDesc.FLOAT,
+ addTypeDescriptor("Float", new StandardTypeConstructor(Types.FLOAT, Kinds.STAR, TypeDesc.FLOAT,
"32-bit floating point number"));
- addTypeConstructor("Double", new StandardTypeConstructor(Types.DOUBLE, Kinds.STAR, TypeDesc.DOUBLE,
+ addTypeDescriptor("Double", new StandardTypeConstructor(Types.DOUBLE, Kinds.STAR, TypeDesc.DOUBLE,
"64-bit floating point number"));
- addTypeConstructor("String", new StandardTypeConstructor(Types.STRING, Kinds.STAR, TypeDesc.STRING,
+ addTypeDescriptor("String", new StandardTypeConstructor(Types.STRING, Kinds.STAR, TypeDesc.STRING,
"Unicode string"));
- addTypeConstructor("BooleanArray", new StandardTypeConstructor(Types.BOOLEAN_ARRAY, Kinds.STAR, TypeDesc.forClass(boolean[].class)));
- addTypeConstructor("ByteArray", new StandardTypeConstructor(Types.BYTE_ARRAY, Kinds.STAR, TypeDesc.forClass(byte[].class)));
- addTypeConstructor("CharacterArray", new StandardTypeConstructor(Types.CHARACTER_ARRAY, Kinds.STAR, TypeDesc.forClass(char[].class)));
- addTypeConstructor("ShortArray", new StandardTypeConstructor(Types.SHORT_ARRAY, Kinds.STAR, TypeDesc.forClass(short[].class)));
- addTypeConstructor("IntegerArray", new StandardTypeConstructor(Types.INTEGER_ARRAY, Kinds.STAR, TypeDesc.forClass(int[].class)));
- addTypeConstructor("LongArray", new StandardTypeConstructor(Types.LONG_ARRAY, Kinds.STAR, TypeDesc.forClass(long[].class)));
- addTypeConstructor("FloatArray", new StandardTypeConstructor(Types.FLOAT_ARRAY, Kinds.STAR, TypeDesc.forClass(float[].class)));
- addTypeConstructor("DoubleArray", new StandardTypeConstructor(Types.DOUBLE_ARRAY, Kinds.STAR, TypeDesc.forClass(double[].class)));
+ 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)));
- addTypeConstructor("Array", new StandardTypeConstructor(Types.con(Types.BUILTIN, "Array"), Kinds.STAR_TO_STAR, TypeDesc.forClass(Object[].class)));
+ addTypeDescriptor("Array", new StandardTypeConstructor(Types.con(Types.BUILTIN, "Array"), Kinds.STAR_TO_STAR, TypeDesc.forClass(Object[].class)));
- addTypeConstructor("Maybe", MaybeType.INSTANCE);
+ addTypeDescriptor("Maybe", MaybeType.INSTANCE);
- addTypeConstructor("Variant", new StandardTypeConstructor(Types.VARIANT, Kinds.STAR, TypeDesc.forClass(Variant.class)));
+ addTypeDescriptor("Variant", new StandardTypeConstructor(Types.VARIANT, Kinds.STAR, TypeDesc.forClass(Variant.class)));
addEffectConstructor("Proc", new EffectConstructor(Types.PROC));
+ addEffectConstructor("Exception", new EffectConstructor(Types.EXCEPTION));
- //addTypeConstructor("->", new StandardTypeConstructor(Kinds.STAR_TO_STAR_TO_STAR, Constants.FUNCTION));
- addTypeConstructor("[]", new StandardTypeConstructor(Types.LIST, Kinds.STAR_TO_STAR, Constants.LIST));
- addTypeConstructor("@", new StandardTypeConstructor(Types.PUNIT, Kinds.STAR, Constants.TUPLE[0]));
- addTypeConstructor("TypeProxy", new StandardTypeConstructor(Types.TYPE_PROXY, Kinds.STAR_TO_STAR, Constants.TUPLE[0]));
+ //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 ***
TCon constructor = Types.tupleConstructor(arity);
StandardTypeConstructor typeConstructor =
new StandardTypeConstructor(constructor, tupleKind, Constants.TUPLE[arity]);
- addTypeConstructor(constructor.name, typeConstructor);
+ addTypeDescriptor(constructor.name, typeConstructor);
Type returnType = Types.apply(constructor, vars);
typeConstructor.setType(constructor, vars);
Constant cons;
// *** Lists ***
for(int arity=0;arity<=Constants.MAX_LIST_LITERAL_LENGTH;++arity) {
- LIST_CONSTRUCTORS[arity] = addValue("_list_literal_" + arity + "_",
+ SCLValue value = addValue("_list_literal_" + arity + "_",
arity == 0 ? new EmptyListConstructor() :
new ListConstructor(arity)
);
+ value.addProperty(PrivateProperty.INSTANCE);
+ LIST_CONSTRUCTORS[arity] = value;
}
// *** Boolean ***
new Constructor(Locations.NO_LOCATION, MaybeType.INSTANCE, Just.getName(), new Type[] {MaybeType.INSTANCE.parameters[0]}, null)
);
+ // *** Dynamic ***
+
+ addValue("Dynamic", DynamicConstructor.INSTANCE);
+
// *** Vector ***
TypeClass VecCompC = new TypeClass(Locations.NO_LOCATION,
Fundep.EMPTY_ARRAY);
addTypeClass("VecComp", VecCompC);
- addTypeConstructor("Vector", new VectorType(Types.VECTOR));
+ addTypeDescriptor("Vector", new VectorType(Types.VECTOR));
addValue("getVector", new GetVector(Types.NO_EFFECTS, Types.VECTOR));
addValue("lengthVector", new LengthVector(Types.VECTOR));
//addValue("createVectorFromList", CreateVectorFromList.INSTANCE);
- addTypeConstructor("MVector", new VectorType(Types.MVECTOR));
+ addTypeDescriptor("MVector", new VectorType(Types.MVECTOR));
addValue("createMVector", CreateMVector.INSTANCE);
addValue("createMVectorProto", CreateMVectorProto.INSTANCE);
addValue("getMVector", new GetVector(Types.PROC, Types.MVECTOR));
addValue("freezeMVector", new FreezeMVector());
addValue("setMVector", SetMVector.INSTANCE);
+ StandardTypeConstructor ClassC = new StandardTypeConstructor(Types.CLASS, Kinds.STAR_TO_STAR,
+ TypeDesc.forClass("java/lang/Class"));
+ ClassC.setType(Types.CLASS, A);
+ addTypeDescriptor("Class", ClassC);
+ addValue("classObject", ClassConstant.INSTANCE);
+
// *** fail ***
addValue("fail", FailFunction.INSTANCE).documentation =
"Throws a runtime exeception with the given string as a description.";
+ addValue("throw", ThrowFunction.INSTANCE).documentation =
+ "Throws a given exception.";
// *** runProc ***
x.createOccurrence()));
runProcFunction.addBlock(block);
- SCLConstant runProc = new SCLConstant(Name.create(Types.BUILTIN, "runProc"), runProcFunction.getType());
+ SCLConstant runProc = new SCLConstant(Names.Builtin_runProc, runProcFunction.getType());
runProc.setDefinition(runProcFunction);
runProc.setInlineArity(1, 0xffffffff);
runProc.setBase(new JavaStaticMethod("org/simantics/scl/runtime/procedure/Procedures",
Types.NO_EFFECTS,
TypeDesc.forClass(TUnion.class),
Type, -1));
- /*addValue("TUnion", new JavaStaticMethod(
+ addValue("TUnion2", new JavaStaticMethod(
"org/simantics/scl/compiler/types/Types",
"union",
Types.NO_EFFECTS,
- Type, Types.list(Type)));*/
-
+ Type, Type, Type));
+ addValue("TUnion3", new JavaStaticMethod(
+ "org/simantics/scl/compiler/types/Types",
+ "union",
+ Types.NO_EFFECTS,
+ Type, Type, Type, Type));
+
StandardTypeConstructor TypeC = new StandardTypeConstructor(Type, Kinds.STAR,
TypeDesc.forClass("org/simantics/scl/compiler/types/Type"));
TypeC.setType(Type);
TypeC.isOpen = true;
TypeC.documentation = "Represents an SCL data type.";
- addTypeConstructor("Type", TypeC);
+ addTypeDescriptor("Type", TypeC);
// typeOf :: Typeable a => a -> Type
addValue("typeOf", TypeOfConstant.INSTANCE)
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.";
- addTypeConstructor("Binding", BindingC);
+ addTypeDescriptor("Binding", BindingC);
// typeOf :: Typeable a => a -> TypeReps
addValue("binding", BindingConstant.INSTANCE)
addRelation("Execute10", new ExecuteRelation(10));
}
- addValue("newEq", EqualsFunction.INSTANCE);
- addValue("newHash", HashCodeFunction.INSTANCE);
+ {
+ 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));
- addTypeConstructor("BranchPoint", branchPoint);
+ addTypeDescriptor("BranchPoint", branchPoint);
addValue("visitBranchPoint", VisitBranchPoint.INSTANCE);
}
+
+ setParentClassLoader(getClass().getClassLoader());
+
+ // CHR
+
+ addTypeDescriptor("CHRContext", new StandardTypeConstructor(Types.CHRContext, Kinds.STAR, TypeDesc.forClass(CHRContext.class)));
}
@Override
return documentation;
}
+ public static void flush() {
+ INSTANCE = new Builtins();
+ }
+
}