Ejemplo n.º 1
0
        public override void Inherit(VirtualMachine vm, IodineObject self, IodineObject [] arguments)
        {
            var obj = Invoke(vm, arguments);

            foreach (KeyValuePair <string, IodineObject> kv in Attributes)
            {
                if (!self.HasAttribute(kv.Key))
                {
                    self.SetAttribute(kv.Key, kv.Value);
                }
                if (!obj.HasAttribute(kv.Key))
                {
                    obj.SetAttribute(kv.Key, kv.Value);
                }
            }
            Dictionary <string, IodineObject> childAttributes = obj.Attributes;

            foreach (KeyValuePair <string, IodineObject> kv in childAttributes)
            {
                if (kv.Value is IodineBoundMethod)
                {
                    IodineBoundMethod wrapper = (IodineBoundMethod)kv.Value;
                    wrapper.Bind(self);
                }
            }
            self.SetAttribute("__super__", obj);
            self.Base = obj;
        }
Ejemplo n.º 2
0
 public void SetAttribute(string name, IodineObject value)
 {
     if (value is IodineMethod)
     {
         IodineMethod method = (IodineMethod)value;
         Attributes [name] = new IodineBoundMethod(this, method);
     }
     else if (value is BuiltinMethodCallback)
     {
         BuiltinMethodCallback callback = (BuiltinMethodCallback)value;
         callback.Self     = this;
         Attributes [name] = value;
     }
     else if (value is IodineBoundMethod)
     {
         IodineBoundMethod wrapper = (IodineBoundMethod)value;
         Attributes [name] = new IodineBoundMethod(this, wrapper.Method);
     }
     else if (value is IodineProperty)
     {
         IodineProperty property = (IodineProperty)value;
         Attributes [name] = new IodineProperty(property.Getter, property.Setter, this);
     }
     else
     {
         Attributes [name] = value;
     }
 }
Ejemplo n.º 3
0
        public IodineGenerator(StackFrame frame,
                               IodineBoundMethod baseMethod,
                               IodineObject[] args,
                               IodineObject initialValue)
            : base(TypeDefinition)
        {
            arguments       = args;
            value           = initialValue;
            self            = baseMethod.Self;
            stackFrame      = frame;
            this.baseMethod = baseMethod.Method;

            SetAttribute("__iter__", new BuiltinMethodCallback((VirtualMachine vm, IodineObject self, IodineObject[] arguments) => {
                return(GetIterator(vm));
            }, this));
        }