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.

58 lines
1.3 KiB

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