Exemplo n.º 1
0
 public void Initialize(ScriptContext parent, Dictionary<String, ScriptObject> variable)
 {
     m_parent = parent;
     m_variableDictionary.Clear();
     foreach (var pair in variable)
         m_variableDictionary[pair.Key] = pair.Value;
 }
Exemplo n.º 2
0
 public ScriptContext(Script script, ScriptExecutable scriptExecutable, ScriptContext parent, Executable_Block block)
 {
     m_script = script;
     m_parent = parent;
     m_scriptExecutable = scriptExecutable;
     m_variableDictionary.Clear();
     m_block = block;
     m_InstructionCount = m_scriptExecutable != null ? m_scriptExecutable.Count : 0;
 }
Exemplo n.º 3
0
 public ScriptContext(Script script, ScriptExecutable scriptExecutable, ScriptContext parent, Executable_Block block) {
     m_script = script;
     m_parent = parent;
     m_block = block;
     m_variableDictionary = new Dictionary<String, ScriptObject>();
     if (scriptExecutable != null) {
         m_scriptInstructions = scriptExecutable.ScriptInstructions;
         m_InstructionCount = m_scriptInstructions.Length;
     }
 }
        private ScriptExecutable m_ScriptExecutable; //函数执行命令

        #endregion Fields

        #region Constructors

        public ScorpioScriptFunction(Script script, List<String> listParameters, ScriptExecutable scriptExecutable, bool bParams)
        {
            this.m_Script = script;
            this.m_ListParameters = new List<string>(listParameters);
            this.m_ScriptExecutable = scriptExecutable;
            this.m_ParameterCount = listParameters.Count;
            this.m_Params = bParams;
            this.m_ParamsArray = bParams ? script.CreateArray() : null;
            this.m_Context = new ScriptContext(m_Script, m_ScriptExecutable, null, Executable_Block.Function);
        }
 public ScriptObject Call(ScriptContext parentContext, Dictionary<String, ScriptObject> objs, ScriptObject[] parameters) {
     int length = parameters.Length;
     if (m_Params) {
         ScriptArray paramsArray = m_Script.CreateArray();
         for (int i = 0; i < m_ParameterCount - 1; ++i) {
             objs[m_ListParameters[i]] = (parameters != null && length > i) ? parameters[i] : m_Script.Null;
         }
         for (int i = m_ParameterCount - 1; i < length; ++i) {
             paramsArray.Add(parameters[i]);
         }
         objs[m_ListParameters[m_ParameterCount - 1]] = paramsArray;
     } else {
         for (int i = 0; i < m_ParameterCount; ++i) {
             objs[m_ListParameters[i]] = (parameters != null && length > i) ? parameters[i] : m_Script.Null;
         }
     }
     ScriptContext context = new ScriptContext(m_Script, m_ScriptExecutable, parentContext, Executable_Block.Function);
     context.Initialize(objs);
     return context.Execute();
 }
Exemplo n.º 6
0
 public ScriptContext(Script script, ScriptExecutable scriptExecutable, ScriptContext parent) : this(script, scriptExecutable, parent, Executable_Block.None) { }
Exemplo n.º 7
0
 private void Initialize(ScriptContext parent)
 {
     m_parent = parent;
     m_variableDictionary.Clear();
 }
Exemplo n.º 8
0
 void ProcessCallForeach()
 {
     CodeForeach code = (CodeForeach)m_scriptInstruction.Operand0;
     ScriptObject loop = ResolveOperand(code.LoopObject);
     if (!(loop is ScriptFunction)) throw new ExecutionException(m_script, "foreach函数必须返回一个ScriptFunction");
     object obj;
     ScriptFunction func = (ScriptFunction)loop;
     ScriptContext context;
     for ( ; ; ) {
         obj = func.Call();
         if (obj == null) return;
         context = new ScriptContext(m_script, code.BlockExecutable, this, Executable_Block.Foreach);
         context.Initialize(code.Identifier, m_script.CreateObject(obj));
         context.Execute();
         if (context.IsOver) break;
     }
 }
Exemplo n.º 9
0
 void ProcessCallWhile() {
     CodeWhile code = (CodeWhile)m_scriptInstruction.Operand0;
     TempCondition condition = code.While;
     ScriptContext context;
     for ( ; ; ) {
         if (!ProcessAllow(condition)) {
             break;
         }
         context = new ScriptContext(m_script, condition.Executable, this, Executable_Block.While);
         context.Execute();
         if (context.IsOver) {
             break;
         }
     }
 }
Exemplo n.º 10
0
 void ProcessCallFor()
 {
     CodeFor code = (CodeFor)m_scriptInstruction.Operand0;
     ScriptContext context = new ScriptContext(m_script, null, this, Executable_Block.For);
     context.Execute(code.BeginExecutable);
     for ( ; ; ) {
         if (code.Condition != null) {
             if (!context.ResolveOperand(code.Condition).LogicOperation()) break;
         }
         ScriptContext blockContext = new ScriptContext(m_script, code.BlockExecutable, context, Executable_Block.For);
         blockContext.Execute();
         if (blockContext.IsOver) break;
         context.Execute(code.LoopExecutable);
     }
 }
Exemplo n.º 11
0
 void ProcessCallForSimple()
 {
     CodeForSimple code = (CodeForSimple)m_scriptInstruction.Operand0;
     ScriptNumber beginNumber = ResolveOperand(code.Begin) as ScriptNumber;
     if (beginNumber == null) throw new ExecutionException(m_script, "forsimple 初始值必须是number");
     ScriptNumber finishedNumber = ResolveOperand(code.Finished) as ScriptNumber;
     if (finishedNumber == null) throw new ExecutionException(m_script, "forsimple 最大值必须是number");
     int begin = beginNumber.ToInt32();
     int finished = finishedNumber.ToInt32();
     int step;
     if (code.Step != null) {
         ScriptNumber stepNumber = ResolveOperand(code.Step) as ScriptNumber;
         if (stepNumber == null) throw new ExecutionException(m_script, "forsimple Step必须是number");
         step = stepNumber.ToInt32();
     } else {
         step = 1;
     }
     ScriptContext context;
     for (double i = begin; i <= finished; i += step) {
         context = new ScriptContext(m_script, code.BlockExecutable, this, Executable_Block.For);
         context.Initialize(code.Identifier, new ScriptNumberDouble(m_script, i));
         context.Execute();
         if (context.IsOver) break;
     }
 }
Exemplo n.º 12
0
        private Script m_Script; //脚本引擎

        #endregion Fields

        #region Constructors

        public CodeFor(Script script)
        {
            m_Script = script;
            Context = new ScriptContext(script, null, null, Executable_Block.For);
        }
Exemplo n.º 13
0
 private void Initialize(ScriptContext parent)
 {
     m_parent = parent;
     m_variableDictionary.Clear();
 }
 public ScriptScriptFunction SetParentContext(ScriptContext context) {
     m_ParentContext = context;
     return this;
 }
Exemplo n.º 15
0
 private ScriptObject Load(String strBreviary, List<Token> tokens, ScriptContext context)
 {
     if (tokens.Count == 0) return Null;
     ScriptParser scriptParser = new ScriptParser(this, tokens, strBreviary);
     ScriptExecutable scriptExecutable = scriptParser.Parse();
     return new ScriptContext(this, scriptExecutable, context, Executable_Block.Context).Execute();
 }
Exemplo n.º 16
0
 bool ProcessCondition(TempCondition con, ScriptContext context, Executable_Block block)
 {
     if (con == null) return false;
     if (con.Allow != null) {
         object b = ResolveOperand(con.Allow).ObjectValue;
         if (b == null || b.Equals(false)) return false;
     }
     context.Initialize(this);
     context.Execute();
     return true;
 }
Exemplo n.º 17
0
 void ProcessCallBlock()
 {
     ScriptContext context = new ScriptContext(m_script, (ScriptExecutable)m_scriptInstruction.Value);
     context.Initialize(this);
     context.Execute();
 }
Exemplo n.º 18
0
        public ScriptExecutable Executable; //指令列表

        #endregion Fields

        #region Constructors

        public TempCase(Script script, List<object> allow, ScriptExecutable executable, Executable_Block block)
        {
            this.Allow = allow;
            this.Executable = executable;
            this.Context = new ScriptContext(script, executable, null, block);
        }
Exemplo n.º 19
0
 void ProcessTry()
 {
     CodeTry code = (CodeTry)m_scriptInstruction.Operand0;
     try {
         new ScriptContext(m_script, code.TryExecutable, this).Execute();
     } catch (InteriorException ex) {
         ScriptContext context = new ScriptContext(m_script, code.CatchExecutable, this);
         context.Initialize(code.Identifier, ex.obj);
         context.Execute();
     } catch (System.Exception ex) {
         ScriptContext context = new ScriptContext(m_script, code.CatchExecutable, this);
         context.Initialize(code.Identifier, m_script.CreateObject(ex));
         context.Execute();
     }
 }
Exemplo n.º 20
0
 private void Initialize(ScriptContext parent, string name, ScriptObject obj)
 {
     m_parent = parent;
     m_variableDictionary.Clear();
     m_variableDictionary.Add(name, obj);
 }
Exemplo n.º 21
0
 internal ScriptObject LoadString(String strBreviary, String strBuffer, ScriptContext context, bool clearStack)
 {
     try {
         if (Util.IsNullOrEmpty(strBuffer)) return Null;
         if (clearStack) m_StackInfoStack.Clear();
         ScriptLexer scriptLexer = new ScriptLexer(strBuffer);
         strBreviary = Util.IsNullOrEmpty(strBreviary) ? scriptLexer.GetBreviary() : strBreviary;
         return Load(strBreviary, scriptLexer.GetTokens(), context);
     } catch (System.Exception e) {
         throw new ScriptException("load buffer [" + strBreviary + "] is error : " + e.ToString());
     }
 }
Exemplo n.º 22
0
 private void Initialize(ScriptContext parent, string name, ScriptObject obj)
 {
     m_parent = parent;
     m_variableDictionary.Clear();
     m_variableDictionary.Add(name, obj);
 }
Exemplo n.º 23
0
        public ScriptExecutable Executable; //指令列表

        #endregion Fields

        #region Constructors

        public TempCondition(Script script, CodeObject allow, ScriptExecutable executable, Executable_Block block)
        {
            this.Allow = allow;
            this.Executable = executable;
            this.Context = new ScriptContext(script, executable, null, block);
        }
 public void SetParentContext(ScriptContext context)
 {
     m_ParentContext = context;
 }
Exemplo n.º 25
0
 public void SetContextExecutable(ScriptExecutable blockExecutable)
 {
     BlockExecutable = blockExecutable;
     BlockContext = new ScriptContext(m_Script, blockExecutable, null, Executable_Block.For);
 }
Exemplo n.º 26
0
 }                                                                //此逻辑块是否已经执行完成
 public void Initialize(ScriptContext parent, Dictionary <String, ScriptObject> variable)
 {
     m_parent             = parent;
     m_variableDictionary = variable;
 }