Skip to content

Instantly share code, notes, and snippets.

@propella
Created August 6, 2009 05:11
Show Gist options
  • Save propella/163147 to your computer and use it in GitHub Desktop.
Save propella/163147 to your computer and use it in GitHub Desktop.
(*
Generate Hello World Flash version
./outsprite
build:
ocamlc -g -I ocaml -I ocaml/swflib ocaml/extLib.cma ocaml/swflib/swflib.cma -o abcsprite abcsprite.ml
*)
open As3
let filename = "abcsprite.abc" (* the filename for new abc file *)
let id i = As3parse.magic_index i
let idz i = As3parse.magic_index_nz i
(* constants *)
let idents:as3_ident array =
[|"abcsprite"; ""; "TextField"; "flash.display:Sprite"; "Object";
"flash.text"; "Hello, World!"; "text"; "addChild"; "flash.display";
"Sprite"|]
let namespaces:as3_namespace array =
[|A3NPublic None;
A3NPublic (Some (id 6)); (* "flash.text":6 *)
A3NPublic (Some (id 10))|] (* "flash.display":10 *)
let nsets:as3_ns_set array = [||]
let names:as3_multi_name array =
[|(A3MName (id 3, id 2)); (* flash.text::TextField *)
(A3MName (id 8, id 1)); (* public::text *)
(A3MName (id 9, id 1)); (* public::addChild *)
(A3MName (id 1, id 1)); (* public::abcsprite *)
(A3MName (id 11, id 3)); (* flash.display::Sprite *)
(A3MName (id 5, id 1)); (* public::Object *)
|]
(* code *)
let method_type:as3_method_type = {
mt3_ret = None;
mt3_args = [];
mt3_native = false;
mt3_var_args = false;
mt3_arguments_defined = false;
mt3_uses_dxns = false;
mt3_new_block = false;
mt3_unused_flag = false;
mt3_debug_name = None;
mt3_dparams = None;
mt3_pnames = None;
}
let classes:as3_class array = [|
{cl3_name=(id 4);
cl3_super=(Some (id 5));
cl3_sealed=true; cl3_final=false; cl3_interface=false;
cl3_namespace=(Some (id 1));
cl3_implements=[||];
cl3_construct=(idz 1);
cl3_fields=[||];} |]
let statics:as3_static array = [|
{st3_method=(idz 0);
st3_fields=[||]} |]
let inits:as3_static array = [|
{st3_method=(idz 2);
st3_fields=[|{f3_name=(id 4);
f3_slot=1;
f3_kind=A3FClass (idz 0);
f3_metas=None}
|]}|]
let code0:as3_function = {
fun3_id=(idz 0);
fun3_stack_size=1;
fun3_nregs=1;
fun3_init_scope =4;
fun3_max_scope=5;
fun3_code=[| A3This;
A3Scope;
A3RetVoid; |];
fun3_trys=[||];
fun3_locals=[||]}
let code1:as3_function = {
fun3_id = (idz 1);
fun3_stack_size = 2;
fun3_nregs = 2;
fun3_init_scope = 5;
fun3_max_scope = 6;
fun3_code = [| A3This;
A3Scope;
A3This;
A3ConstructSuper 0;
A3FindPropStrict (id 1); (* TextField *)
A3ConstructProperty (id 1, 0); (* TextField 0 *)
A3SetReg 1;
A3Reg 1;
A3String (id 7); (* "Hello, World!" *)
A3SetProp (id 2); (* text *)
A3FindPropStrict (id 3); (* addChild *)
A3Reg 1;
A3CallProperty (id 3, 1); (* addChild 1 *)
A3Pop;
A3RetVoid; |];
fun3_trys = [||];
fun3_locals = [||]}
let code2:as3_function = {
fun3_id = (idz 2);
fun3_stack_size = 2;
fun3_nregs = 1;
fun3_init_scope = 1;
fun3_max_scope = 4;
fun3_code = [| A3This;
A3Scope;
A3GetScope 0;
A3FindPropStrict (id 6); (* Object *)
A3GetProp (id 6); (* Object *)
A3Scope;
A3FindPropStrict (id 5); (* Sprite *)
A3GetProp (id 5); (* Sprite *)
A3Scope;
A3FindPropStrict (id 5); (* Sprite *)
A3GetProp (id 5); (* Sprite *)
A3ClassDef (idz 0); (* abcsprite *)
A3PopScope;
A3PopScope;
A3InitProp (id 4); (* abcsprite *)
A3RetVoid; |];
fun3_trys = [||];
fun3_locals = [||]}
(* structure *)
let script : as3_tag = {
as3_ints = [||];
as3_uints = [||];
as3_floats = [||];
as3_idents = idents;
as3_namespaces = namespaces;
as3_nsets = nsets;
as3_names = names;
as3_method_types = [|method_type; method_type; method_type|];
as3_metadatas = [||];
as3_classes = classes;
as3_statics = statics;
as3_inits = inits;
as3_functions = [|code0; code1; code2|];
as3_unknown = ""
}
let write_abc (outfile:string) (ctx:as3_tag) =
let ch = IO.output_channel (open_out_bin outfile) in
As3parse.write ch ctx;
IO.close_out ch
;; (* main *)
write_abc filename script;;
(* Rmove the comment to dump the result *)
(* Std.print script;; *)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment