200 likes | 342 Views
Nicolas Cannasse. MTASC. No more Coffee Break while compiling. M otion- T win A ction S cript C ompiler. Rich Internet Applications – RIA . AJAX Dynamic HTML, RAD, Browser Integration Flash Vector Engine, LowLevel, better control, more powerful. MTASC.
E N D
Nicolas Cannasse MTASC No more Coffee Break while compiling Motion-Twin ActionScript Compiler
Rich Internet Applications – RIA • AJAXDynamic HTML, RAD, Browser Integration • FlashVector Engine, LowLevel, better control, more powerful
MTASC • Is an ActionScript version 2 compiler • Works from CommandLine • Can be integrated in « your favorite IDE » • Is not an IDE : • Can’t edit Flash Graphics or Code • Is OpenSource • GPL License, MotionTwin offering support
The History of MTASC • Prehistory : ActionScript 1 • MiddleAge : 09/2003 FlashMX2004 ActionScript2 • Need More Checks : 12/2003 ASML • Need More Types : 04/2004 MotionTypes • Back to AS2 : 10/2004 MTASC Beta 1 01/2005 MTASC 1.0 05/2005 FAME Platform / OSFlash.org 07/2005 MTASC 1.09
ASML : ActionScriptMetaLanguage • December 2003 • Run before Macromedia Compiler • Add « Type Inference » to AS2 • Check number of parameters (no optional parameters) • Faster compilation process
Type Inference • To « Guess » the types at compilation time function length(o) { return Math.sqrt(o.x*o.x + o.y*o.y); }
Type Inference • To « Guess » the types at compilation time function length(o : Tmp) : Number { return Math.sqrt(o.x*o.x + o.y*o.y); } Tmp { var x : Number; var y : Number; }
Type Inference • Pros : • Do not write Types • Your program is still checked • Changes propagate everywhere • Cons : • You need to understand how it works • Error reporting is difficult • Typing order matters
MotionTypes • April 2004 • More Types need more Syntax • Different Language ( .mt files ) • Anonymous Types :var o : { x : Number, y : Number }; • Lambda Types :var onConnect : Boolean -> Void; • First AS1 generation, then SWF generation
MTASC • Back to AS2 : compatibility • Improves Macromedia Compiler : • Faster • More strict • Use SWF generation developed for MotionTypes • Ready for RIA : • V2 Components • ActionStep
MTASC Internals • Bunch of AS text files • Lexing : produce tokens • Parsing : build AST • Typing : type-check the AST • SWF Code-Generation • MTASC is Written in OCAML (www.ocaml.org)
Flash Bytecode function add x : reg0 y : reg1 push reg0 push reg1 add ret function add(x,y) { return x + y; } Stack-based Virtual Machine. Registers for local variables (since Flash7).
Flash Bytecode function max x : reg0 y : reg1 push reg0 push reg1 lt condjump +2 push reg1 ret push reg0 ret function max(x,y) { if( x < y ) return y; else return x; } Conditional Jumps
From AS2 to AS1 if( !Ref ) { _global.Ref = function(r) { this.r = r; } Ref.prototype.add = function(p) { this.r = this.r + p.r; } } class Ref { var v : Number; function Ref(v) { this.v = v; } function add(r : Ref) { r += p.r; } } AS2 is Class-based AS1 is Prototype-based
From AS1 to SWF push ‘Ref’ eval not compjump +XXX push ‘_global’ eval push ‘Ref’ function (r:r1) this:r0 push r0 push ‘r’ push r1 objset objset . . . . if( !Ref ) { _global.Ref = function(r) { this.r = r; } Ref.prototype.add = function(p) { this.r = this.r + p.r; } }
MTASC in Numbers • MTASC sources (without libs) are : • 8 files • 113 Ko • 20’000 words • 4’000 lines • It takes 3-4 seconds for compiling more than 300 Classes (20-30 seconds with Macromedia Compiler)
The FAMES Platform A complete OpenSource platform : • Flashout : SWF Preview, Log • ASDT : AS2 Dev. Eclipse plugin • MTASC : AS2 Compiler • Eclipse : IDE • SwfMill : Resources (Fonts, JPEG,…)
The FAMES Platform A complete OpenSource platform : • Open Source IDE and Tools • Edit / Compile / Test • Ready for RIA dev • Using Macromedia V2 Components (need license) • Using OS Components • More complete everyday • See http://osflash.org
Flash OpenSource Tools • A lot of tools Available on OSFlash.org • General Purpose • AS2Lib, ASUnit… • UI Frameworks • ActionStep, EnFlash, ARP, AsWing… • Debug/Log • AdminTool • Protocols • AMFPHP, OpenAMF… • Tutorials, tips, …