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.

59 lines
1.3 KiB

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. |> C.program
  20. |> A.assm_program
  21. |> write_bytes outfile
  22. | Left e -> printerror e
  23. | _ -> ()
  24. close_file infile
  25. close_file outfile
  26. let go' infile outfile =
  27. go infile outfile
  28. dofile outfile
  29. let test str =
  30. match lex prog str with
  31. | Right (ds, _) ->
  32. let code = ds |> T.tc_program |> C.program
  33. let lua = code |> A.assm_program
  34. print code
  35. put_line lua
  36. | Left e -> printerror e
  37. let test_file infile =
  38. let infile = open_for_reading infile
  39. match read_all infile with
  40. | Some str -> test str
  41. | None -> ()
  42. close_file infile
  43. external val args : string * string =
  44. "{ _1 = select(1, ...), _2 = select(2, ...) }"
  45. external val has_args : bool = "select('#', ...) ~= 0"
  46. let () =
  47. if has_args then
  48. let (from, into) = args
  49. go from into
  50. else ()