]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Expose CommandSession in SCL 39/2739/1
authorHannu Niemistö <hannu.niemisto@semantum.fi>
Thu, 28 Feb 2019 14:34:22 +0000 (16:34 +0200)
committerHannu Niemistö <hannu.niemisto@semantum.fi>
Thu, 28 Feb 2019 14:34:22 +0000 (16:34 +0200)
Change-Id: Ie4bee3c9a56f357e8e8797f96254731dcd9878a6

bundles/org.simantics.scl.compiler/scl/SCL/CommandSession.scl [new file with mode: 0644]
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/commands/CommandSession.java
bundles/org.simantics.scl.runtime/src/org/simantics/scl/runtime/reporting/SCLReporting.java

diff --git a/bundles/org.simantics.scl.compiler/scl/SCL/CommandSession.scl b/bundles/org.simantics.scl.compiler/scl/SCL/CommandSession.scl
new file mode 100644 (file)
index 0000000..33b4dd7
--- /dev/null
@@ -0,0 +1,19 @@
+// This module is meant to be imported with namespace
+import "SCL/ModuleRepository"
+import "SafeDynamic"
+
+importJava "org.simantics.scl.compiler.commands.CommandSession" where
+    data CommandSession
+    
+    @JavaName "<init>"
+    create :: ModuleRepository -> <Proc> CommandSession
+
+    execute :: CommandSession -> String -> <Proc> ()
+    
+    @JavaName getVariableValueAndType
+    get :: CommandSession -> String -> <Proc> Maybe SafeDynamic
+    @JavaName setVariable
+    set :: CommandSession -> String -> SafeDynamic -> <Proc> ()
+    
+    @JavaName removeVariable
+    remove :: CommandSession -> String -> <Proc> ()
\ No newline at end of file
index d0e44a9c7b263a36c0a75b60cc5f678432081165..00a7714a63640a3f2ae31bd29df0625c7f455ff4 100644 (file)
@@ -17,6 +17,7 @@ import java.util.Set;
 
 import org.simantics.scl.compiler.common.names.Names;
 import org.simantics.scl.compiler.constants.StringConstant;
+import org.simantics.scl.compiler.dynamic.SafeDynamic;
 import org.simantics.scl.compiler.elaboration.expressions.EApply;
 import org.simantics.scl.compiler.elaboration.expressions.EBlock;
 import org.simantics.scl.compiler.elaboration.expressions.EConstant;
@@ -84,6 +85,10 @@ public class CommandSession {
      */
     private boolean validateOnly; 
     
+    public CommandSession(ModuleRepository moduleRepository) {
+        this(moduleRepository, SCLReporting.getCurrentReportingHandler());
+    }
+
     public CommandSession(ModuleRepository moduleRepository, SCLReportingHandler handler) {
         this.moduleRepository = moduleRepository;
         this.defaultHandler = new PrintDecorator(
@@ -615,6 +620,11 @@ public class CommandSession {
         variableTypes.put(name, type);
     }
 
+    public void setVariable(String name, SafeDynamic typeAndValue) {
+        variableValues.put(name, typeAndValue.value);
+        variableTypes.put(name, typeAndValue.type_);
+    }
+
     public Object getVariableValue(String name) {
         return variableValues.get(name);
     }
@@ -623,6 +633,14 @@ public class CommandSession {
         return variableTypes.get(name);
     }
     
+    public SafeDynamic getVariableValueAndType(String name) {
+        Type type = variableTypes.get(name);
+        if(type == null)
+            return null;
+        Object value = variableValues.get(name);
+        return new SafeDynamic(type, value);
+    }
+    
     public void removeVariable(String name) {
        variableValues.remove(name);
        variableTypes.remove(name);
index 97ef75f8b498e0d6a7382c7f84e626d0ceac8ee9..5266b13a21e61c7892a6efc39698abf60a18c4a8 100644 (file)
@@ -18,6 +18,11 @@ public class SCLReporting {
 
     private static final Logger LOGGER = LoggerFactory.getLogger(SCLReporting.class);
 
+    public static SCLReportingHandler getCurrentReportingHandler() {
+        SCLReportingHandler handler = ((SCLReportingHandler)SCLContext.getCurrent().get(SCLReportingHandler.REPORTING_HANDLER));
+        return handler == null ? SCLReportingHandler.DEFAULT : handler;
+    }
+    
     public static void print(String text) {
         SCLReportingHandler handler = ((SCLReportingHandler)SCLContext.getCurrent().get(SCLReportingHandler.REPORTING_HANDLER));
         if(handler != null)