diff --git a/generator/js_of_ast.ml b/generator/js_of_ast.ml index 21317e996d135adc3ff338ea7777eb1f0967dd6d..9145c14d5299a99677d700d7a41ae82e9a616c23 100644 --- a/generator/js_of_ast.ml +++ b/generator/js_of_ast.ml @@ -82,7 +82,7 @@ let ppf_let_in decl exp = in ppf_lambda_wrap s let ppf_function args body= - (L.log_line (Printf.sprintf "function (%s) {@," args) (L.CreateCtx args)) ^ (Printf.sprintf "@;<1 2>@[<v 0>return %s;@]@,}" body) + (L.log_line (Printf.sprintf "function (%s) {" args) [L.Enter; (L.CreateCtx args)]) ^ (Printf.sprintf "@;<1 2>@[<v 0>return %s;@]@,}" body) let ppf_apply f args = Printf.sprintf "%s(%s)" @@ -252,7 +252,7 @@ and js_of_branch ?(mod_gen=[]) b obj = let typ = match List.rev (Str.split (Str.regexp " ") spat) with | [] -> assert false | x :: xs -> String.sub x 0 (String.length x) - in L.log_line (ppf_branch spat binders se) (L.Add (binders, typ)) + in L.log_line (ppf_branch spat binders se) [(L.Add (binders, typ))] and js_of_expression ?(mod_gen=[]) e = let locn = e.exp_loc in @@ -279,8 +279,8 @@ and js_of_expression ?(mod_gen=[]) e = |> List.map (fun (_, eo, _) -> match eo with None -> out_of_scope locn "optional apply arguments" | Some ei -> js_of_expression ~mod_gen ei) in let se = js_of_expression ~mod_gen f in if is_infix f sl' && List.length exp_l = 2 - then L.log_line (ppf_apply_infix se (List.hd sl) (List.hd (List.tl sl))) (L.ApplyInfix (se, (List.hd sl), (List.hd (List.tl sl)))) - else L.log_line (ppf_apply se (String.concat ", " sl)) (L.ApplyFunc (se, (String.concat ", " sl))) + then ppf_apply_infix se (List.hd sl) (List.hd (List.tl sl)) + else ppf_apply se (String.concat ", " sl) | Texp_match (exp, l, [], Total) -> let se = js_of_expression ~mod_gen exp in diff --git a/generator/log.ml b/generator/log.ml index c94c46dd5aafe68c8d6e59332bdfa64e4405cad2..1e07da2a05b60f2bfe755ca75443111b1d0d49bf 100644 --- a/generator/log.ml +++ b/generator/log.ml @@ -34,10 +34,9 @@ sig type ctx_operation = | Add of ident * typ | CreateCtx of ident - | ApplyInfix of func * ident * ident - | ApplyFunc of func * ident + | Enter - val log_line : string -> ctx_operation -> string + val log_line : string -> ctx_operation list -> string val strip_log_info : string -> string val logged_output : string -> string val unlogged_output : string -> string @@ -53,8 +52,7 @@ struct type ctx_operation = | Add of ident * typ | CreateCtx of ident - | ApplyInfix of func * ident * ident - | ApplyFunc of func * ident + | Enter type token_info = ctx_operation @@ -99,10 +97,12 @@ struct if l.[len - 1] = '|' then extract (len - 2) 0 else None - let log_line str ctx = - let token, tokenized = bind_token str in - Hashtbl.replace info_tbl token ctx; - tokenized + let log_line str ctxls = + let log_ctx str ctx = + let token, tokenized = bind_token str in + Hashtbl.replace info_tbl token ctx; + tokenized in + List.fold_left log_ctx str ctxls let strip_log_info s = global_replace token_re "" s @@ -195,15 +195,17 @@ struct |> aux in Buffer.add_string buf @@ ctx_processing id ^ "\n" ^ pad ^ "log("^ string_of_int i ^" , ctx, " ^ typ ^ ");\n"; aux i ((tks, str) :: xs) - | CreateCtx args -> + | CreateCtx args -> + (* Creates new context and logs arguments. *) let argslist = split (regexp ", ") args in Buffer.add_string buf str; - Buffer.add_string buf (pad ^ "\nvar ctx = ctx_empty();"); + Buffer.add_string buf ("\n" ^ pad ^ "var ctx = ctx_empty();"); (* Logging needs changing so we can use args actual name instead of t *) - List.map (fun x -> Buffer.add_string buf ("\nctx_push(ctx, \"t\", " ^ x ^ ", \"expr\");") ) argslist; - aux (i + 1) xs - | ApplyInfix (f, e1, e2) -> aux i ((tks, str):: xs) (* Skip infix logging*) - | ApplyFunc (f, args) -> aux i ((tks, nstr) :: xs) (* Skip fun appl logging*) + List.map (fun x -> Buffer.add_string buf ("\n" ^ pad ^ "ctx_push(ctx, \"t\", " ^ x ^ ", \"expr\");") ) argslist; + aux i ((tks, str) :: xs) + | Enter -> + Buffer.add_string buf ("\n" ^ pad ^ "log_custom({line:" ^ string_of_int (i + 1) ^ ", type: \"enter\"});"); + aux (i+1) xs in aux 0 ls; Buffer.contents buf let logged_output s =