Beispiel #1
0
        public object ExecuteScript(BrackRuntimeData brd, object[] arguments, BrackPositionData bpd = null)
        {
            if (brd == null)
            {
                throw new ArgumentNullException("brd");
            }
            if (arguments == null)
            {
                throw new ArgumentNullException("arguments");
            }
            if (arguments.Length != ArgumentCount)
            {
                throw new BrackScriptArgumentCountException(ScriptName, ArgumentCount, arguments.Length, bpd?.FileName, bpd?.StatementID);
            }
            Return ret = null;

            brd.AddLocalMemory();
            for (var i = 0; i < ArgumentCount; i++)
            {
                brd.SetLocalVar(_ArgumentNames[i], arguments[i]);
            }
            ret = (Return)BrackRunner.Execute(brd, FileName, new Type[1] {
                typeof(Return)
            }, null, StatementID);
            brd.RemoveLocalMemory();
            return(ret?.Data);
        }
Beispiel #2
0
 public virtual object Execute(BrackRuntimeData brd, BrackPositionData bpd, object[] args)
 {
     if (!IsParamOperator)
     {
         if (args.Length != _ArgumentTypes.Length)
         {
             throw new BrackOperatorArgumentCountException(ArgumentCount, args.Length, OpName, bpd.FileName, bpd.StatementID);
         }
         for (var i = 0; i < ArgumentCount; i++)
         {
             if (args[i].GetType() != _ArgumentTypes[i])
             {
                 throw new BrackOperatorArgumentTypeException(args[i].GetType(), _ArgumentTypes[i], i, OpName, bpd.FileName, bpd.StatementID);
             }
         }
     }
     else //if (IsParamOperator)
     {
         for (var i = 0; i < args.Length; i++)
         {
             if (args[i].GetType() != _ParamType)
             {
                 throw new BrackOperatorArgumentTypeException(args[i].GetType(), _ParamType, i, OpName, bpd.FileName, bpd.StatementID);
             }
         }
     }
     return(null);
 }
Beispiel #3
0
 public override object Execute(BrackRuntimeData brd, BrackPositionData bpd, object[] args)
 {
     base.Execute(brd, bpd, args);
     T[] final = new T[args.Length];
     for (var i = 0; i < args.Length; i++)
     {
         final[i] = (T)args[i];
     }
     return(((BrackParamDelegate <T>)_OperatorDelegate)(brd, bpd, final));
 }
Beispiel #4
0
 public object GetLocalVar(string varName, BrackPositionData bpd = null)
 {
     for(var scopeLevel = 0; scopeLevel < _Scopes.Count; scopeLevel ++)
     {
         if (_Scopes[scopeLevel].HasLocalVar(varName))
         {
             return _Scopes[scopeLevel].GetLocalVar(varName, bpd);
         }
     }
     if (bpd == null) throw new BrackLocalVariableUndeclaredException(varName);
     else throw new BrackLocalVariableUndeclaredException(varName, bpd.MemoryLevel, -1, bpd.FileName, bpd.StatementID);
 }
Beispiel #5
0
 public void RemoveScript(string scriptName, BrackPositionData bpd = null)
 {
     try
     {
         _Scripts.Remove(scriptName);
     }
     catch (KeyNotFoundException)
     {
         if (bpd == null)
         {
             throw new BrackScriptUndeclaredException(scriptName);
         }
         else
         {
             throw new BrackScriptUndeclaredException(scriptName, bpd.FileName, bpd.StatementID);
         }
     }
 }
Beispiel #6
0
 public void DeleteLocalVar(string varName, BrackPositionData bpd)
 {
     try
     {
         _LocalVars.Remove(varName);
     }
     catch (KeyNotFoundException)
     {
         if (bpd == null)
         {
             throw new BrackLocalVariableUndeclaredException(varName);
         }
         else
         {
             throw new BrackLocalVariableUndeclaredException(varName, bpd.MemoryLevel, -1, bpd.FileName, bpd.StatementID);
         }
     }
 }
Beispiel #7
0
 public object GetLocalVar(string varName, BrackPositionData bpd)
 {
     try
     {
         return(_LocalVars[varName]);
     }
     catch (KeyNotFoundException)
     {
         if (bpd == null)
         {
             throw new BrackLocalVariableUndeclaredException(varName);
         }
         else
         {
             throw new BrackLocalVariableUndeclaredException(varName, bpd.MemoryLevel, -1, bpd.FileName, bpd.StatementID);
         }
     }
 }
Beispiel #8
0
        public static object Execute(BrackRuntimeData brd, string path = null, Type[] returnTypes = null, SpecialTypes[] specialReturnTypes = null, int[] statementID = null)
        {
            BrackPositionData bpd = new BrackPositionData()
            {
                FileName         = path,
                BrackRuntimeData = brd
            };

            object[][] statements = BrackSerialization.ReadBrack(path);
            for (var i = 0; i < statements.Length; i++)
            {
                bpd.NextStatement();
                var ret = brd.ExecuteOperator(statements[i], bpd);
                if ((returnTypes != null && returnTypes.Contains(ret.GetType())) || (specialReturnTypes != null & (ret is SpecialTypes && specialReturnTypes.Contains((SpecialTypes)ret))))
                {
                    return(ret);
                }
            }
            return(null);
        }
Beispiel #9
0
        public BrackScript(string scriptName, string fileName, int[] statementID, object[][] brackStatements, string[] argumentNames, BrackPositionData bpd = null)
        {
            ScriptName       = scriptName;
            FileName         = fileName;
            StatementID      = statementID;
            _BrackStatements = brackStatements;
            _ArgumentNames   = argumentNames;
            var checkedArgs = new List <string>();

            for (var i = 0; i < argumentNames.Length; i++)
            {
                if (checkedArgs.Contains(argumentNames[i]))
                {
                    throw new BrackScriptArgumentNameMatchException(ScriptName, argumentNames[i], FileName, bpd?.StatementID);
                }
            }
        }
Beispiel #10
0
 public Type[] GetTypes(string opName, BrackPositionData bpd = null)
 {
     return(_OperatorDictionary.GetTypes(opName, bpd));
 }
Beispiel #11
0
 public object GetLocalVar(string varName, BrackPositionData bpd = null)
 {
     return(_LocalMemory.Peek().GetLocalVar(varName, bpd));
 }
Beispiel #12
0
 public object GetGlobalVar(string varName, BrackPositionData bpd = null)
 {
     return(_GlobalMemory.GetGlobalVar(varName, bpd));
 }
Beispiel #13
0
 public Delegate GetDelegate(string opName, BrackPositionData bpd = null)
 {
     return(_OperatorDictionary.GetDelegate(opName, bpd));
 }
Beispiel #14
0
 public int GetArgCount(string opName, BrackPositionData bpd = null)
 {
     return(_OperatorDictionary.GetArgCount(opName, bpd));
 }
Beispiel #15
0
 public object ExecuteScript(BrackRuntimeData brd, string scriptName, object[] arguments, BrackPositionData bpd = null)
 {
     try
     {
         return(_Scripts[scriptName].ExecuteScript(brd, arguments, bpd));
     }
     catch (KeyNotFoundException)
     {
         if (bpd == null)
         {
             throw new BrackScriptUndeclaredException(scriptName);
         }
         else
         {
             throw new BrackScriptUndeclaredException(scriptName, bpd.FileName, bpd.StatementID);
         }
     }
 }
Beispiel #16
0
 public Delegate GetDelegate(string opName, BrackPositionData bpd)
 {
     return(_Operators[opName].OperatorDelegate);
 }
Beispiel #17
0
 public object ExecuteOperator(BrackRuntimeData brd, string name, object[] arguments, BrackPositionData bpd)
 {
     return(_Operators[name].Execute(brd, bpd, arguments));
 }
Beispiel #18
0
 public void DeleteGlobalVar(string varName, BrackPositionData bpd = null)
 {
     _GlobalMemory.DeleteGlobalVar(varName, bpd);
 }
Beispiel #19
0
 public void AddScript(string scriptName, object[][] statements, string[] arguments, BrackPositionData bpd = null)
 {
     _GlobalMemory.AddScript(scriptName, statements, arguments, bpd);
 }
Beispiel #20
0
 public void RemoveScript(string scriptName, BrackPositionData bpd = null)
 {
     _GlobalMemory.RemoveScript(scriptName, bpd);
 }
Beispiel #21
0
 public override object Execute(BrackRuntimeData brd, BrackPositionData bpd, object[] args)
 {
     base.Execute(brd, bpd, args);
     return(((BrackDelegate)_OperatorDelegate)(brd, bpd));
 }
Beispiel #22
0
 public void DeleteLocalVar(string varName, BrackPositionData bpd = null)
 {
     _LocalMemory.Peek().DeleteLocalVar(varName, bpd);
 }
Beispiel #23
0
 public void AddScript(string scriptName, object[][] statements, string[] arguments, BrackPositionData bpd = null)
 {
     _Scripts[scriptName] = new BrackScript(scriptName, bpd.FileName, bpd.StatementID, statements, arguments, bpd);
 }
Beispiel #24
0
 public object ExecuteOperator(BrackRuntimeData brd, object[] statement, BrackPositionData bpd)
 {
     return(_Operators[statement[0].ToString()].Execute(brd, bpd, statement.Skip(1).ToArray()));
 }
Beispiel #25
0
 public object ExecuteOperator(object[] statement, BrackPositionData bpd)
 {
     return(_OperatorDictionary.ExecuteOperator(this, statement, bpd));
 }
Beispiel #26
0
 public int GetArgCount(string opName, BrackPositionData bpd)
 {
     return(_Operators[opName].ArgumentCount);
 }
Beispiel #27
0
 public object ExecuteOperator(string name, object[] arguments, BrackPositionData bpd)
 {
     return(_OperatorDictionary.ExecuteOperator(this, name, arguments, bpd));
 }
Beispiel #28
0
 public Type[] GetTypes(string opName, BrackPositionData bpd)
 {
     return(_Operators[opName].ArgumentTypes);
 }
Beispiel #29
0
 public object ExecuteScript(string scriptName, object[] arguments, BrackPositionData bpd = null)
 {
     return(_GlobalMemory.ExecuteScript(this, scriptName, arguments, bpd));
 }