Skip to content

Instantly share code, notes, and snippets.

@propella
Created August 4, 2009 08:18
Show Gist options
  • Save propella/161105 to your computer and use it in GitHub Desktop.
Save propella/161105 to your computer and use it in GitHub Desktop.
(* Generate Hello World program in a ABC file *)
open As3
let filename = "outabc.abc"
let id i = As3parse.magic_index i
let idz i = As3parse.magic_index_nz i
(* constants *)
let idents:as3_ident array = [|"print"; "Hello, World!!"; ""|]
let namespaces:as3_namespace array = [| A3NPublic None |] (* public *)
let nsets:as3_ns_set array = [||]
let names:as3_multi_name array = [|A3MName (id 1, id 1)|] (* public::print *)
(* 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 initialize:as3_static = {
st3_method = idz 0;
st3_fields = [||];
}
let code:as3_function = {
fun3_id = idz 0;
fun3_stack_size = 2;
fun3_nregs = 1;
fun3_init_scope = 0;
fun3_max_scope = 1;
fun3_code = [| A3This; (* A3Reg 0 *)
A3Scope;
A3FindPropStrict (id 1); (* public::print *)
A3String (id 2); (* "Hello, World!!" *)
A3CallProperty (id 1, 1); (* public::print 1 *)
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|];
as3_metadatas = [||];
as3_classes = [||];
as3_statics = [||];
as3_inits = [|initialize|];
as3_functions = [|code|];
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;;
(* Std.print script;; *)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment