]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/ReflectionJavaModule.java
(refs #7595) Started SCL/Reflection module
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / elaboration / java / ReflectionJavaModule.java
1 package org.simantics.scl.compiler.elaboration.java;
2
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;
19
20 @Component
21 public class ReflectionJavaModule extends ConcreteModule {
22     
23     public static ReflectionJavaModule INSTANCE = new ReflectionJavaModule();
24
25     public ReflectionJavaModule() {
26         super("SCL/ReflectionJava");
27         
28         // ModuleRepository type
29         TCon ModuleRepository = Types.con(getName(), "ModuleRepository");
30         StandardTypeConstructor markerConstructor = new StandardTypeConstructor(ModuleRepository,
31                 Kinds.STAR, TypeDesc.forClass(ModuleRepository.class));
32         markerConstructor.external = true;
33         addTypeDescriptor("ModuleRepository", markerConstructor);
34         
35         // MODULE_REPOSITORY value
36         SCLValue value = new SCLValue(Name.create(getName(), "MODULE_REPOSITORY"));
37         value.setType(Types.functionE(Types.PUNIT, Types.NO_EFFECTS, ModuleRepository));
38         value.setMacroRule(new MacroRule() {
39             @Override
40             public Expression apply(SimplificationContext context, Type[] typeParameters, EApply apply) {
41                 if(apply.parameters.length != 1)
42                     return null;
43                 return new EExternalConstant(context.getCompilationContext().moduleRepository, ModuleRepository);
44             }
45         });
46         addValue(value);
47         
48         setParentClassLoader(getClass().getClassLoader());
49     }
50
51 }