]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
(refs #7562) Procedural SCL modules 25/1125/2
authorHannu Niemistö <hannu.niemisto@semantum.fi>
Wed, 18 Oct 2017 12:16:36 +0000 (15:16 +0300)
committerHannu Niemistö <hannu.niemisto@semantum.fi>
Wed, 18 Oct 2017 12:17:08 +0000 (15:17 +0300)
Change-Id: I299d723990673d945e67d46615edf90b55c6e8e6

bundles/org.simantics.scl.compiler/META-INF/MANIFEST.MF
bundles/org.simantics.scl.compiler/build.properties
bundles/org.simantics.scl.compiler/scl/SCL/ProceduralModule.scl [new file with mode: 0644]
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/source/repository/ProceduralModuleSourceRepository.java [new file with mode: 0644]
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/source/repository/procedural/ProceduralValueDefinition.java [new file with mode: 0644]
bundles/org.simantics.scl.osgi/src/org/simantics/scl/osgi/internal/Activator.java

index 1007cf675ad96610a625a8d228e9f09c174c9582..105c28de9b1776c8b86adaaf6f2bc59cd3993fea 100644 (file)
@@ -66,6 +66,7 @@ Export-Package: org.cojen.classfile,
  org.simantics.scl.compiler.runtime,
  org.simantics.scl.compiler.source,
  org.simantics.scl.compiler.source.repository,
+ org.simantics.scl.compiler.source.repository.procedural,
  org.simantics.scl.compiler.testing,
  org.simantics.scl.compiler.testing.repository,
  org.simantics.scl.compiler.top,
index b7f9238d647c94be05c2d121697ad202f0a1b20d..4b829c259221b62e2b80a1d30b47247bcf98527f 100644 (file)
@@ -4,4 +4,5 @@ bin.includes = META-INF/,\
                .,\
                OSGI-INF/org.simantics.scl.compiler.source.repository.BuiltinModuleSourceRepository.xml,\
                OSGI-INF/org.simantics.scl.compiler.elaboration.java.LoggingModule.xml,\
-               sclTests/
+               sclTests/,\
+               scl/
diff --git a/bundles/org.simantics.scl.compiler/scl/SCL/ProceduralModule.scl b/bundles/org.simantics.scl.compiler/scl/SCL/ProceduralModule.scl
new file mode 100644 (file)
index 0000000..a740ded
--- /dev/null
@@ -0,0 +1,5 @@
+importJava "org.simantics.scl.compiler.source.repository.procedural.ProceduralValueDefinition" where
+    data ProceduralValueDefinition
+
+    @JavaName "<init>"
+    valueDefinition :: Typeable t => String -> t -> ProceduralValueDefinition
\ No newline at end of file
diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/source/repository/ProceduralModuleSourceRepository.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/source/repository/ProceduralModuleSourceRepository.java
new file mode 100644 (file)
index 0000000..4899f88
--- /dev/null
@@ -0,0 +1,69 @@
+package org.simantics.scl.compiler.source.repository;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+import org.simantics.scl.compiler.common.names.Name;
+import org.simantics.scl.compiler.elaboration.expressions.EExternalConstant;
+import org.simantics.scl.compiler.elaboration.modules.SCLValue;
+import org.simantics.scl.compiler.errors.Failable;
+import org.simantics.scl.compiler.module.ConcreteModule;
+import org.simantics.scl.compiler.module.repository.ModuleRepository;
+import org.simantics.scl.compiler.module.repository.UpdateListener;
+import org.simantics.scl.compiler.runtime.RuntimeModule;
+import org.simantics.scl.compiler.source.ModuleSource;
+import org.simantics.scl.compiler.source.PrecompiledModuleSource;
+import org.simantics.scl.compiler.source.repository.procedural.ProceduralValueDefinition;
+import org.simantics.scl.compiler.top.ValueNotFound;
+
+public abstract class ProceduralModuleSourceRepository implements ModuleSourceRepository {
+
+    public static final String PREFIX = "procedural:";
+    
+    protected abstract ModuleRepository getModuleRepository(UpdateListener listener);
+    
+    @Override
+    public Collection<String> getModuleNames() {
+        return Collections.emptyList();
+    }
+
+    @Override
+    public ModuleSource getModuleSource(String moduleName, UpdateListener listener) {
+        if(!moduleName.startsWith(PREFIX))
+            return null;
+        
+        String sourceModuleName = moduleName.substring(PREFIX.length());
+        Failable<RuntimeModule> sourceModuleF = getModuleRepository(listener)
+                .getRuntimeModule(sourceModuleName, listener);
+        if(!sourceModuleF.didSucceed())
+            return null;
+        
+        RuntimeModule sourceModule = sourceModuleF.getResult();
+        Object values;
+        try {
+            values = sourceModule.getValue("values");
+        } catch (ValueNotFound e) {
+            return null;
+        }
+        
+        if(!(values instanceof List))
+            return null;
+        
+        ConcreteModule module = new ConcreteModule(moduleName);
+        for(Object item : (List)values) {
+            if(!(item instanceof ProceduralValueDefinition))
+                return null;
+            ProceduralValueDefinition def = (ProceduralValueDefinition)item;
+
+            SCLValue value = new SCLValue(Name.create(moduleName, def.name));
+            value.setType(def.type);
+            value.setExpression(new EExternalConstant(def.value, def.type));
+            value.setInlineInSimplification(true);
+            module.addValue(value);
+        }
+        module.setParentClassLoader(getClass().getClassLoader());
+        return new PrecompiledModuleSource(module);
+    }
+
+}
diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/source/repository/procedural/ProceduralValueDefinition.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/source/repository/procedural/ProceduralValueDefinition.java
new file mode 100644 (file)
index 0000000..dfe3440
--- /dev/null
@@ -0,0 +1,15 @@
+package org.simantics.scl.compiler.source.repository.procedural;
+
+import org.simantics.scl.compiler.types.Type;
+
+public class ProceduralValueDefinition {
+    public final Type type;
+    public final String name;
+    public final Object value;
+    
+    public ProceduralValueDefinition(Type type, String name, Object value) {
+        this.type = type;
+        this.name = name;
+        this.value = value;
+    }
+}
index ea113017a1458790a57567a7498b4d5339285689..d7a9e9e7f771f2802a15ad0b8d13beeae9868cbf 100644 (file)
@@ -4,8 +4,12 @@ import java.util.Hashtable;
 
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
+import org.simantics.scl.compiler.module.repository.ModuleRepository;
+import org.simantics.scl.compiler.module.repository.UpdateListener;
 import org.simantics.scl.compiler.source.repository.ModuleSourceRepository;
+import org.simantics.scl.compiler.source.repository.ProceduralModuleSourceRepository;
 import org.simantics.scl.compiler.source.repository.SourceRepositories;
+import org.simantics.scl.osgi.SCLOsgi;
 
 public class Activator implements BundleActivator {
 
@@ -23,6 +27,14 @@ public class Activator implements BundleActivator {
         bundleContext.registerService(ModuleSourceRepository.class,
                 SourceRepositories.BUILTIN_SOURCE_REPOSITORY,
                 properties);
+        bundleContext.registerService(ModuleSourceRepository.class,
+                new ProceduralModuleSourceRepository() {
+                    @Override
+                    protected ModuleRepository getModuleRepository(UpdateListener listener) {
+                        return SCLOsgi.MODULE_REPOSITORY;
+                    }
+                },
+                properties);
     }
 
     public void stop(BundleContext bundleContext) throws Exception {