示例#1
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);
        }
示例#2
0
        public void RegisterFunction(string name, LibraryFunction functionRef, int numberOfRequiredParameters)
        {
            ExternalFunctionRef extFuncRef = new ExternalFunctionRef(name, functionRef, numberOfRequiredParameters);

            // TODO: check for object redefinition
            libraryData.Insert(name, new ExternalFunctionRefValue(extFuncRef));
        }
示例#3
0
文件: Program.cs 项目: yallie/refal
        public override void EvaluateNode(EvaluationContext context, AstMode mode)
        {
            if (EntryPoint == null)
            {
                context.ThrowError("No entry point defined (entry point is a function named «Go»)");
            }

            // load standard run-time library functions
            var libraryFunctions = LibraryFunction.ExtractLibraryFunctions(context, new RefalLibrary(context));

            foreach (LibraryFunction libFun in libraryFunctions)
            {
                context.SetValue(libFun.Name, libFun);
            }

            // define all functions
            foreach (Function fun in FunctionList)
            {
                fun.Evaluate(context, mode);
            }

            // call entry point with empty expression as an argument
            context.Data.Push(Runtime.PassiveExpression.Build());
            EntryPoint.Call(context);

            // discard execution results
            context.Data.Pop();
            context.ClearLastResult();
        }
示例#4
0
        public void RegisterGlobalFunction(string name, LibraryFunction functionRef, int numberOfRequiredParameters)
        {
            ExternalFunctionRef extFuncRef = new ExternalFunctionRef(name, functionRef, numberOfRequiredParameters);

            // TODO: check for object redefinition
            ValueStore functionObject = state.RegisterGlobalObject(name);

            functionObject.Value = new ExternalFunctionRefValue(extFuncRef);
        }
示例#5
0
 public ExternalFunctionRef(string name, LibraryFunction functionRef, int numberOfDefinedParameters)
 {
     this.name        = name;
     this.functionRef = functionRef;
     this.numParams   = numberOfDefinedParameters;
 }