public Dictionary <string, object> Execute(string name, Dictionary <string, object> semanticInputs) { var executionState = new LogicExecutionState(); executionState.Structures = this.m_Structures; executionState.Functions = this.m_Functions; var function = this.m_Functions.First(x => x.Name == name); foreach (var parameter in function.Parameters) { if (parameter.Semantic != null) { // Map the semantic input to this parameter. executionState.Variables[parameter.Name] = semanticInputs[parameter.Semantic]; } else { // Assume structure // TODO: Validation var structType = this.m_Structures.First(x => x.Name == parameter.Type); var structObj = new LogicStructureInstance(structType); foreach (var field in structType.Fields) { structObj.Fields[field] = semanticInputs[field.Semantic]; } executionState.Variables[parameter.Name] = structObj; } } var result = function.Result(executionState); if (function.ReturnSemantic != null) { return(new Dictionary <string, object> { { function.ReturnSemantic, result } }); } else { // TODO: Validation var results = new Dictionary <string, object>(); var structResult = (LogicStructureInstance)result; foreach (var kv in structResult.Fields) { results[kv.Key.Semantic] = kv.Value; } return(results); } }
public Dictionary<string, object> Execute(string name, Dictionary<string, object> semanticInputs) { var executionState = new LogicExecutionState(); executionState.Structures = this.m_Structures; executionState.Functions = this.m_Functions; var function = this.m_Functions.First(x => x.Name == name); foreach (var parameter in function.Parameters) { if (parameter.Semantic != null) { // Map the semantic input to this parameter. executionState.Variables[parameter.Name] = semanticInputs[parameter.Semantic]; } else { // Assume structure // TODO: Validation var structType = this.m_Structures.First(x => x.Name == parameter.Type); var structObj = new LogicStructureInstance(structType); foreach (var field in structType.Fields) { structObj.Fields[field] = semanticInputs[field.Semantic]; } executionState.Variables[parameter.Name] = structObj; } } var result = function.Result(executionState); if (function.ReturnSemantic != null) { return new Dictionary<string, object> { { function.ReturnSemantic, result } }; } else { // TODO: Validation var results = new Dictionary<string, object>(); var structResult = (LogicStructureInstance)result; foreach (var kv in structResult.Fields) { results[kv.Key.Semantic] = kv.Value; } return results; } }
public Dictionary <string, object> Execute(string name, Dictionary <string, object> semanticInputs) { var executionState = new LogicExecutionState(); executionState.Structures = this.m_Structures; executionState.Functions = this.m_Functions; executionState.AppFunctions = this.m_ApplicationFunctions; var function = this.m_Functions.First(x => x.Name == name); semanticInputs = this.NormalizeSemanticInputs(semanticInputs); foreach (var parameter in function.Parameters) { if (parameter.Semantic != null) { // Map the semantic input to this parameter. executionState.Variables[parameter.Name] = semanticInputs[parameter.Semantic]; } else { // Assume structure // TODO: Validation var structType = this.m_Structures.First(x => x.Name == parameter.Type); var structObj = new LogicStructureInstance(structType); foreach (var field in structType.Fields) { structObj.Fields[field] = semanticInputs[field.Semantic]; } executionState.Variables[parameter.Name] = structObj; } } Func <LogicExecutionState, object> compiledFunc; if (!this.m_CompiledFunctions.TryGetValue(name, out compiledFunc)) { compiledFunc = LogicScriptCompiler.Compile(function); this.m_CompiledFunctions[name] = compiledFunc; } var result = compiledFunc(executionState); if (function.ReturnSemantic != null) { return(new Dictionary <string, object> { { function.ReturnSemantic, result } }); } var instance = result as LogicStructureInstance; if (instance != null) { var results = new Dictionary <string, object>(); var structResult = instance; foreach (var kv in structResult.Fields) { // We only set output fields where the code has explicitly set a value. if (structResult.FieldsSet[kv.Key]) { results[kv.Key.Semantic] = kv.Value; } } return(results); } throw new InvalidOperationException("Missing return semantic for function " + function.Name); }
public Dictionary<string, object> Execute(string name, Dictionary<string, object> semanticInputs) { var executionState = new LogicExecutionState(); executionState.Structures = this.m_Structures; executionState.Functions = this.m_Functions; executionState.AppFunctions = this.m_ApplicationFunctions; var function = this.m_Functions.First(x => x.Name == name); semanticInputs = this.NormalizeSemanticInputs(semanticInputs); foreach (var parameter in function.Parameters) { if (parameter.Semantic != null) { // Map the semantic input to this parameter. executionState.Variables[parameter.Name] = semanticInputs[parameter.Semantic]; } else { // Assume structure // TODO: Validation var structType = this.m_Structures.First(x => x.Name == parameter.Type); var structObj = new LogicStructureInstance(structType); foreach (var field in structType.Fields) { structObj.Fields[field] = semanticInputs[field.Semantic]; } executionState.Variables[parameter.Name] = structObj; } } Func<LogicExecutionState, object> compiledFunc; if (!this.m_CompiledFunctions.TryGetValue(name, out compiledFunc)) { compiledFunc = LogicScriptCompiler.Compile(function); this.m_CompiledFunctions[name] = compiledFunc; } var result = compiledFunc(executionState); if (function.ReturnSemantic != null) { return new Dictionary<string, object> { { function.ReturnSemantic, result } }; } var instance = result as LogicStructureInstance; if (instance != null) { var results = new Dictionary<string, object>(); var structResult = instance; foreach (var kv in structResult.Fields) { // We only set output fields where the code has explicitly set a value. if (structResult.FieldsSet[kv.Key]) { results[kv.Key.Semantic] = kv.Value; } } return results; } throw new InvalidOperationException("Missing return semantic for function " + function.Name); }