--- /dev/null
+// 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
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;
*/
private boolean validateOnly;
+ public CommandSession(ModuleRepository moduleRepository) {
+ this(moduleRepository, SCLReporting.getCurrentReportingHandler());
+ }
+
public CommandSession(ModuleRepository moduleRepository, SCLReportingHandler handler) {
this.moduleRepository = moduleRepository;
this.defaultHandler = new PrintDecorator(
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);
}
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);
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)