public override HeronValue Eval(VM vm)
        {
            HeronValue val = vm.Eval(rvalue);

            if (lvalue is Name)
            {
                string name = (lvalue as Name).name;
                if (vm.HasVar(name))
                {
                    vm.SetVar(name, val);
                    return(val);
                }
                else if (vm.HasField(name))
                {
                    vm.SetField(name, val);
                    return(val);
                }
                else
                {
                    throw new Exception(name + " is not a member field or local variable that can be assigned to");
                }
            }
            else if (lvalue is ChooseField)
            {
                ChooseField field = lvalue as ChooseField;
                HeronValue  self  = vm.Eval(field.self);
                self.SetField(field.name, val);
                return(val);
            }
            else if (lvalue is ReadAt)
            {
                ReadAt     ra    = lvalue as ReadAt;
                HeronValue self  = vm.Eval(ra.self);
                HeronValue index = vm.Eval(ra.index);
                ListValue  list  = self as ListValue;
                if (list != null)
                {
                    list.SetAtIndex(index, val);
                    return(val);
                }
                ArrayValue array = self as ArrayValue;
                if (array != null)
                {
                    array.SetAtIndex(index, val);
                    return(val);
                }

                throw new Exception("Unimplemented");
            }
            else
            {
                throw new Exception("Cannot assign to expression " + lvalue.ToString());
            }
        }
Beispiel #2
0
 public virtual void SetValue(HeronValue self, HeronValue x)
 {
     self.SetField(name, x);
 }