--- /dev/null
+module {
+ export = [possibleUnsafeSclValueByName, unsafeSclValueByName, sclModuleNames]
+}
+
+include "SCL/ReflectionJava"
+
+importJava "org.simantics.scl.compiler.module.repository.ModuleRepository" where
+ @JavaName getValue
+ unsafeSclValueByName_ :: ModuleRepository -> String -> <Proc> a
+
+ @JavaName getSourceRepository
+ moduleSourceRepositoryOf :: ModuleRepository -> ModuleSourceRepository
+
+importJava "org.simantics.scl.compiler.source.repository.ModuleSourceRepository" where
+ data ModuleSourceRepository
+
+ @JavaName getModuleNames
+ sclModuleNames_ :: ModuleSourceRepository -> [String]
+
+unsafeSclValueByName :: String -> <Proc> a
+unsafeSclValueByName = unsafeSclValueByName_ MODULE_REPOSITORY
+
+possibleUnsafeSclValueByName :: String -> <Proc> Maybe a
+possibleUnsafeSclValueByName name = Just (unsafeSclValueByName name) `catch` \(_ :: Exception) -> Nothing
+
+sclModuleNames :: <Proc> [String]
+sclModuleNames = sclModuleNames_ (moduleSourceRepositoryOf MODULE_REPOSITORY)
import org.simantics.scl.compiler.internal.codegen.utils.JavaNamingPolicy;
import org.simantics.scl.compiler.internal.header.ModuleHeader;
import org.simantics.scl.compiler.module.ConcreteModule;
+import org.simantics.scl.compiler.module.repository.ModuleRepository;
import org.simantics.scl.compiler.types.Type;
import gnu.trove.map.hash.THashMap;
public class CompilationContext implements EnvironmentalContext {
public final ErrorLog errorLog = new ErrorLog();
+ public ModuleRepository moduleRepository;
public Environment environment;
public JavaTypeTranslator javaTypeTranslator;
public JavaNamingPolicy namingPolicy;
module = new ConcreteModule(moduleName);
compilationContext.module = module;
+ compilationContext.moduleRepository = localEnvironmentFactory.getModuleRepository();
if(moduleHeader != null) {
if(moduleHeader.defaultLocalName != null)
module.setDefaultLocalName(moduleHeader.defaultLocalName);
--- /dev/null
+package org.simantics.scl.compiler.elaboration.java;
+
+import org.cojen.classfile.TypeDesc;
+import org.osgi.service.component.annotations.Component;
+import org.simantics.scl.compiler.common.names.Name;
+import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext;
+import org.simantics.scl.compiler.elaboration.expressions.EApply;
+import org.simantics.scl.compiler.elaboration.expressions.EExternalConstant;
+import org.simantics.scl.compiler.elaboration.expressions.Expression;
+import org.simantics.scl.compiler.elaboration.macros.MacroRule;
+import org.simantics.scl.compiler.elaboration.modules.SCLValue;
+import org.simantics.scl.compiler.internal.codegen.types.StandardTypeConstructor;
+import org.simantics.scl.compiler.module.ConcreteModule;
+import org.simantics.scl.compiler.module.repository.ModuleRepository;
+import org.simantics.scl.compiler.types.TCon;
+import org.simantics.scl.compiler.types.Type;
+import org.simantics.scl.compiler.types.Types;
+import org.simantics.scl.compiler.types.kinds.Kinds;
+
+@Component
+public class ReflectionJavaModule extends ConcreteModule {
+
+ public static ReflectionJavaModule INSTANCE = new ReflectionJavaModule();
+
+ public ReflectionJavaModule() {
+ super("SCL/ReflectionJava");
+
+ // ModuleRepository type
+ TCon ModuleRepository = Types.con(getName(), "ModuleRepository");
+ StandardTypeConstructor markerConstructor = new StandardTypeConstructor(ModuleRepository,
+ Kinds.STAR, TypeDesc.forClass(ModuleRepository.class));
+ markerConstructor.external = true;
+ addTypeDescriptor("ModuleRepository", markerConstructor);
+
+ // MODULE_REPOSITORY value
+ SCLValue value = new SCLValue(Name.create(getName(), "MODULE_REPOSITORY"));
+ value.setType(Types.functionE(Types.PUNIT, Types.NO_EFFECTS, ModuleRepository));
+ value.setMacroRule(new MacroRule() {
+ @Override
+ public Expression apply(SimplificationContext context, Type[] typeParameters, EApply apply) {
+ if(apply.parameters.length != 1)
+ return null;
+ return new EExternalConstant(context.getCompilationContext().moduleRepository, ModuleRepository);
+ }
+ });
+ addValue(value);
+
+ setParentClassLoader(getClass().getClassLoader());
+ }
+
+}
import org.simantics.scl.compiler.module.ConcreteModule;
import org.simantics.scl.compiler.module.ImportDeclaration;
import org.simantics.scl.compiler.module.repository.ImportFailureException;
+import org.simantics.scl.compiler.module.repository.ModuleRepository;
public interface EnvironmentFactory {
Environment createEnvironment(CompilationContext context, ImportDeclaration[] array) throws ImportFailureException;
void addBuiltinDependencies(ConcreteModule module);
+ ModuleRepository getModuleRepository();
}
this.builtinImports = builtinImports;
this.listener = listener;
}
+
+ @Override
+ public ModuleRepository getModuleRepository() {
+ return environment;
+ }
@Override
public Environment createEnvironment(CompilationContext context, ImportDeclaration[] imports) throws ImportFailureException {
import org.simantics.scl.compiler.elaboration.java.JavaModule;
import org.simantics.scl.compiler.elaboration.java.LoggingModule;
import org.simantics.scl.compiler.elaboration.java.MinigraphModule;
+import org.simantics.scl.compiler.elaboration.java.ReflectionJavaModule;
@Component
public class BuiltinModuleSourceRepository extends MapModuleSourceRepository implements ModuleSourceRepository {
public BuiltinModuleSourceRepository() {
super(Builtins.INSTANCE,
JavaModule.INSTANCE,
+ ReflectionJavaModule.INSTANCE,
MinigraphModule.INSTANCE,
new LoggingModule());
}