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.

54 lines
1.2 KiB

4 years ago
4 years ago
4 years ago
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 printerror (e, { line, col }) =
  7. put_line @@ "line " ^ show line ^ ", col " ^ show col ^ ":"
  8. print e
  9. let go infile outfile =
  10. let infile = open_for_reading infile
  11. let outfile = open_file outfile Write_m
  12. match read_all infile with
  13. | Some str ->
  14. match lex prog str with
  15. | Right (ds, _) ->
  16. ds
  17. |> ds_prog
  18. |> C.program
  19. |> A.assm_program
  20. |> write_bytes outfile
  21. | Left e -> printerror e
  22. | _ -> ()
  23. close_file infile
  24. close_file outfile
  25. let test str =
  26. match lex prog str with
  27. | Right (ds, _) ->
  28. ds
  29. |> ds_prog
  30. |> C.program
  31. |> A.assm_program
  32. |> put_line
  33. | Left e -> printerror e
  34. let test_file infile =
  35. let infile = open_for_reading infile
  36. match read_all infile with
  37. | Some str -> test str
  38. | None -> ()
  39. close_file infile
  40. external val args : string * string =
  41. "{ _1 = select(1, ...), _2 = select(2, ...) }"
  42. external val has_args : bool = "select('#', ...) ~= 0"
  43. let () =
  44. if has_args then
  45. let (from, into) = args
  46. go from into
  47. else ()