Quoting Frank Wienberg <fr...@jangaroo.net>:
Okay, I just pushed to the as-js-runtime-prototype repository (I just
noticed I didn't update the Github pages yet, so please do not use the
online version but pull).
Ok, I know git pretty well but, this makes no sense to me, what does
"but pull" mean when I see no updated source code?
I mainly understand what you have written below, will use it for reference.
Also, I did look at AS3.js yesterday so I understand what you are
doing with that.
Mike
All JavaScript files are updated to the latest and greatest code layout.
Because now I know you'll notice every detail, anyway, I rather tell you in
advance there are still some minor differences between the Wiki page and
the example code:
- To get the code to define a class more concise (avoid having to
write/generate Object.defineProperties(...) over and over), I introduced
utility functions in the AS3 library. They don't do any great magic, after
all, AS3.js is less than 200 lines of code.
- AS3.compilationUnit($exports, function($primaryDeclaration){ ... })
-- helps defining a compilation unit with "lazy static code
execution", as
discussed on the Wiki page. You have to hand in the $exports
object that
defines the module output, and compilationUnit() takes care of
defining the
"_" property. The second argument is a function that contains
the actual
compilation unit code and receives a callback
function $primaryDeclaration() to use for handing the module
value (= the
primary declaration) back to compilationUnit(). Yes, sounds
complicated,
but believe me, especially when dealing with static cyclic references
between compilation unit, the order in which all this happens
is crucial
and this is the way it works best and leads to the smallest
client code.
- AS3.class_({ /* class declaration */ }) -- a helper to use a more
concise, declarative definition of the package, name, members,
and static
members of a class. For example, the standard case of a method
or any other
read-only, non-enumerable, non-configurable property that, for
Object.defineProperty() has to be specified as { value: foo } can be
abbreviated to just foo.
- AS3.interface_({ /* interface declaration */ }) --
the analogous helper for an interface. As interfaces do not contain any
executable code, this is *not* wrapped inside an
AS3.compilationUnit() (see
Wiki page).
- AS3 also provides the built-in operators "as" and "is" as well as
the helpers for casts ("cast") and method binding ("bind").
- In contrast to the Wiki page, private non-static methods are not yet
converted to private static methods and called via method.call(this,
arguments...). Instead, like private non-static fields, they are renamed
using $<inheritance-level> (e.g. in class A: secret$1). This makes code
generation a bit easier, as this pattern has to be implemented for private
non-static fields and bound methods, anyway. The conversion to
static leads
to better optimization results, so we should add it later.
- The Wiki page does not yet discuss super method calls. Class B
contains an example, method "foo": the super method is "backed up" using
the private-name-pattern, here "foo$2", by assigning "super$.foo", so in
"foo", "super.foo(x + 2)" is translated to "this.foo$2(x + 2)". Like
private non-static methods, this could be optimized to a local variable
"var super$foo = super$.foo" and the translation "super$.foo.call(this, x
+2)" later.
- I completely left out the commented ActionScript source line numbers
in the JavaScript code for now. You got the idea; if you feel like it, you
can of course add them in.
Well, this is all that comes to my mind now. If you find more unclear
aspects (either on the Wiki page or in the code), please let me know and
I'll do my best to resolve them.
If there is anything that is not straight-forward to generate with
FalconJx, also please let me know and we'll surely find a simpler way to
have a "spike" solution soon!
Greetings
-Frank-
--
Michael Schmalle - Teoti Graphix, LLC
http://www.teotigraphix.com
http://blog.teotigraphix.com