You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@flex.apache.org by Jesse Nicholson <as...@gmail.com> on 2014/12/04 04:53:36 UTC

Porting To Typescript/Javascript

I commented earlier about porting the flash runtime + flex to
typescript/javascript and was asked to send an email to this list with more
info plus my progress. In terms of progress, I'd say that I have somewhere
north of 250K lines of doc comments and code done, with a lot to fill in.
The entire Flash + AIR API exists with all constants, properties methods
classes etc defined (methods stubbed out) with the implementation details
left to be filled in (for methods).

The largest bit of work to do (by far) is Flex, which I've come up with
really lazy solution to solve. I've started writing a source to source
compiler based on Falcon, that consumes and tokenizes the AS input and
emits X target (for me right now, it's C#, since my initial implementation
is C# which then cross-compiles to Typescript using NetJS. Ultimate goal
for me is to have a platform where users can code in either
JS/TypeScript/C#, whatever they choose, and seamlessly move between targets
(Native with Mono, Native with something like Cordova, or Browser only).

Anyway that's what I'm doing and if anyone is interested in the end result,
let me know. Right now I have a question. While pouring over falcons
source, I noticed comments where MXML "now gets compiled directly to
bytecode". The comment goes on to imply that once upon a time, the compiler
used to convert from MXML to Actionscript and then to ABC. Does anyone know
anything about this and if so, can they point me to it? Thanks and all the
best.

-- 
Jesse Nicholson

RE: Porting To Typescript/Javascript

Posted by "Michael A. Labriola" <la...@digitalprimates.net>.
>1.  An overview of the tools would be great.  The README does not have a lot to start with.  Or, are there any other documentation that I am missing?

You don't need to read through all of this, but if you want to get a sense of what it was all about, there are a bunch of tutorials, etc. Most are likely out of date [1]: 

Basic idea: Combination of a cross-compiler and an SDK using dependency injection and implicit lazy loading of dependencies. You write core AS with a simple DI framework based on the google guice project. The SDK made sure everything was there when it was needed. As you saw, you could then create API definitions (think of the playerglobal.swc) for other dependencies that you were available at runtime, whether they be in the browser itself or in another library that was loaded.

>2.  I see projects for Ember, JQuery, Node, etc.  Does this mean that those frameworks are already supported in Randori?  What would it take to add a new framework (DOJO, for example)?

Yes, versions of those were all supported. It really just takes creating an API definition with the right metadata so that the compiler understands what code to generate. I would need to get all involved to agree (which wouldn't be hard) but all of Randori was under an Apache license so that, if at any point, this project took an interest in what we did, it would be easy to fold it back in. We didn't want to do it within the Apache process itself, but we always hoped it might end up back here.


[1] https://github.com/RandoriAS/randori-plugin-intellij/wiki/Lesson-01-Project-Setup


RE: Porting To Typescript/Javascript

Posted by OmPrakash Muppirala <bi...@gmail.com>.
On Dec 5, 2014 8:36 AM, "Michael A. Labriola" <la...@digitalprimates.net>
wrote:
>
> >In case you want to dig into (what I didn't do), this is the code [1],
indeed, an explanation from M.Labriola or Roland would be welcome :-)
>
> Happy to answer questions as they come up.

Thanks, Mike!

A couple of questions to start with:

1.  An overview of the tools would be great.  The README does not have a
lot to start with.  Or, are there any other documentation that I am missing?

2.  I see projects for Ember, JQuery, Node, etc.  Does this mean that those
frameworks are already supported in Randori?  What would it take to add a
new framework (DOJO, for example)?

Thanks,
Om

>
> Mike

RE: Porting To Typescript/Javascript

Posted by "Michael A. Labriola" <la...@digitalprimates.net>.
>In case you want to dig into (what I didn't do), this is the code [1], indeed, an explanation from M.Labriola or Roland would be welcome :-)

Happy to answer questions as they come up.

Mike

RE: Porting To Typescript/Javascript

Posted by Frédéric THOMAS <we...@hotmail.com>.
In case you want to dig into (what I didn't do), this is the code [1], indeed, an explanation from M.Labriola or Roland would be welcome :-)

Frédéric THOMAS
[1] https://github.com/RandoriAS/randori-tools

> From: bigosmallm@gmail.com
> Date: Thu, 4 Dec 2014 11:00:27 -0800
> Subject: Re: Porting To Typescript/Javascript
> To: dev@flex.apache.org
> 
> On Thu, Dec 4, 2014 at 10:56 AM, Alex Harui <ah...@adobe.com> wrote:
> 
> >
> >
> > On 12/4/14, 10:47 AM, "Kessler CTR Mark J" <ma...@usmc.mil>
> > wrote:
> >
> > >Sounds good, thanks Alex.  Sounds like a new namespace down the road of
> > >more aligned / streamlined components.
> >
> > Yes, actually, many namespaces.  FlexJS doesn’t want to have one component
> > library or even two (like Spark and MX).  It hopes to be able to support
> > many component libraries.  FlexJS is building one “simple” one so we can
> > understand how the pieces work together without having to debug through
> > the complex code of existing component libraries.  One library will
> > probably wrap Jquery components.  Ideally, fans of each popular JS
> > component library will provide AS equivalents.  If it all works out, you
> > can switch what component library to use by changing the URI of your xmlns.
> >
> >
> One thing to consider is if we can write some tools to automatically
> generate AS stubs for JS components.  Instead of having to manually write
> the ports.  I believe that the Randori framework was able to do that.
> 
> Michael(s), any chance we can get an understand of how that works?
> 
> Thanks,
> Om
> 
> 
> > -Alex
> >
> >
 		 	   		  

Re: Porting To Typescript/Javascript

Posted by OmPrakash Muppirala <bi...@gmail.com>.
On Thu, Dec 4, 2014 at 10:56 AM, Alex Harui <ah...@adobe.com> wrote:

>
>
> On 12/4/14, 10:47 AM, "Kessler CTR Mark J" <ma...@usmc.mil>
> wrote:
>
> >Sounds good, thanks Alex.  Sounds like a new namespace down the road of
> >more aligned / streamlined components.
>
> Yes, actually, many namespaces.  FlexJS doesn’t want to have one component
> library or even two (like Spark and MX).  It hopes to be able to support
> many component libraries.  FlexJS is building one “simple” one so we can
> understand how the pieces work together without having to debug through
> the complex code of existing component libraries.  One library will
> probably wrap Jquery components.  Ideally, fans of each popular JS
> component library will provide AS equivalents.  If it all works out, you
> can switch what component library to use by changing the URI of your xmlns.
>
>
One thing to consider is if we can write some tools to automatically
generate AS stubs for JS components.  Instead of having to manually write
the ports.  I believe that the Randori framework was able to do that.

Michael(s), any chance we can get an understand of how that works?

Thanks,
Om


> -Alex
>
>

Re: Porting To Typescript/Javascript

Posted by Alex Harui <ah...@adobe.com>.

On 12/4/14, 10:47 AM, "Kessler CTR Mark J" <ma...@usmc.mil>
wrote:

>Sounds good, thanks Alex.  Sounds like a new namespace down the road of
>more aligned / streamlined components.

Yes, actually, many namespaces.  FlexJS doesn’t want to have one component
library or even two (like Spark and MX).  It hopes to be able to support
many component libraries.  FlexJS is building one “simple” one so we can
understand how the pieces work together without having to debug through
the complex code of existing component libraries.  One library will
probably wrap Jquery components.  Ideally, fans of each popular JS
component library will provide AS equivalents.  If it all works out, you
can switch what component library to use by changing the URI of your xmlns.

-Alex


RE: Porting To Typescript/Javascript

Posted by Kessler CTR Mark J <ma...@usmc.mil>.
Sounds good, thanks Alex.  Sounds like a new namespace down the road of more aligned / streamlined components.

-Mark

-----Original Message-----
From: Alex Harui [mailto:aharui@adobe.com]
Sent: Thursday, December 04, 2014 1:33 PM
To: dev@flex.apache.org
Subject: Re: Porting To Typescript/Javascript



On 12/4/14, 10:25 AM, "Kessler CTR Mark J" <ma...@usmc.mil>
wrote:

>BTW is there any plans to support things like Margin in the Flex SDK
>since they can't be native in the JS anyways?

FlexJS containers do support both margin and padding, although I’ll bet
there are bugs in the current code.  That’s part of my principles for
FlexJS.  Understand what is common/efficient/expected in HTML/JS/CSS and
emulate it in AS on Flash, not the other way around, so that the
cross-compiled HTML/JS/CSS is as good as it can be.  That way, the
cross-compiled output can simply set the margin and padding styles on the
HTMLElement and trust the browser to do the work instead of trying to
figure out how to emulate Flex padding without margins at run-time.

-Alex


Re: Porting To Typescript/Javascript

Posted by Alex Harui <ah...@adobe.com>.

On 12/4/14, 10:25 AM, "Kessler CTR Mark J" <ma...@usmc.mil>
wrote:

>BTW is there any plans to support things like Margin in the Flex SDK
>since they can't be native in the JS anyways?

FlexJS containers do support both margin and padding, although I’ll bet
there are bugs in the current code.  That’s part of my principles for
FlexJS.  Understand what is common/efficient/expected in HTML/JS/CSS and
emulate it in AS on Flash, not the other way around, so that the
cross-compiled HTML/JS/CSS is as good as it can be.  That way, the
cross-compiled output can simply set the margin and padding styles on the
HTMLElement and trust the browser to do the work instead of trying to
figure out how to emulate Flex padding without margins at run-time.

-Alex


RE: Porting To Typescript/Javascript

Posted by Kessler CTR Mark J <ma...@usmc.mil>.
BTW is there any plans to support things like Margin in the Flex SDK since they can't be native in the JS anyways?

-Mark

-----Original Message-----
From: Alex Harui [mailto:aharui@adobe.com]
Sent: Thursday, December 04, 2014 1:06 PM
To: dev@flex.apache.org
Subject: Re: Porting To Typescript/Javascript



On 12/4/14, 5:08 AM, "Erik de Bruin" <er...@ixsoftware.nl> wrote:

>You should take a look at FalconJX (same repo as Falcon): it is
>designed specifically to be a cross-compiler that can compile to
>various output languages. It sounds to me you are trying to re-invent
>the wheel by starting from Falcon. FalconJX currently has code
>branches that handle the various flavours of JS we're putting out, but
>you can use those as the basis and your guide for creating a path that
>will result in nice clear C# output.

To add a bit more to this:  The falcon repo has a compiler.jx folder that
contains the FlexJS cross compiler.  Inside it uses an Emitter to emit the
AST into JS.  IMO, it would be totally awesome to see someone create an
Emitter to emit the AST into TS.

Erik did get “all” of Flex cross-compiled into JS, so there may be things
you can learn from him on that.  My approach for FlexJS is a bit
different:  I believe that Flex needs a new API that is better suited for
cross-compilation.  There are some things in the Flash runtime that are
painful or tricky to implement in browsers so the FlexJS API set simply
tries to not use them.  My vision for FlexJS is that folks will code in
MXML and AS, and then choose a JS runtime library and output language as
the target.  We are building our own JS library full of widgets, but also
have prototypes of libraries based on Jquery and CreateJS and hope to add
others someday.  And if folks would rather output TS instead of JS, that’s
totally fine as well, so that’s why what you are working on is interesting
to me.

>>
>> Anyway that's what I'm doing and if anyone is interested in the end
>>result,
>> let me know. Right now I have a question. While pouring over falcons
>> source, I noticed comments where MXML "now gets compiled directly to
>> bytecode". The comment goes on to imply that once upon a time, the
>>compiler
>> used to convert from MXML to Actionscript and then to ABC. Does anyone
>>know
>> anything about this and if so, can they point me to it? Thanks and all
>>the
>> best.
>>

The MXMLC compiler currently effectively generates AS and then compiles
it.  For Falcon, the design team felt they could improve compiler
performance by skipping the AS generation and simply go straight to ABC,
but also felt that there could be better/faster run-time performance if
they had the option to generate ABC in ways that don’t directly map to AS.
 AFAIK, there is no hard evidence that it was the correct thing to do, and
it will be interesting as more folks use Falcon whether they miss the
ability to examine the generated AS, but my understanding of why things
are the way they are.

-Alex


Re: Porting To Typescript/Javascript

Posted by Alex Harui <ah...@adobe.com>.

On 12/4/14, 5:08 AM, "Erik de Bruin" <er...@ixsoftware.nl> wrote:

>You should take a look at FalconJX (same repo as Falcon): it is
>designed specifically to be a cross-compiler that can compile to
>various output languages. It sounds to me you are trying to re-invent
>the wheel by starting from Falcon. FalconJX currently has code
>branches that handle the various flavours of JS we're putting out, but
>you can use those as the basis and your guide for creating a path that
>will result in nice clear C# output.

To add a bit more to this:  The falcon repo has a compiler.jx folder that
contains the FlexJS cross compiler.  Inside it uses an Emitter to emit the
AST into JS.  IMO, it would be totally awesome to see someone create an
Emitter to emit the AST into TS.

Erik did get “all” of Flex cross-compiled into JS, so there may be things
you can learn from him on that.  My approach for FlexJS is a bit
different:  I believe that Flex needs a new API that is better suited for
cross-compilation.  There are some things in the Flash runtime that are
painful or tricky to implement in browsers so the FlexJS API set simply
tries to not use them.  My vision for FlexJS is that folks will code in
MXML and AS, and then choose a JS runtime library and output language as
the target.  We are building our own JS library full of widgets, but also
have prototypes of libraries based on Jquery and CreateJS and hope to add
others someday.  And if folks would rather output TS instead of JS, that’s
totally fine as well, so that’s why what you are working on is interesting
to me.

>>
>> Anyway that's what I'm doing and if anyone is interested in the end
>>result,
>> let me know. Right now I have a question. While pouring over falcons
>> source, I noticed comments where MXML "now gets compiled directly to
>> bytecode". The comment goes on to imply that once upon a time, the
>>compiler
>> used to convert from MXML to Actionscript and then to ABC. Does anyone
>>know
>> anything about this and if so, can they point me to it? Thanks and all
>>the
>> best.
>>

The MXMLC compiler currently effectively generates AS and then compiles
it.  For Falcon, the design team felt they could improve compiler
performance by skipping the AS generation and simply go straight to ABC,
but also felt that there could be better/faster run-time performance if
they had the option to generate ABC in ways that don’t directly map to AS.
 AFAIK, there is no hard evidence that it was the correct thing to do, and
it will be interesting as more folks use Falcon whether they miss the
ability to examine the generated AS, but my understanding of why things
are the way they are.

-Alex


Re: Porting To Typescript/Javascript

Posted by Erik de Bruin <er...@ixsoftware.nl>.
You should take a look at FalconJX (same repo as Falcon): it is
designed specifically to be a cross-compiler that can compile to
various output languages. It sounds to me you are trying to re-invent
the wheel by starting from Falcon. FalconJX currently has code
branches that handle the various flavours of JS we're putting out, but
you can use those as the basis and your guide for creating a path that
will result in nice clear C# output.

EdB



On Thu, Dec 4, 2014 at 4:53 AM, Jesse Nicholson
<as...@gmail.com> wrote:
> I commented earlier about porting the flash runtime + flex to
> typescript/javascript and was asked to send an email to this list with more
> info plus my progress. In terms of progress, I'd say that I have somewhere
> north of 250K lines of doc comments and code done, with a lot to fill in.
> The entire Flash + AIR API exists with all constants, properties methods
> classes etc defined (methods stubbed out) with the implementation details
> left to be filled in (for methods).
>
> The largest bit of work to do (by far) is Flex, which I've come up with
> really lazy solution to solve. I've started writing a source to source
> compiler based on Falcon, that consumes and tokenizes the AS input and
> emits X target (for me right now, it's C#, since my initial implementation
> is C# which then cross-compiles to Typescript using NetJS. Ultimate goal
> for me is to have a platform where users can code in either
> JS/TypeScript/C#, whatever they choose, and seamlessly move between targets
> (Native with Mono, Native with something like Cordova, or Browser only).
>
> Anyway that's what I'm doing and if anyone is interested in the end result,
> let me know. Right now I have a question. While pouring over falcons
> source, I noticed comments where MXML "now gets compiled directly to
> bytecode". The comment goes on to imply that once upon a time, the compiler
> used to convert from MXML to Actionscript and then to ABC. Does anyone know
> anything about this and if so, can they point me to it? Thanks and all the
> best.
>
> --
> Jesse Nicholson



-- 
Ix Multimedia Software

Jan Luykenstraat 27
3521 VB Utrecht

T. 06-51952295
I. www.ixsoftware.nl

Re: Porting To Typescript/Javascript

Posted by Jesse Nicholson <as...@gmail.com>.
Thanks Darrell for pointing me to the codegen.
On 6 Dec 2014 10:06, "Darrell Loverin" <da...@gmail.com> wrote:

> >used to convert from MXML to Actionscript and then to ABC. Does anyone
> know
> >anything about this and if so, can they point me to it? Thanks and all the
> >best.
>
> For a prime example of generating AS code look in the PreLink class in the
> MXML compiler (in the sdk repo). Look at methods that start with "codegen".
> There are also velocity templates in the flex2.compiler.mxml.gen package.
>
>
> -Darrell
>
> On Wed, Dec 3, 2014 at 10:53 PM, Jesse Nicholson <
> ascensionsystems@gmail.com
> > wrote:
>
> > I commented earlier about porting the flash runtime + flex to
> > typescript/javascript and was asked to send an email to this list with
> more
> > info plus my progress. In terms of progress, I'd say that I have
> somewhere
> > north of 250K lines of doc comments and code done, with a lot to fill in.
> > The entire Flash + AIR API exists with all constants, properties methods
> > classes etc defined (methods stubbed out) with the implementation details
> > left to be filled in (for methods).
> >
> > The largest bit of work to do (by far) is Flex, which I've come up with
> > really lazy solution to solve. I've started writing a source to source
> > compiler based on Falcon, that consumes and tokenizes the AS input and
> > emits X target (for me right now, it's C#, since my initial
> implementation
> > is C# which then cross-compiles to Typescript using NetJS. Ultimate goal
> > for me is to have a platform where users can code in either
> > JS/TypeScript/C#, whatever they choose, and seamlessly move between
> targets
> > (Native with Mono, Native with something like Cordova, or Browser only).
> >
> > Anyway that's what I'm doing and if anyone is interested in the end
> result,
> > let me know. Right now I have a question. While pouring over falcons
> > source, I noticed comments where MXML "now gets compiled directly to
> > bytecode". The comment goes on to imply that once upon a time, the
> compiler
> > used to convert from MXML to Actionscript and then to ABC. Does anyone
> know
> > anything about this and if so, can they point me to it? Thanks and all
> the
> > best.
> >
> > --
> > Jesse Nicholson
> >
>

Re: Porting To Typescript/Javascript

Posted by Darrell Loverin <da...@gmail.com>.
>used to convert from MXML to Actionscript and then to ABC. Does anyone know
>anything about this and if so, can they point me to it? Thanks and all the
>best.

For a prime example of generating AS code look in the PreLink class in the
MXML compiler (in the sdk repo). Look at methods that start with "codegen".
There are also velocity templates in the flex2.compiler.mxml.gen package.


-Darrell

On Wed, Dec 3, 2014 at 10:53 PM, Jesse Nicholson <ascensionsystems@gmail.com
> wrote:

> I commented earlier about porting the flash runtime + flex to
> typescript/javascript and was asked to send an email to this list with more
> info plus my progress. In terms of progress, I'd say that I have somewhere
> north of 250K lines of doc comments and code done, with a lot to fill in.
> The entire Flash + AIR API exists with all constants, properties methods
> classes etc defined (methods stubbed out) with the implementation details
> left to be filled in (for methods).
>
> The largest bit of work to do (by far) is Flex, which I've come up with
> really lazy solution to solve. I've started writing a source to source
> compiler based on Falcon, that consumes and tokenizes the AS input and
> emits X target (for me right now, it's C#, since my initial implementation
> is C# which then cross-compiles to Typescript using NetJS. Ultimate goal
> for me is to have a platform where users can code in either
> JS/TypeScript/C#, whatever they choose, and seamlessly move between targets
> (Native with Mono, Native with something like Cordova, or Browser only).
>
> Anyway that's what I'm doing and if anyone is interested in the end result,
> let me know. Right now I have a question. While pouring over falcons
> source, I noticed comments where MXML "now gets compiled directly to
> bytecode". The comment goes on to imply that once upon a time, the compiler
> used to convert from MXML to Actionscript and then to ABC. Does anyone know
> anything about this and if so, can they point me to it? Thanks and all the
> best.
>
> --
> Jesse Nicholson
>