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.

65 lines
1.4 KiB

4 years ago
4 years ago
4 years ago
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. module T = import "./tc.ml"
  4. open import "./parser.ml"
  5. open import "prelude.ml"
  6. open import "lua/io.ml"
  7. external val dofile : string -> () = "dofile"
  8. let printerror (e, { line, col }) =
  9. put_line @@ "line " ^ show line ^ ", col " ^ show col ^ ":"
  10. print e
  11. let go infile outfile =
  12. let infile = open_for_reading infile
  13. let outfile = open_file outfile Write_m
  14. match read_all infile with
  15. | Some str ->
  16. match lex prog str with
  17. | Right (ds, _) ->
  18. ds
  19. |> T.tc_program [] []
  20. |> fun (_, _, z) -> z
  21. |> C.program
  22. |> A.assm_program
  23. |> write_bytes outfile
  24. | Left e -> printerror e
  25. | _ -> ()
  26. close_file infile
  27. close_file outfile
  28. let go' infile outfile =
  29. go infile outfile
  30. dofile outfile
  31. let test str =
  32. match lex prog str with
  33. | Right (ds, _) ->
  34. let code =
  35. ds
  36. |> T.tc_program [] []
  37. |> fun (_, _, z) -> z
  38. |> C.program
  39. let lua = code |> A.assm_program
  40. print code
  41. put_line lua
  42. | Left e -> printerror e
  43. let test_file infile =
  44. let infile = open_for_reading infile
  45. match read_all infile with
  46. | Some str -> test str
  47. | None -> ()
  48. close_file infile
  49. external val args : string * string =
  50. "{ _1 = select(1, ...), _2 = select(2, ...) }"
  51. external val has_args : bool = "select('#', ...) ~= 0"
  52. let () =
  53. if has_args then
  54. let (from, into) = args
  55. go from into
  56. else ()