Skip to content
Browse files

Initial import

  • Loading branch information...
0 parents commit 681d2a99f1c18d8f30c1d1e3171138c38c0bec94 @bomberstudios committed Nov 26, 2009
Showing with 8,173 additions and 0 deletions.
  1. +340 −0 LICENSE
  2. +242 −0 class.ml
  3. +299 −0 doc/CHANGES.txt
  4. +13 −0 doc/Future.txt
  5. +15 −0 doc/HelloWorld.as
  6. +35 −0 doc/INSTALL.txt
  7. +24 −0 doc/Makefile
  8. +8 −0 doc/Readme.linux
  9. +361 −0 doc/Readme.txt
  10. +119 −0 doc/install.ml
  11. +77 −0 doc/mtasc.1
  12. +416 −0 expr.ml
  13. +1,836 −0 genSwf.ml
  14. +230 −0 lexer.mll
  15. +172 −0 main.ml
  16. +141 −0 mtasc.dsp
  17. +29 −0 mtasc.dsw
  18. +21 −0 mtasc.sln
  19. +73 −0 mtasc.vcproj
  20. +397 −0 parser.ml
  21. +43 −0 plugin.ml
  22. +7 −0 std/Accessibility.as
  23. +25 −0 std/Array.as
  24. +2 −0 std/ArrayParam.as
  25. +17 −0 std/ArrayPoly.as
  26. +6 −0 std/AsBroadcaster.as
  27. +5 −0 std/Boolean.as
  28. +46 −0 std/Button.as
  29. +32 −0 std/Camera.as
  30. +10 −0 std/Color.as
  31. +12 −0 std/ContextMenu.as
  32. +14 −0 std/ContextMenuItem.as
  33. +58 −0 std/Date.as
  34. +6 −0 std/Error.as
  35. +16 −0 std/ExtendedKey.as
  36. +8 −0 std/Function.as
  37. +4 −0 std/FunctionArguments.as
  38. +32 −0 std/Key.as
  39. +21 −0 std/LoadVars.as
  40. +15 −0 std/LocalConnection.as
  41. +32 −0 std/Math.as
  42. +26 −0 std/Microphone.as
  43. +9 −0 std/Mouse.as
  44. +99 −0 std/MovieClip.as
  45. +9 −0 std/MovieClipLoader.as
  46. +14 −0 std/NetConnection.as
  47. +30 −0 std/NetStream.as
  48. +11 −0 std/Number.as
  49. +19 −0 std/Object.as
  50. +12 −0 std/PrintJob.as
  51. +13 −0 std/Selection.as
  52. +27 −0 std/SharedObject.as
  53. +32 −0 std/Sound.as
  54. +12 −0 std/Stage.as
  55. +3 −0 std/StdPresent.as
  56. +20 −0 std/String.as
  57. +10 −0 std/System.as
  58. +54 −0 std/System/capabilities.as
  59. +6 −0 std/System/security.as
  60. +76 −0 std/TextField.as
  61. +12 −0 std/TextField/StyleSheet.as
  62. +26 −0 std/TextFormat.as
  63. +15 −0 std/TextSnapshot.as
  64. +53 −0 std/TopLevel.as
  65. +28 −0 std/Video.as
  66. +23 −0 std/XML.as
  67. +30 −0 std/XMLNode.as
  68. +13 −0 std/XMLSocket.as
  69. +53 −0 std8/Button.as
  70. +36 −0 std8/Key.as
  71. +114 −0 std8/MovieClip.as
  72. +16 −0 std8/Stage.as
  73. +19 −0 std8/System/IME.as
  74. +7 −0 std8/System/security.as
  75. +84 −0 std8/TextField.as
  76. +30 −0 std8/TextFormat.as
  77. +37 −0 std8/XMLNode.as
  78. +41 −0 std8/flash/display/BitmapData.as
  79. +7 −0 std8/flash/external/ExternalInterface.as
  80. +19 −0 std8/flash/filters/BevelFilter.as
  81. +6 −0 std8/flash/filters/BitmapFilter.as
  82. +10 −0 std8/flash/filters/BlurFilter.as
  83. +8 −0 std8/flash/filters/ColorMatrixFilter.as
  84. +16 −0 std8/flash/filters/ConvolutionFilter.as
  85. +16 −0 std8/flash/filters/DisplacementMapFilter.as
  86. +18 −0 std8/flash/filters/DropShadowFilter.as
  87. +15 −0 std8/flash/filters/GlowFilter.as
  88. +18 −0 std8/flash/filters/GradientBevelFilter.as
  89. +18 −0 std8/flash/filters/GradientGlowFilter.as
  90. +17 −0 std8/flash/geom/ColorTransform.as
  91. +30 −0 std8/flash/geom/Matrix.as
  92. +22 −0 std8/flash/geom/Point.as
  93. +42 −0 std8/flash/geom/Rectangle.as
  94. +11 −0 std8/flash/geom/Transform.as
  95. +20 −0 std8/flash/net/FileReference.as
  96. +11 −0 std8/flash/net/FileReferenceList.as
  97. +6 −0 std8/flash/text/TextRenderer.as
  98. +117 −0 std9/MovieClip.as
  99. +17 −0 std9/MovieClipLoader.as
  100. +33 −0 std9/NetStream.as
  101. +35 −0 std9/Sound.as
  102. +19 −0 std9/Stage.as
  103. +91 −0 std9/flash/display/BitmapData.as
  104. +23 −0 std9/flash/net/FileReference.as
  105. +12 −0 std9/flash/text/TextRenderer.as
  106. +1,138 −0 typer.ml
340 LICENSE
@@ -0,0 +1,340 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
+ 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users. This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it. (Some other Free Software Foundation software is covered by
+the GNU Library General Public License instead.) You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+ To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have. You must make sure that they, too, receive or can get the
+source code. And you must show them these terms so they know their
+rights.
+
+ We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+ Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software. If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+ Finally, any free program is threatened constantly by software
+patents. We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary. To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ GNU GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License. The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language. (Hereinafter, translation is included without limitation in
+the term "modification".) Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+ 1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+ 2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) You must cause the modified files to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ b) You must cause any work that you distribute or publish, that in
+ whole or in part contains or is derived from the Program or any
+ part thereof, to be licensed as a whole at no charge to all third
+ parties under the terms of this License.
+
+ c) If the modified program normally reads commands interactively
+ when run, you must cause it, when started running for such
+ interactive use in the most ordinary way, to print or display an
+ announcement including an appropriate copyright notice and a
+ notice that there is no warranty (or else, saying that you provide
+ a warranty) and that users may redistribute the program under
+ these conditions, and telling the user how to view a copy of this
+ License. (Exception: if the Program itself is interactive but
+ does not normally print such an announcement, your work based on
+ the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+ a) Accompany it with the complete corresponding machine-readable
+ source code, which must be distributed under the terms of Sections
+ 1 and 2 above on a medium customarily used for software interchange; or,
+
+ b) Accompany it with a written offer, valid for at least three
+ years, to give any third party, for a charge no more than your
+ cost of physically performing source distribution, a complete
+ machine-readable copy of the corresponding source code, to be
+ distributed under the terms of Sections 1 and 2 above on a medium
+ customarily used for software interchange; or,
+
+ c) Accompany it with the information you received as to the offer
+ to distribute corresponding source code. (This alternative is
+ allowed only for noncommercial distribution and only if you
+ received the program in object code or executable form with such
+ an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it. For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable. However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License. Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+ 5. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Program or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+ 6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+ 7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all. For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded. In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+ 9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation. If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+ 10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission. For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this. Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+ NO WARRANTY
+
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+ Gnomovision version 69, Copyright (C) year name of author
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+ <signature of Ty Coon>, 1 April 1989
+ Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs. If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library. If this is what you want to do, use the GNU Library General
+Public License instead of this License.
242 class.ml
@@ -0,0 +1,242 @@
+(*
+ * MTASC - MotionTwin ActionScript2 Compiler
+ * Copyright (c)2004 Nicolas Cannasse
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *)
+open Expr
+
+type vars = (string,static_flag) Hashtbl.t
+
+type generated =
+ | NotYet
+ | Generating
+ | Done
+
+type context = {
+ path : type_path;
+ vars : vars;
+ herits : herit list;
+ exprs : signature list;
+ expr : expr;
+ classes : (type_path , context) Hashtbl.t;
+ filename : string;
+ is_interface : bool;
+ mutable interfaces : context list;
+ mutable superclass : context option;
+ mutable constructor : func option;
+ mutable generated : generated;
+ mutable initvars : (string * static_flag * eval) list;
+ mutable methods : func list;
+}
+
+let empty = {
+ path = ([],"<empty>");
+ vars = Hashtbl.create 0;
+ herits = [];
+ expr = (EBlock [],null_pos);
+ classes = Hashtbl.create 0;
+ filename = "<empty>";
+ is_interface = false;
+ interfaces = [];
+ superclass = None;
+ constructor = None;
+ generated = NotYet;
+ initvars = [];
+ exprs = [];
+ methods = [];
+}
+
+
+let path clctx =
+ clctx.path
+
+let getclass clctx p =
+ Hashtbl.find clctx.classes p
+
+let filename clctx =
+ clctx.filename
+
+let expr clctx =
+ clctx.expr
+
+let full_exprs clctx =
+ clctx.exprs
+
+let constructor clctx =
+ clctx.constructor
+
+let superclass clctx =
+ clctx.superclass
+
+let methods clctx =
+ clctx.methods
+
+let initvars clctx =
+ clctx.initvars
+
+let intrinsic clctx =
+ List.exists (( = ) HIntrinsic) clctx.herits
+
+let interface clctx =
+ clctx.is_interface
+
+let interfaces clctx =
+ clctx.interfaces
+
+let is_getset clctx v =
+ match clctx.superclass with
+ | None -> false
+ | Some c ->
+ List.exists (fun f -> f.fname = v && f.fgetter <> Normal) c.methods
+
+let rec resolve_supervar c name =
+ match c.superclass with
+ | None ->
+ assert false
+ | Some c ->
+ try
+ if Hashtbl.find c.vars name = IsStatic then
+ resolve_supervar c name
+ else
+ c.path
+ with
+ Not_found -> resolve_supervar c name
+
+
+let generate_exprs h fname el =
+ let add_class interf path herits e =
+ Hashtbl.add h path {
+ filename = fname;
+ path = path;
+ vars = Hashtbl.create 0;
+ herits = herits;
+ is_interface = interf;
+ classes = h;
+ constructor = None;
+ superclass = None;
+ interfaces = [];
+ initvars = [];
+ methods = [];
+ generated = NotYet;
+ expr = e;
+ exprs = el;
+ }
+ in
+ let rec loop (e,p) =
+ match e with
+ | EClass (path,herits,e) ->
+ add_class false path herits e
+ | EInterface (path,herits,e) ->
+ add_class true path herits e
+ | EImport _ ->
+ ()
+ in
+ List.iter loop el
+
+let rec generate_class_vars h gen clctx (e,p) =
+ match e with
+ | EVars (static_flag,public_flag,vl) ->
+ List.iter (fun (name,_,vinit) ->
+ Hashtbl.add clctx.vars name static_flag;
+ match vinit with
+ | Some v ->
+ clctx.initvars <- (name,static_flag,v) :: clctx.initvars;
+ if static_flag = IsStatic then generate_class_static_refs h gen clctx v
+ | _ -> ()
+ ) vl
+ | EFunction f ->
+ if f.fname = snd clctx.path then
+ clctx.constructor <- Some f
+ else begin
+ Hashtbl.add clctx.vars f.fname f.fstatic;
+ clctx.methods <- f :: clctx.methods
+ end
+ | EBlock el ->
+ List.iter (generate_class_vars h gen clctx) el
+ | _ ->
+ assert false
+
+and generate_class_static_refs h gen clctx v =
+ let check p =
+ let clctx2 = (try Hashtbl.find h p with Not_found -> assert false) in
+ if clctx2 != clctx then generate_class h gen clctx2
+ in
+ let rec loop (v,p) =
+ match v with
+ | EField (v,_)
+ | EParenthesis v
+ | EUnop (_,_,v) ->
+ loop v
+ | EArray (v1,v2)
+ | ECast (v1,v2)
+ | EBinop (_,v1,v2) ->
+ loop v1;
+ loop v2
+ | EObjDecl vl ->
+ List.iter (fun (_,v) -> loop v) vl
+ | EArrayDecl vl ->
+ List.iter loop vl
+ | ECall (v,vl) ->
+ List.iter loop (v :: vl)
+ | EQuestion (v,v1,v2) ->
+ loop v;
+ loop v1;
+ loop v2
+ | EStatic p ->
+ check p;
+ | ENew (v,vl) ->
+ List.iter loop (v :: vl)
+ | EConst _
+ | ELambda _ ->
+ ()
+ in
+ loop v
+
+and generate_class h gen clctx =
+ match clctx.generated with
+ | Done -> ()
+ | Generating -> prerr_endline ("Warning : loop in generation for class " ^ s_type_path clctx.path)
+ | NotYet ->
+ let generate_herit = function
+ | HIntrinsic | HDynamic -> ()
+ | HExtends path when not clctx.is_interface ->
+ (try
+ let hctx = Hashtbl.find h path in
+ clctx.superclass <- Some hctx;
+ generate_class h gen hctx
+ with
+ Not_found -> assert false)
+ | HExtends path
+ | HImplements path ->
+ try
+ let hctx = Hashtbl.find h path in
+ clctx.interfaces <- hctx :: clctx.interfaces;
+ generate_class h gen hctx
+ with
+ Not_found -> assert false
+ in
+ clctx.generated <- Generating;
+ List.iter generate_herit clctx.herits;
+ generate_class_vars h gen clctx clctx.expr;
+ clctx.methods <- List.rev clctx.methods;
+ clctx.initvars <- List.rev clctx.initvars;
+ gen clctx;
+ clctx.generated <- Done
+
+let generate gen exprs =
+ let h = Hashtbl.create 0 in
+ Hashtbl.iter (fun fname el -> generate_exprs h fname el) exprs;
+ Hashtbl.iter (fun _ cl -> generate_class h gen cl) h
299 doc/CHANGES.txt
@@ -0,0 +1,299 @@
+2009-10-07 : 1.15
+ Forked from Motion-Twin's defunct original version
+ New project home is at https://sourceforge.net/projects/mtasc/
+ Changes made:
+ Support for classes with 32 KB (really 32 KiB) or more of bytecode.
+ Support for publishing version 9 SWFs.
+
+2008-08-31 : 1.14
+ added stopAllSounds() support
+ added lineStyle F8 additional parameters
+ fixed FSCommand2 stack
+ added Stage.fullScreenSourceRect
+ compiling with version 9+ now uses std8 folder
+
+2007-02-04 : 1.13
+ updated Video and NetStream headers.
+ fixed small bug if environment variable in new E()
+ fixed multivars declarations
+ fixed bug with filters inside buttons
+ fscommand2 ret value fix
+ fixed various bugs in SWF for Flash8
+ interfaces can't have a constructor
+ inverted % and *,/ priorities
+ fixed missing types for local functions when -strict
+ fix in getTimer()
+ always allow 'add' deprecated keyword
+ bugfix in exclude files (when line endings differs from OS default)
+ allow more than 255 locals
+ more flash lite 2 support for standard headers
+
+2006-01-31 : 1.12
+ prevented -keep with -header
+ allowed dynamic static classes
+ improved Flash8 shapes support
+ allowed access to private variables inside local defined functions
+ faster SWF parsing
+ (hotfixes)
+ added FSCommand2 support for FlashLite
+
+2005-11-29 : 1.11
+ added typed arrays
+ no casts when compiling for flash6
+ warning "imports not used" off by default (added -wimp)
+ catched errors in swf parsing
+ some fixes in flash8 headers and file format handling
+ fixed duplicate main calls when registerClass calls found
+ fixed bug when using "with"
+ added error cannot have same field in class (static + member)
+ (hotfixes)
+ fixed resolve path for typed Arrays.
+ allowed new and literal Array init for typed Arrays.
+
+2005-09-13 : 1.10
+ fixed small problem with class case and import wildcards
+ added -infer parameter
+ fixed bug with += with properties
+ added exclude wildcards and exclude without file
+ changed TRACE in "trace"
+ added AS keywords as real keywords (including deprecated ones)
+ fixed parsing of objects and array declarations and parameters lists
+ fixed escape sequences in strings and added unicode escape sequences.
+ fixed && and || precedence.
+ fixed duplicate public/static/private qualifiers.
+ fixed for...in variable forced as String
+ no more private and static fields in interfaces
+ implemented field cannot be private
+ better error when same file referenced several times.
+ delete now returns Boolean
+ fixed getVersion() in TopLevel
+ fixed problem in class replace when not -keep and -mx
+ changed -main : now in DoAction and not InitAction
+ fixed stack corruption in new var(expr).
+ fixed break with several stacked for..in
+ disabled variables in interfaces
+ added error message when several classes in same file
+ changed switch implementation
+ fixed typing of ?:
+ fixed stack problem with "for"
+ separate directory and "add" keyword hack for Flash8
+ (hotfixes 1.10b)
+ fixed bug in switchs (default cause stack corruption)
+
+2005-07-14 : 1.09
+ fixed problems in escape sequences such as \\t
+ fixed problem with "delete"
+ more strict checks of interface fields : same type and structure and not only unifiable.
+ allowed variance on interface fields implementation.
+ -keep with -separate replace compiled packages.
+ added check for file name case on Win32
+ changed -main and algorithm for updating SWF
+ fixed problem when autoregisterclass with classname = linkagename
+ added -version X (removed -flash6)
+ added Flash8 headers
+ (hotfixes)
+ removed -separate (now on by default), added -group (turn off separate)
+ fixed clips id generation (bug when compiling several times).
+
+2005-06-20 : 1.08
+ fixed getUrl2 stack.
+ renamed and hide variable defined by main.
+ fixed x instanceof y ? a : b parsing
+ fixed try with no catch clauses
+ removed mtasc trace message
+ added -out
+ a lot of small fixes in "std" header
+ fixed bug in check for implemented interfaces
+
+2005-05-28 : 1.07
+ fixed -keep + -main
+ added 'con' error message
+ SharedObject.getRemote argument to Object.
+ added "print".
+ added deprecated keywords usage error.
+ fixed "main" duplication
+ added / to classpath (for absolute file paths)
+ fixed for(;cond;incr) parsing error
+ fixed (unop) expr ? parsing error
+
+2005-05-20 : 1.06
+ fixed IO.No_more_input message
+ fixed 32K limit calculation
+ fixed bug with auto register class
+ main now takes "this" as parameter and is delayed (onEnterFrame)
+ added Object.valueOf intrinsic
+ fixed Malformed_expression when using >32 bits integers
+
+2005-04-30 : 1.05
+ fixed type required to String for for...in variable
+ fixed operator priority : a || b && c -> a || (b && c)
+ error when multiple extends, interface cannot extends class
+ warning when import not used (no longer add class)
+ fixed error message when class not found
+ register only one time the package
+ errors on 32K bytecode size limit reached
+ fixed operators priority for | ^ & against >> and % against * /
+ forbid contructor returns and return type (modified headers)
+ fixed class ordering problem with -keep
+ fixed calls to super getter/setter problem
+ (hotfixes)
+ remove "return" in contructors restriction (allowed by MMC)
+ import warnings disabled for mx classes when -mx
+ fixed missing "," between function call parameters
+
+2005-04-14 : 1.04
+ "for" optional first parameter and expression
+ fixed while( o )++ i;
+ added error when duplicate import statement (with same or different package)
+ added class-exist import check
+ => import will now link classes
+ fixed typing error with single "var" in a block
+ fixed parser error with a?b:c and big left-expression
+ fixed bug when catching "imported" exception class
+ changed boolean operators typing
+ added -flash6 for F6 compilation
+ added -trace for custom trace function
+ added optional color component for -header
+ (hotfixes)
+ fixed compiler crash in "try"
+ fixed boolean operators typing : returns most common type
+
+2005-03-24 : 1.03
+ fixed "interface extends interface" bytecode generation
+ some missing headers
+ fixed problem with -mx (classes initialized before mx components)
+ added check function for values without side effects
+ relaxed array access typing
+ fixed 820 size limit for -header
+ changed bitshifts operator priority
+ trace now use flash opcode
+
+2005-03-10 : 1.02
+ test if class already exists (multiple swf statics init)
+ -frame now works with -header
+ fixed "class Number not found" when no std
+ relaxed restriction on input file names
+ added getURL with one argument only
+ fixed "prototype" static resolved.
+ fixed typeof syntax
+ added "with"
+ added _levelXX
+ added scientific floats : 1.23e-23
+ fixed instanceof & typeof parsing.
+
+2005-02-21 : 1.01
+ fixed doaction/showframe inversion
+ Number, String and Boolean now perform conversion
+ fixed error in inherited statics
+ fixed break in for...in
+ added fscommand.
+ added -exclude
+ fixed $ in identifiers
+ fixed return in for..in bug.
+ fixed inherited statics and super constructor typecheck.
+
+2005-01-26 : 1.0
+ fixed super field accesses
+ fixed -separate with -main issues
+ relaxed new so constructor can return any value.
+ Void now unify with Any
+ added -mx , good support for mx.controls parsing
+
+2005-01-13 : rc2
+ fixed throw parsing
+ fixed <fun> , Function unification
+ fixed small parsing problem with typeof
+ fixed multi-interface subtyping.
+ fixed constructor handling
+ fixed bug in enum
+ added superconstructor autocall
+ added -separate
+
+2005-01-05 : rc1
+ private methods can be called from childs
+ fixed super calls without superclass failure
+ added warning when package is missing.
+ fixed error when package not found
+ NetConnection is now dynamic
+ trace() takes any object, not just Strings
+ added "-main" argument
+ added try/catch/finally+throw support
+ added documentation tutorial
+ fixed utf8 encoding problems
+ fixed "new x" problem (when x is a variable)
+
+2004-12-08 : beta7
+ released restriction on super
+ fixed imports in lambdas
+ pop instead of trace for string mark.
+ fixed missing implementation of import wildcards for genSwf
+ fixed bug when accessing superclass in static.
+ no strict mode for native classes.
+ fixed multiple implements syntax
+ allowed private access to local class variables in lambdas
+
+2004-11-22 : beta6
+ fixed stack overflow in parsing metadata
+ added missing intrinsic headers
+ allowed to have a method named "get" or "set"
+ warning instead of error on #include
+ allowing call object "Function"
+ relaxed array access to Array only
+ improved typing of classnames as Function
+ allowed Array[Boolean]
+ fixed parsing of x = y ? z : w;
+ fixed auto self import in swf generation
+ forbidden calls to super when no super available
+ typeof as operator (parenthesis are optional)
+
+2004-11-17 : beta5
+ fixed back the Export name to "MTASC" (causing problem with -keep)
+ fixed member variable declaration with init value
+ fixed multivariable ops
+ added delete call without parenthesis
+ fixed numbers starting with '.'
+ fixed Function object unify with any function.
+ fixed lexer for mac newlines.
+ fixed parser for a (op) b ? x : x'
+ added -strict mode
+
+2004-11-09 : beta4
+ support for "arguments"
+ fixed bug when a class reference itself : lookup was member constructor
+ support for targetPath
+ improved precision of some error messages
+ import wildcards
+ added -pack
+ enabled specifying AS2 classes for MC directly into Flash IDE.
+ fixed little inheritance problem in generated SWF
+ (hotfixes)
+ fixed multiple assignations
+ fixed swfLib linking for Linux
+
+2004-11-03 : beta3
+ checks that implements an interface and extends a class
+ added physical (in)equality operation
+ added eval
+ added casts
+ fixed issue when std is not installed
+ added getter/setter
+ optimized prototype registration
+ fixed problem with AS2 classes not removed from SWF
+ added -frame for choosing export frame
+ added -header for creating SWF
+ (hotfixes)
+ added static getter/setters
+ fixed interface A extends B
+ class import itself
+
+2004-10-27 : beta2
+ fixed typing of super constructor
+ removed naming conventions
+ added error on import x.* usage
+ fixed var x : Function = Class typing
+ new build model : update SWF by removing AS2 classes (and -keep)
+ fixed registerClass in statics : classes just before first ShowFrame
+ partly rewrote usage documentation
+
+2004-10-25 : beta1
+ compiler working, starting beta
13 doc/Future.txt
@@ -0,0 +1,13 @@
+MTASC is very stable right now, so the releases since
+version 1.11 are focused on minor fixes and enhancements.
+Some people asked about the Future of MTASC, related to
+the next version of Flash 8.5 player and ActionScript 3.
+
+MTASC will not support AS3, as we are currently working on
+a new and powerful language name haXe that will support
+Flash Players 6-7-8 and 9 as well as Javascript and
+Server-Side scripting with PHP and Neko.
+
+You can check about it on http://haxe.org
+
+Nicolas
15 doc/HelloWorld.as
@@ -0,0 +1,15 @@
+// Run: mtasc -swf helloworld.swf -main -header 640:480:20 HelloWorld.as
+// Your basic Hello World app that every language needs
+class HelloWorld {
+
+ static var app : HelloWorld;
+
+ function HelloWorld() {
+ _root.createTextField("tf",0,0,0,640,480);
+ _root.tf.text = "Hello world !";
+ }
+
+ static function main(mc) {
+ app = new HelloWorld();
+ }
+}
35 doc/INSTALL.txt
@@ -0,0 +1,35 @@
+This document is dedicated to people who want to compile MTASC from sources.
+
+Quick Guide :
+-------------
+
+- install OCaml (at http://caml.inria.fr ). 3.08 is recommanded
+- install CVS (http://www.cvshome.org)
+- download and compile ZLIB (http://www.zlib.org)
+- put the "install.ml" MTASC install script into a directory of your choice
+- configure ocaml and cvs so it can run from commandline
+- edit and *configure* install.ml (see below)
+- run the following command "ocaml install.ml" to run compilation script
+- the binary can be found in the "bin" subdirectory of install.ml
+- you also need to copy somewhere on your system the "ocaml/mtasc/std"
+ subdirectory (and use -cp <path to std> for mtasc commandline).
+
+Configuration
+-------------
+
+install.ml is an install script that will download and compile sources.
+It needs some minimal configuration in order to work correctly.
+
+First you need to choose which of the two build you want to compile :
+- native : native is compiled for your processor, it will run a lot faster
+- bytecode : ocaml bytecode program, however it is not platform independant
+ since it links some C code for ZLib bindings
+
+Then you need to configure the path where zlib.lib or zlib.a can be found.
+For example on Linux you will have to replace it by something like :
+ let zlib = "/usr/lib/libz.a"
+
+Problems :
+----------
+In case of problem please join the MTASC mailing list here :
+http://lists.motion-twin.com/mailman/listinfo/mtasc
24 doc/Makefile
@@ -0,0 +1,24 @@
+DESTDIR=
+PREFIX=/usr/local
+ZLIB=/usr/lib/libz.so
+
+build:
+ ( cd ocaml/extc ; ocamlc extc_stubs.c ;\
+ ocamlfind ocamlopt -package extlib -a -o extc.cmxa -cclib ../extc/extc_stubs.o -cclib $(ZLIB) extc.mli extc.ml )
+ cd ocaml/swflib ; ocamlfind ocamlopt -package extlib -a -o swflib.cmxa -I .. -I ../extc swf.ml swfZip.ml actionScript.ml swfParser.ml
+ ( cd ocaml/mtasc ; ocamllex lexer.mll ; ocamlopt -c expr.ml lexer.ml ; ocamlopt -c -pp camlp4o parser.ml ;\
+ ocamlfind ocamlopt -package extlib -c -I .. -I ../extc -I ../swflib typer.ml class.ml plugin.ml genSwf.ml main.ml ;\
+ ocamlfind ocamlopt -package extlib -linkpkg -o mtasc -cclib $(ZLIB) extLib.cmxa ../extc/extc.cmxa ../swflib/swflib.cmxa expr.cmx lexer.cmx parser.cmx typer.cmx class.cmx plugin.cmx genSwf.cmx main.cmx )
+
+clean:
+ rm -f ocaml/*/*.cma ocaml/*/*.cmi ocaml/*/*.cmo ocaml/*/*.cmx
+ rm -f ocaml/*/*.cmxa ocaml/*/*.o ocaml/*/*.a
+ rm -f ocaml/mtasc/lexer.ml ocaml/mtasc/mtasc
+
+install:
+ mkdir -p $(DESTDIR)$(PREFIX)/bin/ $(DESTDIR)$(PREFIX)/share/
+ cp ocaml/mtasc/mtasc $(DESTDIR)$(PREFIX)/bin/
+ cp -r ocaml/mtasc/std $(DESTDIR)$(PREFIX)/share/
+ cp -r ocaml/mtasc/std8 $(DESTDIR)$(PREFIX)/share/
+
+.PHONY: build install clean
8 doc/Readme.linux
@@ -0,0 +1,8 @@
+MTASC : Motion-Twin ActionScript 2 OpenSource Compiler.
+http://team.motion-twin.com/ncannasse/mtasc.html
+
+You can put the "std" directory as a subdirectory of the
+dir you installed the mtasc binary, or you can specify each
+time you want to compile the classpath to flash class headers
+stored into the "std" directory using the -cp commandline
+parameter.
361 doc/Readme.txt
@@ -0,0 +1,361 @@
+This is a fork of MTASC. The original version was built and maintained by
+Motion-Twin, but it is no longer updated due to Motion-Twin's new focus on haXe
+(http://haxe.org). The homepage for this fork is:
+
+https://sourceforge.net/projects/mtasc/
+
+The original Motion-Twin website is:
+
+http://www.mtasc.org
+
+MTASC is Licensed under the GNU General Public License (GPL)
+The compiler sources are available on the above websites.
+
+The GPL license does NOT imply that you source code will
+have to be GPL or Open Source. You can use MTASC in order to
+compiler any source code without restrictions. Only if you
+want use the compiler as part of your application you'll have
+to apply the GPL rules.
+
+---------------------------------------------------
+
+ GNU GENERAL PUBLIC LICENSE
+ Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
+ 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users. This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it. (Some other Free Software Foundation software is covered by
+the GNU Library General Public License instead.) You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+ To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have. You must make sure that they, too, receive or can get the
+source code. And you must show them these terms so they know their
+rights.
+
+ We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+ Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software. If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+ Finally, any free program is threatened constantly by software
+patents. We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary. To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ GNU GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License. The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language. (Hereinafter, translation is included without limitation in
+the term "modification".) Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+ 1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+ 2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) You must cause the modified files to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ b) You must cause any work that you distribute or publish, that in
+ whole or in part contains or is derived from the Program or any
+ part thereof, to be licensed as a whole at no charge to all third
+ parties under the terms of this License.
+
+ c) If the modified program normally reads commands interactively
+ when run, you must cause it, when started running for such
+ interactive use in the most ordinary way, to print or display an
+ announcement including an appropriate copyright notice and a
+ notice that there is no warranty (or else, saying that you provide
+ a warranty) and that users may redistribute the program under
+ these conditions, and telling the user how to view a copy of this
+ License. (Exception: if the Program itself is interactive but
+ does not normally print such an announcement, your work based on
+ the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+ a) Accompany it with the complete corresponding machine-readable
+ source code, which must be distributed under the terms of Sections
+ 1 and 2 above on a medium customarily used for software interchange; or,
+
+ b) Accompany it with a written offer, valid for at least three
+ years, to give any third party, for a charge no more than your
+ cost of physically performing source distribution, a complete
+ machine-readable copy of the corresponding source code, to be
+ distributed under the terms of Sections 1 and 2 above on a medium
+ customarily used for software interchange; or,
+
+ c) Accompany it with the information you received as to the offer
+ to distribute corresponding source code. (This alternative is
+ allowed only for noncommercial distribution and only if you
+ received the program in object code or executable form with such
+ an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it. For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable. However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License. Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+ 5. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Program or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+ 6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+ 7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all. For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded. In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+ 9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation. If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+ 10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission. For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this. Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+ NO WARRANTY
+
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+ Gnomovision version 69, Copyright (C) year name of author
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+ <signature of Ty Coon>, 1 April 1989
+ Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs. If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library. If this is what you want to do, use the GNU Library General
+Public License instead of this License.
119 doc/install.ml
@@ -0,0 +1,119 @@
+(*
+ * MTASC installer
+ * Copyright (c)2004 Nicolas Cannasse
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *)
+
+#load "unix.cma"
+
+(* This file is identical to the install.ml file that Motion-Twin provides,
+ except that it skips the "cvs update" step. *)
+
+(* ----- BEGIN CONFIGURATION ---- *)
+
+let zlib = match Sys.os_type with "Win32" -> "zlib.lib" | _ -> "-lz"
+let bytecode = true
+let native = true
+
+(* ------ END CONFIGURATION ----- *)
+
+let obj_ext = match Sys.os_type with "Win32" -> ".obj" | _ -> ".o"
+let exe_ext = match Sys.os_type with "Win32" | "Cygwin" -> ".exe" | _ -> ""
+
+let msg m =
+ prerr_endline m;
+ flush stdout
+
+let command c =
+ msg ("> " ^ c);
+ if Sys.command c <> 0 then failwith ("Error while running " ^ c)
+
+let cvs root cmd =
+ command ("cvs -z3 -d" ^ root ^ " " ^ cmd)
+
+let ocamlc file =
+ if bytecode then command ("ocamlc -c " ^ file);
+ if native then command ("ocamlopt -c " ^ file)
+
+let modules l ext =
+ String.concat " " (List.map (fun f -> f ^ ext) l)
+
+;;
+
+(*
+
+let motiontwin = ":pserver:anonymous@cvs.motion-twin.com:/cvsroot" in
+
+let download () =
+
+ msg "*** Please hit enter on login (empty password) ***";
+ cvs motiontwin "login";
+ cvs motiontwin "co ocaml/extlib-dev";
+ cvs motiontwin "co ocaml/mtasc";
+ cvs motiontwin "co ocaml/swflib";
+ cvs motiontwin "co ocaml/extc";
+
+in
+
+*)
+
+let compile() =
+
+ (try Unix.mkdir "bin" 0o740 with Unix.Unix_error(Unix.EEXIST,_,_) -> ());
+
+ (* EXTLIB *)
+ Sys.chdir "ocaml/extlib-dev";
+ command ("ocaml install.ml -nodoc -d .. " ^ (if bytecode then "-b " else "") ^ (if native then "-n" else ""));
+ msg "";
+ Sys.chdir "../..";
+
+ (* EXTC *)
+ Sys.chdir "ocaml/extc";
+ let c_opts = (if Sys.ocaml_version < "3.08" then " -ccopt -Dcaml_copy_string=copy_string " else " ") in
+ command ("ocamlc" ^ c_opts ^ "extc_stubs.c");
+
+ let options = "-cclib ../extc/extc_stubs" ^ obj_ext ^ " -cclib " ^ zlib ^ " extc.mli extc.ml" in
+ if bytecode then command ("ocamlc -a -o extc.cma " ^ options);
+ if native then command ("ocamlopt -a -o extc.cmxa " ^ options);
+ Sys.chdir "../..";
+
+ (* SWFLIB *)
+ Sys.chdir "ocaml/swflib";
+ let files = "-I .. -I ../extc as3.mli as3code.ml as3parse.ml swf.ml swfZip.ml actionScript.ml swfParser.ml" in
+ if bytecode then command ("ocamlc -a -o swflib.cma " ^ files);
+ if native then command ("ocamlopt -a -o swflib.cmxa " ^ files);
+ Sys.chdir "../..";
+
+ (* MTASC *)
+ Sys.chdir "ocaml/mtasc";
+ command "ocamllex lexer.mll";
+ ocamlc "expr.ml lexer.ml";
+ ocamlc "-pp camlp4o parser.ml";
+ ocamlc "-I .. -I ../extc -I ../swflib typer.ml class.ml plugin.ml genSwf.ml main.ml";
+ let mlist = ["expr";"lexer";"parser";"typer";"class";"plugin";"genSwf";"main"] in
+ if bytecode then command ("ocamlc -custom -o ../../bin/mtasc-byte" ^ exe_ext ^ " ../extLib.cma ../extc/extc.cma ../swflib/swflib.cma " ^ modules mlist ".cmo");
+ if native then command ("ocamlopt -o ../../bin/mtasc" ^ exe_ext ^ " ../extLib.cmxa ../extc/extc.cmxa ../swflib/swflib.cmxa " ^ modules mlist ".cmx");
+
+in
+let startdir = Sys.getcwd() in
+try
+ (* download(); *)
+ compile();
+ Sys.chdir startdir;
+with
+ Failure msg ->
+ Sys.chdir startdir;
+ prerr_endline msg; exit 1
77 doc/mtasc.1
@@ -0,0 +1,77 @@
+.TH MTASC "1" "February 2006" "mtasc " "User Commands"
+.SH NAME
+mtasc \- ActionScript 2 to Flash (SWF) compiler
+.SH DESCRIPTION
+.PP
+This manual page documents briefly the \fBmtasc\fR command.
+.PP
+It was written for Debian as \fBmtasc\fR does not have a manual page.
+.PP
+\fBmtasc\fR compiles ActionScript 2 files to Flash (SWF) files.
+.PP
+.SH SYNOPSIS
+\fBmtasc\fP [options] <files...>
+.SH OPTIONS
+.PP
+The options are processed from left to right. All of the options use a single dash.
+.TP
+\fB\-pack\fR <path>
+Compile all files in target package.
+.TP
+\fB\-cp\fR <path>
+Add classpath.
+.TP
+\fB\-v\fR
+Turn on verbose mode.
+.TP
+\fB\-strict\fR
+Turn on strict mode.
+.TP
+\fB\-infer\fR
+Turn on local variables inference.
+.TP
+\fB\-wimp\fR
+Turn on warnings for unused imports.
+.TP
+\fB\-msvc\fR
+Use MSVC style errors.
+.TP
+\fB\-mx\fR
+Use precompiled mx package.
+.TP
+\fB\-swf\fR <file>
+Input SWF file to update.
+.TP
+\fB\-out\fR <file>
+SWF output file.
+.TP
+\fB\-keep\fR
+Do not remove AS2 classes from input SWF.
+.TP
+\fB\-frame\fR <frame>
+Export into target frame (it must exist in the SWF).
+.TP
+\fB\-main\fR
+Enable the main entry point.
+.TP
+\fB\-header\fR <header>
+Specify header format. The format of this option is 'width:height:fps',
+where fps means frames per second.
+.TP
+\fB\-group\fR
+Group classes into a single clip
+.TP
+\fB\-exclude\fR <file>
+Exclude classes listed in a file.
+.TP
+\fB\-version\fR
+Change SWF version (6,7,8,...)
+.TP
+\fB\-trace\fR <function>
+Specify a TRACE function.
+.TP
+\fB\-help\fR or \fB\-\-help\fR
+Display a list of options and what they do.
+.SH "SEE ALSO"
+.PP
+The mtasc website (http://www.mtasc.org) and the mtasc osflash page (http://osflash.org/mtasc).
416 expr.ml
@@ -0,0 +1,416 @@
+(*
+ * MTASC - MotionTwin ActionScript2 Compiler
+ * Copyright (c)2004 Nicolas Cannasse
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *)
+
+type pos = {
+ pfile : string;
+ pmin : int;
+ pmax : int;
+}
+
+type keyword =
+ | Function
+ | Class
+ | Var
+ | If
+ | Else
+ | While
+ | Do
+ | For
+ | Break
+ | Continue
+ | Return
+ | Interface
+ | Extends
+ | Implements
+ | Import
+ | Switch
+ | Case
+ | Default
+ | Static
+ | Intrinsic
+ | Dynamic
+ | Public
+ | Private
+ | Try
+ | Catch
+ | Finally
+ | With
+ | In
+ | InstanceOf
+ | New
+ | This
+ | Throw
+ | Typeof
+ | Delete
+ | Void
+ (* deprecated *)
+ | Add | And | Or | Eq | Ne | KwdNot | Le | Lt | Ge | Gt
+ | IfFrameLoaded | On | OnClipEvent | TellTarget
+
+type binop =
+ | OpAdd
+ | OpMult
+ | OpDiv
+ | OpSub
+ | OpAssign
+ | OpEq
+ | OpPhysEq
+ | OpNotEq
+ | OpPhysNotEq
+ | OpGt
+ | OpGte
+ | OpLt
+ | OpLte
+ | OpAnd
+ | OpOr
+ | OpXor
+ | OpBoolAnd
+ | OpBoolOr
+ | OpShl
+ | OpShr
+ | OpUShr
+ | OpMod
+ | OpAssignOp of binop
+
+type unop =
+ | Increment
+ | Decrement
+ | Not
+ | Neg
+ | NegBits
+
+type constant =
+ | Int of string
+ | Float of string
+ | String of string
+ | Ident of string
+
+type token =
+ | Eof
+ | Const of constant
+ | Kwd of keyword
+ | Comment of string
+ | CommentLine of string
+ | Binop of binop
+ | Unop of unop
+ | Next
+ | Sep
+ | BrOpen
+ | BrClose
+ | BkOpen
+ | BkClose
+ | POpen
+ | PClose
+ | Dot
+ | DblDot
+ | Question
+ | Sharp
+
+type unop_flag =
+ | Prefix
+ | Postfix
+
+type while_flag =
+ | NormalWhile
+ | DoWhile
+
+type static_flag =
+ | IsMember
+ | IsStatic
+
+type public_flag =
+ | IsPublic
+ | IsPrivate
+
+type getter_flag =
+ | Normal
+ | Getter
+ | Setter
+
+type type_path = string list * string
+
+type func = {
+ fname : string;
+ fargs : (string * type_path option) list;
+ ftype : type_path option;
+ fstatic : static_flag;
+ fpublic : public_flag;
+ fgetter : getter_flag;
+ fexpr : expr option;
+}
+
+and herit =
+ | HExtends of type_path
+ | HImplements of type_path
+ | HIntrinsic
+ | HDynamic
+
+and eval_def =
+ | EConst of constant
+ | EArray of eval * eval
+ | EBinop of binop * eval * eval
+ | EField of eval * string
+ | EParenthesis of eval
+ | EObjDecl of (string * eval) list
+ | EArrayDecl of eval list
+ | ECall of eval * eval list
+ | ENew of eval * eval list
+ | EUnop of unop * unop_flag * eval
+ | EQuestion of eval * eval * eval
+ | ELambda of func
+ | EStatic of type_path
+ | ECast of eval * eval
+
+and eval = eval_def * pos
+
+and expr_def =
+ | EVars of static_flag * public_flag * (string * type_path option * eval option) list
+ | EFunction of func
+ | EBlock of expr list
+ | EFor of expr list * eval list * eval list * expr
+ | EForIn of expr * eval * expr
+ | EIf of eval * expr * expr option
+ | EWhile of eval * expr * while_flag
+ | ESwitch of eval * (eval option * expr) list
+ | ETry of expr * (string * type_path option * expr) list ref * expr option
+ | EWith of eval * expr
+ | EReturn of eval option
+ | EBreak
+ | EContinue
+ | EVal of eval
+
+and expr = expr_def * pos
+
+and sign_def =
+ | EClass of type_path * herit list * expr
+ | EInterface of type_path * herit list * expr
+ | EImport of string list * string option
+
+and signature = sign_def * pos
+
+let pos = snd
+
+let is_postfix (e,_) = function
+ | Increment | Decrement -> (match e with EConst _ | EField _ | EStatic _ | EArray _ -> true | _ -> false)
+ | Not | Neg | NegBits -> false
+
+let is_prefix = function
+ | Increment | Decrement -> true
+ | Not | Neg | NegBits -> true
+
+let base_class_name = snd
+
+let null_pos = { pfile = "<null>"; pmin = -1; pmax = -1 }
+
+let set_eval (e : eval) (v : eval_def) =
+ Obj.set_field (Obj.repr e) 0 (Obj.repr v)
+
+let punion p p2 =
+ {
+ pfile = p.pfile;
+ pmin = min p.pmin p2.pmin;
+ pmax = max p.pmax p2.pmax;
+ }
+
+let s_type_path (p,s) = match p with [] -> s | _ -> String.concat "." p ^ "." ^ s
+
+let s_escape s =
+ let b = Buffer.create (String.length s) in
+ for i = 0 to (String.length s) - 1 do
+ match s.[i] with
+ | '\n' -> Buffer.add_string b "\\n"
+ | '\t' -> Buffer.add_string b "\\t"
+ | '\r' -> Buffer.add_string b "\\r"
+ | c -> Buffer.add_char b c
+ done;
+ Buffer.contents b
+
+let s_constant = function
+ | Int s -> s
+ | Float s -> s
+ | String s -> "\"" ^ s_escape s ^ "\""
+ | Ident s -> s
+
+let s_keyword = function
+ | Function -> "function"
+ | Class -> "class"
+ | Static -> "static"
+ | Var -> "var"
+ | If -> "if"
+ | Else -> "else"
+ | While -> "while"
+ | Do -> "do"
+ | For -> "for"
+ | Break -> "break"
+ | Return -> "return"
+ | Continue -> "continue"
+ | Interface -> "interface"
+ | Extends -> "extends"
+ | Implements -> "implements"
+ | Import -> "import"
+ | Switch -> "switch"
+ | Case -> "case"
+ | Default -> "default"
+ | Intrinsic -> "intrinsic"
+ | Dynamic -> "dynamic"
+ | Private -> "private"
+ | Public -> "public"
+ | Try -> "try"
+ | Catch -> "catch"
+ | Finally -> "finally"
+ | With -> "with"
+ | In -> "in"
+ | InstanceOf -> "instanceof"
+ | New -> "new"
+ | This -> "this"
+ | Throw -> "throw"
+ | Typeof -> "typeof"
+ | Delete -> "delete"
+ | Void -> "void"
+ (* deprecated *)
+ | Add -> "add"
+ | And -> "and"
+ | Or -> "or"
+ | Eq -> "eq"
+ | Ne -> "ne"
+ | KwdNot -> "not"
+ | Le -> "le"
+ | Lt -> "lt"
+ | Ge -> "ge"
+ | Gt -> "gt"
+ | IfFrameLoaded -> "ifFrameLoaded"
+ | On -> "on"
+ | OnClipEvent -> "onClipEvent"
+ | TellTarget -> "tellTarget"
+
+let rec s_binop = function
+ | OpAdd -> "+"
+ | OpMult -> "*"
+ | OpDiv -> "/"
+ | OpSub -> "-"
+ | OpAssign -> "="
+ | OpEq -> "=="
+ | OpPhysEq -> "==="
+ | OpNotEq -> "!="
+ | OpPhysNotEq -> "!=="
+ | OpGte -> ">="
+ | OpLte -> "<="
+ | OpGt -> ">"
+ | OpLt -> "<"
+ | OpAnd -> "&"
+ | OpOr -> "|"
+ | OpXor -> "^"
+ | OpBoolAnd -> "&&"
+ | OpBoolOr -> "||"
+ | OpShr -> ">>"
+ | OpUShr -> ">>>"
+ | OpShl -> "<<"
+ | OpMod -> "%"
+ | OpAssignOp op -> s_binop op ^ "="
+
+let s_unop = function
+ | Increment -> "++"
+ | Decrement -> "--"
+ | Not -> "!"
+ | Neg -> "-"
+ | NegBits -> "~"
+
+let s_token = function
+ | Eof -> "<end of file>"
+ | Const c -> s_constant c
+ | Kwd k -> s_keyword k
+ | Comment s -> "/*"^s^"*/"
+ | CommentLine s -> "//"^s
+ | Binop o -> s_binop o
+ | Unop o -> s_unop o
+ | Next -> ";"
+ | Sep -> ","
+ | BkOpen -> "["
+ | BkClose -> "]"
+ | BrOpen -> "{"
+ | BrClose -> "}"
+ | POpen -> "("
+ | PClose -> ")"
+ | Dot -> "."
+ | DblDot -> ":"
+ | Question -> "?"
+ | Sharp -> "#"
+
+exception Invalid_expression of pos
+
+let rec check_val (v,p) =
+ match v with
+ | EBinop (OpAssign,_,_)
+ | EBinop (OpAssignOp _,_,_)
+ | ECall _
+ | EUnop (Increment,_,_)
+ | EUnop (Decrement,_,_)
+ | EQuestion _
+ -> ()
+ | ENew _
+ | EConst _
+ | EArray _
+ | EBinop _
+ | EField _
+ | EObjDecl _
+ | EArrayDecl _
+ | EUnop _
+ | ELambda _
+ | EStatic _
+ | ECast _
+ -> raise (Invalid_expression p)
+ | EParenthesis v ->
+ check_val v
+
+let rec check_expr (e,p) =
+ match e with
+ | EVars (_,_,vl) -> ()
+ | EFunction f ->
+ (match f.fexpr with None -> () | Some e -> check_expr e)
+ | EBlock el ->
+ List.iter check_expr el
+ | EFor (el, _ , _ , e ) ->
+ List.iter check_expr el;
+ check_expr e
+ | EForIn (_,_,e) ->
+ check_expr e
+ | EIf (_,e,eo) ->
+ check_expr e;
+ (match eo with None -> () | Some e -> check_expr e)
+ | EWhile (_,e,_) ->
+ check_expr e
+ | ESwitch (_,cl) ->
+ List.iter (fun (_,e) -> check_expr e) cl;
+ | ETry (e,cl,eo) ->
+ check_expr e;
+ List.iter (fun (_,_,e) -> check_expr e) !cl;
+ (match eo with None -> () | Some e -> check_expr e)
+ | EWith (_,e) ->
+ check_expr e;
+ | EReturn _
+ | EBreak
+ | EContinue -> ()
+ | EVal v ->
+ check_val v
+
+let check_sign (s,p) =
+ match s with
+ | EClass (_,_,e) -> check_expr e
+ | EInterface (_,_,e) -> check_expr e
+ | EImport _ -> ()
1,836 genSwf.ml
1,836 additions, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
230 lexer.mll
@@ -0,0 +1,230 @@
+(*
+ * MTASC - MotionTwin ActionScript2 Compiler
+ * Copyright (c)2004 Nicolas Cannasse
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *)
+
+{
+open Lexing
+open Expr
+
+type error_msg =
+ | Invalid_character of char
+ | Unterminated_string
+ | Unclosed_comment
+
+exception Error of error_msg * pos
+
+let error_msg = function
+ | Invalid_character c when int_of_char c > 32 && int_of_char c < 128 -> Printf.sprintf "Invalid character '%c'" c
+ | Invalid_character c -> Printf.sprintf "Invalid character 0x%.2X" (int_of_char c)
+ | Unterminated_string -> "Unterminated string"
+ | Unclosed_comment -> "Unclosed comment"
+
+let cur_file = ref ""
+let all_lines = Hashtbl.create 0
+let lines = ref []
+let buf = Buffer.create 100
+
+let error e pos =
+ raise (Error (e,{ pmin = pos; pmax = pos; pfile = !cur_file }))
+
+let keywords =
+ let h = Hashtbl.create 3 in
+ List.iter (fun k -> Hashtbl.add h (s_keyword k) k)
+ [Function;Class;Static;Var;If;Else;While;Do;For;
+ Break;Return;Continue;Interface;Extends;Implements;Import;
+ Switch;Case;Default;Intrinsic;Dynamic;Public;Private;Try;
+ Catch;Finally;With;
+ In;InstanceOf;New;This;Throw;Typeof;Delete;Void;
+ Add;And;Or;Eq;Ne;KwdNot;Le;Lt;Ge;Gt;IfFrameLoaded;On;OnClipEvent;TellTarget];
+ h
+
+let init file =
+ cur_file := file;
+ lines := []
+
+let save_lines() =
+ Hashtbl.replace all_lines !cur_file !lines
+
+let save() =
+ save_lines();
+ !cur_file
+
+let restore file =
+ save_lines();
+ cur_file := file;
+ lines := Hashtbl.find all_lines file
+
+let newline lexbuf =
+ lines := (lexeme_end lexbuf) :: !lines
+
+let find_line p lines =
+ let rec loop n delta = function
+ | [] -> n , p - delta
+ | lp :: l when lp > p -> n , p - delta
+ | lp :: l -> loop (n+1) lp l
+ in
+ loop 1 0 lines
+
+let get_error_line p =
+ let lines = List.rev (try Hashtbl.find all_lines p.pfile with Not_found -> []) in
+ let l, _ = find_line p.pmin lines in
+ l
+
+let get_error_pos printer p =
+ if p.pmin = -1 then
+ "(unknown)"
+ else
+ let lines = List.rev (try Hashtbl.find all_lines p.pfile with Not_found -> []) in
+ let l1, p1 = find_line p.pmin lines in
+ let l2, p2 = find_line p.pmax lines in
+ if l1 = l2 then begin
+ let s = (if p1 = p2 then Printf.sprintf " %d" p1 else Printf.sprintf "s %d-%d" p1 p2) in
+ Printf.sprintf "%s character%s" (printer p.pfile l1) s
+ end else
+ Printf.sprintf "%s lines %d-%d" (printer p.pfile l1) l1 l2
+
+let reset() = Buffer.reset buf
+let contents() = Buffer.contents buf
+let store lexbuf = Buffer.add_string buf (lexeme lexbuf)
+let add c = Buffer.add_string buf c
+
+let mk_tok t pmin pmax =
+ t , { pfile = !cur_file; pmin = pmin; pmax = pmax }
+
+let mk lexbuf t =
+ mk_tok t (lexeme_start lexbuf) (lexeme_end lexbuf)
+
+let mk_ident lexbuf =
+ match lexeme lexbuf with
+ | s ->
+ mk lexbuf (try Kwd (Hashtbl.find keywords s) with Not_found -> Const (Ident s))
+
+}
+
+let ident = ['_' '$' 'a'-'z' 'A'-'Z'] ['_' 'a'-'z' 'A'-'Z' '0'-'9' '$']*
+
+rule token = parse
+ | eof { mk lexbuf Eof }
+ | "\239\187\191" { token lexbuf }
+ | [' ' '\t']+ { token lexbuf }
+ | "\r\n" { newline lexbuf; token lexbuf }
+ | '\n' | '\r' { newline lexbuf; token lexbuf }
+ | "0x" ['0'-'9' 'a'-'f' 'A'-'F']+ { mk lexbuf (Const (Int (lexeme lexbuf))) }
+ | ['0'-'9']+ { mk lexbuf (Const (Int (lexeme lexbuf))) }
+ | ['0'-'9']+ '.' ['0'-'9']* { mk lexbuf (Const (Float (lexeme lexbuf))) }
+ | '.' ['0'-'9']+ { mk lexbuf (Const (Float (lexeme lexbuf))) }
+ | ['0'-'9']+ ['e' 'E'] ['+' '-']? ['0'-'9']+ { mk lexbuf (Const (Float (lexeme lexbuf))) }
+ | ['0'-'9']+ '.' ['0'-'9']* ['e' 'E'] ['+' '-']? ['0'-'9']+ { mk lexbuf (Const (Float (lexeme lexbuf))) }
+ | "//" [^'\n' '\r']* {
+ let s = lexeme lexbuf in
+ mk lexbuf (CommentLine (String.sub s 2 ((String.length s)-2)))
+ }
+ | "++" { mk lexbuf (Unop Increment) }
+ | "--" { mk lexbuf (Unop Decrement) }
+ | "~" { mk lexbuf (Unop NegBits) }
+ | "%=" { mk lexbuf (Binop (OpAssignOp OpMod)) }
+ | "&=" { mk lexbuf (Binop (OpAssignOp OpAnd)) }
+ | "|=" { mk lexbuf (Binop (OpAssignOp OpOr)) }
+ | "^=" { mk lexbuf (Binop (OpAssignOp OpXor)) }
+ | "+=" { mk lexbuf (Binop (OpAssignOp OpAdd)) }
+ | "-=" { mk lexbuf (Binop (OpAssignOp OpSub)) }
+ | "*=" { mk lexbuf (Binop (OpAssignOp OpMult)) }
+ | "/=" { mk lexbuf (Binop (OpAssignOp OpDiv)) }
+ | "<<=" { mk lexbuf (Binop (OpAssignOp OpShl)) }
+ | ">>=" { mk lexbuf (Binop (OpAssignOp OpShr)) }
+ | ">>>=" { mk lexbuf (Binop (OpAssignOp OpUShr)) }
+ | "===" { mk lexbuf (Binop OpPhysEq) }
+ | "!==" { mk lexbuf (Binop OpPhysNotEq) }
+ | "==" { mk lexbuf (Binop OpEq) }
+ | "!=" { mk lexbuf (Binop OpNotEq) }
+ | "<=" { mk lexbuf (Binop OpLte) }
+ | ">=" { mk lexbuf (Binop OpGte) }
+ | "&&" { mk lexbuf (Binop OpBoolAnd) }
+ | "||" { mk lexbuf (Binop OpBoolOr) }
+ | "<<" { mk lexbuf (Binop OpShl) }
+ | ">>" { mk lexbuf (Binop OpShr) }
+ | ">>>" { mk lexbuf (Binop OpUShr) }
+ | "!" { mk lexbuf (Unop Not) }
+ | "<" { mk lexbuf (Binop OpLt) }
+ | ">" { mk lexbuf (Binop OpGt) }
+ | ";" { mk lexbuf Next }
+ | ":" { mk lexbuf DblDot }
+ | "," { mk lexbuf Sep }
+ | "." { mk lexbuf Dot }
+ | "%" { mk lexbuf (Binop OpMod) }
+ | "&" { mk lexbuf (Binop OpAnd) }
+ | "|" { mk lexbuf (Binop OpOr) }
+ | "^" { mk lexbuf (Binop OpXor) }
+ | "+" { mk lexbuf (Binop OpAdd) }
+ | "*" { mk lexbuf (Binop OpMult) }
+ | "/" { mk lexbuf (Binop OpDiv) }
+ | "-" { mk lexbuf (Binop OpSub) }
+ | "=" { mk lexbuf (Binop OpAssign) }
+ | "[" { mk lexbuf BkOpen }
+ | "]" { mk lexbuf BkClose }
+ | "{" { mk lexbuf BrOpen }
+ | "}" { mk lexbuf BrClose }
+ | "(" { mk lexbuf POpen }
+ | ")" { mk lexbuf PClose }
+ | "?" { mk lexbuf Question }
+ | "#" { mk lexbuf Sharp }
+ | "/*" {
+ reset();
+ let pmin = lexeme_start lexbuf in
+ let pmax = (try comment lexbuf with Exit -> error Unclosed_comment pmin) in
+ mk_tok (Comment (contents())) pmin pmax;
+ }
+ | '"' {
+ reset();
+ let pmin = lexeme_start lexbuf in
+ let pmax = (try string lexbuf with Exit -> error Unterminated_string pmin) in
+ mk_tok (Const (String (contents()))) pmin pmax;
+ }
+ | "'" {
+ reset();
+ let pmin = lexeme_start lexbuf in
+ let pmax = (try string2 lexbuf with Exit -> error Unterminated_string pmin) in
+ mk_tok (Const (String (contents()))) pmin pmax;
+ }
+ | ident { mk_ident lexbuf }
+ | _ { error (Invalid_character (lexeme_char lexbuf 0)) (lexeme_start lexbuf) }
+
+and comment = parse
+ | eof { raise Exit }
+ | '\n' | '\r' | "\r\n" { newline lexbuf; store lexbuf; comment lexbuf }
+ | "*/" { lexeme_end lexbuf }
+ | '*' { store lexbuf; comment lexbuf }
+ | [^'*' '\n' '\r']+ { store lexbuf; comment lexbuf }
+
+and string = parse
+ | eof { raise Exit }
+ | '\n' | '\r' | "\r\n" { newline lexbuf; store lexbuf; string lexbuf }
+ | "\\\"" { store lexbuf; string lexbuf }
+ | "\\\\" { store lexbuf; string lexbuf }
+ | '\\' { store lexbuf; string lexbuf }
+ | '"' { lexeme_end lexbuf }
+ | [^'"' '\\' '\r' '\n']+ { store lexbuf; string lexbuf }
+
+and string2 = parse
+ | eof { raise Exit }
+ | '\n' | '\r' | "\r\n" { newline lexbuf; store lexbuf; string2 lexbuf }
+ | '\\' { store lexbuf; string2 lexbuf }
+ | "\\\\" { store lexbuf; string2 lexbuf }
+ | "\\'" { store lexbuf; string2 lexbuf }
+ | "'" { lexeme_end lexbuf }
+ | [^'\'' '\\' '\r' '\n']+ { store lexbuf; string2 lexbuf }
172 main.ml
@@ -0,0 +1,172 @@
+(*
+ * MTASC - MotionTwin ActionScript2 Compiler
+ * Copyright (c)2004 Nicolas Cannasse
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *)
+open Printf
+open ExtString
+
+type p_style =
+ | StyleJava
+ | StyleMSVC
+
+let print_style = ref StyleJava
+
+let rec split l str =
+ let rec loop = function
+ | [] -> -1
+ | x :: l ->
+ try
+ let p = String.index str x in
+ let p2 = loop l in
+ if p2 = -1 || p2 > p then
+ p
+ else
+ p2
+ with
+ Not_found -> loop l
+ in
+ let p = loop l in
+ if p = -1 then
+ [str]
+ else if p = 0 then
+ split l (String.sub str 1 (String.length str - 1))
+ else
+ let sub = String.sub str 0 p in
+ sub :: (split l (String.sub str (p+1) (String.length str - (p+1))))
+
+let class_name file =
+ let path = Filename.dirname file in
+ let path = (match split ['/';'\\'] path with "." :: l -> l | l -> l) in