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); }
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()); }