From 114ec834da3b3b26835deaea08062f7792d00de4 Mon Sep 17 00:00:00 2001 From: Michael Zhang Date: Sat, 9 Jan 2021 11:28:05 -0600 Subject: [PATCH] initial --- .gitignore | 1 + Cargo.lock | 5 ++++ Cargo.toml | 9 ++++++ src/ast.rs | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++ src/hir.rs | 1 + src/main.rs | 13 +++++++++ 6 files changed, 109 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 src/ast.rs create mode 100644 src/hir.rs create mode 100644 src/main.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..8c5ed02 --- /dev/null +++ b/Cargo.lock @@ -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" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..319f87a --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "gust" +version = "0.1.0" +authors = ["Michael Zhang "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/src/ast.rs b/src/ast.rs new file mode 100644 index 0000000..7e07a2c --- /dev/null +++ b/src/ast.rs @@ -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, + funcs: HashMap, +} + +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); + } +} diff --git a/src/hir.rs b/src/hir.rs new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/src/hir.rs @@ -0,0 +1 @@ + diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..772c83f --- /dev/null +++ b/src/main.rs @@ -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!"); +}