X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.scl.compiler%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Felaboration%2Fjava%2FBuiltins.java;h=4846f75a13b2b605297807d11fe5c60a9fd800be;hp=14808c820f3b4c91f5ac305645ff9b9ffc1d3260;hb=91682baa9a8252390f09b80fd724f47e5957b234;hpb=c26409b1caf2f1e560d37c5befd11b442399c3fe diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/Builtins.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/Builtins.java index 14808c820..4846f75a1 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/Builtins.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/Builtins.java @@ -15,14 +15,18 @@ 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.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.constants.singletons.TypeValueConstant; 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; @@ -47,14 +51,15 @@ 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.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; @@ -85,16 +90,7 @@ public class Builtins extends ConcreteModule { "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); @@ -102,6 +98,7 @@ public class Builtins extends ConcreteModule { addTypeDescriptor("Variant", new StandardTypeConstructor(Types.VARIANT, Kinds.STAR, TypeDesc.forClass(Variant.class))); addEffectConstructor("Proc", new EffectConstructor(Types.PROC)); + addEffectConstructor("Exception", new EffectConstructor(Types.EXCEPTION)); //addTypeDescriptor("->", new StandardTypeConstructor(Kinds.STAR_TO_STAR_TO_STAR, Constants.FUNCTION)); addTypeDescriptor("[]", new StandardTypeConstructor(Types.LIST, Kinds.STAR_TO_STAR, Constants.LIST)); @@ -151,10 +148,12 @@ public class Builtins extends ConcreteModule { // *** 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 *** @@ -176,6 +175,10 @@ public class Builtins extends ConcreteModule { 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, @@ -199,10 +202,18 @@ public class Builtins extends ConcreteModule { 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 *** @@ -220,7 +231,7 @@ public class Builtins extends ConcreteModule { ); block.addStatement(apply); - block.setExit(new Jump(runProcFunction.getReturnCont().createOccurrence(), + block.setExit(new Jump(-1, runProcFunction.getReturnCont().createOccurrence(), x.createOccurrence())); runProcFunction.addBlock(block); @@ -277,7 +288,12 @@ public class Builtins extends ConcreteModule { "union", Types.NO_EFFECTS, 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); @@ -288,6 +304,7 @@ public class Builtins extends ConcreteModule { // typeOf :: Typeable a => a -> Type addValue("typeOf", TypeOfConstant.INSTANCE) .documentation = "Returns the type of the value given as a parameter."; + addValue("typeValue", TypeValueConstant.INSTANCE); addValue("typeOfProxy", TypeOfProxyConstant.INSTANCE) .documentation = "Returns the type of the type proxy given as a parameter."; addValue("TypeProxy", TypeProxyConstant.INSTANCE); @@ -350,6 +367,10 @@ public class Builtins extends ConcreteModule { } setParentClassLoader(getClass().getClassLoader()); + + // CHR + + addTypeDescriptor("CHRContext", new StandardTypeConstructor(Types.CHRContext, Kinds.STAR, TypeDesc.forClass(CHRContext.class))); } @Override @@ -357,4 +378,8 @@ public class Builtins extends ConcreteModule { return documentation; } + public static void flush() { + INSTANCE = new Builtins(); + } + }