/// <summary> /// For a given list of formal parameters, get the function end points that resolve /// </summary> /// <param name="context"></param> /// <param name="formalParams"></param> /// <param name="replicationInstructions"></param> /// <param name="stackFrame"></param> /// <param name="core"></param> /// <param name="unresolvable">The number of argument sets that couldn't be resolved</param> /// <returns></returns> public Dictionary<FunctionEndPoint, int> GetExactMatchStatistics( Runtime.Context context, List<List<StackValue>> reducedFormalParams, StackFrame stackFrame, RuntimeCore runtimeCore, out int unresolvable) { List<ReplicationInstruction> replicationInstructions = new List<ReplicationInstruction>(); //We've already done the reduction before calling this unresolvable = 0; Dictionary<FunctionEndPoint, int> ret = new Dictionary<FunctionEndPoint, int>(); foreach (List<StackValue> formalParamSet in reducedFormalParams) { List<FunctionEndPoint> feps = GetExactTypeMatches(context, formalParamSet, replicationInstructions, stackFrame, runtimeCore); if (feps.Count == 0) { //We have an arugment set that couldn't be resolved unresolvable++; } foreach (FunctionEndPoint fep in feps) { if (ret.ContainsKey(fep)) ret[fep]++; else ret.Add(fep, 1); } } return ret; }
internal static ProtoCore.Core TestRunnerRunOnly(string code, out RuntimeCore runtimeCore) { ProtoCore.Core core; ProtoScript.Runners.ProtoScriptRunner fsr = new ProtoScriptRunner(); // Specify some of the requirements of IDE. var options = new ProtoCore.Options(); options.ExecutionMode = ProtoCore.ExecutionMode.Serial; string testPath = @"..\..\..\test\Engine\ProtoTest\ImportFiles\"; options.IncludeDirectories.Add(testPath); core = new ProtoCore.Core(options); core.Compilers.Add(ProtoCore.Language.Associative, new ProtoAssociative.Compiler(core)); core.Compilers.Add(ProtoCore.Language.Imperative, new ProtoImperative.Compiler(core)); fsr = new ProtoScriptRunner(); DLLFFIHandler.Register(FFILanguage.CSharp, new CSModuleHelper()); CLRModuleType.ClearTypes(); //Run runtimeCore = fsr.Execute(code, core); return core; }
public override void Setup() { // Create a dummy runtimeCore because these tests dont really need to execute // The base class will expect to cleanup the runtimeCore base.Setup(); runtimeCore = new RuntimeCore(new Heap()); }
public void TestCompilerAndRuntimeComponent01() { String code = @" a = 10; "; // Compile core var opts = new Options(); opts.ExecutionMode = ExecutionMode.Serial; ProtoCore.Core core = new Core(opts); core.Compilers.Add(ProtoCore.Language.kAssociative, new ProtoAssociative.Compiler(core)); core.Compilers.Add(ProtoCore.Language.kImperative, new ProtoImperative.Compiler(core)); ProtoScriptRunner runner = new ProtoScriptRunner(); // Compiler instance ProtoCore.DSASM.Executable dsExecutable; bool compileSucceeded = runner.CompileMe(code, core, out dsExecutable); Assert.IsTrue(compileSucceeded == true); // Pass compile data to the runtime RuntimeCore runtimeCore = new RuntimeCore(core.Heap); runtimeCore.SetProperties(core.Options, dsExecutable); // Runtime ExecutionMirror mirror = runner.ExecuteMe(runtimeCore); Obj o = mirror.GetValue("a");
public void SetUp() { testCore = thisTest.SetupTestCore(); testRuntimeCore = new RuntimeCore(testCore.Heap, testCore.Options); testExecutive = new TestExecutive(testRuntimeCore); }
internal static ProtoCore.Core DebugRunnerRunOnly(string code, out RuntimeCore runtimeCore) { ProtoCore.Core core; DebugRunner fsr; // Specify some of the requirements of IDE. var options = new ProtoCore.Options(); options.ExecutionMode = ProtoCore.ExecutionMode.Serial; options.SuppressBuildOutput = false; options.GCTempVarsOnDebug = false; string testPath = @"..\..\..\test\Engine\ProtoTest\ImportFiles\"; options.IncludeDirectories.Add(testPath); core = new ProtoCore.Core(options); core.Compilers.Add(ProtoCore.Language.kAssociative, new ProtoAssociative.Compiler(core)); core.Compilers.Add(ProtoCore.Language.kImperative, new ProtoImperative.Compiler(core)); fsr = new DebugRunner(core); DLLFFIHandler.Register(FFILanguage.CSharp, new CSModuleHelper()); CLRModuleType.ClearTypes(); //Run fsr.PreStart(code); DebugRunner.VMState vms = null; vms = fsr.Run(); runtimeCore = fsr.runtimeCore; return core; }
public void SetUp() { testCore = thisTest.SetupTestCore(); testRuntimeCore = new RuntimeCore(testCore.Heap); testRuntimeCore.SetProperties(testCore.Options, null); testExecutive = new TestExecutive(testRuntimeCore); }
public bool RegisterExtensionApplicationType(RuntimeCore runtimeCore, SysType type) { if (!typeof(IExtensionApplication).IsAssignableFrom(type)) return false; FFIExecutionSession session = GetSession(runtimeCore, true); session.AddExtensionAppType(type); return true; }
internal static ProtoCore.Core TestRunnerRunOnly(string includePath, string code, Dictionary<int, List<string>> map, string geometryFactory, string persistentManager, out ExecutionMirror mirror, out RuntimeCore runtimeCoreOut) { ProtoCore.Core core; ProtoScript.Runners.ProtoScriptTestRunner fsr = new ProtoScriptTestRunner(); ProtoScript.Config.RunConfiguration runnerConfig; // Specify some of the requirements of IDE. var options = new ProtoCore.Options(); options.ExecutionMode = ProtoCore.ExecutionMode.Serial; options.SuppressBuildOutput = false; options.WatchTestMode = true; // Cyclic dependency threshold is lowered from the default (2000) // as this causes the test framework to be painfully slow options.kDynamicCycleThreshold = 5; // Pass the absolute path so that imported filepaths can be resolved // in "FileUtils.GetDSFullPathName()" includePath = Path.GetDirectoryName(includePath); options.IncludeDirectories.Add(includePath); //StreamWriter sw = File.CreateText(executionLogFilePath); TextOutputStream fs = new TextOutputStream(map); core = new ProtoCore.Core(options); core.Configurations.Add(ConfigurationKeys.GeometryXmlProperties, true); //core.Configurations.Add(ConfigurationKeys.GeometryFactory, geometryFactory); //core.Configurations.Add(ConfigurationKeys.PersistentManager, persistentManager); // By specifying this option we inject a mock Executive ('InjectionExecutive') // that prints stackvalues at every assignment statement // by overriding the POP_handler instruction - pratapa //core.ExecutiveProvider = new InjectionExecutiveProvider(); core.BuildStatus.MessageHandler = fs; core.Compilers.Add(ProtoCore.Language.kAssociative, new ProtoAssociative.Compiler(core)); core.Compilers.Add(ProtoCore.Language.kImperative, new ProtoImperative.Compiler(core)); runnerConfig = new ProtoScript.Config.RunConfiguration(); runnerConfig.IsParrallel = false; DLLFFIHandler.Register(FFILanguage.CSharp, new CSModuleHelper()); //Run mirror = fsr.Execute(code, core, out runtimeCoreOut); //sw.Close(); return core; }
private FFIExecutionSession GetSession(RuntimeCore runtimeCore, bool createIfNone) { FFIExecutionSession session = null; lock (mSessions) { if (!mSessions.TryGetValue(runtimeCore, out session) && createIfNone) { session = new FFIExecutionSession(runtimeCore); runtimeCore.ExecutionEvent += OnExecutionEvent; runtimeCore.Dispose += OnDispose; mSessions.Add(runtimeCore, session); } } return session; }
private void OnDispose(RuntimeCore sender) { if (mSessions == null) return; FFIExecutionSession session = null; lock (mSessions) { if (mSessions.TryGetValue(sender, out session)) { mSessions.Remove(sender); session.Dispose(); sender.Dispose -= OnDispose; sender.ExecutionEvent -= OnExecutionEvent; } mSelf = null; } }
/// <summary> /// For a given list of formal parameters, get the function end points that resolve /// </summary> /// <param name="context"></param> /// <param name="formalParams"></param> /// <param name="replicationInstructions"></param> /// <param name="stackFrame"></param> /// <param name="core"></param> /// <param name="unresolvable">The number of argument sets that couldn't be resolved</param> /// <returns></returns> public bool CanGetExactMatchStatics( Runtime.Context context, List<List<StackValue>> reducedFormalParams, StackFrame stackFrame, RuntimeCore runtimeCore, out HashSet<FunctionEndPoint> lookup) { lookup = new HashSet<FunctionEndPoint>(); foreach (List<StackValue> formalParamSet in reducedFormalParams) { List<FunctionEndPoint> feps = GetExactTypeMatches(context, formalParamSet, new List<ReplicationInstruction>(), stackFrame, runtimeCore); if (feps.Count == 0) { return false; } foreach (FunctionEndPoint fep in feps) { lookup.Add(fep); } } return true; }
/// <summary> /// Given deltaGraphNodes, estimate the reachable graphnodes from the live core /// </summary> /// <param name="liveCore"></param> /// <param name="deltaGraphNodes"></param> /// <returns></returns> private List<GraphNode> EstimateReachableGraphNodes(RuntimeCore rt, List<GraphNode> deltaGraphNodes) { List<GraphNode> reachableNodes = new List<GraphNode>(); foreach (GraphNode executingNode in deltaGraphNodes) { reachableNodes.AddRange(ProtoCore.AssociativeEngine.Utils.UpdateDependencyGraph( executingNode, rt.CurrentExecutive.CurrentDSASMExec, executingNode.exprUID, executingNode.IsSSANode(), true, 0, true)); } return reachableNodes; }
public ChangeSetComputer(ProtoCore.Core core, ProtoCore.RuntimeCore runtimeCore) { this.core = core; this.runtimeCore = runtimeCore; currentSubTreeList = new Dictionary<Guid, Subtree>(); }
public void Apply(ProtoCore.Core core, RuntimeCore runtimeCore, ChangeSetData changeSet) { Validity.Assert(null != changeSet); this.core = core; this.runtimeCore = runtimeCore; ApplyChangeSetDeleted(changeSet); ApplyChangeSetModified(changeSet); ApplyChangeSetForceExecute(changeSet); }
/// <summary> /// Cretes a new instance of the RuntimeCore object /// </summary> private void CreateRuntimeCore() { runtimeCore = new ProtoCore.RuntimeCore(runnerCore.Heap, runnerCore.Options); }
/// <summary> /// Retrieves an existing instance of a callsite associated with a UID /// It creates a new callsite if non was found /// </summary> /// <param name="core"></param> /// <param name="uid"></param> /// <returns></returns> public CallSite GetCallSite(int classScope, string methodName, Executable executable, RuntimeCore runtimeCore) { Validity.Assert(null != executable.FunctionTable); CallSite csInstance = null; var graphNode = executable.ExecutingGraphnode; var topGraphNode = graphNode; // If it is a nested function call, append all callsite ids List<string> callsiteIdentifiers = new List<string>(); foreach (var prop in runtimeCore.InterpreterProps) { if (prop != null && prop.executingGraphNode != null && graphNode != prop.executingGraphNode) { topGraphNode = prop.executingGraphNode; if (!string.IsNullOrEmpty(topGraphNode.CallsiteIdentifier)) { callsiteIdentifiers.Add(topGraphNode.CallsiteIdentifier); } } } if (graphNode != null) { callsiteIdentifiers.Add(graphNode.CallsiteIdentifier); } var callsiteID = string.Join(";", callsiteIdentifiers.ToArray()); // TODO Jun: Currently generates a new callsite for imperative and // internally generated functions. // Fix the issues that cause the cache to go out of sync when // attempting to cache internal functions. This may require a // secondary callsite cache for internal functions so they dont // clash with the graphNode UID key var language = executable.instrStreamList[runtimeCore.RunningBlock].language; bool isImperative = language == Language.Imperative; bool isInternalFunction = CoreUtils.IsInternalFunction(methodName); if (isInternalFunction || isImperative) { csInstance = new CallSite(classScope, methodName, executable.FunctionTable, runtimeCore.Options.ExecutionMode); } else if (!CallsiteCache.TryGetValue(callsiteID, out csInstance)) { // Attempt to retrieve a preloaded callsite data (optional). var traceData = GetAndRemoveTraceDataForNode(topGraphNode.guid, callsiteID); csInstance = new CallSite(classScope, methodName, executable.FunctionTable, runtimeCore.Options.ExecutionMode, traceData); CallsiteCache[callsiteID] = csInstance; CallSiteToNodeMap[csInstance.CallSiteID] = topGraphNode.guid; } if (graphNode != null && !CoreUtils.IsDisposeMethod(methodName)) { csInstance.UpdateCallSite(classScope, methodName); if (runtimeCore.Options.IsDeltaExecution) { runtimeCore.RuntimeStatus.ClearWarningForExpression(graphNode.exprUID); } } return csInstance; }
/*internal static void VerifyWatch_Run(int lineAtPrevBreak, string symbolName, Core core, StreamReader log, bool watchNestedMode = false) { //bool check = true; // search for the line and LHS string in the log file // verify that the LHS identifier name equals 'symbolName' // pass the LHS string to GetWatchValue() and inspect it // verify the watch values with the log output string line = null; while ((line = log.ReadLine()) != null) { // Get line no. Match m = Regex.Match(line, @"At line, (\d+)"); if (m.Success) { int lineNo = int.Parse(m.Groups[1].Value); if (lineNo == lineAtPrevBreak) { // Get lhs string // m = Regex.Match(line, @"(\d+), (\w+)"); m = Regex.Match(line, @"(\d+), (.*)([^\s]+)"); if (m.Success) { string lhsString = m.Groups[2].Value; // Get lhs symbol name m = Regex.Match(lhsString, @"(\w+)"); if (m.Success) { string lhsName = m.Groups[1].Value; if (lhsName.Equals(symbolName)) { ExpressionInterpreterRunner watchRunner = new ExpressionInterpreterRunner(core); ProtoCore.DSASM.Mirror.ExecutionMirror mirror = watchRunner.Execute(lhsString); Obj obj = mirror.GetWatchValue(); if (!watchNestedMode) { // Cheat by peeking into heap etc. to dump output string // match string with log output to verify string result = mirror.GetStringValue(obj.DsasmValue, core.Heap, 0, true); line = log.ReadLine(); m = Regex.Match(line, @"Info: (.*)"); if (m.Success) { string output = m.Groups[1].Value; if (!output.Equals(result)) { Assert.Fail(string.Format("\tThe value of expression \"{0}\" doesn't match in run mode and in watch.\n", lhsString)); return; } } } else { // TODO: Implement this - pratapa // if obj is a class pointer, handle separately // if obj is an array pointer, handle separately // if obj is a literal, verify watch value with log output directly GetStringValue(obj, mirror); } break; } } } } } } }*/ internal static void VerifyWatch_Run(int lineAtPrevBreak, string symbolName, Core core, RuntimeCore runtimeCore, Dictionary<int, List<string>> map, bool watchNestedMode = false, int ci = Constants.kInvalidIndex, string defectID = "") { //bool check = true; // search for the line and LHS string in the map // verify that the LHS identifier name equals 'symbolName' // pass the LHS string to GetWatchValue() and inspect it // verify the watch values with the log output if (!map.ContainsKey(lineAtPrevBreak)) return; List<string> expressions = map[lineAtPrevBreak]; foreach(string exp in expressions) { // Get line no. // Get lhs symbol name string lhsName = null; int index = exp.IndexOf('.'); if (index != -1) { string[] parts = exp.Split('.'); lhsName = parts[parts.Length - 1]; } else { Match m = Regex.Match(exp, @"(\w+)"); if (m.Success) { lhsName = m.Groups[1].Value; } } if (lhsName.Equals(symbolName)) { ExpressionInterpreterRunner watchRunner = new ExpressionInterpreterRunner(core, runtimeCore); ProtoCore.DSASM.Mirror.ExecutionMirror mirror = watchRunner.Execute(exp); Obj obj = mirror.GetWatchValue(); if (!watchNestedMode) { // Cheat by peeking into heap etc. to dump output string // match string with map output to verify string result = mirror.GetStringValue(obj.DsasmValue, runtimeCore.RuntimeMemory.Heap, 0, true); Expression expr = new Expression(lineAtPrevBreak, exp, ci); if (!InjectionExecutive.ExpressionMap.ContainsKey(expr)) return; List<string> values = InjectionExecutive.ExpressionMap[expr]; if (!values.Contains(result)) { Assert.Fail(string.Format("\tThe value of expression \"{0}\" doesn't match in run mode and in watch.\nTracked by Defect: {1}", exp, defectID)); return; } } else { // TODO: Implement this! - pratapa // if obj is a class pointer, handle separately // if obj is an array pointer, handle separately // if obj is a literal, verify watch value with log output directly GetStringValue(obj, mirror); } //break; } } }
public InjectionExecutive(RuntimeCore runtimeCore, bool isFep = false) : base(runtimeCore, isFep) { }
public ProtoCore.DSASM.Executive CreateExecutive(RuntimeCore runtimeCore, bool isFep) { return new InjectionExecutive(runtimeCore, isFep); }
public void SetUpStepOverFunctionCalls(RuntimeCore runtimeCore, ProcedureNode fNode, GraphNode graphNode, bool hasDebugInfo) { int tempPC = DebugEntryPC; int limit = 0; // end pc of current expression InstructionStream istream; int pc = tempPC; if (runtimeCore.DebugProps.InlineConditionOptions.isInlineConditional) { tempPC = InlineConditionOptions.startPc; limit = InlineConditionOptions.endPc; istream = runtimeCore.DSExecutable.instrStreamList[InlineConditionOptions.instructionStream]; } else { pc = tempPC; istream = runtimeCore.DSExecutable.instrStreamList[runtimeCore.RunningBlock]; if (istream.language == Language.kAssociative) { limit = FindEndPCForAssocGraphNode(pc, istream, fNode, graphNode, runtimeCore.Options.ExecuteSSA); //Validity.Assert(limit != ProtoCore.DSASM.Constants.kInvalidIndex); } else if (istream.language == Language.kImperative) { // Check for 'SETEXPUID' instruction to check for end of expression while (++pc < istream.instrList.Count) { Instruction instr = istream.instrList[pc]; if (instr.opCode == OpCode.SETEXPUID) { limit = pc; break; } } } } // Determine if this is outermost CALLR in the expression // until then do not restore any breakpoints // If outermost CALLR, restore breakpoints after end of expression pc = tempPC; int numNestedFunctionCalls = 0; while (++pc <= limit) { Instruction instr = istream.instrList[pc]; if (instr.opCode == OpCode.CALLR && instr.debug != null) { numNestedFunctionCalls++; } } if (numNestedFunctionCalls == 0) { // If this is the outermost function call runtimeCore.Breakpoints.Clear(); runtimeCore.Breakpoints.AddRange(AllbreakPoints); pc = tempPC; while (++pc <= limit) { Instruction instr = istream.instrList[pc]; // We still want to break at the closing brace of a function or ctor call or language block if (instr.debug != null && instr.opCode != OpCode.RETC && instr.opCode != OpCode.RETURN && (instr.opCode != OpCode.RETB)) { if (runtimeCore.Breakpoints.Contains(instr)) { runtimeCore.Breakpoints.Remove(instr); } } } } }
public static StackValue Coerce(StackValue sv, int UID, int rank, RuntimeCore runtimeCore) { Type t = new Type(); t.UID = UID; t.rank = rank; return Coerce(sv, t, runtimeCore); }
public static bool CheckInvalidArrayCoersion(FunctionEndPoint fep, List<StackValue> reducedSVs, ClassTable classTable, RuntimeCore runtimeCore, bool allowArrayPromotion) { for (int i = 0; i < reducedSVs.Count; i++) { Type typ = fep.FormalParams[i]; if (typ.UID == (int)ProtoCore.PrimitiveType.kInvalidType) return true; if (!typ.IsIndexable) continue; //It wasn't an array param, skip //Compute the type of target param if (!allowArrayPromotion) Validity.Assert(reducedSVs[i].IsArray, "This should be an array otherwise this shouldn't have passed previous tests"); if (!allowArrayPromotion) { if (typ.rank != ArrayUtils.GetMaxRankForArray(reducedSVs[i], runtimeCore) && typ.rank != DSASM.Constants.kArbitraryRank) return true; //Invalid co-ercsion } else { if (typ.rank < ArrayUtils.GetMaxRankForArray(reducedSVs[i], runtimeCore) && typ.rank != DSASM.Constants.kArbitraryRank) return true; //Invalid co-ercsion } Dictionary<ClassNode, int> arrayTypes = ArrayUtils.GetTypeStatisticsForArray(reducedSVs[i], runtimeCore); ClassNode cn = null; if (arrayTypes.Count == 0) { //This was an empty array Validity.Assert(cn == null, "If it was an empty array, there shouldn't be a type node"); cn = runtimeCore.DSExecutable.classTable.ClassNodes[(int)PrimitiveType.kTypeNull]; } else if (arrayTypes.Count == 1) { //UGLY, get the key out of the array types, of which there is only one foreach (ClassNode key in arrayTypes.Keys) cn = key; } else if (arrayTypes.Count > 1) { ClassNode commonBaseType = ArrayUtils.GetGreatestCommonSubclassForArray(reducedSVs[i], runtimeCore); if (commonBaseType == null) throw new ProtoCore.Exceptions.ReplicationCaseNotCurrentlySupported( string.Format(Resources.ArrayWithNotSupported, "{0C644179-14F5-4172-8EF8-A2F3739901B2}")); cn = commonBaseType; //From now on perform tests on the commmon base type } ClassNode argTypeNode = classTable.ClassNodes[typ.UID]; //cn now represents the class node of the argument //argTypeNode represents the class node of the argument bool isNotExactTypeMatch = cn != argTypeNode; bool argumentsNotNull = cn != runtimeCore.DSExecutable.classTable.ClassNodes[(int) PrimitiveType.kTypeNull]; bool recievingTypeNotAVar = argTypeNode != runtimeCore.DSExecutable.classTable.ClassNodes[(int) PrimitiveType.kTypeVar]; bool isNotConvertible = !cn.ConvertibleTo(typ.UID); //bool isCalleeVar = cn == core.classTable.list[(int) PrimitiveType.kTypeVar]; //Is it an invalid conversion? if (isNotExactTypeMatch && argumentsNotNull && recievingTypeNotAVar && isNotConvertible)// && !isCalleeVar) { return true; //It's an invalid coersion } } return false; }
/// <summary> /// Get a list of all the function end points that are type compliant, there maybe more than one due to pattern matches /// </summary> /// <returns></returns> public List<FunctionEndPoint> GetExactTypeMatches(ProtoCore.Runtime.Context context, List<StackValue> formalParams, List<ReplicationInstruction> replicationInstructions, StackFrame stackFrame, RuntimeCore runtimeCore) { List<FunctionEndPoint> ret = new List<FunctionEndPoint>(); List<List<StackValue>> allReducedParamSVs = Replicator.ComputeAllReducedParams(formalParams, replicationInstructions, runtimeCore); //@TODO(Luke): Need to add type statistics checks to the below if it is an array to stop int[] matching char[] //Now test the reduced Params over all of the available end points StackValue thisptr = stackFrame.ThisPtr; bool isInstance = thisptr.IsPointer && thisptr.opdata != Constants.kInvalidIndex; bool isGlobal = thisptr.IsPointer && thisptr.opdata == Constants.kInvalidIndex; foreach (FunctionEndPoint fep in FunctionEndPoints) { var proc = fep.procedureNode; // Member functions are overloaded with thisptr as the first // parameter, so if member function replicates on the left hand // side, the type matching should only be applied to overloaded // member functions, otherwise should only be applied to original // member functions. if (isInstance && context.IsReplicating != proc.IsAutoGeneratedThisProc) { continue; } else if (isGlobal && !proc.IsConstructor && !proc.IsStatic && proc.ClassID != Constants.kGlobalScope) { continue; } bool typesOK = true; foreach (List<StackValue> reducedParamSVs in allReducedParamSVs) { if (!fep.DoesTypeDeepMatch(reducedParamSVs, runtimeCore)) { typesOK = false; break; } } if (typesOK) ret.Add(fep); } return ret; }
/*internal static void VerifyWatch_Run(int lineAtPrevBreak, string symbolName, Core core, StreamReader log, * bool watchNestedMode = false) * { * //bool check = true; * * // search for the line and LHS string in the log file * // verify that the LHS identifier name equals 'symbolName' * // pass the LHS string to GetWatchValue() and inspect it * // verify the watch values with the log output * string line = null; * while ((line = log.ReadLine()) != null) * { * // Get line no. * Match m = Regex.Match(line, @"At line, (\d+)"); * if (m.Success) * { * int lineNo = int.Parse(m.Groups[1].Value); * if (lineNo == lineAtPrevBreak) * { * // Get lhs string * // m = Regex.Match(line, @"(\d+), (\w+)"); * m = Regex.Match(line, @"(\d+), (.*)([^\s]+)"); * if (m.Success) * { * string lhsString = m.Groups[2].Value; * * // Get lhs symbol name * m = Regex.Match(lhsString, @"(\w+)"); * if (m.Success) * { * string lhsName = m.Groups[1].Value; * if (lhsName.Equals(symbolName)) * { * ExpressionInterpreterRunner watchRunner = new ExpressionInterpreterRunner(core); * ProtoCore.DSASM.Mirror.ExecutionMirror mirror = watchRunner.Execute(lhsString); * Obj obj = mirror.GetWatchValue(); * * if (!watchNestedMode) * { * // Cheat by peeking into heap etc. to dump output string * // match string with log output to verify * string result = mirror.GetStringValue(obj.DsasmValue, core.Heap, 0, true); * line = log.ReadLine(); * * m = Regex.Match(line, @"Info: (.*)"); * if (m.Success) * { * string output = m.Groups[1].Value; * if (!output.Equals(result)) * { * Assert.Fail(string.Format("\tThe value of expression \"{0}\" doesn't match in run mode and in watch.\n", lhsString)); * return; * } * } * } * else * { * // TODO: Implement this - pratapa * // if obj is a class pointer, handle separately * // if obj is an array pointer, handle separately * // if obj is a literal, verify watch value with log output directly * GetStringValue(obj, mirror); * } * break; * } * } * } * } * } * } * }*/ internal static void VerifyWatch_Run(int lineAtPrevBreak, string symbolName, Core core, Dictionary <int, List <string> > map, bool watchNestedMode = false, int ci = Constants.kInvalidIndex, string defectID = "") { //bool check = true; // search for the line and LHS string in the map // verify that the LHS identifier name equals 'symbolName' // pass the LHS string to GetWatchValue() and inspect it // verify the watch values with the log output ProtoCore.RuntimeCore runtimeCore = core.__TempCoreHostForRefactoring; if (!map.ContainsKey(lineAtPrevBreak)) { return; } List <string> expressions = map[lineAtPrevBreak]; foreach (string exp in expressions) { // Get line no. // Get lhs symbol name string lhsName = null; int index = exp.IndexOf('.'); if (index != -1) { string[] parts = exp.Split('.'); lhsName = parts[parts.Length - 1]; } else { Match m = Regex.Match(exp, @"(\w+)"); if (m.Success) { lhsName = m.Groups[1].Value; } } if (lhsName.Equals(symbolName)) { ExpressionInterpreterRunner watchRunner = new ExpressionInterpreterRunner(core, runtimeCore); ProtoCore.DSASM.Mirror.ExecutionMirror mirror = watchRunner.Execute(exp); Obj obj = mirror.GetWatchValue(); if (!watchNestedMode) { // Cheat by peeking into heap etc. to dump output string // match string with map output to verify string result = mirror.GetStringValue(obj.DsasmValue, runtimeCore.RuntimeMemory.Heap, 0, true); Expression expr = new Expression(lineAtPrevBreak, exp, ci); if (!InjectionExecutive.ExpressionMap.ContainsKey(expr)) { return; } List <string> values = InjectionExecutive.ExpressionMap[expr]; if (!values.Contains(result)) { Assert.Fail(string.Format("\tThe value of expression \"{0}\" doesn't match in run mode and in watch.\nTracked by Defect: {1}", exp, defectID)); return; } } else { // TODO: Implement this! - pratapa // if obj is a class pointer, handle separately // if obj is an array pointer, handle separately // if obj is a literal, verify watch value with log output directly GetStringValue(obj, mirror); } //break; } } }
/// <summary> /// Get a dictionary of the function end points that are type compatible /// with the costs of the associated conversions /// </summary> /// <param name="context"></param> /// <param name="formalParams"></param> /// <param name="replicationInstructions"></param> /// <returns></returns> public Dictionary<FunctionEndPoint, int> GetConversionDistances(Runtime.Context context, List<StackValue> formalParams, List<ReplicationInstruction> replicationInstructions, ClassTable classTable, RuntimeCore runtimeCore, bool allowArrayPromotion = false) { Dictionary<FunctionEndPoint, int> ret = new Dictionary<FunctionEndPoint, int>(); //@PERF: Consider parallelising this List<FunctionEndPoint> feps = FunctionEndPoints; List<StackValue> reducedParamSVs = Replicator.EstimateReducedParams(formalParams, replicationInstructions, runtimeCore); foreach (FunctionEndPoint fep in feps) { int distance = fep.GetConversionDistance(reducedParamSVs, classTable, allowArrayPromotion, runtimeCore); if (distance != (int)ProcedureDistance.kInvalidDistance) ret.Add(fep, distance); } return ret; }
private bool IsFunctionGroupAccessible(RuntimeCore runtimeCore, ref FunctionGroup funcGroup) { bool methodAccessible = true; if (classScope != Constants.kGlobalScope) { // If last stack frame is not member function, then only public // functions are acessible in this context. int callerci, callerfi; runtimeCore.CurrentExecutive.CurrentDSASMExec.GetCallerInformation(out callerci, out callerfi); if (callerci == Constants.kGlobalScope || (classScope != callerci && !runtimeCore.DSExecutable.classTable.ClassNodes[classScope].IsMyBase(callerci))) { bool hasFEP = funcGroup.FunctionEndPoints.Count > 0; FunctionGroup visibleFuncGroup = new FunctionGroup(); visibleFuncGroup.CopyPublic(funcGroup.FunctionEndPoints); funcGroup = visibleFuncGroup; if (hasFEP && funcGroup.FunctionEndPoints.Count == 0) { methodAccessible = false; } } } return methodAccessible; }
public Dictionary<FunctionEndPoint, int> GetCastDistances(ProtoCore.Runtime.Context context, List<StackValue> formalParams, List<ReplicationInstruction> replicationInstructions, ClassTable classTable, RuntimeCore runtimeCore) { Dictionary<FunctionEndPoint, int> ret = new Dictionary<FunctionEndPoint, int>(); //@PERF: Consider parallelising this List<FunctionEndPoint> feps = FunctionEndPoints; List<StackValue> reducedParamSVs = Replicator.EstimateReducedParams(formalParams, replicationInstructions, runtimeCore); foreach (FunctionEndPoint fep in feps) { int dist = fep.ComputeCastDistance(reducedParamSVs, classTable, runtimeCore); ret.Add(fep, dist); } return ret; }
/// <summary> /// Get complete match attempts to locate a function endpoint where 1 FEP matches all of the requirements for dispatch /// </summary> /// <param name="context"></param> /// <param name="arguments"></param> /// <param name="funcGroup"></param> /// <param name="replicationControl"></param> /// <param name="stackFrame"></param> /// <param name="core"></param> /// <param name="log"></param> /// <returns></returns> private FunctionEndPoint Case1GetCompleteMatchFEP(Context context, List<StackValue> arguments, FunctionGroup funcGroup, List<ReplicationInstruction> replicationInstructions, StackFrame stackFrame, RuntimeCore runtimeCore, StringBuilder log) { //Exact match List<FunctionEndPoint> exactTypeMatchingCandindates = funcGroup.GetExactTypeMatches(context, arguments, replicationInstructions, stackFrame, runtimeCore); FunctionEndPoint fep = null; if (exactTypeMatchingCandindates.Count > 0) { if (exactTypeMatchingCandindates.Count == 1) { //Exact match fep = exactTypeMatchingCandindates[0]; log.AppendLine("1 exact match found - FEP selected" + fep); } else { //Exact match with upcast fep = SelectFEPFromMultiple(stackFrame, runtimeCore, exactTypeMatchingCandindates, arguments); log.AppendLine(exactTypeMatchingCandindates.Count + "exact matches found - FEP selected" + fep); } } return fep; }
//@TODO: Factor this into the type system public static StackValue ClassCoerece(StackValue sv, Type targetType, RuntimeCore runtimeCore) { //@TODO: Add proper coersion testing here. if (targetType.UID == (int)PrimitiveType.kTypeBool) return StackValue.BuildBoolean(true); return sv; }
/// <summary> /// Cretes a new instance of the RuntimeCore object /// </summary> private void CreateRuntimeCore() { runtimeCore = new ProtoCore.RuntimeCore(runnerCore.Heap, runnerCore.Options); runtimeCore.FFIPropertyChangedMonitor.FFIPropertyChangedEventHandler += FFIPropertyChanged; }
public static StackValue Coerce(StackValue sv, Type targetType, RuntimeCore runtimeCore) { ProtoCore.Runtime.RuntimeMemory rmem = runtimeCore.RuntimeMemory; //@TODO(Jun): FIX ME - abort coersion for default args if (sv.IsDefaultArgument) return sv; if (!( sv.metaData.type == targetType.UID || (runtimeCore.DSExecutable.classTable.ClassNodes[sv.metaData.type].ConvertibleTo(targetType.UID)) || sv.IsArray)) { runtimeCore.RuntimeStatus.LogWarning(Runtime.WarningID.kConversionNotPossible, Resources.kConvertNonConvertibleTypes); return StackValue.Null; } //if it's an array if (sv.IsArray && !targetType.IsIndexable) { //This is an array rank reduction //this may only be performed in recursion and is illegal here string errorMessage = String.Format(Resources.kConvertArrayToNonArray, runtimeCore.DSExecutable.TypeSystem.GetType(targetType.UID)); runtimeCore.RuntimeStatus.LogWarning(Runtime.WarningID.kConversionNotPossible, errorMessage); return StackValue.Null; } if (sv.IsArray && targetType.IsIndexable) { Validity.Assert(sv.IsArray); //We're being asked to convert an array into an array //walk over the structure converting each othe elements //Validity.Assert(targetType.rank != -1, "Arbitrary rank array conversion not yet implemented {2EAF557F-62DE-48F0-9BFA-F750BBCDF2CB}"); //Decrease level of reductions by one Type newTargetType = new Type(); newTargetType.UID = targetType.UID; if (targetType.rank != Constants.kArbitraryRank) { newTargetType.rank = targetType.rank - 1; } else { if (ArrayUtils.GetMaxRankForArray(sv, runtimeCore) == 1) { //Last unpacking newTargetType.rank = 0; } else { newTargetType.rank = Constants.kArbitraryRank; } } var array = runtimeCore.Heap.ToHeapObject<DSArray>(sv); return array.CopyArray(newTargetType, runtimeCore); } if (!sv.IsArray && !sv.IsNull && targetType.IsIndexable && targetType.rank != DSASM.Constants.kArbitraryRank) { //We're being asked to promote the value into an array if (targetType.rank == 1) { Type newTargetType = new Type(); newTargetType.UID = targetType.UID; newTargetType.Name = targetType.Name; newTargetType.rank = 0; //Upcast once StackValue coercedValue = Coerce(sv, newTargetType, runtimeCore); StackValue newSv = rmem.Heap.AllocateArray(new StackValue[] { coercedValue }); return newSv; } else { Validity.Assert(targetType.rank > 1, "Target rank should be greater than one for this clause"); Type newTargetType = new Type(); newTargetType.UID = targetType.UID; newTargetType.Name = targetType.Name; newTargetType.rank = targetType.rank - 1; //Upcast once StackValue coercedValue = Coerce(sv, newTargetType, runtimeCore); StackValue newSv = rmem.Heap.AllocateArray(new StackValue[] { coercedValue }); return newSv; } } if (sv.IsPointer) { StackValue ret = ClassCoerece(sv, targetType, runtimeCore); return ret; } //If it's anything other than array, just create a new copy switch (targetType.UID) { case (int)PrimitiveType.kInvalidType: runtimeCore.RuntimeStatus.LogWarning(Runtime.WarningID.kInvalidType, Resources.kInvalidType); return StackValue.Null; case (int)PrimitiveType.kTypeBool: return sv.ToBoolean(runtimeCore); case (int)PrimitiveType.kTypeChar: { StackValue newSV = sv.ShallowClone(); newSV.metaData = new MetaData { type = (int)PrimitiveType.kTypeChar }; return newSV; } case (int)PrimitiveType.kTypeDouble: return sv.ToDouble(); case (int)PrimitiveType.kTypeFunctionPointer: if (sv.metaData.type != (int)PrimitiveType.kTypeFunctionPointer) { runtimeCore.RuntimeStatus.LogWarning(Runtime.WarningID.kTypeMismatch, Resources.kFailToConverToFunction); return StackValue.Null; } return sv; case (int)PrimitiveType.kTypeInt: { if (sv.metaData.type == (int)PrimitiveType.kTypeDouble) { //TODO(lukechurch): Once the API is improved (MAGN-5174) //Replace this with a log entry notification //core.RuntimeStatus.LogWarning(RuntimeData.WarningID.kTypeConvertionCauseInfoLoss, Resources.kConvertDoubleToInt); } return sv.ToInteger(); } case (int)PrimitiveType.kTypeNull: { if (sv.metaData.type != (int)PrimitiveType.kTypeNull) { runtimeCore.RuntimeStatus.LogWarning(Runtime.WarningID.kTypeMismatch, Resources.kFailToConverToNull); return StackValue.Null; } return sv; } case (int)PrimitiveType.kTypePointer: { if (sv.metaData.type != (int)PrimitiveType.kTypeNull) { runtimeCore.RuntimeStatus.LogWarning(Runtime.WarningID.kTypeMismatch, Resources.kFailToConverToPointer); return StackValue.Null; } return sv; } case (int)PrimitiveType.kTypeString: { StackValue newSV = sv.ShallowClone(); newSV.metaData = new MetaData { type = (int)PrimitiveType.kTypeString }; if (sv.metaData.type == (int)PrimitiveType.kTypeChar) { char ch = EncodingUtils.ConvertInt64ToCharacter(newSV.opdata); newSV = StackValue.BuildString(ch.ToString(), rmem.Heap); } return newSV; } case (int)PrimitiveType.kTypeVar: { return sv; } case (int)PrimitiveType.kTypeArray: { var array = runtimeCore.Heap.ToHeapObject<DSArray>(sv); return array.CopyArray(targetType, runtimeCore); } default: if (sv.IsNull) return StackValue.Null; else throw new NotImplementedException("Requested coercion not implemented"); } throw new NotImplementedException("Requested coercion not implemented"); }
public void SetUpCallrForDebug(RuntimeCore runtimeCore, DSASM.Executive exec, ProcedureNode fNode, int pc, bool isBaseCall = false, CallSite callsite = null, List <StackValue> arguments = null, List <List <ReplicationGuide> > replicationGuides = null, StackFrame stackFrame = null, List <StackValue> dotCallDimensions = null, bool hasDebugInfo = false, bool isMember = false, StackValue?thisPtr = null) { //ProtoCore.DSASM.Executive exec = core.CurrentExecutive.CurrentDSASMExec; DebugFrame debugFrame = new DebugFrame(); debugFrame.IsBaseCall = isBaseCall; debugFrame.Arguments = arguments; debugFrame.IsMemberFunction = isMember; debugFrame.ThisPtr = thisPtr; debugFrame.HasDebugInfo = hasDebugInfo; if (CoreUtils.IsDisposeMethod(fNode.name)) { debugFrame.IsDisposeCall = true; ReturnPCFromDispose = DebugEntryPC; } if (RunMode == Runmode.StepNext) { debugFrame.FunctionStepOver = true; } bool isReplicating = false; bool isExternalFunction = false; // callsite is set to null for a base class constructor call in CALL if (callsite == null) { isReplicating = false; isExternalFunction = false; SetUpCallr(ref debugFrame, isReplicating, isExternalFunction, exec); DebugStackFrame.Push(debugFrame); return; } // Comment Jun: A dot call does not replicate and must be handled immediately if (fNode.name == Constants.kDotMethodName) { isReplicating = false; isExternalFunction = false; debugFrame.IsDotCall = true; debugFrame.DotCallDimensions = dotCallDimensions; SetUpCallr(ref debugFrame, isReplicating, isExternalFunction, exec); DebugStackFrame.Push(debugFrame); return; } List <List <ReplicationInstruction> > replicationTrials; bool willReplicate = callsite.WillCallReplicate(new Context(), arguments, replicationGuides, stackFrame, runtimeCore, out replicationTrials); // the inline conditional built-in is handled separately as 'WillCallReplicate' is always true in this case if (fNode.name.Equals(Constants.kInlineConditionalMethodName)) { // The inline conditional built-in is created only for associative blocks and needs to be handled separately as below InstructionStream istream = runtimeCore.DSExecutable.instrStreamList[CurrentBlockId]; Validity.Assert(istream.language == Language.kAssociative); { runtimeCore.DebugProps.InlineConditionOptions.isInlineConditional = true; runtimeCore.DebugProps.InlineConditionOptions.startPc = pc; runtimeCore.DebugProps.InlineConditionOptions.endPc = FindEndPCForAssocGraphNode(pc, istream, fNode, exec.Properties.executingGraphNode, runtimeCore.Options.ExecuteSSA); runtimeCore.DebugProps.InlineConditionOptions.instructionStream = runtimeCore.RunningBlock; debugFrame.IsInlineConditional = true; } // no replication case if (willReplicate && replicationTrials.Count == 1) { runtimeCore.DebugProps.InlineConditionOptions.ActiveBreakPoints.AddRange(runtimeCore.Breakpoints); /*if (core.DebugProps.RunMode == Runmode.StepNext) * { * core.Breakpoints.Clear(); * }*/ isReplicating = false; isExternalFunction = false; } else // an inline conditional call that replicates { #if !__DEBUG_REPLICATE // Clear all breakpoints for outermost replicated call if (!DebugStackFrameContains(StackFrameFlagOptions.IsReplicating)) { ActiveBreakPoints.AddRange(runtimeCore.Breakpoints); runtimeCore.Breakpoints.Clear(); } #endif isExternalFunction = false; isReplicating = true; } SetUpCallr(ref debugFrame, isReplicating, isExternalFunction, exec, 0); DebugStackFrame.Push(debugFrame); return; } // Prevent breaking inside a function that is external except for dot calls // by clearing all breakpoints from outermost external function call // This check takes precedence over the replication check else if (fNode.isExternal && fNode.name != Constants.kDotMethodName) { // Clear all breakpoints if (!DebugStackFrameContains(StackFrameFlagOptions.IsExternalFunction) && fNode.name != Constants.kFunctionRangeExpression) { ActiveBreakPoints.AddRange(runtimeCore.Breakpoints); runtimeCore.Breakpoints.Clear(); } isExternalFunction = true; isReplicating = false; } // Find if function call will replicate or not and if so // prevent stepping in by removing all breakpoints from outermost replicated call else if (willReplicate) { #if !__DEBUG_REPLICATE // Clear all breakpoints for outermost replicated call if (!DebugStackFrameContains(StackFrameFlagOptions.IsReplicating)) { ActiveBreakPoints.AddRange(runtimeCore.Breakpoints); runtimeCore.Breakpoints.Clear(); } #endif isReplicating = true; isExternalFunction = false; } // For all other function calls else { isReplicating = false; isExternalFunction = false; } SetUpCallr(ref debugFrame, isReplicating, isExternalFunction, exec); DebugStackFrame.Push(debugFrame); }