public YSStateModule()
    {
        Console.WriteLine ("Creating scope...");
        Global_Scope = new ScopeFrame ("", ScopeFrame.FrameTypes.None);
        Scope_Stack = new Stack<ScopeFrame> ();

        TemporaryStorage = new ScopeFrame();
        Console.WriteLine ("Finished Scope Creation...");
    }
Example #2
0
 private static object Resolve(string var, ScopeFrame scopeFrame)
 {
     object actual;
     if (var.Contains("."))
     {
         var parts = var.Split('.');
         actual = scopeFrame.Resolve(parts[0]);
         for (int i = 1; i < parts.Length; i++)
         {
             actual = ((IScope)actual).Resolve(parts[i]);
         }
     }
     else
     {
         actual = scopeFrame.Resolve(var);
     }
     return ToClrType(actual);
 }
    /* Address format:
     * <type>:<name>
     * s:<name> - structure
     * f:<name> - function
     * l:<name> - loop
     * u - unknown
     *
     * [feature redacted] ..	go back into parent scope
     * / 	global scope
     */
    void FindNameScope(IDPacket packet, out ScopeFrame scope)
    {
        Debug("Attempting to find scope of " + packet.Address + ", name: " + packet.Name);
        if (packet.Address.Length == 0) {
            scope = TemporaryStorage;
            return;
        }
        string[] _path = packet.Address.Split ('/');
        List<string> pathList = new List<string>();
        foreach (string tok in _path)
            if (tok.Length > 0)
                pathList.Add (tok);

        string[] path = pathList.ToArray ();
        scope = Global_Scope;
        int PARENT_COUNTER = 0;
        ScopeFrame[] _SS = Scope_Stack.ToArray ();
        for (int i = 0; i < path.Length; i++) {
            string str = path [i];

            /* -- parent keyword feature has been removed
             *
            if (str.Equals (IDPacket.PARENT_TYPE)) {
                scope = _SS [_SS.Length - 1 - ++PARENT_COUNTER];
                continue;
            }
            */

            string[] addr_parts = str.Split (':');
            string addr_type = addr_parts [0], addr_name = addr_parts [1];

            if (!addr_type.Equals ("s")) {
                Debug ("Searching scope stack...");
                if (_SS [i].Name.Equals (addr_name)) {
                    Debug (String.Format ("Found {0} on top of {1}", addr_name, scope.Name));
                    scope = _SS [i];
                } else {
                    Debug (String.Format ("Didn't find {0} on top of {1}", addr_name, scope.Name));
                }
            } else {
                Debug ("Searching Generics...");
                GenericFrame schild;
                if (scope.Generics.TryGetValue (addr_name, out schild)) {
                    Debug ("[Generic] Child " + addr_name + " found");
                    scope = StructureFrame.Appropriate (addr_name, schild);
                } else {
                    Error (String.Format ("There is no structure named {0} in the scope", addr_name));
                }
            }
        }
        Debug ("Exiting Finder");
    }
 public void PushScope(ScopeFrame push)
 {
     if (push.Name == "")
         Error ("Scope above Level 0 cannot have no name");
     Scope_Stack.Push (push);
 }
    public ScopeFrame CreateParseFunctionScope(FunctionFrame ftype, string FunctionName)
    {
        ScopeFrame fscope = new ScopeFrame (current_scope, FunctionName, ScopeFrame.FrameTypes.Function);

        fscope.Name = FunctionName;
        fscope.Type = ScopeFrame.FrameTypes.Function;
        PushScope (fscope);
        foreach (FunctionParameter fp in ftype.Parameters) {
            if (IsPrimitive (fp.Type)) {
                CreateParsePrimitive (fp.Name, fp.Type);
            } else if (fp.Type == IdentityType.Structure) {
                StructureFrame trash = new StructureFrame();
                PutParseStructure (fp.Name, trash);
            } else if (fp.Type == IdentityType.Function) {
                FunctionFrame trash = new FunctionFrame();
                PutParseFunction (fp.Name, trash);
            } else {
                Error ("Unknown parameter type, cannot create function scope");
            }
        }
        return PopScopeNoSave ();
    }
        public static ScopeFrame Appropriate(string name, GenericFrame gframe)
        {
            ScopeFrame scope = new ScopeFrame ();
            scope.Type = ScopeFrame.FrameTypes.Structure;
            scope.Name = name;

            scope.Primitives = gframe.Primitives;
            scope.Generics = gframe.Generics;
            scope.Functions = gframe.Functions;

            return scope;
        }
 public ScopeFrame UpdateOriginal(ScopeFrame original)
 {
     return (ScopeFrame)base.UpdateOriginal ((StructureFrame)original);
 }
 public void Merge(ScopeFrame merge)
 {
     base.Merge ((StructureFrame)merge);
 }
 public ScopeFrame(ScopeFrame original)
     : base((StructureFrame) original)
 {
     Name = original.Name;
     Type = original.Type;
 }
Example #10
0
        public static GenericFrame CopyAndPreserveHeirarchy(GenericFrame oval)
        {
            ScopeFrame SCF = new ScopeFrame ();
            StructureFrame SF = new StructureFrame ();
            ArrayFrame AF = new ArrayFrame ();
            GenericFrame GF = new GenericFrame ();

            if (GF.GetType () == oval.GetType ()) {
                return oval;
            } else if (AF.GetType () == oval.GetType ()) {
                AF = (ArrayFrame)oval;
                return AF;
            } else if (SF.GetType () == oval.GetType ()) {
                SF = (StructureFrame)oval;
                return SF;
            } else {
                SCF = (ScopeFrame)oval;
                return SCF;
            }
        }