This commit is contained in:
Michael Zhang 2021-01-09 11:28:05 -06:00
commit 114ec834da
Signed by: michael
GPG key ID: BDA47A31A3C8EE6B
6 changed files with 109 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/target

5
Cargo.lock generated Normal file
View file

@ -0,0 +1,5 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "gust"
version = "0.1.0"

9
Cargo.toml Normal file
View file

@ -0,0 +1,9 @@
[package]
name = "gust"
version = "0.1.0"
authors = ["Michael Zhang <mail@mzhang.io>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

80
src/ast.rs Normal file
View file

@ -0,0 +1,80 @@
use std::collections::HashMap;
#[derive(Debug, Hash, PartialEq, Eq)]
pub struct Id(pub u32);
#[derive(Debug)]
pub enum Decl {
Iface(Iface),
Impl(Impl),
Struct(Struct),
Enum(Enum),
Func(Func),
}
#[derive(Debug)]
pub struct Iface {
}
#[derive(Debug)]
pub struct Impl {
}
#[derive(Debug)]
pub struct Struct {
}
#[derive(Debug)]
pub struct Enum {
}
#[derive(Debug)]
pub struct Func {
}
#[derive(Debug)]
pub enum Expr {
}
#[derive(Default, Debug)]
pub struct TypeChecker<'a> {
gen: u32,
enums: HashMap<u32, &'a Enum>,
funcs: HashMap<u32, &'a Func>,
}
impl<'a> TypeChecker<'a> {
pub fn new() -> Self {
Self::default()
}
fn new_id(&mut self) -> u32 {
let id = self.gen;
self.gen += 1;
id
}
pub fn process(&mut self, decls: &'a [Decl]) {
for decl in decls.iter() {
match decl {
Decl::Enum(v) => {
let id = self.new_id();
self.enums.insert(id, v);
}
Decl::Func(v) => {
let id = self.new_id();
self.funcs.insert(id, v);
}
_ => {}
}
}
println!("self: {:?}", self);
}
}

1
src/hir.rs Normal file
View file

@ -0,0 +1 @@

13
src/main.rs Normal file
View file

@ -0,0 +1,13 @@
mod ast;
mod hir;
fn main() {
let ast = vec![
ast::Decl::Enum(ast::Enum { }),
];
let mut tc = ast::TypeChecker::new();
tc.process(&ast);
println!("Hello, world!");
}