1 package org.simantics.scl.compiler.elaboration.java;
3 import org.cojen.classfile.TypeDesc;
4 import org.osgi.service.component.annotations.Component;
5 import org.simantics.scl.compiler.common.names.Name;
6 import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext;
7 import org.simantics.scl.compiler.elaboration.expressions.EApply;
8 import org.simantics.scl.compiler.elaboration.expressions.EExternalConstant;
9 import org.simantics.scl.compiler.elaboration.expressions.Expression;
10 import org.simantics.scl.compiler.elaboration.macros.MacroRule;
11 import org.simantics.scl.compiler.elaboration.modules.SCLValue;
12 import org.simantics.scl.compiler.internal.codegen.types.StandardTypeConstructor;
13 import org.simantics.scl.compiler.module.ConcreteModule;
14 import org.simantics.scl.compiler.module.repository.ModuleRepository;
15 import org.simantics.scl.compiler.types.TCon;
16 import org.simantics.scl.compiler.types.Type;
17 import org.simantics.scl.compiler.types.Types;
18 import org.simantics.scl.compiler.types.kinds.Kinds;
20 public class ReflectionJavaModule extends ConcreteModule {
22 public static ReflectionJavaModule INSTANCE = new ReflectionJavaModule();
24 public ReflectionJavaModule() {
25 super("SCL/ReflectionJava");
27 // ModuleRepository type
28 TCon ModuleRepository = Types.con(getName(), "ModuleRepository");
29 StandardTypeConstructor markerConstructor = new StandardTypeConstructor(ModuleRepository,
30 Kinds.STAR, TypeDesc.forClass(ModuleRepository.class));
31 markerConstructor.external = true;
32 addTypeDescriptor("ModuleRepository", markerConstructor);
34 // MODULE_REPOSITORY value
35 SCLValue value = new SCLValue(Name.create(getName(), "MODULE_REPOSITORY"));
36 value.setType(Types.functionE(Types.PUNIT, Types.NO_EFFECTS, ModuleRepository));
37 value.setMacroRule(new MacroRule() {
39 public Expression apply(SimplificationContext context, Type[] typeParameters, EApply apply) {
40 if(apply.parameters.length != 1)
42 return new EExternalConstant(context.getCompilationContext().moduleRepository, ModuleRepository);
47 setParentClassLoader(getClass().getClassLoader());