Ejemplo n.º 1
0
 public int Eval(RuntimeEnvironment runtimeEnvironment, FunctionEnvironment functionEnvironment, int argument)
 {
     runtimeEnvironment.AllocateLocal(_argument.Item1);
     runtimeEnvironment.GetVariable(_argument.Item1).Value = argument;
     var v = _body.Eval(runtimeEnvironment, functionEnvironment);
     runtimeEnvironment.Pop();
     return v;
 }
Ejemplo n.º 2
0
        public override int Eval(RuntimeEnvironment env, FunctionEnvironment fEnv)
        {
            int value = e1.Eval(env, fEnv);

            env.AllocateLocal(name);                    // It pushes a new Pair<String, Storage>(name, new Storage()) to the stack called locals. The Storage value is 0 or null the String name is the type the storage.value is the value.

            Storage storage = env.GetVariable(name);    // this method returns a Storage object. The storage variable that we create here, is pointing to the same object as the other Storage variable in the Stack<Pair<String, Storage> locals.

            storage.Value = value;                      // The Storage has only a value field. If we modify the value of this Storage variable, the value of the object will be modofied.

            int result = e2.Eval(env, fEnv);

            env.Pop();

            return(result);
        }
 public int Eval(RuntimeEnvironment env, FunctionEnvironment fenv, int[] values)
 {
     if (args.Count > 0)
     {
         int index = 0;
         foreach (Tuple <string, Type> tuple in args)
         {
             env.AllocateLocal(tuple.Item1);
             env.GetVariable(tuple.Item1).Value = values[index++];
         }
         int v = body.Eval(env, fenv);
         foreach (Tuple <string, Type> tuple in args)
         {
             env.Pop();
         }
         return(v);
     }
     else
     {
         int v = body.Eval(env, fenv);
         return(v);
     }
 }