Skip to content

Commit

Permalink
Begin implementing mlc
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Evans committed Sep 10, 2024
1 parent fc40cce commit 9bb1152
Show file tree
Hide file tree
Showing 5 changed files with 7,434 additions and 0 deletions.
7 changes: 7 additions & 0 deletions bootstrap/bin/mlc/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(executables
(names mlc)
(libraries Basis Hmc Mlc))

(install
(section bin)
(files (mlc.exe as mlc)))
40 changes: 40 additions & 0 deletions bootstrap/bin/mlc/mlc.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
open Basis
include Basis.Rudiments
open Mlc

let scan_file path =
let rec fn scanner = begin
let scanner', tok = Scan.next scanner in
File.Fmt.stdout
|> Fmt.fmt " "
|> Scan.Token.pp tok
|> Fmt.fmt "\n"
|> ignore;
match tok with
| Scan.Token.Tok_end_of_input _ -> ()
| _ -> fn scanner'
end in
let () = match File.of_path path with
| Ok f -> begin
let stream = File.Stream.of_file f in
let text = Text.of_bytes_stream ~path stream in
let scanner = Scan.init text in
fn scanner
end
| Error err -> halt (
String.Fmt.empty
|> Fmt.fmt "File.of_path error: "
|> Fmt.fmt (Errno.to_string err)
|> Fmt.fmt "\n"
|> Fmt.to_string
)
in
()

let _ =
match Array.length Os.argv with
| 0L | 1L -> halt "mlc usage: mlc <path>"
| _ -> begin
let path = Path.of_bytes (Bytes.Slice.init (Array.get 1L Os.argv)) in
scan_file path
end
6 changes: 6 additions & 0 deletions bootstrap/src/mlc/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
(library
(name Mlc)
(public_name Hemlock.Mlc)
(libraries Basis Hmc)
(synopsis "OCaml bootstrap transpiler library")
)
Loading

0 comments on commit 9bb1152

Please sign in to comment.