Example #1
0
        private PerlangEnvironment Ancestor(int distance)
        {
            PerlangEnvironment environment = this;

            for (int i = 0; i < distance; i++)
            {
                environment = environment.enclosing;
            }

            return(environment);
        }
Example #2
0
        public object Call(IInterpreter interpreter, List <object> arguments)
        {
            var environment = new PerlangEnvironment(closure);

            for (int i = 0; i < declaration.Parameters.Count; i++)
            {
                environment.Define(declaration.Parameters[i].Name, arguments[i]);
            }

            try
            {
                interpreter.ExecuteBlock(declaration.Body, environment);
                return(null);
            }
            catch (Return returnValue)
            {
                return(returnValue.Value);
            }
        }
Example #3
0
 public PerlangEnvironment(IEnvironment enclosing = null)
 {
     // Cast is safe as long as we are the sole implementation of the IEnvironment interface.
     this.enclosing = (PerlangEnvironment)enclosing;
 }