示例#1
0
		protected override object DoEvaluate(ScriptThread thread)
		{
			// standard prolog
			thread.CurrentNode = this;

			var binding = thread.Bind(FunctionName, BindingRequestFlags.Read);
			var result = binding.GetValueRef(thread);
			if (result == null)
			{
				thread.ThrowScriptError("Unknown identifier: {0}", FunctionName);
				return null;
			}

			CallTarget = result as ICallTarget;
			if (CallTarget == null)
			{
				thread.ThrowScriptError("This identifier cannot be called: {0}", FunctionName);
				return null;
			}

			// set Evaluate pointer
			Evaluate = DoCall;

			// standard epilog is done by DoCall
			return DoCall(thread);
		}
示例#2
0
        protected override object DoEvaluate(Irony.Interpreter.ScriptThread thread)
        {
            thread.CurrentNode = this;
            try
            {
                var res = new MtResult();

                var accessor = thread.Bind(_targetName.AsString, BindingRequestFlags.Write | BindingRequestFlags.ExistingOrNew);
                accessor.SetValueRef(thread, res);

                // To allow recursive definitions, we have
                // to evaluate _expression inside the new context.
                var exprResult = _expression.Evaluate(thread) as MtResult;
                exprResult.GetValue((o) =>
                {
                    res.SetValue((state) =>
                    {
                        return(o);
                    });
                });

                return(res);
            }
            catch (Exception e)
            {
                throw new Exception("Exception on MtBind.DoEvaluate", e);
            }
            finally
            {
                //thread.CurrentNode = Parent;
            }
        }
示例#3
0
 //Executed only once, on the first call
 protected override object DoEvaluate(ScriptThread thread)
 {
     thread.CurrentNode = this;  //standard prolog
       _accessor = thread.Bind(Symbol, BindingRequestFlags.Read);
       this.Evaluate = _accessor.GetValueRef; // Optimization - directly set method ref to accessor's method. EvaluateReader;
       var result = this.Evaluate(thread);
       thread.CurrentNode = Parent; //standard epilog
       return result;
 }
示例#4
0
 public override void DoSetValue(ScriptThread thread, object value)
 {
     thread.CurrentNode = this;  //standard prolog
       if (_accessor == null) {
     _accessor = thread.Bind(Symbol, BindingRequestFlags.Write | BindingRequestFlags.ExistingOrNew);
       }
       _accessor.SetValueRef(thread, value);
       thread.CurrentNode = Parent;  //standard epilog
 }
示例#5
0
		public string Name { get; set; } // TODO: value.Replace("-", "__")

		protected override object DoEvaluate(ScriptThread thread)
		{
			// standard prolog
			thread.CurrentNode = this;

			// define function: bind function name to the current instance
			var binding = thread.Bind(Name, BindingRequestFlags.Write | BindingRequestFlags.NewOnly);
			binding.SetValueRef(thread, this);

			// set Evaluate method and return the current node
			Evaluate = t => this;

			// standard epilog
			thread.CurrentNode = Parent;
			return this;
		}
示例#6
0
		protected override object DoEvaluate(ScriptThread thread)
		{
			// standard prolog
			thread.CurrentNode = this;

			if (EntryPoint == null)
			{
				thread.ThrowScriptError("No entry point defined (entry point is a function named «Go»)");
				return null;
			}

			// define built-in runtime library functions
			var libraryFunctions = LibraryFunction.ExtractLibraryFunctions(thread, new RefalLibrary(thread));
			foreach (var libFun in libraryFunctions)
			{
				var binding = thread.Bind(libFun.Name, BindingRequestFlags.Write | BindingRequestFlags.ExistingOrNew);
				binding.SetValueRef(thread, libFun);
			}

			// define functions declared in the compiled program
			foreach (var fun in FunctionList)
			{
				fun.Evaluate(thread);
			}

			// call entry point with an empty expression
			EntryPoint.Call(thread, new object[] { PassiveExpression.Build() });

			// standard epilog
			thread.CurrentNode = Parent;
			return null;
		}