Пример #1
0
 /// <summary>
 /// Initializes a new instance of the Lambda class.
 /// </summary>
 /// <param name="formalParameters">A list of variable names, to be matched with 
 ///    values given later.</param>
 /// <param name="body">The program to execute.</param>
 /// <param name="env">The environment in which to execute it.</param>
 protected Lambda(SchemeObject formalParameters, SchemeObject body, Environment env)
     : base(null, new ArgsInfo(CountFormals(formalParameters)))
 {
     this.formalParameters = formalParameters;
     this.env = env;
     this.body = body;
 }
Пример #2
0
        /// <summary>
        /// Create a list evaluator.
        /// </summary>
        /// <param name="expr">The expression to evaluate.</param>
        /// <param name="env">The environment to make the expression in.</param>
        /// <param name="caller">The caller.  Return to this when done.</param>
        /// <returns>A list evaluator.</returns>
        internal static Evaluator Call(SchemeObject expr, Environment env, Evaluator caller)
        {
            // first check for degenerate cases
            if (expr is EmptyList)
            {
                caller.ReturnedExpr = EmptyList.Instance;
                return caller;
            }

            if (!(expr is Pair))
            {
                ErrorHandlers.SemanticError("Bad args for list: " + expr, null);
            }

            if (AllEvaluated(expr))
            {
                // Skip creating an evaluator or a list if all elements are constants.
                caller.ReturnedExpr = expr;
                return caller;
            }

            if (AllSimple(expr))
            {
                // Skip creating an evaluator if all elements are constants or symbols.
                caller.ReturnedExpr = EvaluateSymbolsInList(expr, env);
                return caller;
            }

            // Something actually needs to be evaluated.
            return new EvaluateList(expr, env, caller);
        }
Пример #3
0
        public ShipModule TransformScheme(SchemeObject scheme)
        {
            ModuleDropper.ModuleDropParams dropParams = new ModuleDropper.ModuleDropParams(this.resources, scheme.ModuleId, scheme.Level, Difficulty.none, scheme.CraftMaterials, scheme.Color, scheme.SetID);
            ModuleDropper dropper = new ModuleDropper(dropParams);

            return((ShipModule)dropper.Drop());
        }
Пример #4
0
        /// <summary>
        /// Call letrec evaluator.
        /// </summary>
        /// <param name="expr">The expression to evaluate.</param>
        /// <param name="env">The environment to make the expression in.</param>
        /// <param name="caller">The caller.  Return to this when done.</param>
        /// <returns>The let evaluator.</returns>
        internal static Evaluator Call(SchemeObject expr, Environment env, Evaluator caller)
        {
            if (expr is EmptyList)
            {
                ErrorHandlers.SemanticError("No arguments for letrec", null);
            }

            if (!(expr is Pair))
            {
                ErrorHandlers.SemanticError("Bad arg list for letrec: " + expr, null);
            }

            SchemeObject body = Rest(expr);
            if (body is EmptyList)
            {
                caller.ReturnedExpr = Undefined.Instance;
                return caller;
            }

            SchemeObject bindings = First(expr);
            //// In the bindings, the variables are first, the values are second, and anything left over is discarded.
            //// If either is missing, an empty list is used instead.
            //// To start with, bindings are undefined.
            SchemeObject formals = MapFun(First, bindings);
            SchemeObject inits = MapFun(Second, bindings);
            SchemeObject initVals = Fill(ListLength(formals), Undefined.Instance);

            return new EvaluateLetRec(expr, new Environment(formals, initVals, env), caller, body, formals, inits);
        }
Пример #5
0
        /// <summary>
        /// Call let* evaluator.
        /// </summary>
        /// <param name="expr">The expression to evaluate.</param>
        /// <param name="env">The environment to make the expression in.</param>
        /// <param name="caller">The caller.  Return to this when done.</param>
        /// <returns>The let evaluator.</returns>
        internal static Evaluator Call(SchemeObject expr, Environment env, Evaluator caller)
        {
            if (expr is EmptyList)
            {
                ErrorHandlers.SemanticError("No arguments arguments for let*", null);
            }

            if (!(expr is Pair))
            {
                ErrorHandlers.SemanticError("Bad arg list for let*: " + expr, null);
            }

            SchemeObject bindings = First(expr);
            SchemeObject body = Rest(expr);

            if (body is EmptyList)
            {
                caller.ReturnedExpr = Undefined.Instance;
                return caller;
            }

            SchemeObject vars = MapFun(First, bindings);
            SchemeObject inits = MapFun(Second, bindings);
            SchemeObject formals = EmptyList.Instance;
            SchemeObject vals = EmptyList.Instance;
            return new EvaluateLetStar(expr, env, caller, body, vars, inits, formals, vals);
        }
Пример #6
0
 /// <summary>
 /// Initializes a new instance of the EvaluateList class.
 /// This is used in the "list" primitive, and ALSO to evaluate the
 ///   arguments in a list that is part of procedure application.
 /// Because it is used internally, the evaluator must not use destructive
 ///   operations on its member variables.
 /// </summary>
 /// <param name="expr">The expression to evaluate.</param>
 /// <param name="env">The evaluation environment</param>
 /// <param name="caller">The caller.  Return to this when done.</param>
 private EvaluateList(SchemeObject expr, Environment env, Evaluator caller)
     : base(EvalExprStep, expr, env, caller)
 {
     // Start with an empty list.  As exprs are evaluated, they will be consed on the
     //  front.  The list will be reversed before it is returned.  Because this is done
     //  destructively, cloning needs to copy the result.
     this.result = EmptyList.Instance;
 }
Пример #7
0
 /// <summary>
 /// Initializes a new instance of the EvaluateLet class.
 /// </summary>
 /// <param name="expr">The expression to evaluate.</param>
 /// <param name="env">The evaluation environment</param>
 /// <param name="caller">The caller.  Return to this when done.</param>
 /// <param name="name">The name of a named let.</param>
 /// <param name="body">The let body.</param>
 /// <param name="vars">The variables to bind.</param>
 /// <param name="inits">The initial values of the variables.</param>
 private EvaluateLet(SchemeObject expr, Environment env, Evaluator caller, Symbol name, SchemeObject body, SchemeObject vars, SchemeObject inits)
     : base(InitialStep, expr, env, caller)
 {
     this.name = name;
     this.body = body;
     this.vars = vars;
     this.inits = inits;
 }
Пример #8
0
 /// <summary>
 /// Initializes a new instance of the EvaluateLetStar class.
 /// </summary>
 /// <param name="expr">The expression to evaluate.</param>
 /// <param name="env">The evaluation environment</param>
 /// <param name="caller">The caller.  Return to this when done.</param>
 /// <param name="body">The let* body.</param>
 /// <param name="vars">The list of variables to bind.</param>
 /// <param name="inits">The initialization expressions.</param>
 /// <param name="formals">The list of parameters to pass to the lambda.</param>
 /// <param name="vals">Evaluated values of inits.</param>
 private EvaluateLetStar(SchemeObject expr, Environment env, Evaluator caller, SchemeObject body, SchemeObject vars, SchemeObject inits, SchemeObject formals, SchemeObject vals)
     : base(EvalInitStep, expr, env, caller)
 {
     this.body = body;
     this.vars = vars;
     this.inits = inits;
     this.formals = formals;
     this.vals = vals;
 }
Пример #9
0
 /// <summary>
 /// Initializes a new instance of the EvaluateLetRec class.
 /// </summary>
 /// <param name="expr">The expression to evaluate.</param>
 /// <param name="env">The evaluation environment</param>
 /// <param name="caller">The caller.  Return to this when done.</param>
 /// <param name="body">The let body.</param>
 /// <param name="vars">The variables to be bound.</param>
 /// <param name="inits">The initialization expressions.</param>
 private EvaluateLetRec(SchemeObject expr, Environment env, Evaluator caller, SchemeObject body, SchemeObject vars, SchemeObject inits)
     : base(EvalInitStep, expr, env, caller)
 {
     this.body = body;
     this.vars = vars;
     this.inits = inits;
     this.formals = vars;
     this.vals = EmptyList.Instance;
 }
Пример #10
0
 /// <summary>
 /// Initializes a new instance of the EvaluateDo class.
 /// </summary>
 /// <param name="expr">The expression to evaluate.</param>
 /// <param name="env">The evaluation environment</param>
 /// <param name="caller">The caller.  Return to this when done.</param>
 /// <param name="vars">The variables.</param>
 /// <param name="inits">The initialization expressions.</param>
 /// <param name="steps">The steps.</param>
 /// <param name="exprs">The expressions.</param>
 /// <param name="commands">The commands.</param>
 /// <param name="testProc">The test proc to execute each interation.</param>
 private EvaluateDo(SchemeObject expr, Environment env, Evaluator caller, SchemeObject vars, SchemeObject inits, SchemeObject steps, SchemeObject exprs, SchemeObject commands, Lambda testProc)
     : base(InitialStep, expr, new Environment(env), caller)
 {
     this.vars = vars;
     this.inits = inits;
     this.steps = steps;
     this.exprs = exprs;
     this.commands = commands;
     this.testProc = testProc;
 }
Пример #11
0
        /// <summary>
        /// Calls an or evaluator.
        /// </summary>
        /// <param name="expr">The expression to evaluate.</param>
        /// <param name="env">The environment to make the expression in.</param>
        /// <param name="caller">The caller.  Return to this when done.</param>
        /// <returns>The or evaluator.</returns>
        internal static Evaluator Call(SchemeObject expr, Environment env, Evaluator caller)
        {
            // If no expr, avoid creating an evaluator.
            if (expr is EmptyList)
            {
                caller.ReturnedExpr = (SchemeBoolean)false;
                return caller;
            }

            return new EvaluateOr(expr, env, caller);
        }
Пример #12
0
        /// <summary>
        /// Calls a set evaluator.
        /// </summary>
        /// <param name="expr">The expression to evaluate.</param>
        /// <param name="env">The environment to evaluate the expression in.</param>
        /// <param name="caller">The caller.  Return to this when done.</param>
        /// <returns>The set evaluator.</returns>
        internal static Evaluator Call(SchemeObject expr, Environment env, Evaluator caller)
        {
            SchemeObject lhs = First(expr);
            SchemeObject rhs = Second(expr);
            if (!(lhs is Symbol))
            {
                ErrorHandlers.SemanticError(string.Format(@"Set: first argument must be a symbol.  Got: ""{0}""", lhs), null);
            }

            return new EvaluateSet(expr, env, caller, lhs, rhs);
        }
Пример #13
0
        private void AddStartItemToInventory()
        {
            Workshop       workshop      = (Workshop)(byte)(int)nebulaObject.Tag((byte)PlayerTags.Workshop);
            SchemeDropper  schemeDropper = new SchemeDropper(workshop, 1, resource, ObjectColor.white);
            MaterialObject material      = new MaterialObject("CraftOre0001", workshop, 1, resource.Materials.Ore("CraftOre0001"));
            SchemeObject   scheme        = schemeDropper.Drop() as SchemeObject;

            scheme.ReplaceCraftingMaterials(new Dictionary <string, int> {
                { "CraftOre0001", 1 }
            });
            Inventory.Add(scheme, 1);
            Inventory.Add(material, 5);
            log.InfoFormat("adding tutorial crafting materials at start yellow");
        }
Пример #14
0
        private ServerInventoryItem GiveSchemeReward(MmoActor player, ContractSchemeDataReward schemeReward)
        {
            Workshop workshop = (Workshop)player.GetComponent <CharacterObject>().workshop;

            SchemeObject scheme = new SchemeObject(new SchemeObject.SchemeInitData(
                                                       Guid.NewGuid().ToString(),
                                                       string.Empty,
                                                       player.GetComponent <CharacterObject>().level,
                                                       workshop,
                                                       player.resource.ModuleTemplates.RandomModule(workshop).Id,
                                                       schemeReward.color,
                                                       new Dictionary <string, int>(),
                                                       string.Empty)
                                                   );

            return(new ServerInventoryItem(scheme, 1));
        }
Пример #15
0
        /// <summary>
        /// Call the map evaluator
        /// </summary>
        /// <param name="proc">The map proc.</param>
        /// <param name="expr">The map list to traverse.</param>
        /// <param name="returnResult">If true, return the result of the map.</param>
        /// <param name="env">The environment to make the expression in.</param>
        /// <param name="caller">The caller -- return to this when done.</param>
        /// <returns>The evaluator to execute.</returns>
        internal static Evaluator Call(Procedure proc, SchemeObject expr, bool returnResult, Environment env, Evaluator caller)
        {
            // first check for degenerate cases
            if (expr is EmptyList)
            {
                caller.ReturnedExpr = EmptyList.Instance;
                return caller;
            }

            if (!(expr is Pair))
            {
                ErrorHandlers.SemanticError("Bad args for map: " + expr, null);
            }

            SchemeObject result = returnResult ? EmptyList.Instance : null;
            return new EvaluateMap(expr, env, caller, proc, result);
        }
Пример #16
0
        private void UpdateDropList()
        {
            content.Clear();
            switch (dropList)
            {
            case DropList.RandomSchemeOfWorldLevel:
            {
                SchemeDropper dropper = new SchemeDropper(
                    CommonUtils.GetRandomEnumValue <Workshop>(new List <Workshop>()),
                    (nebulaObject.world as MmoWorld).Zone.Level,
                    nebulaObject.resource);

                SchemeObject scheme = dropper.Drop() as SchemeObject;
                AddContent(new ServerInventoryItem(scheme, 1));
            }
            break;
            }
        }
Пример #17
0
        /// <summary>
        /// Call a define evaluator.
        /// Handle the two forms of define.
        /// In the first case, just save the lambda and return.
        /// This is what would result if we prepend "lambda" and call EvaluateExpression.
        /// In the second case, we need create an evaluator to evaluate the expression.
        /// </summary>
        /// <param name="expr">The expression to evaluate.</param>
        /// <param name="env">The environment to make the expression in.</param>
        /// <param name="caller">The caller.  Return to this when done.</param>
        /// <returns>The define evaluator.</returns>
        internal static Evaluator Call(SchemeObject expr, Environment env, Evaluator caller)
        {
            if (First(expr) is Pair)
            {
                // Defun case -- create a lambda and bind it to the variable.
                var symbol = First(First(expr));
                if (!(symbol is Symbol))
                {
                    ErrorHandlers.SemanticError(string.Format(@"Attempt to define a non-symbol: ""{0}""", symbol.ToString(true)), null);
                }

                env.Define((Symbol)symbol, Lambda.New(Rest(First(expr)), Rest(expr), env));
                caller.ReturnedExpr = Undefined.Instance;
                return caller;
            }

            return new EvaluateDefine(expr, env, caller);
        }
Пример #18
0
        /// <summary>
        /// Call let evaluator.
        /// Start by checking the number of arguments.
        /// Then test for named let.  
        /// Grab bindings, body, and optionally name.
        /// </summary>
        /// <param name="expr">The expression to evaluate.</param>
        /// <param name="env">The environment to make the expression in.</param>
        /// <param name="caller">The caller.  Return to this when done.</param>
        /// <returns>The let evaluator.</returns>
        internal static Evaluator Call(SchemeObject expr, Environment env, Evaluator caller)
        {
            if (expr is EmptyList)
            {
                ErrorHandlers.SemanticError("No arguments for let", null);
                caller.ReturnedExpr = Undefined.Instance;
                return caller;
            }

            if (!(expr is Pair))
            {
                ErrorHandlers.SemanticError("Bad arg list for let: " + expr, null);
                caller.ReturnedExpr = Undefined.Instance;
                return caller;
            }

            Symbol name = null;
            SchemeObject bindings;
            SchemeObject body;
            if (First(expr) is Symbol)
            {
                // named let
                name = (Symbol)First(expr);
                bindings = Second(expr);
                body = Rest(Rest(expr));
            }
            else
            {
                bindings = First(expr);
                body = Rest(expr);
            }

            if (body is EmptyList)
            {
                caller.ReturnedExpr = Undefined.Instance;
                return caller;
            }

            SchemeObject vars = MapFun(First, bindings);
            SchemeObject inits = MapFun(Second, bindings);
            return new EvaluateLet(expr, env, caller, name, body, vars, inits);
        }
Пример #19
0
 private void CheckComplete()
 {
     if (pirates.Count > 0)
     {
         if (allIsDead)
         {
             log.InfoFormat("Activator complete create chest".Yellow());
             pirates.Clear();
             SchemeDropper dropper = new SchemeDropper(CommonUtils.GetRandomEnumValue <Workshop>(new List <Workshop>()), 1, nebulaObject.resource, ObjectColor.orange);
             SchemeObject  scheme  = dropper.Drop() as SchemeObject;
             ConcurrentBag <ServerInventoryItem> dropList = new ConcurrentBag <ServerInventoryItem> {
                 new ServerInventoryItem(scheme, 1)
             };
             var obj = ObjectCreate.SharedChest((nebulaObject.world as MmoWorld), transform.position + Rand.UnitVector3() * 4, 5 * 60, dropList);
             obj.AddToWorld();
             SetCooldownTimer(cooldown);
             SetInteractable(false);
         }
     }
 }
Пример #20
0
 /// <summary>
 /// Initializes a new instance of the EvaluateMap class.
 /// This is used in the "map" primitive, and as part of "for-each".
 /// Because it is used internally, the evaluator must not use destructive
 ///   operations on its member variables.
 /// </summary>
 /// <param name="expr">The expression to evaluate.</param>
 /// <param name="env">The evaluation environment</param>
 /// <param name="caller">The caller.  Return to this when done.</param>
 /// <param name="proc">The proc to apply to each element of the list.</param>
 /// <param name="result">Accumulate the result here, if not null.</param>
 private EvaluateMap(SchemeObject expr, Environment env, Evaluator caller, Procedure proc, SchemeObject result)
     : base(ApplyFunStep, expr, env, caller)
 {
     this.proc = proc;
     this.result = result;
 }
Пример #21
0
 /// <summary>
 /// Check the number of args passed.
 /// </summary>
 /// <param name="numArgs">The number of arguments expected.</param>
 /// <param name="args">The arguments passed to the procedure.</param>
 /// <param name="evaluatorName">Name, for the error message.</param>
 /// <param name="caller">The calling evaluator</param>
 protected void CheckArgCount(int numArgs, SchemeObject args, string evaluatorName, Evaluator caller)
 {
     if (numArgs < this.minArgs || numArgs > this.maxArgs)
     {
         this.ArgCountError(numArgs, minArgs, args, evaluatorName, caller);
     }
 }
Пример #22
0
 /// <summary>
 /// Generate an error when the argument count check fails.
 /// This is also called by CLR procedures, which check their arguments differently.
 /// </summary>
 /// <param name="numArgs">The actual number of arguments.</param>
 /// <param name="expectedArgs">The expected number of arguments.</param>
 /// <param name="args">The arguments actually passed.</param>
 /// <param name="evaluatorName">The name of the evaluator that is checking the count.</param>
 /// <param name="caller">The calling evaluator.</param>
 protected void ArgCountError(int numArgs, int expectedArgs, SchemeObject args, string evaluatorName, Evaluator caller)
 {
     string msg = numArgs < expectedArgs ? "few" : "many";
         int lineNumber = caller.FindLineNumberInCallStack();
         string lineMsg = lineNumber == 0 ? string.Empty : " at line: " + lineNumber;
         ErrorHandlers.SemanticError(
             string.Format(
                 @"""{0}"" too {1} args ({2}) for {3}: ""{4}""{5}",
                 evaluatorName,
                 msg,
                 numArgs,
                 this.ProcedureName,
                 args,
                 lineMsg),
             null);
 }
Пример #23
0
 /// <summary>
 /// Call apply proc evaluator after evaluating args.
 /// </summary>
 /// <param name="fn">The function to apply.</param>
 /// <param name="args">The arguments to evaluate, the pass to fn.</param>
 /// <param name="env">The environment to evaluate the expression in.</param>
 /// <param name="caller">The caller.  Return to this when done.</param>
 /// <returns>The proc evaluator.</returns>
 internal static Evaluator Call(Procedure fn, SchemeObject args, Environment env, Evaluator caller)
 {
     return new EvaluateProc(fn, args, env, caller, true);
 }
Пример #24
0
 /// <summary>
 /// Call the sequence evaluator.
 /// </summary>
 /// <param name="expr">The expressions to evaluate.</param>
 /// <param name="env">The environment to evaluate in.</param>
 /// <param name="caller">The caller.  Return to this when done.</param>
 /// <returns>The sequence evaluator.</returns>
 internal static Evaluator Call(SchemeObject expr, Environment env, Evaluator caller)
 {
     return new EvaluateSequence(expr, env, caller);
 }
Пример #25
0
        private void RewardItemImpl(InventoryItemQuestReward reward)
        {
            ServerInventoryItem targetItem = null;

            switch (reward.ObjectType)
            {
            case InventoryObjectType.Material: {
                MaterialItemQuestReward materialReward = reward as MaterialItemQuestReward;
                if (materialReward != null)
                {
                    MaterialObject material = new MaterialObject(materialReward.OreId);
                    targetItem = new ServerInventoryItem(material, materialReward.Count);
                }
            }
            break;

            case InventoryObjectType.Scheme: {
                SchemeItemQuestReward schemeReward = reward as SchemeItemQuestReward;
                if (schemeReward != null)
                {
                    SchemeObject scheme = new SchemeObject(new SchemeObject.SchemeInitData(
                                                               id: Guid.NewGuid().ToString(),
                                                               name: string.Empty,
                                                               level: PlayerLevel,
                                                               workshop: PlayerWorkshop,
                                                               templateModuleId: resource.ModuleTemplates.Module(PlayerWorkshop, schemeReward.Slot).Id,
                                                               color: schemeReward.Color,
                                                               craftingMaterials: new Dictionary <string, int>(),
                                                               inSetID: string.Empty
                                                               ));
                    targetItem = new ServerInventoryItem(scheme, schemeReward.Count);
                }
            }
            break;

            case InventoryObjectType.Weapon: {
                WeaponItemQuestReward weaponReward = reward as WeaponItemQuestReward;
                if (weaponReward != null)
                {
                    WeaponDropper.WeaponDropParams weaponDropParams = new WeaponDropper.WeaponDropParams(
                        resource: resource,
                        level: PlayerLevel,
                        workshop: PlayerWorkshop,
                        damageType: WeaponDamageType.damage,
                        difficulty: Difficulty.none
                        );
                    ColorInfo     colorInfo     = resource.ColorRes.Color(ColoredObjectType.Weapon, weaponReward.Color);
                    DropManager   dropManager   = DropManager.Get(resource);
                    WeaponDropper weaponDropper = dropManager.GetWeaponDropper(dropParams: weaponDropParams);
                    WeaponObject  weapon        = weaponDropper.DropWeapon(colorInfo);
                    targetItem = new ServerInventoryItem(weapon, weaponReward.Count);
                }
            }
            break;
            }

            if (targetItem != null)
            {
                GetComponent <MmoActor>()?.AddToStationInventory(item: targetItem, sendUpdateEvent: true);
            }
        }
Пример #26
0
 /// <summary>
 /// Call an expand evaluator.
 /// This comes here with a macro (fn) and a set of macro arguments (args).
 /// The args are unevaluated.  
 /// The macro is applied to the unevaluated arguments, yielding an expanded program.
 /// Then the result is evaluated as an expression.
 /// </summary>
 /// <param name="fn">The macro to expand.</param>
 /// <param name="args">The expression to evaluate.</param>
 /// <param name="env">The environment to make the expression in.</param>
 /// <param name="caller">The caller.  Return to this when done.</param>
 /// <returns>The expand evaluator.</returns>
 internal static Evaluator Call(Macro fn, SchemeObject args, Environment env, Evaluator caller)
 {
     return new EvaluateExpandMacro(args, env, caller, fn);
 }
Пример #27
0
 /// <summary>
 /// Initializes a new instance of the EvaluateExpandMacro class.
 /// </summary>
 /// <param name="expr">The expression to evaluate.</param>
 /// <param name="env">The evaluation environment</param>
 /// <param name="caller">The caller.  Return to this when done.</param>
 /// <param name="fn">The macro to expand.</param>
 private EvaluateExpandMacro(SchemeObject expr, Environment env, Evaluator caller, Macro fn)
     : base(ExpandStep, expr, env, caller)
 {
     this.fn = fn;
 }
Пример #28
0
 /// <summary>
 /// Initializes a new instance of the SuspendedEvaluator class.
 /// It is used to indicate that an evaluation has suspended rather than returning a value.
 /// The caller is needed so that we can search for a catcher.
 /// The SuspendedEvaluator is given as the ReturnedExpr of the evaluaton, and of the whole Eval.
 /// The AsyncResult can be extracted from this if necessary, but is NOT the final async result,
 ///   just the intermediate result of this suspension.
 /// AsyncResult is stored in Expr.
 /// </summary>
 /// <param name="res">The IAsyncResult associated with the suspension.</param>
 /// <param name="caller">The calling evaluator.</param>
 internal SuspendedEvaluator(SchemeObject res, Evaluator caller)
     : base(null, res, null, caller)
 {
 }
Пример #29
0
 /// <summary>
 /// Initializes a new instance of the FinalEvaluator class.
 /// </summary>
 /// <param name="expr">The expression to return.</param>
 internal FinalEvaluator(SchemeObject expr)
     : base(null, null, null, null)
 {
     this.ReturnedExpr = expr;
     this.Finished = true;
 }
Пример #30
0
        /// <summary>
        /// Ensure that the given object is a procedure.
        /// Used for checking before attempting to Apply a computed value.
        /// </summary>
        /// <param name="obj">The object to check</param>
        /// <returns>The object as a procedure.</returns>
        internal static Procedure EnsureProcedure(SchemeObject obj)
        {
            if (!(obj is Procedure))
            {
                ErrorHandlers.ProcError("Attempt to use as a procedure", obj);
            }

            return (Procedure)obj;
        }
Пример #31
0
 /// <summary>
 /// Initializes a new instance of the EvaluateSequence class.
 /// </summary>
 /// <param name="expr">The expressions to evaluate.</param>
 /// <param name="env">The evaluation environment</param>
 /// <param name="caller">The caller.  Return to this when done.</param>
 private EvaluateSequence(SchemeObject expr, Environment env, Evaluator caller)
     : base(EvalExprStep, expr, env, caller)
 {
 }
Пример #32
0
 /// <summary>
 /// All subclasses have to be able to apply the procedure to arguments.
 /// That is what it means to be a procedure.
 /// </summary>
 /// <param name="args">The arguments to the procedure, which may or may not have 
 ///   been evaluated.</param>
 /// <param name="env">The application environment.</param>
 /// <param name="returnTo">The evaluator to return to.  This can be different from caller if this is the last step in evaluation</param>
 /// <param name="caller">The calling evaluator.</param>
 /// <returns>The next evaluator to run after the application.</returns>
 internal abstract Evaluator Apply(SchemeObject args, Environment env, Evaluator returnTo, Evaluator caller);
Пример #33
0
 /// <summary>
 /// Initializes a new instance of the EvaluateProc class.
 /// </summary>
 /// <param name="fn">The function to apply.</param>
 /// <param name="args">The arguments to evaluate.</param>
 /// <param name="env">The evaluation environment</param>
 /// <param name="caller">The caller.  Return to this when done.</param>
 /// <param name="evaluate">If true, evaluate the args.  If false, do not evaluate them.</param>
 private EvaluateProc(Procedure fn, SchemeObject args, Environment env, Evaluator caller, bool evaluate)
     : base(EvalArgsStep, args, env, caller)
 {
     this.fn = fn;
 }
Пример #34
0
 /// <summary>
 /// Evaluate the procedure.
 /// At this point, the args are NOT evaluated
 /// Macro is evaluated differently, and overrides this method.
 /// This is a primitive, a lambda, a continuation, or a CLR Procedure.
 /// Evaluate the arguments in the environment, then apply the function 
 ///    to the arguments.
 /// </summary>
 /// <param name="args">The arguments to the procedure.</param>
 /// <param name="env">The environment to use for the application.</param>
 /// <param name="caller">Return here when done.</param>
 /// <returns>The next evaluator to execute.</returns>
 internal virtual Evaluator Evaluate(SchemeObject args, Environment env, Evaluator caller)
 {
     return EvaluateProc.Call(this, args, env, caller);
 }
Пример #35
0
 /// <summary>
 /// Call apply proc evaluator, but do not evaluate arguments.
 /// In this case, we can avoid having to instantiate an instance.
 /// </summary>
 /// <param name="fn">The function to apply.</param>
 /// <param name="args">The arguments to pass to fn.</param>
 /// <param name="env">The environment to evaluate the expression in.</param>
 /// <param name="caller">The caller.  Return to this when done.</param>
 /// <returns>The proc evaluator.</returns>
 internal static Evaluator CallQuoted(Procedure fn, SchemeObject args, Environment env, Evaluator caller)
 {
     return fn.Apply(args, null, caller, caller);
 }
Пример #36
0
 /// <summary>
 /// Initializes a new instance of the EvaluateOr class.
 /// </summary>
 /// <param name="expr">The expression to evaluate.</param>
 /// <param name="env">The evaluation environment</param>
 /// <param name="caller">The caller.  Return to this when done.</param>
 private EvaluateOr(SchemeObject expr, Environment env, Evaluator caller)
     : base(EvalTestStep, expr, env, caller)
 {
 }