| Let of (string*ast) list * ast
| Var of string
-let find name table =
- let rec sub i = function
- [] ->
- failwith @@ "no name: " ^ name
- | x::xs ->
- try
- i,List.assoc name x
- with Not_found ->
- sub (i+1) xs in
- sub 0 table
-
let scope_depth = function
[] -> 0
- | (_,(scope,_))::_ -> scope
+ | (_,scope)::_ -> scope
let rec generate_expr ast table =
let expr ast =
traits=[];
instructions=inst}]
| Var name ->
- let scope,slot =
+ let scope =
List.assoc name table in
Right [GetScopeObject scope;
- GetSlot slot]
+ GetProperty (Cpool.QName ((Cpool.Namespace ""),name))]
| Let (vars,body) ->
let depth =
scope_depth table + 1 in
let table' =
- (ExtList.List.mapi (fun i (name,_) -> name,(depth,i+1)) vars)@table in
+ (ExtList.List.mapi (fun i (name,_) -> name,depth) vars)@table in
let inits =
concatMap (fun (name,init)->
- let scope,slot =
- List.assoc name table' in
- List.concat [ expr init;
- [GetScopeObject scope;Swap;SetSlot slot]]) vars in
- Right (List.concat [[NewObject 0; PushScope];
- inits;
- right @@ generate_expr body table'])
+ List.concat [[PushString name;];
+ expr init]) vars in
+ Right (List.concat [inits;
+ [NewObject (List.length vars);PushScope];
+ right @@ generate_expr body table';
+ [PopScope]])
| Call (name,args) ->
let mname =
Cpool.QName ((Cpool.Namespace ""),name) in
GetGlobalSlot of int:op=0x6e; stack=1; args=const [u30 arg0]
SetGlobalSlot of int:op=0x6f; stack= ~-1; args=const [u30 arg0]
+GetProperty of Cpool.multiname: op=0x66; const=multiname arg0; args=fun cmap ->[multiname_get arg0 cmap]
+
ReturnVoid: op=0x47
FindPropStrict of Cpool.multiname: op=0x5D; stack=1; const=multiname arg0; args=fun cmap ->[multiname_get arg0 cmap]
PushUInt of int: op=0x2E; stack=1; const=uint arg0; args=fun cmap -> [uint_get arg0 cmap]
CallPropLex of Cpool.multiname * int: op=0x4c; stack= ~-arg1; args=fun cmap->[multiname_get arg0 cmap;Bytes.u30 arg1]
Pop: op=0x29; stack= ~-1
Swap:op=0x2b
+PopScope:op=0x1d; scope= ~-1
-NewObject of int:op=0x55; args=const [u30 arg0]
\ No newline at end of file
+NewObject of int:op=0x55; args=const [u30 arg0]
+NewArray of int:op=0x56; args=const [u30 arg0]