open Ast (* command line options *) let dump = ref false let test = ref false let vtest = ref false let ifile = ref "" let usage = "usage: analyzer [options] file.scade" let options = [ "--dump", Arg.Set dump, "Dump program source."; "--vtest", Arg.Set vtest, "Verbose testing."; "--test", Arg.Set test, "Simple testing."; ] let () = Arg.parse options (fun f -> ifile := f) usage; if !ifile = "" then begin Format.eprintf "No input file...@."; exit 1 end; let prog = File_parser.parse_file !ifile in if !dump then Ast_printer.print_prog Format.std_formatter prog; try if !vtest then begin let s0 = Interpret.program_init_state prog "test" in Format.printf "Init state:@."; Data.print_state s0; let rec it i st = let st, outputs, next_st = Interpret.program_step prog st ["i", Data.VInt i] "test" in Format.printf "@.> Step %d:@." i; Data.print_state st; match List.assoc "exit" outputs with | Data.VBool false -> it (i+1) next_st | _ -> () in it 0 s0 end; if !test then begin let s0 = Interpret.program_init_state prog "test" in let rec it i st = let st, outputs, next_st = Interpret.program_step prog st ["i", Data.VInt i] "test" in Format.printf "%d. %s %s %s@." i (Data.str_of_value (List.assoc "a" outputs)) (Data.str_of_value (List.assoc "b" outputs)) (Data.str_of_value (List.assoc "c" outputs)); match List.assoc "exit" outputs with | Data.VBool false -> it (i+1) next_st | _ -> () in it 0 s0 end with | Data.Combinatorial_cycle v -> Format.eprintf "Combinatorial cycle (%s)@." v | Data.Type_error e -> Format.eprintf "Typing error: %s@." e | Data.Not_implemented l -> Format.eprintf "Not implemented: %s@." l | Data.No_variable id -> Format.eprintf "No such variable: %s@." id