[Laszlo-dev] Mixins in swf9

André Bargull a.bargull at intensis.de
Sat Apr 19 14:43:32 PDT 2008


Just made some tests, and here's the way it goes:

/* compiler sees a mixin */
mixin LzDataNodeMixin {
  public var nodeType:int = 0;
}

/* compiler declares the interface as usual */
/* additionally it will generate getters/setters for public var 
declarations from mixin */
interface LzDataNodeMixin {
  function get nodeType() :int;
  function set nodeType(nodeType:int) :void;
}

/* an interstitial class will look like this */
class $lzsc$mixin$LzDataNodeMixin$LzMiniNode extends LzMiniNode 
implements LzDataNodeMixin {
  /* compiler emits a private var to hold the actual value */
  private var $lzsc$nodeType:int = 0;

  /* compiler emits public getter/setter to meet interface specification */
  public function get nodeType() :int {
    return this.$lzsc$nodeType;
  }
  public function set nodeType(nodeType:int) :void {
    this.$lzsc$nodeType = nodeType;
  }
}

On 4/19/2008 10:02 PM, P T Withington wrote:
> I see what your are getting at, and it does seem like a good idea.  My 
> question is, will it work?  Currently mixin state is replicated in 
> intermediate classes as necessary.  Is the compiler going to have to 
> emit getter/setter and (anonymous) state to meet the interface spec?  
> I would think the compiler would complain if you say you implement an 
> interface with getter/setter and you try to implement it by a public 
> var declaration.
>
> On 2008-04-19, at 10:50 EDT, Donald Anderson wrote:
>> That seems like a natural extension to
>> the mechanism.   Can you file a JIRA enhancement
>> for this, please?  Any thoughts, Tucker?
>>
>> On Apr 19, 2008, at 10:04 AM, André Bargull wrote:
>>
>>> But only (public) functions from mixins will be taken for the AS3 
>>> interface declaration.
>>> The Flex3 Language Reference says:
>>>> Unlike ActionScript 2.0, ActionScript 3.0 allows the use of getter 
>>>> and setter methods in interface definitions.
>>> So, it'd be supercool if normal var declarations in a mixin will be 
>>> transformed into getter/setter declarations in the AS3-interface.
>>> Currently this will trigger an error in the flex compiler, because 
>>> "nodeType" is unknown for the LzDataNodeMixin interface:
>>> ---
>>> var node:LzDataNodeMixin = ...
>>> Debug.write(node.nodeType);
>>> ---
>>>
>>> If we had getters/setters, this wouldn't be a problem. Or did I miss 
>>> something?
>>>
>>> As an example:
>>> This Laszlo-Mixin declaration:
>>> ---
>>> mixin LzDataNodeMixin {
>>> public var nodeType:int;
>>> }
>>> ---
>>>
>>> will be transformed to the following AS3 interface declaration:
>>> ---
>>> interface LzDataNodeMixin {
>>> public function get nodeType() :int;
>>> public function set nodeType(nodeType:int) :void;
>>> }
>>> ---
>>>
>>> and an actual implementation would look like this:
>>> ---
>>> class $lzsc$mixin$LzDataNodeMixin$LzMiniNode extends LzMiniNode 
>>> implements LzDataNodeMixin {
>>> public var nodeType:int = 0;
>>>
>>> /* auto generated getter/setter for nodeType */
>>> public function get nodeType() :int {
>>>  return this.nodeType;
>>> }
>>> public function set nodeType(nodeType:int) :void {
>>>  this.nodeType = nodeType;
>>> }
>>> }
>>> ---
>>>
>>> On 4/19/2008 3:34 PM, André Bargull wrote:
>>>> Oh, I see. Thank you!
>>>>
>>>>
>>>> On 4/19/2008 2:21 PM, Donald Anderson wrote:
>>>>> Hi Andre.
>>>>>
>>>>> It was implemented for SWF9, and I have examples that work.
>>>>> The functions appearing in the interface must be declared 'public',
>>>>> and that is not the case here.
>>>>>
>>>>> - Don
>>>>>
>>>>> On Apr 19, 2008, at 7:02 AM, André Bargull wrote:
>>>>>
>>>>>> Mixins produce only an empty interface declaration for swf9? The 
>>>>>> description of LPP-5266 says:
>>>>>>> 1) It should output an `interface`, that consists of the 
>>>>>>> signature of the mixin, i.e., all the method declarations. This 
>>>>>>> will make it so `instanceof` can work on mixins.
>>>>>>
>>>>>> So (1) wasn't implemented? For example LzDataElementMixin will be 
>>>>>> transformed to:
>>>>>>> package {
>>>>>>> interface LzDataElementMixin {
>>>>>>> }
>>>>>>> }
>>>>>>
>>>>>> But I've expected:
>>>>>>> package {
>>>>>>> interface LzDataElementMixin {
>>>>>>> function insertBefore (newChild, refChild);
>>>>>>> function replaceChild (newChild, oldChild);
>>>>>>> function removeChild (oldChild);
>>>>>>> [...]
>>>>>>> }
>>>>>>> }
>>>>>>
>>>>>
>>>>>
>>>>> -- 
>>>>>
>>>>> Don Anderson
>>>>> Java/C/C++, Berkeley DB, systems consultant
>>>>>
>>>>> voice: 617-547-7881
>>>>> email: dda at ddanderson.com
>>>>> www: http://www.ddanderson.com
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>
>>
>>
>> -- 
>>
>> Don Anderson
>> Java/C/C++, Berkeley DB, systems consultant
>>
>> voice: 617-547-7881
>> email: dda at ddanderson.com
>> www: http://www.ddanderson.com
>>
>>
>>
>>
>
>


More information about the Laszlo-dev mailing list