From 6a21e5d7013b62d0cf2a99d7206ca95f9600d18a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwena=EBl=20Delaval?= Date: Fri, 28 Sep 2012 15:26:01 +0200 Subject: [PATCH] Iostream for Java Added support of Iostream.printf (not fprintf) for Java code gen. --- compiler/obc/java/obc2java.ml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/compiler/obc/java/obc2java.ml b/compiler/obc/java/obc2java.ml index eb2f4b9..83fc5f5 100644 --- a/compiler/obc/java/obc2java.ml +++ b/compiler/obc/java/obc2java.ml @@ -298,10 +298,20 @@ let obj_ref param_env o = match o with let idx_l = List.map (fun p -> pattern_to_exp param_env p) p_l in Earray_elem (Evar id, idx_l) +let jop_of_op param_env op_name e_l = + match op_name with + | { qual = Module "Iostream"; name = "printf" } -> + Emethod_call (Eclass(Names.qualname_of_string "java.lang.System.out"), + "print", + (exp_list param_env e_l)) + | _ -> + Efun (op_name, exp_list param_env e_l) + + let rec act_list param_env act_l acts = let _act act acts = match act with | Obc.Aassgn (p,e) -> (Aassgn (pattern param_env p, exp param_env e))::acts - | Obc.Aop (op,e_l) -> Aexp (Efun (op, exp_list param_env e_l)) :: acts + | Obc.Aop (op,e_l) -> Aexp (jop_of_op param_env op e_l) :: acts | Obc.Acall ([], obj, Mstep, e_l) -> let acall = Emethod_call (obj_ref param_env obj, "step", exp_list param_env e_l) in Aexp acall::acts