private static HashSet <SppfNode> GetAllNodes(SymbolNode sppf) { var nodes = new HashSet <SppfNode>(); var stack = new Stack <SppfNode>(); stack.Push(sppf); while (stack.Count > 0) { var node = stack.Pop(); if (nodes.Contains(node)) { continue; } nodes.Add(node); foreach (var family in node.Families) { foreach (var child in family.Members) { stack.Push(child); } } } return(nodes); }
public void Bind(SymbolNode symbol) { IdentifierNode = new BoundIdentifierNode(Identifier, symbol, IdentifierNode.LineNumber, Index) { ParentNode = this }; }
private ValueNode ParseQuote(ParseInfo info, ref int index) { var node = new ConsNode(); node.Args = new List <object>(); var idNode = new SymbolNode(); idNode.Name = "quote"; idNode.CodeStartIndex = index; idNode.CodeLength = 1; SetupNode(info, idNode); node.Args.Add(idNode); node.CodeStartIndex = index; index++; object expression = ParseArg(info, ref index); node.Args.Add(expression); node.CodeLength = index - node.CodeStartIndex; SetupNode(info, node); return(node); }
public void Reset() { buttonColors.normalColor = normalColor; button.colors = buttonColors; representation = new SymbolNode(); representation.Id = gameObject.name; }
protected void ParseBaseTypes() { if (baseTypeTokens == null) { return; } var baseTypes = new List <InheritableType>(); foreach (var tokens in baseTypeTokens) { if (!SymbolNode.CouldBeIdentifier(tokens)) { throw new UnexpectedTokenException(tokens[0]); } var type = Expression.Parse(Scope, tokens); if (type.Root is SymbolNode symbolNode && symbolNode.Symbol is InheritableType) { baseTypes.Add(symbolNode.Symbol as InheritableType); // TODO: Declare self to base type caster here //var childTypeCaster = new FunctionType( // Token.Anonymous(""), // this, // Access.@public, // this, // $"!as_{ Name }", // new FunctionType.ParameterType[] {}, // new Token[] {} //); //Scope.Declare() }
public StackValue SetStackData(int blockId, int symbol, int classScope, Object data) { int offset = Constants.kInvalidIndex; SymbolNode symbolNode = null; if (Constants.kInvalidIndex == classScope) { symbolNode = Executable.runtimeSymbols[blockId].symbolList[symbol]; offset = GetStackIndex(symbolNode); } else { symbolNode = ClassTable.ClassNodes[classScope].symbols.symbolList[symbol]; offset = GetStackIndex(symbolNode); } Validity.Assert(null != symbolNode); UpdateModifiedSymbols(symbolNode); int n = GetRelative(offset); StackValue opPrev = Stack[n]; Stack[n] = (null == data) ? Pop() : (StackValue)data; return(opPrev); }
public void Bind(SymbolNode symbol) { IdentifierNode = new BoundIdentifierNode(Identifier, symbol, IdentifierNode.LineNumber, IdentifierNode.Index); }
private INode ParseIdentifier(string identifier) { INode node; switch (identifier) { case "nil": node = NilNode.Instance; break; case "true": node = BooleanNode.True; break; case "false": node = BooleanNode.False; break; default: node = new SymbolNode(identifier); break; } return(node); }
private INode EvaluateBuiltinFunction(SymbolNode head, List <INode> tail, Environment env) { var functionName = head.Value; if (!_builtinFunctions.ContainsKey(functionName)) { return(new ErrorNode($"function is not defined: {functionName}")); } var function = _builtinFunctions[functionName]; var expectedTypeAttr = function.GetMethodInfo().GetCustomAttribute <ExpectedTypeAttribute>(); if (expectedTypeAttr != null) { var expectedType = expectedTypeAttr.ExpectedType; foreach (var arg in tail) { var actualType = arg.GetType(); if (actualType != expectedType) { return(new ErrorNode($"expected argument of type {expectedType} but got type {actualType}")); } } } var expectedTypesAttr = function.GetMethodInfo().GetCustomAttribute <ExpectedTypesAttribute>(); if (expectedTypesAttr != null) { var expectedTypes = expectedTypesAttr.ExpectedTypes; var expectedCount = expectedTypes.Length; var actualCount = tail.Count; if (actualCount != expectedCount) { return(new ErrorNode($"function takes exactly {expectedCount} arguments ({actualCount} given)")); } for (var i = 0; i < expectedCount; i++) { var expectedType = expectedTypes[i]; var actualType = tail[i].GetType(); if (expectedType == typeof(INode)) { continue; } if (actualType != expectedType) { return(new ErrorNode($"expected argument of type {expectedType} but got type {actualType}")); } } } return(function.Invoke(tail, env)); }
public void Should_call_compatible_method() { var sampleVisitor = new SampleVisitor(); var symbol = new SymbolNode("foo"); sampleVisitor.Invoke("Visit", symbol); sampleVisitor.NumberOfTimesCalled.ShouldBe(1); }
public void Should_throw_exception_when_defining_already_defined_symbol() { var symbol = new SymbolNode("foo"); var scope = new AnonymousScope <SymbolNode>(null); // Defining the same scope twice should cause an error scope.Define(symbol.Symbol, symbol); scope.Define(symbol.Symbol, symbol); }
public void Should_resolve_defined_symbol() { var symbol = new SymbolNode("foo"); var scope = new AnonymousScope <SymbolNode>(null); scope.Define(symbol.Symbol, symbol); scope.Resolve("foo").ShouldBe(symbol); }
private void CreateSearchNodes() { // "flat" structure root = new SymbolNode("Test template", "", "testTemplace.zzz", 0, 0, SymbolNode.LibraryNodeType.Hierarchy); namespaceNode = new NamespaceNode("ClassLibrary1", "", "Class1.cs", 7, 0); classNode = new ModelNode("Class1", "ClassLibrary1.", "Class1.cs", 7, 17); memberNode = new MemberNode("GetBlaBlaBla", "ClassLibrary1.Class1.", "Class1.cs", 9, 22); ModelReferenceList classReferenceNode = new ModelReferenceList( @"C:\Users\sivanov\Documents\Visual Studio 2010\Projects\ClassLibrary1\ClassLibrary1\Class1.cs - (8, 18) : public class Class1(NDjango symbol)", @"C:\Users\sivanov\Documents\Visual Studio 2010\Projects\ClassLibrary1\ClassLibrary1\Class1.cs", "", 8, 18), classReferenceNode1 = new ModelReferenceList( @"C:\Users\sivanov\Documents\Visual Studio 2010\Projects\ClassLibrary1\ClassLibrary1\Class2.cs - (7, 13) : Class1 c1 = new Class1();(NDjango symbol)", @"C:\Users\sivanov\Documents\Visual Studio 2010\Projects\ClassLibrary1\ClassLibrary1\Class2.cs", "", 7, 13); classNode.AddChild(classReferenceNode); classNode.AddChild(classReferenceNode1); MemberReferenceList methodReferenceNode = new MemberReferenceList( @"C:\Users\sivanov\Documents\Visual Studio 2010\Projects\ClassLibrary1\ClassLibrary1\Class1.cs - (10, 23) : public Class1 GetBlaBlaBla()(NDjango symbol)", @"C:\Users\sivanov\Documents\Visual Studio 2010\Projects\ClassLibrary1\ClassLibrary1\Class1.cs", "", 10, 23), methodReferenceNode1 = new MemberReferenceList( @"C:\Users\sivanov\Documents\Visual Studio 2010\Projects\ClassLibrary1\ClassLibrary1\Class1.cs - (0, 0) : public Class1 GetBlaBlaBla()(NDjango symbol)", @"C:\Users\sivanov\Documents\Visual Studio 2010\Projects\ClassLibrary1\ClassLibrary1\Class1.cs", "", 0, 0), methodReferenceNode2 = new MemberReferenceList( @"C:\Users\sivanov\Documents\Visual Studio 2010\Projects\ClassLibrary1\ClassLibrary1\Class1.cs - (0, 0) : public Class1 GetBlaBlaBla()(NDjango symbol)", @"C:\Users\sivanov\Documents\Visual Studio 2010\Projects\ClassLibrary1\ClassLibrary1\Class1.cs", "", 0, 0); memberNode.AddChild(methodReferenceNode); memberNode.AddChild(methodReferenceNode1); memberNode.AddChild(methodReferenceNode2); NamespaceReferenceList nsl1 = new NamespaceReferenceList( @"C:\Users\sivanov\Documents\Visual Studio 2010\Projects\ClassLibrary1\ClassLibrary1\Class1.cs - (2, 2) (NDjango symbol)", @"C:\Users\sivanov\Documents\Visual Studio 2010\Projects\ClassLibrary1\ClassLibrary1\Class1.cs", "", 0, 0), nsl2 = new NamespaceReferenceList( @"C:\Users\sivanov\Documents\Visual Studio 2010\Projects\ClassLibrary1\ClassLibrary1\Class2.cs - (3, 3) (NDjango symbol)", @"C:\Users\sivanov\Documents\Visual Studio 2010\Projects\ClassLibrary1\ClassLibrary1\Class2.cs", "", 0, 0); namespaceNode.AddChild(nsl1); namespaceNode.AddChild(nsl2); root.AddChild(memberNode); root.AddChild(classNode); root.AddChild(namespaceNode); }
private bool ShouldBeConverted(INode <AstNode> node, SymbolNode symbolNode) { if (node == null || symbolNode == null) { return(false); } return(ShouldBeConverted(symbolNode) && node is ListNode); }
public IBoundScope <TItem> GetScope(SymbolNode node, IScope <TItem> parentScope) { // Method definitions don't count as scope references if (node is MethodDefinitionNode) { return(GetScope(node as MethodDefinitionNode, parentScope)); } return(new BoundScope <TItem>(parentScope, node)); }
/// <summary> /// Logs the unbound variable warning and sets the unbound symbol /// </summary> /// <param name="unboundSymbol"></param> /// <param name="message"></param> /// <param name="fileName"></param> /// <param name="line"></param> /// <param name="col"></param> /// <param name="graphNode"></param> public void LogUnboundVariableWarning( SymbolNode unboundSymbol, string message, string fileName = null, int line = -1, int col = -1, AssociativeGraph.GraphNode graphNode = null) { LogWarning(BuildData.WarningID.IdUnboundIdentifier, message, core.CurrentDSFileName, line, col, graphNode, unboundSymbol); }
public static SymbolNode ResolveSymbolNode(SymbolNode n) { if (n.Symbol is CompositeType) { return(ResolveCompositeType(n.Symbol as CompositeType)); } else { return(n); } }
public void Should_return_root_scope_by_default() { var globalScope = new GlobalScope <SymbolNode>(); var node = new SymbolNode("abc"); var builder = CreateScopeBuilder(globalScope); var scope = builder.Visit(node); scope.ShouldBeOfType <BoundScope <SymbolNode> >(); scope.TargetScope.ShouldBe(globalScope); scope.Node.ShouldBe(node); }
protected internal override INode Build(Dictionary <dynNodeModel, Dictionary <int, INode> > preBuilt, int outPort) { Dictionary <int, INode> result; if (!preBuilt.TryGetValue(this, out result)) { result = new Dictionary <int, INode>(); result[outPort] = new SymbolNode(GUID.ToString()); preBuilt[this] = result; } return(result[outPort]); }
public void Should_scope_method_body() { var fooNode = new SymbolNode("foo"); var body = new ListNode(fooNode); var methodDefinitionNode = new MethodDefinitionNode("sayMessage", new ParameterDefinitionNode[] { new ParameterDefinitionNode("message"), }, body); var globalScope = new GlobalScope <SymbolNode>(); var builder = CreateScopeBuilder(globalScope); var resultScope = builder.GetScope(methodDefinitionNode, globalScope); resultScope.Descendants().OfType <BoundScope <SymbolNode> >().Any(scope => scope.Node == fooNode).ShouldBe(true); }
private void UpdateModifiedSymbols(SymbolNode symbol) { Validity.Assert(null != symbol); Validity.Assert(!string.IsNullOrEmpty(symbol.name)); Validity.Assert(null != mapModifiedSymbols); // TODO Jun: Turn this into a multi-key dictionary where the keys are: name, classindex and procindex string key = symbol.name; if (!mapModifiedSymbols.ContainsKey(key)) { mapModifiedSymbols.Add(key, symbol); } }
protected override void POPM_Handler(Instruction instruction) { int blockId; int ci = Constants.kInvalidIndex; StackValue svData = POPM_Helper(instruction, out blockId, out ci); //if (callrLineNo != Constants.kInvalidIndex) { SymbolNode symbolNode = null; if (instruction.op1.IsStaticVariableIndex) { symbolNode = exe.runtimeSymbols[blockId].symbolList[(int)instruction.op1.opdata]; } else { symbolNode = exe.classTable.ClassNodes[ci].symbols.symbolList[(int)instruction.op1.opdata]; } string symbolName = symbolNode.name; if (Core.Options.IDEDebugMode && Core.ExecMode != ProtoCore.DSASM.InterpreterMode.kExpressionInterpreter) { if (!Core.DebugProps.DebugStackFrameContains(DebugProperties.StackFrameFlagOptions.IsReplicating)) { Core.DebugProps.CurrentSymbolName = symbolName; Core.DebugProps.IsPopmCall = true; } } // Add stackvalue against lineNo and variable name if (!Core.Options.IDEDebugMode) { int lineNo = -1; if (instruction.debug == null) { lineNo = callrLineNo; } // In Imperative block, POPM instruction has debug info so in this case we get the correct line no. from debug info else { lineNo = instruction.debug.Location.StartInclusive.LineNo; } if (IsPopToPropertyArray) { svData = propSV; IsPopToPropertyArray = false; } Print(svData, lineNo, symbolName, ci); } } }
private void UpdateModifiedSymbols(SymbolNode symbol) { Validity.Assert(null != symbol); Validity.Assert(!string.IsNullOrEmpty(symbol.name)); Validity.Assert(null != mapModifiedSymbols); // TODO Jun: Turn this into a multi-key dictionary where the keys are: name, classindex and procindex string key = symbol.name; if (!mapModifiedSymbols.ContainsKey(key)) { mapModifiedSymbols.Add(key, symbol); } }
void Awake() { //Get button and associated colors button = gameObject.GetComponent <Button>(); buttonColors = button.colors; normalColor = buttonColors.normalColor; pressedColor = buttonColors.pressedColor; //Add click event listener to button button.onClick.AddListener(ClickHandler); //Setup node representation of button representation = new SymbolNode(); representation.Id = gameObject.name; }
private void CompareSymbolSets() { //Compare input to the list of know symbols foreach (var symbol in symbols) { //Debug.Log(inputSymbol); //If a button wasn't selected this will be null if (inputSymbol != null) { //Debug.Log("Input Symbol: " + inputSymbol); //Debug.Log("Comparison Symbol: " + symbol); //Check to see if the user entered a correct symbol if (inputSymbol.Equals(symbol)) { //Debug.Log("The user entered a correct combination."); foreach (var abstraction in abstractSymbols) { //Construct the comparison string of a symbol from the associated gameobject Symbol _symbol = abstraction.GetComponent <Symbol>(); string[] symbolArray = _symbol.symbol; string symbolPath = symbolArray[0]; for (int i = 1; i < symbolArray.Length; i++) { symbolPath += "-->" + symbolArray[i]; } //Determine which symbol game object to be used after user entered the correct symbol if (symbol.Equals(symbolPath) && _gestureMeter.isMeterAvailable) { //Debug.Log("Successfully constructed symbol from gameobject inputs"); //Debug.Log("Path: " + symbolPath); //Debug.Log("Actual Symbol: " + symbol); _symbol.item.SetActive(true); _gestureMeter.DecrementMeter(_symbol.itemCost); symbolInterface.SetActive(false); currentNode = null; inputSymbol = ""; foreach (var button in buttons) { button.Reset(); } } } } } } }
public override string ToString() { //Show node and all following nodes string symbol = Id; SymbolNode nextNode = Next; while (nextNode != null) { symbol += "-->" + nextNode.Id; nextNode = nextNode.Next; } return(symbol); }
/// <summary> /// Return stack index of symbol for specified frame. /// </summary> /// <param name="symbol"></param> /// <param name="framePointer"></param> /// <returns></returns> private int GetStackIndex(SymbolNode symbol, int framePointer) { int offset = symbol.index; if (symbol.absoluteClassScope != Constants.kGlobalScope || symbol.absoluteFunctionIndex != Constants.kGlobalScope) { int depth = (int)GetAtRelative(StackFrame.kFrameIndexStackFrameDepth, framePointer).opdata; int blockOffset = depth * StackFrame.kStackFrameSize; offset -= blockOffset; } return(offset >= 0 ? offset : framePointer + offset); }
public void PushSymbolReference(SymbolNode symbol, UpdateNodeType type = UpdateNodeType.kSymbol) { Validity.Assert(null != symbol); UpdateNode updateNode = new UpdateNode(); updateNode.symbol = symbol; updateNode.nodeType = type; UpdateNodeRef nodeRef = new UpdateNodeRef(); nodeRef.PushUpdateNode(updateNode); updateNodeRefList.Add(nodeRef); }
// // 1. Get the graphnode given the varname // 2. Get the sv of the symbol // 3. set the sv to the new value // 4. Get all graphnpodes dependent on the symbol and mark them dirty // 5. Re-execute the script // proc AssociativeEngine.SetValue(string varname, int block, StackValue, sv) // symbol = dsEXE.GetSymbol(varname, block) // globalStackIndex = symbol.stackindex // runtime.stack[globalStackIndex] = sv // AssociativeEngine.Propagate(symbol) // runtime.Execute() // end // private bool SetValue(string varName, int?value, out int nodesMarkedDirty) { int blockId = 0; // 1. Get the graphnode given the varname AssociativeGraph.GraphNode graphNode = MirrorTarget.GetFirstGraphNode(varName, out blockId); if (graphNode == null) { nodesMarkedDirty = 0; return(false); } SymbolNode symbol = graphNode.updateNodeRefList[0].nodeList[0].symbol; // 2. Get the sv of the symbol int globalStackIndex = symbol.index; // 3. set the sv to the new value StackValue sv; if (null == value) { sv = StackValue.Null; } else { sv = StackValue.BuildInt((long)value); } MirrorTarget.rmem.Stack[globalStackIndex] = sv; // 4. Get all graphnpodes dependent on the symbol and mark them dirty const int outerBlock = 0; ProtoCore.DSASM.Executable exe = MirrorTarget.exe; List <AssociativeGraph.GraphNode> reachableGraphNodes = AssociativeEngine.Utils.UpdateDependencyGraph( graphNode, MirrorTarget, graphNode.exprUID, false, runtimeCore.Options.ExecuteSSA, outerBlock, false); // Mark reachable nodes as dirty Validity.Assert(reachableGraphNodes != null); nodesMarkedDirty = reachableGraphNodes.Count; foreach (AssociativeGraph.GraphNode gnode in reachableGraphNodes) { gnode.isDirty = true; } // 5. Re-execute the script - re-execution occurs after this call return(true); }
public int AddSymbol(string ident, int size, int stackIndex, int funcIndex) { if (GetSymbolByIdent(ident, funcIndex) != null) { return(-1); } var newSym = new SymbolNode { ident = ident, stackIndex = stackIndex, funcIndex = funcIndex, index = table.Length }; table.Push(newSym); return(newSym.index); }
public void PushSymbolReference(SymbolNode symbol) { Validity.Assert(null != symbol); UpdateNode updateNode = new UpdateNode(); updateNode.symbol = symbol; updateNode.nodeType = UpdateNodeType.kSymbol; UpdateNodeRef nodeRef = new UpdateNodeRef(); nodeRef.block = symbol.runtimeTableIndex; nodeRef.PushUpdateNode(updateNode); updateNodeRefList.Add(nodeRef); }
public object Evaluate(SymbolNode node, Environment environment) { if (node.Name.StartsWith(".")) { return new NativeMethodFunctionNode(node.Name.Substring(1)); } if (node.Name.EndsWith(".")) { return new NativeConstructorFunctionNode(node.Name.TrimEnd('.')); } var split = node.Name.Split('/'); if (split.Length > 1) { if (split.Length != 2) { throw new ArgumentException("A symbol may not contain more than one '/'!"); } return new NativeStaticMethodFunctionNode(split[0], split[1]); } if (node.Name.Contains(".")) { Type t = AppDomain.CurrentDomain.GetAssemblies().Select(a => a.GetType(node.Name, false, false)).FirstOrDefault(x => x != null); return t; } if (environment.CanLookUpSymbol(node)) { return environment.LookUpSymbol(node); } throw new ArgumentException("Could not resolve symbol: " + node.Name); }
private int GetSymbolIndex(string name, out int ci, ref int block, out SymbolNode symbol) { ProtoCore.DSASM.Executable exe = core.Rmem.Executable; int functionIndex = Constants.kGlobalScope; ci = Constants.kInvalidIndex; int functionBlock = Constants.kGlobalScope; if (core.DebugProps.DebugStackFrameContains(DebugProperties.StackFrameFlagOptions.FepRun)) { ci = core.watchClassScope = (int)core.Rmem.GetAtRelative(core.Rmem.GetStackIndex(ProtoCore.DSASM.StackFrame.kFrameIndexClass)).opdata; functionIndex = (int)core.Rmem.GetAtRelative(core.Rmem.GetStackIndex(ProtoCore.DSASM.StackFrame.kFrameIndexFunction)).opdata; functionBlock = (int)core.Rmem.GetAtRelative(core.Rmem.GetStackIndex(ProtoCore.DSASM.StackFrame.kFrameIndexFunctionBlock)).opdata; } // TODO Jun: 'block' is incremented only if there was no other block provided by the programmer // This is only to address NUnit issues when retrieving a global variable // Some predefined functions are hard coded in the AST so isSingleAssocBlock will never be true //if (exe.isSingleAssocBlock) //{ // ++block; //} int index = -1; if (ci != Constants.kInvalidIndex) { ClassNode classnode = core.Rmem.Executable.classTable.ClassNodes[ci]; if (functionIndex != ProtoCore.DSASM.Constants.kInvalidIndex && functionBlock != core.RunningBlock) { index = exe.runtimeSymbols[block].IndexOf(name, Constants.kGlobalScope, Constants.kGlobalScope); } if (index == Constants.kInvalidIndex) { index = classnode.symbols.IndexOfClass(name, ci, functionIndex); } if (index != Constants.kInvalidIndex) { if (classnode.symbols.symbolList[index].arraySizeList != null) { throw new NotImplementedException("{C5877FF2-968D-444C-897F-FE83650D5201}"); } symbol = classnode.symbols.symbolList[index]; return index; } } else { CodeBlock searchBlock = core.CompleteCodeBlockList[block]; // To detal with the case that a language block defined in a function // // def foo() // { // [Imperative] // { // a; // } // } if (functionIndex != ProtoCore.DSASM.Constants.kInvalidIndex) { if (searchBlock.IsMyAncestorBlock(functionBlock)) { while (searchBlock.codeBlockId != functionBlock) { index = exe.runtimeSymbols[searchBlock.codeBlockId].IndexOf(name, ci, ProtoCore.DSASM.Constants.kInvalidIndex); if (index == ProtoCore.DSASM.Constants.kInvalidIndex) { searchBlock = searchBlock.parent; } else { break; } } } if (index == ProtoCore.DSASM.Constants.kInvalidIndex) { index = exe.runtimeSymbols[searchBlock.codeBlockId].IndexOf(name, ci, functionIndex); } if (index == ProtoCore.DSASM.Constants.kInvalidIndex) { index = exe.runtimeSymbols[searchBlock.codeBlockId].IndexOf(name, ci, ProtoCore.DSASM.Constants.kInvalidIndex); } } else { index = exe.runtimeSymbols[searchBlock.codeBlockId].IndexOf(name, ci, ProtoCore.DSASM.Constants.kInvalidIndex); } if (index == ProtoCore.DSASM.Constants.kInvalidIndex) { searchBlock = searchBlock.parent; while (searchBlock != null) { block = searchBlock.codeBlockId; index = exe.runtimeSymbols[searchBlock.codeBlockId].IndexOf(name, ci, ProtoCore.DSASM.Constants.kInvalidIndex); if (index != ProtoCore.DSASM.Constants.kInvalidIndex) { break; } else { searchBlock = searchBlock.parent; } } } if (index != ProtoCore.DSASM.Constants.kInvalidIndex) { if (exe.runtimeSymbols[searchBlock.codeBlockId].symbolList[index].arraySizeList != null) { throw new NotImplementedException("{C5877FF2-968D-444C-897F-FE83650D5201}"); } block = searchBlock.codeBlockId; symbol = exe.runtimeSymbols[searchBlock.codeBlockId].symbolList[index]; return index; } //if (block == 0) //{ // for (block = 0; block < exe.runtimeSymbols.Length; ++block) // { // index = exe.runtimeSymbols[block].IndexOf(name, ci, functionIndex); // if (index != -1) // break; // } //} //else //{ // while (block >= 0) // { // index = exe.runtimeSymbols[block].IndexOf(name, ci, functionIndex); // if (index != -1) // break; // else // block--; // } //} } throw new NameNotFoundException { Name = name }; //throw new NotImplementedException("{F5ACC95F-AEC9-486D-BC82-FF2CB26E7E6A}"); //@TODO(Luke): Replace this with a symbol lookup exception }
private void PrettyPrintSub(SymbolNode node) { stringWriter.Write(node.Name); }
public void SetAtSymbol(SymbolNode symbol, StackValue data) { int n = GetRelative(GetStackIndex(symbol)); Stack[n] = data; }
private int GetSymbolIndex(string name, out int ci, ref int block, out SymbolNode symbol) { RuntimeMemory rmem = MirrorTarget.rmem; ProtoCore.DSASM.Executable exe = runtimeCore.DSExecutable; int functionIndex = Constants.kGlobalScope; ci = Constants.kInvalidIndex; int functionBlock = Constants.kGlobalScope; if (runtimeCore.DebugProps.DebugStackFrameContains(DebugProperties.StackFrameFlagOptions.FepRun)) { ci = runtimeCore.watchClassScope = rmem.CurrentStackFrame.ClassScope; functionIndex = rmem.CurrentStackFrame.FunctionScope; functionBlock = rmem.CurrentStackFrame.FunctionBlock; } // TODO Jun: 'block' is incremented only if there was no other block provided by the programmer // This is only to address NUnit issues when retrieving a global variable // Some predefined functions are hard coded in the AST so isSingleAssocBlock will never be true //if (exe.isSingleAssocBlock) //{ // ++block; //} int index = -1; if (ci != Constants.kInvalidIndex) { ClassNode classnode = runtimeCore.DSExecutable.classTable.ClassNodes[ci]; if (functionIndex != ProtoCore.DSASM.Constants.kInvalidIndex && functionBlock != runtimeCore.RunningBlock) { index = exe.runtimeSymbols[block].IndexOf(name, Constants.kGlobalScope, Constants.kGlobalScope); } if (index == Constants.kInvalidIndex) { index = classnode.Symbols.IndexOfClass(name, ci, functionIndex); } if (index != Constants.kInvalidIndex) { symbol = classnode.Symbols.symbolList[index]; return index; } } else { CodeBlock searchBlock = runtimeCore.DSExecutable.CompleteCodeBlocks[block]; // To detal with the case that a language block defined in a function // // def foo() // { // [Imperative] // { // a; // } // } if (functionIndex != ProtoCore.DSASM.Constants.kInvalidIndex) { if (searchBlock.IsMyAncestorBlock(functionBlock)) { while (searchBlock.codeBlockId != functionBlock) { index = exe.runtimeSymbols[searchBlock.codeBlockId].IndexOf(name, ci, ProtoCore.DSASM.Constants.kInvalidIndex); if (index == ProtoCore.DSASM.Constants.kInvalidIndex) { searchBlock = searchBlock.parent; } else { break; } } } if (index == ProtoCore.DSASM.Constants.kInvalidIndex) { index = exe.runtimeSymbols[searchBlock.codeBlockId].IndexOf(name, ci, functionIndex); } if (index == ProtoCore.DSASM.Constants.kInvalidIndex) { index = exe.runtimeSymbols[searchBlock.codeBlockId].IndexOf(name, ci, ProtoCore.DSASM.Constants.kInvalidIndex); } } else { index = exe.runtimeSymbols[searchBlock.codeBlockId].IndexOf(name, ci, ProtoCore.DSASM.Constants.kInvalidIndex); } if (index == ProtoCore.DSASM.Constants.kInvalidIndex) { searchBlock = searchBlock.parent; while (searchBlock != null) { block = searchBlock.codeBlockId; index = exe.runtimeSymbols[searchBlock.codeBlockId].IndexOf(name, ci, ProtoCore.DSASM.Constants.kInvalidIndex); if (index != ProtoCore.DSASM.Constants.kInvalidIndex) { break; } else { searchBlock = searchBlock.parent; } } } if (index != ProtoCore.DSASM.Constants.kInvalidIndex) { block = searchBlock.codeBlockId; symbol = exe.runtimeSymbols[searchBlock.codeBlockId].symbolList[index]; return index; } } throw new NameNotFoundException { Name = name }; //throw new NotImplementedException("{F5ACC95F-AEC9-486D-BC82-FF2CB26E7E6A}"); //@TODO(Luke): Replace this with a symbol lookup exception }
public StackValue GetAtRelative(SymbolNode symbol) { int n = GetRelative(GetStackIndex(symbol)); return Stack[n]; }
public int GetStackIndex(SymbolNode symbolNode) { int offset = symbolNode.index; int depth = 0; int blockOffset = 0; // TODO Jun: the property 'localFunctionIndex' must be deprecated and just use 'functionIndex'. // The GC currenlty has an issue of needing to reset 'functionIndex' at codegen bool isGlobal = Constants.kInvalidIndex == symbolNode.absoluteClassScope && Constants.kGlobalScope == symbolNode.absoluteFunctionIndex; if (!isGlobal) { depth = (int)GetAtRelative(ProtoCore.DSASM.StackFrame.kFrameIndexStackFrameDepth).opdata; blockOffset = depth * StackFrame.kStackFrameSize; } offset -= blockOffset; return offset; }
protected internal override INode Build(Dictionary<dynNodeModel, Dictionary<int, INode>> preBuilt, int outPort) { Dictionary<int, INode> result; if (!preBuilt.TryGetValue(this, out result)) { result = new Dictionary<int, INode>(); result[outPort] = new SymbolNode(GUID.ToString()); preBuilt[this] = result; } return result[outPort]; }