This commit is contained in:
Michael Zhang 2022-03-08 00:16:27 -06:00
commit 5015468bd4
Signed by: michael
GPG key ID: BDA47A31A3C8EE6B
14 changed files with 146 additions and 0 deletions

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
_build

4
bin/dune Normal file
View file

@ -0,0 +1,4 @@
(executable
(public_name e0)
(name main)
(libraries e0))

6
bin/main.ml Normal file
View file

@ -0,0 +1,6 @@
open E0
let () = print_endline "Hello, World!"
let () =
Lexing.from_channel stdin |> Parser.program Lexer.f

28
dune-project Normal file
View file

@ -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

31
e0.opam Normal file
View file

@ -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"

3
examples/basic.e0 Normal file
View file

@ -0,0 +1,3 @@
fn main(argc: u32, argv: **u8) -> u8 {
return 42
}

22
lib/ast.ml Normal file
View file

@ -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

7
lib/dune Normal file
View file

@ -0,0 +1,7 @@
(library
(name e0))
(ocamllex lexer)
(menhir
(modules parser))

8
lib/ir.ml Normal file
View file

@ -0,0 +1,8 @@
type expr
= Expr
type global = Global
type program =
{ globals : global list
}

5
lib/lexer.mll Normal file
View file

@ -0,0 +1,5 @@
{ open Parser }
rule f = parse
| "fn" { KWD_FN }
| ['a'-'z']* as i { IDENT i }

19
lib/parser.mly Normal file
View file

@ -0,0 +1,19 @@
%{
open Ast
%}
%token KWD_FN
%token <string> IDENT
%start <program> program
%%
program:
| decls=decl* { decls }
decl:
| func=func { DeclFunc func }
func:
| KWD_FN name=IDENT { { name = name } }

9
spec.md Normal file
View file

@ -0,0 +1,9 @@
Types
-----
- Primitive ints {u,i}{8,16,32,64}
- Pointer
- Struct
IR
--

2
test/dune Normal file
View file

@ -0,0 +1,2 @@
(test
(name e0))

0
test/e0.ml Normal file
View file