예제 #1
0
 public void PutParseFunction(string name, FunctionFrame value)
 {
     if (!current_scope.Functions.ContainsKey(name))
     {
         current_scope.Functions.Add(name, value);
     }
 }
예제 #2
0
        /// <summary>
        /// Resets execution of the script context.
        /// </summary>
        public void Reset()
        {
            m_stackFunctionFrames.Clear();
            FunctionFrame functionFrame = new FunctionFrame();

            functionFrame.m_scriptFunction = m_scriptFunction;
            functionFrame.m_variableDictionary
                = VariableDictionary.CreateLocalDictionary(
                      m_scriptExecutable.ScriptDictionary);
            functionFrame.m_iNextInstruction = (int)m_scriptFunction.EntryPoint.Address;
            m_stackFunctionFrames.Push(functionFrame);

            m_stackParameters.Clear();

            m_scriptInstruction       = null;
            m_variableDictionaryLocal = functionFrame.m_variableDictionary;

            // release all locks held by this context
            foreach (object objectLock in m_dictLocks.Keys)
            {
                m_script.Manager.Locks.Remove(objectLock);
            }
            m_dictLocks.Clear();

            m_bTerminated = false;
            m_bInterruped = false;
        }
예제 #3
0
    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());
    }
예제 #4
0
        private void ProcessLOCK()
        {
            object objectValue
                = ResolveOperand(m_scriptInstruction.Operand0);

            if (objectValue.GetType() == typeof(NullReference))
            {
                throw new ExecutionException("Lock key must be a literal value.");
            }

            if (m_script.Manager.Locks.ContainsKey(objectValue))
            {
                ScriptContext scriptContextLocks
                    = m_script.Manager.Locks[objectValue];
                if (scriptContextLocks == this && m_dictLocks[objectValue] != m_scriptInstruction)
                {
                    throw new ExecutionException(
                              "Nested locks cannot share the same locking key.");
                }

                // repeat instruction
                FunctionFrame functionFrame = m_stackFunctionFrames.Peek();
                --functionFrame.m_iNextInstruction;


                // interrupt
                m_bInterruped = true;
            }
            else
            {
                m_script.Manager.Locks[objectValue] = this;
                m_dictLocks[objectValue]            = m_scriptInstruction;
            }
        }
예제 #5
0
        public void Merge(GenericFrame merge)
        {
            //Copy primitives

            if (Primitives.Numbers != null && merge.Primitives.Numbers != null)
            {
                foreach (string key in merge.Primitives.Numbers.Keys)
                {
                    double val;
                    merge.Primitives.Numbers.TryGetValue(key, out val);
                    Primitives.Numbers.Add(key, val);
                }
            }

            if (Primitives.Booleans != null && merge.Primitives.Booleans != null)
            {
                foreach (string key in merge.Primitives.Booleans.Keys)
                {
                    bool val;
                    merge.Primitives.Booleans.TryGetValue(key, out val);
                    Primitives.Booleans.Add(key, val);
                }
            }

            if (Primitives.Text != null && merge.Primitives.Text != null)
            {
                foreach (string key in merge.Primitives.Text.Keys)
                {
                    string val;
                    merge.Primitives.Text.TryGetValue(key, out val);
                    Primitives.Text.Add(key, val);
                }
            }

            //copy structures
            if (Generics != null && merge.Generics != null)
            {
                foreach (string key in merge.Generics.Keys)
                {
                    GenericFrame oval;
                    merge.Generics.TryGetValue(key, out oval);
                    //TODO Preserve the heirarchy

                    GenericFrame cval = GenericFrame.CopyAndPreserveHeirarchy(oval);                     //new GenericFrame (oval);
                    Generics.Add(key, cval);
                }
            }

            //copy functions
            if (Functions != null && merge.Functions != null)
            {
                foreach (string key in merge.Functions.Keys)
                {
                    FunctionFrame oval;
                    merge.Functions.TryGetValue(key, out oval);
                    FunctionFrame cval = new FunctionFrame(oval);
                    Functions.Add(key, cval);
                }
            }
        }
예제 #6
0
    public bool TryGetFunction(IDPacket packet, out FunctionFrame value)
    {
        ScopeFrame scope;

        FindNameScope(packet, out scope);
        return(scope.Functions.TryGetValue(packet.Name, out value));
    }
예제 #7
0
        private void ProcessJMP()
        {
            ScriptInstruction scriptInstructionTarget
                = m_scriptInstruction.Operand0.InstructionRef;
            FunctionFrame functionFrame = m_stackFunctionFrames.Peek();

            functionFrame.m_iNextInstruction
                = (int)scriptInstructionTarget.Address;
        }
예제 #8
0
    public ScopeFrame CreateFunctionScope(FunctionFrame ftype, string FunctionName, List <IDPacket> Bindings)
    {
        ScopeFrame fscope = CreateParseFunctionScope(ftype, FunctionName);

        //delete function frame inside scope
        fscope.Functions.Remove(FunctionName);

        PushScope(fscope);
        int BINDCNT = 0;

        foreach (FunctionParameter fp in ftype.Parameters)
        {
            IDPacket Binding = Bindings [BINDCNT];
            IDPacket Address = IDPacket.CreateIDPacket(this, fp.Name, Binding.Type);
            if (Binding.Type != fp.Type)
            {
                Error("Binding Error: Parameter type mismatch, expected: " + fp.Type + " got " + Binding.Type);
            }
            if (Binding.ArrayType != IdentityType.Unknown)
            {
                if (fp.TypeDimensions != null)
                {
                    if (Binding.ArrayType != fp.Type)
                    {
                        Error("Binding Error: Parameter type mismatch, expected: Array of " + fp.Type + " got Array of " + Binding.ArrayType);
                    }
                    int dcnt = 0;
                    foreach (int dim in fp.TypeDimensions)
                    {
                        if (dim == -1)
                        {
                            continue;
                        }
                        if (dim != Binding.TypeDimensions [dcnt++])
                        {
                            Error(String.Format("Binding Error: Dimension Mismatch, expecting {0} got {1}", fp.TypeDimensions,
                                                Binding.TypeDimensions));
                        }
                    }
                }
                else
                {
                    Error(String.Format("Binding Error: Expecting a Primitive {0} got Array of {1}", fp.Type, Binding.ArrayType));
                }
            }
            else if (fp.TypeDimensions != null)
            {
                Error(String.Format("Binding Error: Expecting an Array of {0} got Primitive {1}", fp.Type, Binding.ArrayType));
            }

            COPY(Address, Binding);
            Debug("After copy");
        }
        return(PopScopeNoSave());
    }
예제 #9
0
 void RegisterFunction(string name, FunctionFrame ftype)
 {
     if (!IdentityExists(name))
     {
         current_scope.Functions.Add(name, ftype);
     }
     else
     {
         Error("Function with name " + name + " already exists.");
     }
 }
예제 #10
0
        public FunctionFrame(FunctionFrame original)
        {
            Start      = original.Start;
            Returns    = original.Returns;
            Parameters = new List <FunctionParameter> ();

            foreach (FunctionParameter ofp in original.Parameters)
            {
                FunctionParameter copyfp = new FunctionParameter(ofp);
                Parameters.Add(copyfp);
            }
        }
예제 #11
0
    public void PutFunction(IDPacket packet, FunctionFrame function)
    {
        ScopeFrame scope;

        FindNameScope(packet, out scope);
        FunctionFrame trash;

        if (TryGetFunction(packet, out trash))
        {
            scope.Functions [packet.Name] = function;
        }
        else
        {
            scope.Functions.Add(packet.Name, function);
        }
    }
예제 #12
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            Home HomeFrame = new Home(this);

            MainFrame.Navigate(HomeFrame);

            RightMenu rightMenuFrame = new RightMenu(this);

            FunctionFrame.Navigate(rightMenuFrame);

            Archives archivesFrame = new Archives(this);

            ProductFrame.Navigate(archivesFrame);

            LeftMenu leftMenuFrame = new LeftMenu(this);

            UserFrame.Navigate(leftMenuFrame);
        }
예제 #13
0
        private void ProcessJF()
        {
            object objectCondition
                = ResolveOperand(m_scriptInstruction.Operand0);
            bool bCondition = (bool)objectCondition;

            if (bCondition)
            {
                return;
            }

            ScriptInstruction scriptInstructionTarget
                = m_scriptInstruction.Operand1.InstructionRef;
            FunctionFrame functionFrame = m_stackFunctionFrames.Peek();

            functionFrame.m_iNextInstruction
                = (int)scriptInstructionTarget.Address;
        }
예제 #14
0
 public void PrintCallstack(params string[] args)
 {
     OutputWriter.WriteLine("Stack Size: " + (callStack.Count));
     PrintLine();
     PrintRow("Type", "Identifier", "Arguments");
     PrintLine();
     foreach (CallFrame structure in callStack.ToArray())
     {
         if (structure.GetType() == typeof(FunctionFrame))
         {
             FunctionFrame function = (FunctionFrame)structure;
             PrintRow("Function", function.Identifier, function.ExpectedArguments.ToString());
         }
         else
         {
             PrintRow(structure.GetType().ToString(), "N/A", "N/A");
         }
     }
     PrintLine();
 }
예제 #15
0
        private void ProcessCALL()
        {
            // get function
            ScriptFunction scriptFunction
                = m_scriptInstruction.Operand0.ScriptFunctionRef;
            ScriptInstruction scriptInstructionTarget
                = scriptFunction.EntryPoint;

            FunctionFrame functionFrame = new FunctionFrame();

            functionFrame.m_scriptFunction = scriptFunction;
            functionFrame.m_variableDictionary
                = VariableDictionary.CreateLocalDictionary(
                      m_scriptExecutable.ScriptDictionary);
            m_variableDictionaryLocal = functionFrame.m_variableDictionary;
            functionFrame.m_iNextInstruction
                = (int)scriptInstructionTarget.Address;

            m_stackFunctionFrames.Push(functionFrame);
        }
예제 #16
0
 public void PrintWatch(params string[] args)
 {
     PrintLine();
     PrintRow("Identifier", "Accessibility", "Type", "Value");
     if (hasFlag(args, "-g"))
     {
         foreach (string id in interpreter.GlobalVariables.Keys)
         {
             PrintRow(id, "GLOBAL", interpreter.GlobalVariables[id].Type.ToString(), interpreter.GlobalVariables[id].ToString().Replace("\r\n", "").Replace("\n", ""));
         }
     }
     foreach (CallFrame structure in callStack.ToArray())
     {
         if (structure.GetType() == typeof(FunctionFrame))
         {
             FunctionFrame function = (FunctionFrame)structure;
             foreach (string id in function.LocalVariables.Keys)
             {
                 PrintRow(id, "LOCAL(" + function.Identifier + ")", function.LocalVariables[id].Type.ToString(), function.LocalVariables[id].ToString().Replace("\r\n", "").Replace("\n", ""));
             }
         }
     }
 }
예제 #17
0
        public FunctionFrame(FunctionFrame original)
        {
            Start = original.Start;
            Returns = original.Returns;
            Parameters = new List<FunctionParameter> ();

            foreach (FunctionParameter ofp in original.Parameters) {
                FunctionParameter copyfp = new FunctionParameter(ofp);
                Parameters.Add (copyfp);
            }
        }
예제 #18
0
    public ScopeFrame CreateFunctionScope(FunctionFrame ftype, string FunctionName, List<IDPacket> Bindings)
    {
        ScopeFrame fscope = CreateParseFunctionScope (ftype, FunctionName);

        //delete function frame inside scope
        fscope.Functions.Remove (FunctionName);

        PushScope (fscope);
        int BINDCNT = 0;
        foreach (FunctionParameter fp in ftype.Parameters) {
            IDPacket Binding = Bindings [BINDCNT];
            IDPacket Address = IDPacket.CreateIDPacket (this, fp.Name, Binding.Type);
            if (Binding.Type != fp.Type)
                Error ("Binding Error: Parameter type mismatch, expected: " + fp.Type + " got " + Binding.Type);
            if (Binding.ArrayType != IdentityType.Unknown) {
                if (fp.TypeDimensions != null) {
                    if (Binding.ArrayType != fp.Type) {
                        Error ("Binding Error: Parameter type mismatch, expected: Array of " + fp.Type + " got Array of " + Binding.ArrayType);
                    }
                    int dcnt = 0;
                    foreach (int dim in fp.TypeDimensions) {
                        if (dim == -1)
                            continue;
                        if (dim != Binding.TypeDimensions [dcnt++]) {
                            Error (String.Format ("Binding Error: Dimension Mismatch, expecting {0} got {1}", fp.TypeDimensions,
                                Binding.TypeDimensions));
                        }
                    }
                } else {
                    Error(String.Format("Binding Error: Expecting a Primitive {0} got Array of {1}", fp.Type, Binding.ArrayType));
                }
            } else if (fp.TypeDimensions != null) {
                Error(String.Format("Binding Error: Expecting an Array of {0} got Primitive {1}", fp.Type, Binding.ArrayType));
            }

            COPY (Address, Binding);
            Debug ("After copy");
        }
        return PopScopeNoSave ();
    }
예제 #19
0
    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 ();
    }
예제 #20
0
 public void PutFunction(IDPacket packet, FunctionFrame function)
 {
     ScopeFrame scope;
     FindNameScope (packet, out scope);
     FunctionFrame trash;
     if (TryGetFunction (packet, out trash))
         scope.Functions [packet.Name] = function;
     else
         scope.Functions.Add (packet.Name, function);
 }
예제 #21
0
 public void PutParseFunction(string name, FunctionFrame value)
 {
     if(!current_scope.Functions.ContainsKey(name))
         current_scope.Functions.Add (name, value);
 }
예제 #22
0
        private void ExecuteInstruction()
        {
            // get top frame
            FunctionFrame functionFrame = m_stackFunctionFrames.Peek();

            // fetch next instruction
            m_scriptInstruction
                = m_scriptExecutable.InstructionsInternal[
                      functionFrame.m_iNextInstruction++];

            switch (m_scriptInstruction.Opcode)
            {
            case Opcode.DBG:  ProcessDBG();  break;

            case Opcode.NOP:  ProcessNOP();  break;

            case Opcode.DCG:  ProcessDCG();  break;

            case Opcode.DCL:  ProcessDCL();  break;

            case Opcode.INT:  ProcessINT();  break;

            case Opcode.LOCK: ProcessLOCK(); break;

            case Opcode.ULCK: ProcessULCK(); break;

            case Opcode.MOV:  ProcessMOV();  break;

            case Opcode.INC:  ProcessINC(); break;

            case Opcode.DEC:  ProcessDEC(); break;

            case Opcode.NEG:  ProcessNEG(); break;

            case Opcode.ADD:  ProcessADD();  break;

            case Opcode.SUB:  ProcessSUB();  break;

            case Opcode.MUL:  ProcessMUL();  break;

            case Opcode.DIV:  ProcessDIV();  break;

            case Opcode.POW:  ProcessPOW();  break;

            case Opcode.MOD:  ProcessMOD(); break;

            case Opcode.CNL: ProcessCNL(); break;

            case Opcode.CEQ:  ProcessCEQ();  break;

            case Opcode.CNE:  ProcessCNE();  break;

            case Opcode.CG:   ProcessCG();   break;

            case Opcode.CGE:  ProcessCGE();  break;

            case Opcode.CL:   ProcessCL();   break;

            case Opcode.CLE:  ProcessCLE();  break;

            case Opcode.OR:   ProcessOR();   break;

            case Opcode.AND:  ProcessAND();  break;

            case Opcode.NOT:  ProcessNOT();  break;

            case Opcode.JMP:  ProcessJMP();  break;

            case Opcode.JT:   ProcessJT();   break;

            case Opcode.JF:   ProcessJF();   break;

            case Opcode.CLRA: ProcessCLRA(); break;

            case Opcode.NEXT: ProcessNEXT(); break;

            case Opcode.PUSH: ProcessPUSH(); break;

            case Opcode.POP:  ProcessPOP();  break;

            case Opcode.CALL: ProcessCALL(); break;

            case Opcode.RET:  ProcessRET();  break;

            case Opcode.HOST: ProcessHOST(); break;

            case Opcode.THRD: ProcessTHRD(); break;
            }
        }
예제 #23
0
 public bool TryGetFunction(IDPacket packet, out FunctionFrame value)
 {
     ScopeFrame scope;
     FindNameScope (packet, out scope);
     return scope.Functions.TryGetValue (packet.Name, out value);
 }
예제 #24
0
 public bool TryGetFunction(string name, ref FunctionFrame function)
 {
     return current_scope.Functions.TryGetValue (name, out function);
 }
예제 #25
0
 public bool TryGetParseFunction(string name, out FunctionFrame value)
 {
     return current_scope.Functions.TryGetValue (name, out value);
 }
예제 #26
0
 public bool TryGetFunction(string name, ref FunctionFrame function)
 {
     return(current_scope.Functions.TryGetValue(name, out function));
 }
예제 #27
0
 void RegisterFunction(string name, FunctionFrame ftype)
 {
     if (!IdentityExists (name))
         current_scope.Functions.Add (name, ftype);
     else
         Error ("Function with name " + name + " already exists.");
 }
예제 #28
0
        public void Merge(GenericFrame merge)
        {
            //Copy primitives

            if (Primitives.Numbers != null && merge.Primitives.Numbers != null) {
                foreach (string key in merge.Primitives.Numbers.Keys) {
                    double val;
                    merge.Primitives.Numbers.TryGetValue (key, out val);
                    Primitives.Numbers.Add (key, val);
                }
            }

            if (Primitives.Booleans != null && merge.Primitives.Booleans != null) {
                foreach (string key in merge.Primitives.Booleans.Keys) {
                    bool val;
                    merge.Primitives.Booleans.TryGetValue (key, out val);
                    Primitives.Booleans.Add (key, val);
                }
            }

            if (Primitives.Text != null && merge.Primitives.Text != null) {
                foreach (string key in merge.Primitives.Text.Keys) {
                    string val;
                    merge.Primitives.Text.TryGetValue (key, out val);
                    Primitives.Text.Add (key, val);
                }
            }

            //copy structures
            if (Generics != null && merge.Generics != null) {
                foreach (string key in merge.Generics.Keys) {
                    GenericFrame oval;
                    merge.Generics.TryGetValue (key, out oval);
                    //TODO Preserve the heirarchy

                    GenericFrame cval = GenericFrame.CopyAndPreserveHeirarchy (oval);//new GenericFrame (oval);
                    Generics.Add (key, cval);
                }
            }

            //copy functions
            if (Functions != null && merge.Functions != null) {
                foreach (string key in merge.Functions.Keys) {
                    FunctionFrame oval;
                    merge.Functions.TryGetValue (key, out oval);
                    FunctionFrame cval = new FunctionFrame (oval);
                    Functions.Add (key, cval);
                }
            }
        }
예제 #29
0
 public bool TryGetParseFunction(string name, out FunctionFrame value)
 {
     return(current_scope.Functions.TryGetValue(name, out value));
 }