コード例 #1
0
        public void Run(string coreCodePath, string filePath = null)
        {
            try
            {
                LoadAndExecute(coreCodePath);
            }
            catch (Exception e)
            {
                if (!(e is InterpreterException))
                {
                    throw new InterpreterException("Cannot load core library", e);
                }
                throw;
            }
            Func <object> func = () =>
            {
                if (filePath != null)
                {
                    LoadAndExecute(filePath);
                }
                return(null);
            };

            InterpreterHelper.ActAndHandleException(func);
        }
コード例 #2
0
        public override object Walk(ConditionalExpression node)
        {
            var cond = node.Condition.Accept(this);

            return(InterpreterHelper.IsTrue(cond)
                ? node.TrueExpression.Accept(this)
                : node.FalseExpression.Accept(this));
        }
コード例 #3
0
        public override object Walk(IfStatement node)
        {
            var cond = node.Condition.Accept(this);

            if (InterpreterHelper.IsTrue(cond))
            {
                return(node.Body.Accept(this));
            }
            return(node.Else != null?node.Else.Accept(this) : null);
        }
コード例 #4
0
        public override object Walk(WhileStatement node)
        {
            object result = null;

            while (InterpreterHelper.IsTrue(node.Condition.Accept(this)))
            {
                try
                {
                    result = node.Body.Accept(this);
                }
                catch (Break)
                {
                    break;
                }
                catch (Next)
                {
                    continue;
                }
            }
            return(result);
        }
コード例 #5
0
            public object Callback(object[] args)
            {
                bool newThread = false;

                if (callingThread != Thread.CurrentThread)
                {
                    newThread = true;
                    var callingInstance = ContextLocal[callingThread];
                    new InterpretationContext(callingInstance);
                    ContextLocal.ClearCollected();
                }

                Func <object> func = () =>
                {
                    var interpreter = InterpretationContext.Instance.Interpreter;
                    var result      = interpreter.CallBikeFunction(Function,
                                                                   Target,
                                                                   interpreter.
                                                                   MarshallArgumentsToBike(
                                                                       args));
                    if (ReturnType == typeof(void))
                    {
                        return(null);
                    }
                    result = interpreter.MarshallToClr(result);
                    object adjustedResult = result;
                    if (TryConvert(ReturnType, Target, ref adjustedResult))
                    {
                        return(adjustedResult);
                    }
                    throw ErrorFactory.CreateClrError(string.Format(
                                                          "Invalid return type: expect {0}, actual {1}",
                                                          ReturnType, result));
                };

                return(newThread ? InterpreterHelper.ActAndHandleException(func, true) : func());
            }
コード例 #6
0
 public BikeBoolean OpNot(object value)
 {
     return(new BikeBoolean(!InterpreterHelper.IsTrue(value)));
 }
コード例 #7
0
 public object OpOr(object lv, Func <object> rvThunk)
 {
     return(InterpreterHelper.IsTrue(lv) ? lv : rvThunk());
 }
コード例 #8
0
 public object OpAnd(object lv, Func <object> rvThunk)
 {
     return(InterpreterHelper.IsTrue(lv) ? rvThunk() : lv);
 }