commit 5015468bd45e75af7c270dd703d8a389b4241cdb Author: Michael Zhang Date: Tue Mar 8 00:16:27 2022 -0600 init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d4e11e5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +_build + diff --git a/bin/dune b/bin/dune new file mode 100644 index 0000000..c604479 --- /dev/null +++ b/bin/dune @@ -0,0 +1,4 @@ +(executable + (public_name e0) + (name main) + (libraries e0)) diff --git a/bin/main.ml b/bin/main.ml new file mode 100644 index 0000000..c8e6ccb --- /dev/null +++ b/bin/main.ml @@ -0,0 +1,6 @@ +open E0 + +let () = print_endline "Hello, World!" + +let () = + Lexing.from_channel stdin |> Parser.program Lexer.f diff --git a/dune-project b/dune-project new file mode 100644 index 0000000..eb255e4 --- /dev/null +++ b/dune-project @@ -0,0 +1,28 @@ +(lang dune 3.0) + +(name e0) + +(generate_opam_files true) + +(source + (github username/reponame)) + +(authors "Author Name") + +(maintainers "Maintainer Name") + +(license LICENSE) + +(documentation https://url/to/documentation) + +(package + (name e0) + (synopsis "A short synopsis") + (description "A longer description") + (depends ocaml dune) + (tags + (topics "to describe" your project))) + +(using menhir 2.1) + +; See the complete stanza docs at https://dune.readthedocs.io/en/stable/dune-files.html#dune-project diff --git a/e0.opam b/e0.opam new file mode 100644 index 0000000..bfb40c4 --- /dev/null +++ b/e0.opam @@ -0,0 +1,31 @@ +# This file is generated by dune, edit dune-project instead +opam-version: "2.0" +synopsis: "A short synopsis" +description: "A longer description" +maintainer: ["Maintainer Name"] +authors: ["Author Name"] +license: "LICENSE" +tags: ["topics" "to describe" "your" "project"] +homepage: "https://github.com/username/reponame" +doc: "https://url/to/documentation" +bug-reports: "https://github.com/username/reponame/issues" +depends: [ + "ocaml" + "dune" {>= "3.0"} + "odoc" {with-doc} +] +build: [ + ["dune" "subst"] {dev} + [ + "dune" + "build" + "-p" + name + "-j" + jobs + "@install" + "@runtest" {with-test} + "@doc" {with-doc} + ] +] +dev-repo: "git+https://github.com/username/reponame.git" diff --git a/examples/basic.e0 b/examples/basic.e0 new file mode 100644 index 0000000..bdc49bf --- /dev/null +++ b/examples/basic.e0 @@ -0,0 +1,3 @@ +fn main(argc: u32, argv: **u8) -> u8 { + return 42 +} diff --git a/lib/ast.ml b/lib/ast.ml new file mode 100644 index 0000000..ccd93e8 --- /dev/null +++ b/lib/ast.ml @@ -0,0 +1,22 @@ +type op + = OpAdd + | OpSub + | OpMul + | OpDiv + +type lit + = LitInt of int64 + | LitFloat of float + +type expr + = ExprLit of lit + | ExprBin of expr * op * expr + +type func = + { name : string + } + +type decl + = DeclFunc of func + +type program = decl list diff --git a/lib/dune b/lib/dune new file mode 100644 index 0000000..1466ae9 --- /dev/null +++ b/lib/dune @@ -0,0 +1,7 @@ +(library + (name e0)) + +(ocamllex lexer) + +(menhir + (modules parser)) diff --git a/lib/ir.ml b/lib/ir.ml new file mode 100644 index 0000000..2c5cdb8 --- /dev/null +++ b/lib/ir.ml @@ -0,0 +1,8 @@ +type expr + = Expr + +type global = Global + +type program = + { globals : global list + } diff --git a/lib/lexer.mll b/lib/lexer.mll new file mode 100644 index 0000000..ea6f136 --- /dev/null +++ b/lib/lexer.mll @@ -0,0 +1,5 @@ +{ open Parser } + +rule f = parse +| "fn" { KWD_FN } +| ['a'-'z']* as i { IDENT i } diff --git a/lib/parser.mly b/lib/parser.mly new file mode 100644 index 0000000..c02b266 --- /dev/null +++ b/lib/parser.mly @@ -0,0 +1,19 @@ +%{ + open Ast +%} + +%token KWD_FN +%token IDENT + +%start program + +%% + +program: +| decls=decl* { decls } + +decl: +| func=func { DeclFunc func } + +func: +| KWD_FN name=IDENT { { name = name } } diff --git a/spec.md b/spec.md new file mode 100644 index 0000000..5cb6f90 --- /dev/null +++ b/spec.md @@ -0,0 +1,9 @@ +Types +----- + +- Primitive ints {u,i}{8,16,32,64} +- Pointer +- Struct + +IR +-- diff --git a/test/dune b/test/dune new file mode 100644 index 0000000..a26a393 --- /dev/null +++ b/test/dune @@ -0,0 +1,2 @@ +(test + (name e0)) diff --git a/test/e0.ml b/test/e0.ml new file mode 100644 index 0000000..e69de29