royale-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Carlos Rovira <carlosrov...@apache.org>
Subject Re: Check is something is Class or instance in Royale
Date Sun, 07 Oct 2018 18:32:40 GMT
While I'm pro PAYG, I think Language is for me a very internal piece, and
for users will be even more. So we should think as well if in cases like
this we should just implement all the cases since doesn't seems to me more
than what we are talking here, even if we get 2-3 more, I think will be
worth it to not make it more complex. Think that Royale is already complex
for people coming, so between making a pluggable system at Language level
or implement 2-3 more cases, my recommendation is to go for the second.

About what to do, I must say this is not my field, so. I left to Alex or
Harbs do what they think is better. My only thinking is that not having
"Class" around will be strange for any one coming from flash/flex/as3
background, so I bet for have that although it implies few bytes more. I
think is worth it. If the cost will much more I think we could think it
more, but for me is like having Array, Object, String and more....is just
something core in the language.

just my 2ctns...

Carlos


El dom., 7 oct. 2018 a las 16:52, Alex Harui (<aharui@adobe.com.invalid>)
escribió:

> If Language.is needs other handling, maybe it is worth implementing some
> sort of plug-in model for it so folks can alter what it does to suit their
> needs.
>
> Where possible, we want the runtime code to handle PAYG/Just-in-case
> issues.  The compiler's job is really to transpile a syntax tree and not
> generate as much special case code.  The compiler must generate different
> code for e4x since type information is lost at runtime.  For Language.is,
> we don't want the compiler to generate a lengthy run of code that tries to
> handle all of these cases.
>
> Somewhere in the middle is the option is the option of breaking
> Language.is into tests for primitive types, so add a Language.isBoolean,
> Language.isArray, Language.isClass, and leave Language.is for non-primitive
> types.
>
> My 2 cents,
> -Alex
>
> On 10/7/18, 12:05 AM, "Harbs" <harbs.lists@gmail.com> wrote:
>
>     I think”is Array” should be rewritten to Array.isArray() in the
> compiler.
>
>     Some time back, I added some comments to Language.is expressing some
> possible improvements there. I also highlighted a bug where “new
> String(“foo”)” new Number(2) and new Boolean(false) will get wrong results.
> (I don’t know how much something like that is used in the wild…)
>
>     HTH,
>     Harbs
>
>     > On Oct 7, 2018, at 9:28 AM, Alex Harui <aharui@adobe.com.INVALID>
> wrote:
>     >
>     > Ah yes, Class is currently in missing.js in typedefs because so far
> nobody needed it at runtime.
>     >
>     > I kind of wish we could avoid creating a dummy Class and having it
> linked into every app via Language.is <
> https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Flanguage.is%2F&amp;data=02%7C01%7Caharui%40adobe.com%7Cc98391dd9c7c4b5f7e7708d62c234b6e%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636744927457344736&amp;sdata=Q5GxCw%2BR4C6ehRnwRg7cX39Swab2VBrGdtnj7Z%2F0Zxc%3D&amp;reserved=0>
> even thought it will only be around 20 bytes.
>     > We could require a bead that injects the definition so folks can
> opt-in as needed.
>     > We could have a plugin-scheme in Language-is so you can mixin more
> tests if you need it.  Right now it tests for Array which might be
> just-in-case code.
>     >
>     > Thoughts?
>     > -Alex
>     >
>     > On 10/6/18, 9:51 AM, "Carlos Rovira" <carlosrovira@apache.org
> <mailto:carlosrovira@apache.org>> wrote:
>     >
>     >    Hi Piotr,
>     >
>     >    I think the problem is more about what to do with "Class" since
> is valid in
>     >    AS3 and we need proper transpiler to SWF, JS...
>     >    Right now in JS Class is not know
>     >
>     >    [Error] ReferenceError: Can't find variable: Class=
>     >
>     >    As I posted in the first email, I can workaround with
>     >
>     >    typeof myFunc === 'function'
>     >
>     >    I think this could work for both cases, or maybe the solution you
> posted (I
>     >    didn't try it)
>     >
>     >    But the use case comes from trying to compile an existing Flex
> AS3 library
>     >    with Royale, so we'll find "Class" keyword many times out there,
> so I think
>     >    is worth it trying to solve at compiler/Language level.
>     >
>     >    Thanks Piotr for the suggestion
>     >
>     >    Carlos
>     >
>     >
>     >
>     >    El sáb., 6 oct. 2018 a las 15:49, Piotr Zarzycki (<
> piotrzarzycki21@gmail.com>)
>     >    escribió:
>     >
>     >> In the other words you are interested whether there is an object
> not a
>     >> simple type? That's what I mean.
>     >>
>     >> Why not if (are[0] is object) - does it not cover all of the cases?
>     >>
>     >>
>     >> On Sat, Oct 6, 2018, 2:48 PM Carlos Rovira <carlosrovira@apache.org
> >
>     >> wrote:
>     >>
>     >>> No, arr[0] has an instance of a custom typed object.
>     >>>
>     >>> El sáb., 6 oct. 2018 a las 10:58, Piotr Zarzycki (<
>     >>> piotrzarzycki21@gmail.com>)
>     >>> escribió:
>     >>>
>     >>>> Hi Carlos,
>     >>>>
>     >>>> Are you trying to distinguish something from simple type by that
>     >>> if(arr[0]
>     >>>> is Class) ? By simple type I mean String, Boolean?
>     >>>>
>     >>>> Piotr
>     >>>>
>     >>>> On Sat, Oct 6, 2018, 10:54 AM Carlos Rovira <
> carlosrovira@apache.org>
>     >>>> wrote:
>     >>>>
>     >>>>> Hi Alex,
>     >>>>>
>     >>>>> I'm very new to Language.as, so I'll try to do my best.
>     >>>>>
>     >>>>> I'm trying to add to Language.as "is" function this:
>     >>>>>
>     >>>>> if(rightOperand === Class) {
>     >>>>>                return typeof leftOperand === 'function';
>     >>>>>            }
>     >>>>>
>     >>>>> the test case is :
>     >>>>>
>     >>>>> var arr:Array = [main]; //main is a container declared in MXML,
> so is
>     >>> not
>     >>>>> class is an instance
>     >>>>> if(arr[0] is Class)
>     >>>>> {
>     >>>>> trace("is Class");
>     >>>>> } else
>     >>>>> {
>     >>>>> trace("is NOT Class"); // I expect to get this trace
>     >>>>> }
>     >>>>>
>     >>>>> but browser reports:
>     >>>>>
>     >>>>> [Error] ReferenceError: Can't find variable: Class is
>     >> (Language.js:147)
>     >>>>>
>     >>>>> So first point to solve is how to deal with "Class", since is
not
>     >>>>> recognized at javascript level. Seems to me that "Class" should
> be
>     >>> solved
>     >>>>> at compiler level?
>     >>>>>
>     >>>>> Thanks
>     >>>>>
>     >>>>>
>     >>>>> El vie., 5 oct. 2018 a las 23:11, Alex Harui
>     >> (<aharui@adobe.com.invalid
>     >>>>> )
>     >>>>> escribió:
>     >>>>>
>     >>>>>> Hi Carlos,
>     >>>>>>
>     >>>>>> Use of "is" is transpiled into a call to Language.is.  I
think
>     >>>>> Language.is
>     >>>>>> should special case the test for Class.  Try updating
> Language.is
>     >> and
>     >>>> see
>     >>>>>> if that is what you need.
>     >>>>>>
>     >>>>>> -Alex
>     >>>>>>
>     >>>>>> On 10/5/18, 11:13 AM, "Carlos Rovira" <carlosrovira@apache.org>
>     >>>> wrote:
>     >>>>>>
>     >>>>>>    Hi,
>     >>>>>>
>     >>>>>>    in js, check if something is a class or is an instance
is
> like
>     >>> this
>     >>>>> [1]
>     >>>>>>
>     >>>>>>    typeof myFunc === 'function'
>     >>>>>>
>     >>>>>>    In Royale since we are using AS3, doing
>     >>>>>>
>     >>>>>>    if(something is Class)
>     >>>>>>        do this
>     >>>>>>    else
>     >>>>>>       do that
>     >>>>>>
>     >>>>>>    should work either for SWF and for JS, but seems is not
the
>     >> case.
>     >>>>>>    I must make two codes COMPILE::SWF (with "is Class")
and
>     >>>> COMPILE::JS
>     >>>>>> (with
>     >>>>>>    typeof ... ==='function')
>     >>>>>>
>     >>>>>>    Could we have this abstracted by compiler?
>     >>>>>>
>     >>>>>>    Thanks
>     >>>>>>
>     >>>>>>    [1]
>     >>>>>>
>     >>>>>>
>     >>>>>
>     >>>>
>     >>>
>     >>
> https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstackoverflow.com%2Fquestions%2F405164%2Fbest-method-of-testing-for-a-function-in-javascript&amp;data=02%7C01%7Caharui%40adobe.com%7Cc98391dd9c7c4b5f7e7708d62c234b6e%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636744927457344736&amp;sdata=x9s3L1Uj0KAPTNGB4hkpPF8rigt3a9M%2B2EBYqLWAKDc%3D&amp;reserved=0
> <
> https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstackoverflow.com%2Fquestions%2F405164%2Fbest-method-of-testing-for-a-function-in-javascript&amp;data=02%7C01%7Caharui%40adobe.com%7Cc98391dd9c7c4b5f7e7708d62c234b6e%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636744927457354750&amp;sdata=paL2T51YvXGpeQ5I5eICv5XIUUzR7uurh%2BiZHSRIjy0%3D&amp;reserved=0
> >
>     >>>>>>
>     >>>>>>    --
>     >>>>>>    Carlos Rovira
>     >>>>>>
>     >>>>>>
>     >>>>>
>     >>>>
>     >>>
>     >>
> https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fabout.me%2Fcarlosrovira&amp;data=02%7C01%7Caharui%40adobe.com%7Cc98391dd9c7c4b5f7e7708d62c234b6e%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636744927457354750&amp;sdata=Ng%2BNeKJ1BxklA6w2PMb1uTYyWClazORsJPrEsfLuOIg%3D&amp;reserved=0
> <
> https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fabout.me%2Fcarlosrovira&amp;data=02%7C01%7Caharui%40adobe.com%7Cc98391dd9c7c4b5f7e7708d62c234b6e%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636744927457354750&amp;sdata=Ng%2BNeKJ1BxklA6w2PMb1uTYyWClazORsJPrEsfLuOIg%3D&amp;reserved=0
> >
>     >>>>>>
>     >>>>>>
>     >>>>>>
>     >>>>>
>     >>>>> --
>     >>>>> Carlos Rovira
>     >>>>>
> https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fabout.me%2Fcarlosrovira&amp;data=02%7C01%7Caharui%40adobe.com%7Cc98391dd9c7c4b5f7e7708d62c234b6e%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636744927457354750&amp;sdata=Ng%2BNeKJ1BxklA6w2PMb1uTYyWClazORsJPrEsfLuOIg%3D&amp;reserved=0
> <
> https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fabout.me%2Fcarlosrovira&amp;data=02%7C01%7Caharui%40adobe.com%7Cc98391dd9c7c4b5f7e7708d62c234b6e%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636744927457354750&amp;sdata=Ng%2BNeKJ1BxklA6w2PMb1uTYyWClazORsJPrEsfLuOIg%3D&amp;reserved=0
> >
>     >>>>>
>     >>>>
>     >>>
>     >>>
>     >>> --
>     >>> Carlos Rovira
>     >>>
> https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fabout.me%2Fcarlosrovira&amp;data=02%7C01%7Caharui%40adobe.com%7Cc98391dd9c7c4b5f7e7708d62c234b6e%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636744927457354750&amp;sdata=Ng%2BNeKJ1BxklA6w2PMb1uTYyWClazORsJPrEsfLuOIg%3D&amp;reserved=0
> <
> https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fabout.me%2Fcarlosrovira&amp;data=02%7C01%7Caharui%40adobe.com%7Cc98391dd9c7c4b5f7e7708d62c234b6e%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636744927457354750&amp;sdata=Ng%2BNeKJ1BxklA6w2PMb1uTYyWClazORsJPrEsfLuOIg%3D&amp;reserved=0
> >
>     >>>
>     >>
>     >
>     >
>     >    --
>     >    Carlos Rovira
>     >
> https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fabout.me%2Fcarlosrovira&amp;data=02%7C01%7Caharui%40adobe.com%7Cc98391dd9c7c4b5f7e7708d62c234b6e%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636744927457354750&amp;sdata=Ng%2BNeKJ1BxklA6w2PMb1uTYyWClazORsJPrEsfLuOIg%3D&amp;reserved=0
> <
> https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fabout.me%2Fcarlosrovira&amp;data=02%7C01%7Caharui%40adobe.com%7Cc98391dd9c7c4b5f7e7708d62c234b6e%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636744927457354750&amp;sdata=Ng%2BNeKJ1BxklA6w2PMb1uTYyWClazORsJPrEsfLuOIg%3D&amp;reserved=0
> >
>
>
>

-- 
Carlos Rovira
http://about.me/carlosrovira

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message