You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.1 KiB

4 years ago
  1. module C = import "./compile.ml"
  2. module A = import "./assemble.ml"
  3. open import "./parser.ml"
  4. open import "prelude.ml"
  5. open import "lua/io.ml"
  6. let go infile outfile =
  7. let infile = open_for_reading infile
  8. let outfile = open_file outfile Write_m
  9. match read_all infile with
  10. | Some str ->
  11. match lex prog str with
  12. | Right (ds, _) ->
  13. ds
  14. |> ds_prog
  15. |> C.program
  16. |> A.assm_program
  17. |> write_bytes outfile
  18. | Left e -> print e
  19. | _ -> ()
  20. close_file infile
  21. close_file outfile
  22. let test str =
  23. match lex prog str with
  24. | Right (ds, _) ->
  25. ds
  26. |> ds_prog
  27. |> C.program
  28. |> A.assm_program
  29. |> put_line
  30. | Left e -> print e
  31. let test_file infile =
  32. let infile = open_for_reading infile
  33. match read_all infile with
  34. | Some str -> test str
  35. | None -> ()
  36. close_file infile
  37. external val args : string * string =
  38. "{ _1 = select(1, ...), _2 = select(2, ...) }"
  39. external val has_args : bool = "select('#', ...) ~= 0"
  40. let () =
  41. if has_args then
  42. let (from, into) = args
  43. go from into
  44. else ()